aboutsummaryrefslogtreecommitdiffstats
path: root/xmlIO.c
diff options
context:
space:
mode:
authorDaniel Veillard <veillard@src.gnome.org>2001-10-31 17:52:43 +0000
committerDaniel Veillard <veillard@src.gnome.org>2001-10-31 17:52:43 +0000
commit8bdb91dd5c6c6c89cd1668ba78b1048239ca6ca6 (patch)
treef81dc34dd3215b900dff0cb78c2f39d35a9c95c1 /xmlIO.c
parent91c0040acee605a18c1b3bb440fbfea7892010f5 (diff)
downloadandroid_external_libxml2-8bdb91dd5c6c6c89cd1668ba78b1048239ca6ca6.tar.gz
android_external_libxml2-8bdb91dd5c6c6c89cd1668ba78b1048239ca6ca6.tar.bz2
android_external_libxml2-8bdb91dd5c6c6c89cd1668ba78b1048239ca6ca6.zip
cleanup cleanup too added xmlNoNetExternalEntityLoader() from xsltproc
* Makefile.am: cleanup * threads.c: cleanup too * xmlIO.c include/libxml/xmlIO.h: added xmlNoNetExternalEntityLoader() from xsltproc * include/libxml/tree.h include/libxml/parser.h: trying to break a dependancy loop. Daniel
Diffstat (limited to 'xmlIO.c')
-rw-r--r--xmlIO.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/xmlIO.c b/xmlIO.c
index ceb9c4f1..929cee0f 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -2596,3 +2596,134 @@ xmlLoadExternalEntity(const char *URL, const char *ID,
return(xmlCurrentExternalEntityLoader(URL, ID, ctxt));
}
+/************************************************************************
+ * *
+ * Disabling Network access *
+ * *
+ ************************************************************************/
+
+#ifdef LIBXML_CATALOG_ENABLED
+static int
+xmlNoNetExists(const char *URL)
+{
+#ifdef HAVE_STAT
+ int ret;
+ struct stat info;
+ const char *path;
+
+ if (URL == NULL)
+ return (0);
+
+ if (!xmlStrncmp(BAD_CAST URL, BAD_CAST "file://localhost", 16))
+ path = &URL[16];
+ else if (!xmlStrncmp(BAD_CAST URL, BAD_CAST "file:///", 8)) {
+#ifdef _WIN32
+ path = &URL[8];
+#else
+ path = &URL[7];
+#endif
+ } else
+ path = URL;
+ ret = stat(path, &info);
+ if (ret == 0)
+ return (1);
+#endif
+ return (0);
+}
+#endif
+
+/**
+ * xmlNoNetExternalEntityLoader:
+ * @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
+ *
+ * A specific entity loader disabling network accesses, though still
+ * allowing local catalog accesses for resolution.
+ *
+ * Returns a new allocated xmlParserInputPtr, or NULL.
+ */
+xmlParserInputPtr
+xmlNoNetExternalEntityLoader(const char *URL, const char *ID,
+ xmlParserCtxtPtr ctxt) {
+ xmlParserInputPtr input = NULL;
+ 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->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->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 *) resource,
+ (const xmlChar *) "http://", 7))) {
+ xmlGenericError(xmlGenericErrorContext,
+ "Attempt to load network entity %s \n", resource);
+
+ if (resource != (xmlChar *) URL)
+ xmlFree(resource);
+ return(NULL);
+ }
+ }
+ input = xmlDefaultExternalEntityLoader((const char *) resource, ID, ctxt);
+ if (resource != (xmlChar *) URL)
+ xmlFree(resource);
+ return(input);
+}
+