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
diff --git a/xmlIO.c b/xmlIO.c
index ceb9c4f..929cee0 100644
--- a/xmlIO.c
+++ b/xmlIO.c
@@ -2596,3 +2596,134 @@
     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);
+}
+