diff options
author | Daniel Veillard <veillard@src.gnome.org> | 2002-10-15 11:04:51 +0000 |
---|---|---|
committer | Daniel Veillard <veillard@src.gnome.org> | 2002-10-15 11:04:51 +0000 |
commit | 6b5af9ba4ab9f52295c41a7388f531a71998edd1 (patch) | |
tree | 50ecec13dcb81072b8cafec7207a426ec940b2bb /xsltproc/xsltproc.c | |
parent | d02ed1cb1ef7c0c817f717418bb37d67911d9986 (diff) | |
download | libxslt-6b5af9ba4ab9f52295c41a7388f531a71998edd1.tar.gz libxslt-6b5af9ba4ab9f52295c41a7388f531a71998edd1.tar.bz2 libxslt-6b5af9ba4ab9f52295c41a7388f531a71998edd1.zip |
added a --path option to provide the enhancement requested by #79638,
* xsltproc/xsltproc.c: added a --path option to provide the
enhancement requested by #79638, first cur at it, untested yet.
Daniel
Diffstat (limited to 'xsltproc/xsltproc.c')
-rw-r--r-- | xsltproc/xsltproc.c | 78 |
1 files changed, 77 insertions, 1 deletions
diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c index c9580e38..5022f33f 100644 --- a/xsltproc/xsltproc.c +++ b/xsltproc/xsltproc.c @@ -43,6 +43,7 @@ #include <libxml/catalog.h> #endif #include <libxml/parserInternals.h> +#include <libxml/uri.h> #include <libxslt/xslt.h> #include <libxslt/xsltInternals.h> @@ -104,16 +105,80 @@ static int xinclude = 0; static int profile = 0; #define MAX_PARAMETERS 64 +#define MAX_PATHS 64 static const char *params[MAX_PARAMETERS + 1]; static int nbparams = 0; static xmlChar *strparams[MAX_PARAMETERS + 1]; static int nbstrparams = 0; +static xmlChar *paths[MAX_PATHS + 1]; +static int nbpaths = 0; static const char *output = NULL; static int errorno = 0; static const char *writesubtree = NULL; /* + * Entity loading control and customization. + */ +static +void parsePath(const xmlChar *path) { + const xmlChar *cur; + + if (path == NULL) + return; + while (*path != 0) { + if (nbpaths >= MAX_PATHS) { + fprintf(stderr, "MAX_PATHS reached: too many paths\n"); + return; + } + cur = path; + while ((*cur == ' ') || (*cur == ':')) + cur++; + path = cur; + while ((*cur != 0) && (*cur != ' ') && (*cur != ':')) + cur++; + if (cur != path) { + paths[nbpaths] = xmlStrndup(path, cur - path); + if (paths[nbpaths] != NULL) + nbpaths++; + path = cur; + } + } +} + +xmlExternalEntityLoader defaultEntityLoader = NULL; + +static xmlParserInputPtr +xsltprocExternalEntityLoader(const char *URL, const char *ID, + xmlParserCtxtPtr context) { + xmlParserInputPtr ret; + xmlURIPtr uri; + + int i; + + if (defaultEntityLoader != NULL) { + ret = defaultEntityLoader(URL, ID, context); + if (ret != NULL) + return(ret); + } + for (i = 0;i < nbpaths;i++) { + xmlChar *newURL; + int len; + + len = xmlStrlen(paths[i]) + xmlStrlen(URL) + 5; + newURL = xmlMalloc(len); + if (newURL != NULL) { + snprintf(newURL, len, "%s/%s", paths[i], URL); + ret = defaultEntityLoader((const char *)newURL, ID, context); + xmlFree(newURL); + if (ret != NULL) + return(ret); + } + } + return(NULL); +} + +/* * Internal timing routines to remove the necessity to have unix-specific * function calls */ @@ -404,6 +469,7 @@ static void usage(const char *name) { printf("\t string values must be quoted like \"'string'\"\n or"); printf("\t use stringparam to avoid it\n"); printf("\t--stringparam name value : pass a (parameter, UTF8 string value) pair\n"); + printf("\t--path 'paths': provide a set of paths for resources\n"); printf("\t--nonet : refuse to fetch DTDs or entities over network\n"); printf("\t--nowrite : refuse to write to any file or resource\n"); printf("\t--nomkdir : refuse to create directories\n"); @@ -441,6 +507,8 @@ main(int argc, char **argv) xmlLineNumbersDefault(1); sec = xsltNewSecurityPrefs(); xsltSetDefaultSecurityPrefs(sec); + defaultEntityLoader = xmlGetExternalEntityLoader(); + xmlSetExternalEntityLoader(xsltprocExternalEntityLoader); for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-")) @@ -507,7 +575,7 @@ main(int argc, char **argv) profile++; } else if ((!strcmp(argv[i], "-nonet")) || (!strcmp(argv[i], "--nonet"))) { - xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader); + defaultEntityLoader = xmlNoNetExternalEntityLoader; } else if ((!strcmp(argv[i], "-nowrite")) || (!strcmp(argv[i], "--nowrite"))) { xsltSetSecurityPrefs(sec, XSLT_SECPREF_WRITE_FILE, @@ -526,6 +594,10 @@ main(int argc, char **argv) writesubtree = argv[i]; xsltSetSecurityPrefs(sec, XSLT_SECPREF_WRITE_FILE, xsltSubtreeCheck); + } else if ((!strcmp(argv[i], "-path")) || + (!strcmp(argv[i], "--path"))) { + i++; + parsePath(BAD_CAST argv[i]); #ifdef LIBXML_CATALOG_ENABLED } else if ((!strcmp(argv[i], "-catalogs")) || (!strcmp(argv[i], "--catalogs"))) { @@ -639,6 +711,10 @@ main(int argc, char **argv) (!strcmp(argv[i], "--writesubtree"))) { i++; continue; + } else if ((!strcmp(argv[i], "-path")) || + (!strcmp(argv[i], "--path"))) { + i++; + continue; } if ((!strcmp(argv[i], "-param")) || (!strcmp(argv[i], "--param"))) { i += 2; |