From dc8d2805996678d288b9f2a52fe356c088390b59 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Thu, 23 Aug 2001 15:41:05 +0000 Subject: [PATCH] catalog integration, cleanup with the --nonet option closing #59427 * xsltproc/xsltproc.c: catalog integration, cleanup with the --nonet option closing #59427 * libxslt/xslt.c: removed a small memleak when using a stylesheet PI Daniel --- ChangeLog | 7 +++ configure.in | 6 +-- libxslt/xslt.c | 8 +++- libxslt/xsltwin32config.h | 6 +-- xsltproc/xsltproc.c | 112 ++++++++++++++++++++++++++++++++++++++++++---- 5 files changed, 123 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ea8283..a450295 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Thu Aug 23 17:37:40 CEST 2001 Daniel Veillard + + * xsltproc/xsltproc.c: catalog integration, cleanup with + the --nonet option closing #59427 + * libxslt/xslt.c: removed a small memleak when using a + stylesheet PI + Tue Aug 21 13:17:19 CEST 2001 Daniel Veillard * //Makefile.am : fixed an error I propagated to nearly all diff --git a/configure.in b/configure.in index d83c29c..04d1b10 100644 --- a/configure.in +++ b/configure.in @@ -5,12 +5,12 @@ dnl libxslt is the main part of the package dnl LIBXSLT_MAJOR_VERSION=1 LIBXSLT_MINOR_VERSION=0 -LIBXSLT_MICRO_VERSION=2 +LIBXSLT_MICRO_VERSION=3 PACKAGE=libxslt LIBEXSLT_MAJOR_VERSION=0 LIBEXSLT_MINOR_VERSION=3 -LIBEXSLT_MICRO_VERSION=0 -LIBXML_REQUIRED_VERSION=2.4.2 +LIBEXSLT_MICRO_VERSION=1 +LIBXML_REQUIRED_VERSION=2.4.3 LIBXSLT_VERSION=$LIBXSLT_MAJOR_VERSION.$LIBXSLT_MINOR_VERSION.$LIBXSLT_MICRO_VERSION diff --git a/libxslt/xslt.c b/libxslt/xslt.c index 5e0dca8..d1cbae9 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -2119,12 +2119,14 @@ xsltLoadStylesheetPI(xmlDocPtr doc) { } } } else { - xmlChar *URL; + xmlChar *URL, *base; /* * Reference to an external stylesheet */ - URL = xmlBuildURI(href, xmlNodeGetBase(doc, (xmlNodePtr) doc)); + + base = xmlNodeGetBase(doc, (xmlNodePtr) doc); + URL = xmlBuildURI(href, base); if (URL != NULL) { #ifdef WITH_XSLT_DEBUG_PARSING xsltGenericDebug(xsltGenericDebugContext, @@ -2139,6 +2141,8 @@ xsltLoadStylesheetPI(xmlDocPtr doc) { #endif ret = xsltParseStylesheetFile(href); } + if (base != NULL) + xmlFree(base); } xmlFreeURI(URI); xmlFree(href); diff --git a/libxslt/xsltwin32config.h b/libxslt/xsltwin32config.h index 3eab9bf..4252831 100644 --- a/libxslt/xsltwin32config.h +++ b/libxslt/xsltwin32config.h @@ -21,21 +21,21 @@ extern "C" { * * the version string like "1.2.3" */ -#define LIBXSLT_DOTTED_VERSION "1.0.2" +#define LIBXSLT_DOTTED_VERSION "1.0.3" /** * LIBXSLT_VERSION: * * the version number: 1.2.3 value is 1002003 */ -#define LIBXSLT_VERSION 10002 +#define LIBXSLT_VERSION 10003 /** * LIBXSLT_VERSION_STRING: * * the version number string, 1.2.3 value is "1002003" */ -#define LIBXSLT_VERSION_STRING "10002" +#define LIBXSLT_VERSION_STRING "10003" /** * WITH_XSLT_DEBUG: diff --git a/xsltproc/xsltproc.c b/xsltproc/xsltproc.c index 733ddc7..fdfc2a6 100644 --- a/xsltproc/xsltproc.c +++ b/xsltproc/xsltproc.c @@ -14,6 +14,9 @@ #ifdef HAVE_SYS_TIME_H #include #endif +#ifdef HAVE_SYS_STAT_H +#include +#endif #ifdef HAVE_UNISTD_H #include #endif @@ -53,6 +56,16 @@ #include #endif /* WIN32 */ +#ifndef HAVE_STAT +# ifdef HAVE__STAT + /* MS C library seems to define stat and _stat. The definition + * is identical. Still, mapping them to each other causes a warning. */ +# ifndef _MSC_VER +# define stat(x,y) _stat(x,y) +# endif +# define HAVE_STAT +# endif +#endif static int debug = 0; static int repeat = 0; @@ -80,20 +93,99 @@ static const char *output = NULL; static xmlParserInputPtr xsltNoNetExternalEntityLoader(const char *URL, const char *ID, xmlParserCtxtPtr ctxt) { - if (URL != NULL) { - if ((!xmlStrncasecmp((const xmlChar *) URL, + xmlParserInputPtr input = NULL; + xmlChar *resource = NULL; + +#ifdef LIBXML_CATALOG_ENABLED +#ifdef HAVE_STAT + struct stat info; +#endif + xmlCatalogAllow pref; + + /* + * If the resource doesn't exists as a file, + * try to load it from the resource pointed in the catalogs + */ + pref = xmlCatalogGetDefaults(); + + if ((pref != XML_CATA_ALLOW_NONE) +#ifdef HAVE_STAT + && ((URL == NULL) || (stat(URL, &info) < 0)) +#endif + ) { + /* + * Do a local lookup + */ + if ((ctxt->catalogs != NULL) && + ((pref == XML_CATA_ALLOW_ALL) || + (pref == XML_CATA_ALLOW_DOCUMENT))) { + resource = xmlCatalogLocalResolve(ctxt->catalogs, + (const xmlChar *)ID, + (const xmlChar *)URL); + } + /* + * Try a global lookup + */ + if ((resource == NULL) && + ((pref == XML_CATA_ALLOW_ALL) || + (pref == XML_CATA_ALLOW_GLOBAL))) { + resource = xmlCatalogResolve((const xmlChar *)ID, + (const xmlChar *)URL); + } + if ((resource == NULL) && (URL != NULL)) + resource = xmlStrdup((const xmlChar *) URL); + + /* + * TODO: do an URI lookup on the reference + */ + if ((resource != NULL) +#ifdef HAVE_STAT + && (stat((const char *) resource, &info) < 0) +#endif + ) { + xmlChar *tmp = NULL; + + if ((ctxt->catalogs != NULL) && + ((pref == XML_CATA_ALLOW_ALL) || + (pref == XML_CATA_ALLOW_DOCUMENT))) { + tmp = xmlCatalogLocalResolveURI(ctxt->catalogs, resource); + } + if ((tmp == NULL) && + ((pref == XML_CATA_ALLOW_ALL) || + (pref == XML_CATA_ALLOW_GLOBAL))) { + tmp = xmlCatalogResolveURI(resource); + } + + if (tmp != NULL) { + xmlFree(resource); + resource = tmp; + } + } + } +#endif + if (resource == NULL) + resource = (xmlChar *) URL; + + if (resource != NULL) { + if ((!xmlStrncasecmp((const xmlChar *) resource, (const xmlChar *) "ftp://", 6)) || - (!xmlStrncasecmp((const xmlChar *) URL, + (!xmlStrncasecmp((const xmlChar *) resource, (const xmlChar *) "http://", 7))) { - fprintf(stderr, "Attempt to load network entity %s \n", URL); - if (nonet) + fprintf(stderr, "Attempt to load network entity %s \n", resource); + + if (nonet) { + if (resource != (xmlChar *) URL) + xmlFree(resource); return(NULL); + } } } if (defaultLoader != NULL) { - return(defaultLoader(URL, ID, ctxt)); + input = defaultLoader((const char *) resource, ID, ctxt); } - return(NULL); + if (resource != (xmlChar *) URL) + xmlFree(resource); + return(input); } static void @@ -451,7 +543,7 @@ main(int argc, char **argv) /* it is an embedded stylesheet */ xsltProcess(style, cur, argv[i]); xsltFreeStylesheet(cur); - exit(0); + goto done; } cur = xsltParseStylesheetDoc(style); if (cur != NULL) { @@ -460,6 +552,9 @@ main(int argc, char **argv) else xmlIndentTreeOutput = 0; i++; + } else { + xmlFreeDoc(style); + goto done; } } break; @@ -507,6 +602,7 @@ main(int argc, char **argv) } xsltFreeStylesheet(cur); } +done: xsltCleanupGlobals(); xmlCleanupParser(); xmlMemoryDump(); -- 2.7.4