Skip to content
Snippets Groups Projects
Commit 7c7e2a21c9de authored by Daniel Veillard's avatar Daniel Veillard
Browse files

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
parent 436ff03b3fab
No related branches found
No related tags found
No related merge requests found
Tue Oct 15 12:45:42 CEST 2002 Daniel Veillard <daniel@veillard.com>
* xsltproc/xsltproc.c: added a --path option to provide the
enhancement requested by #79638, first cur at it, untested
yet.
Tue Oct 15 13:02:40 CEST 2002 Daniel Veillard <daniel@veillard.com>
* libxslt/xslt.c: seems the media-type attribute wasn't
......
......@@ -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,8 +105,9 @@
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;
......@@ -107,10 +109,12 @@
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;
/*
......@@ -112,8 +116,69 @@
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 @@
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 @@
xmlLineNumbersDefault(1);
sec = xsltNewSecurityPrefs();
xsltSetDefaultSecurityPrefs(sec);
defaultEntityLoader = xmlGetExternalEntityLoader();
xmlSetExternalEntityLoader(xsltprocExternalEntityLoader);
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-"))
......@@ -507,7 +575,7 @@
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 @@
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 @@
(!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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment