aboutsummaryrefslogtreecommitdiffstats
path: root/xmlIO.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2006-09-21 08:36:38 +0000
committerDaniel Veillard <veillard@src.gnome.org>2006-09-21 08:36:38 +0000
commitad4e2963a3087e65c46407e1fa43dbc941ea0145 (patch)
tree56520cef835705b8a5d2ec9a6fb56f1707d640ca /xmlIO.c
parent34c647cfae90c70005fd133f3a431e52c55b27f6 (diff)
downloadandroid_external_libxml2-ad4e2963a3087e65c46407e1fa43dbc941ea0145.tar.gz
android_external_libxml2-ad4e2963a3087e65c46407e1fa43dbc941ea0145.tar.bz2
android_external_libxml2-ad4e2963a3087e65c46407e1fa43dbc941ea0145.zip
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
Diffstat (limited to 'xmlIO.c')
-rw-r--r--xmlIO.c195
1 files changed, 82 insertions, 113 deletions
diff --git a/xmlIO.c b/xmlIO.c
index ca5481cd..89692f2e 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -3616,6 +3616,84 @@ static int xmlNoNetExists(const char *URL) {
return xmlCheckFilename(path);
}
+#ifdef LIBXML_CATALOG_ENABLED
+
+/**
+ * xmlResolveResourceFromCatalog:
+ * @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
+ *
+ * Resolves the URL and ID against the appropriate catalog.
+ * This function is used by xmlDefaultExternalEntityLoader and
+ * xmlNoNetExternalEntityLoader.
+ *
+ * Returns a new allocated URL, or NULL.
+ */
+xmlChar *
+xmlResolveResourceFromCatalog(const char *URL, const char *ID,
+ xmlParserCtxtPtr ctxt) {
+ xmlChar *resource = NULL;
+ 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) && (!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;
+ }
+ }
+ }
+
+ return resource;
+}
+
+#endif
+
/**
* xmlDefaultExternalEntityLoader:
* @URL: the URL for the entity to load
@@ -3633,15 +3711,10 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
xmlParserInputPtr ret = NULL;
xmlChar *resource = NULL;
-#ifdef LIBXML_CATALOG_ENABLED
- 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;
@@ -3650,60 +3723,8 @@ xmlDefaultExternalEntityLoader(const char *URL, const char *ID,
ctxt->options = options;
return(ret);
}
-
- /*
- * 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;
- }
- }
- }
+#ifdef LIBXML_CATALOG_ENABLED
+ resource = xmlResolveResourceFromCatalog(URL, ID, ctxt);
#endif
if (resource == NULL)
@@ -3802,61 +3823,9 @@ xmlNoNetExternalEntityLoader(const char *URL, const char *ID,
xmlChar *resource = NULL;
#ifdef LIBXML_CATALOG_ENABLED
- 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) && (!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;
- }
- }
- }
+ resource = xmlResolveResourceFromCatalog(URL, ID, ctxt);
#endif
+
if (resource == NULL)
resource = (xmlChar *) URL;