mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-10-24 13:33:01 +03:00
applied patch from Michael Day doing some refactoring for the catalog
* xmlIO.c: applied patch from Michael Day doing some refactoring for the catalog entity loaders. Daniel
This commit is contained in:
@@ -1,3 +1,8 @@
|
|||||||
|
Thu Sep 21 10:36:11 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
|
* xmlIO.c: applied patch from Michael Day doing some refactoring
|
||||||
|
for the catalog entity loaders.
|
||||||
|
|
||||||
Thu Sep 21 08:53:06 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
Thu Sep 21 08:53:06 CEST 2006 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* HTMLparser.c include/libxml/HTMLparser.h: exports htmlNewParserCtxt()
|
* HTMLparser.c include/libxml/HTMLparser.h: exports htmlNewParserCtxt()
|
||||||
|
|||||||
139
xmlIO.c
139
xmlIO.c
@@ -3616,40 +3616,25 @@ static int xmlNoNetExists(const char *URL) {
|
|||||||
return xmlCheckFilename(path);
|
return xmlCheckFilename(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* xmlDefaultExternalEntityLoader:
|
* xmlResolveResourceFromCatalog:
|
||||||
* @URL: the URL for the entity to load
|
* @URL: the URL for the entity to load
|
||||||
* @ID: the System ID for the entity to load
|
* @ID: the System ID for the entity to load
|
||||||
* @ctxt: the context in which the entity is called or NULL
|
* @ctxt: the context in which the entity is called or NULL
|
||||||
*
|
*
|
||||||
* By default we don't load external entitites, yet.
|
* Resolves the URL and ID against the appropriate catalog.
|
||||||
|
* This function is used by xmlDefaultExternalEntityLoader and
|
||||||
|
* xmlNoNetExternalEntityLoader.
|
||||||
*
|
*
|
||||||
* Returns a new allocated xmlParserInputPtr, or NULL.
|
* Returns a new allocated URL, or NULL.
|
||||||
*/
|
*/
|
||||||
static xmlParserInputPtr
|
xmlChar *
|
||||||
xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
|
xmlResolveResourceFromCatalog(const char *URL, const char *ID,
|
||||||
xmlParserCtxtPtr ctxt)
|
xmlParserCtxtPtr ctxt) {
|
||||||
{
|
|
||||||
xmlParserInputPtr ret = NULL;
|
|
||||||
xmlChar *resource = NULL;
|
xmlChar *resource = NULL;
|
||||||
|
|
||||||
#ifdef LIBXML_CATALOG_ENABLED
|
|
||||||
xmlCatalogAllow pref;
|
xmlCatalogAllow pref;
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef DEBUG_EXTERNAL_ENTITIES
|
|
||||||
xmlGenericError(xmlGenericErrorContext,
|
|
||||||
"xmlDefaultExternalEntityLoader(%s, xxx)\n", URL);
|
|
||||||
#endif
|
|
||||||
#ifdef LIBXML_CATALOG_ENABLED
|
|
||||||
if ((ctxt != NULL) && (ctxt->options & XML_PARSE_NONET)) {
|
|
||||||
int options = ctxt->options;
|
|
||||||
|
|
||||||
ctxt->options -= XML_PARSE_NONET;
|
|
||||||
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
|
||||||
ctxt->options = options;
|
|
||||||
return(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the resource doesn't exists as a file,
|
* If the resource doesn't exists as a file,
|
||||||
@@ -3665,8 +3650,8 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
|
|||||||
((pref == XML_CATA_ALLOW_ALL) ||
|
((pref == XML_CATA_ALLOW_ALL) ||
|
||||||
(pref == XML_CATA_ALLOW_DOCUMENT))) {
|
(pref == XML_CATA_ALLOW_DOCUMENT))) {
|
||||||
resource = xmlCatalogLocalResolve(ctxt->catalogs,
|
resource = xmlCatalogLocalResolve(ctxt->catalogs,
|
||||||
(const xmlChar *) ID,
|
(const xmlChar *)ID,
|
||||||
(const xmlChar *) URL);
|
(const xmlChar *)URL);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Try a global lookup
|
* Try a global lookup
|
||||||
@@ -3674,8 +3659,8 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
|
|||||||
if ((resource == NULL) &&
|
if ((resource == NULL) &&
|
||||||
((pref == XML_CATA_ALLOW_ALL) ||
|
((pref == XML_CATA_ALLOW_ALL) ||
|
||||||
(pref == XML_CATA_ALLOW_GLOBAL))) {
|
(pref == XML_CATA_ALLOW_GLOBAL))) {
|
||||||
resource = xmlCatalogResolve((const xmlChar *) ID,
|
resource = xmlCatalogResolve((const xmlChar *)ID,
|
||||||
(const xmlChar *) URL);
|
(const xmlChar *)URL);
|
||||||
}
|
}
|
||||||
if ((resource == NULL) && (URL != NULL))
|
if ((resource == NULL) && (URL != NULL))
|
||||||
resource = xmlStrdup((const xmlChar *) URL);
|
resource = xmlStrdup((const xmlChar *) URL);
|
||||||
@@ -3683,8 +3668,7 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
|
|||||||
/*
|
/*
|
||||||
* TODO: do an URI lookup on the reference
|
* TODO: do an URI lookup on the reference
|
||||||
*/
|
*/
|
||||||
if ((resource != NULL)
|
if ((resource != NULL) && (!xmlNoNetExists((const char *)resource))) {
|
||||||
&& (!xmlNoNetExists((const char *) resource))) {
|
|
||||||
xmlChar *tmp = NULL;
|
xmlChar *tmp = NULL;
|
||||||
|
|
||||||
if ((ctxt != NULL) && (ctxt->catalogs != NULL) &&
|
if ((ctxt != NULL) && (ctxt->catalogs != NULL) &&
|
||||||
@@ -3704,6 +3688,43 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return resource;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xmlDefaultExternalEntityLoader:
|
||||||
|
* @URL: the URL for the entity to load
|
||||||
|
* @ID: the System ID for the entity to load
|
||||||
|
* @ctxt: the context in which the entity is called or NULL
|
||||||
|
*
|
||||||
|
* By default we don't load external entitites, yet.
|
||||||
|
*
|
||||||
|
* Returns a new allocated xmlParserInputPtr, or NULL.
|
||||||
|
*/
|
||||||
|
static xmlParserInputPtr
|
||||||
|
xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
|
||||||
|
xmlParserCtxtPtr ctxt)
|
||||||
|
{
|
||||||
|
xmlParserInputPtr ret = NULL;
|
||||||
|
xmlChar *resource = NULL;
|
||||||
|
|
||||||
|
#ifdef DEBUG_EXTERNAL_ENTITIES
|
||||||
|
xmlGenericError(xmlGenericErrorContext,
|
||||||
|
"xmlDefaultExternalEntityLoader(%s, xxx)\n", URL);
|
||||||
|
#endif
|
||||||
|
if ((ctxt != NULL) && (ctxt->options & XML_PARSE_NONET)) {
|
||||||
|
int options = ctxt->options;
|
||||||
|
|
||||||
|
ctxt->options -= XML_PARSE_NONET;
|
||||||
|
ret = xmlNoNetExternalEntityLoader(URL, ID, ctxt);
|
||||||
|
ctxt->options = options;
|
||||||
|
return(ret);
|
||||||
|
}
|
||||||
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
|
resource = xmlResolveResourceFromCatalog(URL, ID, ctxt);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
@@ -3802,61 +3823,9 @@ xmlNoNetExternalEntityLoader(const char *URL, const char *ID,
|
|||||||
xmlChar *resource = NULL;
|
xmlChar *resource = NULL;
|
||||||
|
|
||||||
#ifdef LIBXML_CATALOG_ENABLED
|
#ifdef LIBXML_CATALOG_ENABLED
|
||||||
xmlCatalogAllow pref;
|
resource = xmlResolveResourceFromCatalog(URL, ID, ctxt);
|
||||||
|
|
||||||
/*
|
|
||||||
* 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) && (!xmlNoNetExists(URL))) {
|
|
||||||
/*
|
|
||||||
* Do a local lookup
|
|
||||||
*/
|
|
||||||
if ((ctxt != NULL) && (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) && (!xmlNoNetExists((const char *)resource))) {
|
|
||||||
xmlChar *tmp = NULL;
|
|
||||||
|
|
||||||
if ((ctxt != NULL) && (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
|
#endif
|
||||||
|
|
||||||
if (resource == NULL)
|
if (resource == NULL)
|
||||||
resource = (xmlChar *) URL;
|
resource = (xmlChar *) URL;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user