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/ChangeLog b/ChangeLog
index f93cc73..d6c1ef3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Oct 31 18:50:08 CET 2001 Daniel Veillard <daniel@veillard.com>
+
+ * 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.
+
Tue Oct 30 18:38:53 CET 2001 Daniel Veillard <daniel@veillard.com>
* catalog.c: Justin Fletcher pointed out that xmlParseXMLCatalog
diff --git a/Makefile.am b/Makefile.am
index 98aea6e..dd4d960 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -443,7 +443,7 @@
@echo "##"
@echo "## Threaded regression tests"
@echo "##"
- testThreads
+ $(top_builddir)/testThreads
SAXtests : testSAX
@(echo > .memdump)
diff --git a/include/libxml/parser.h b/include/libxml/parser.h
index 21244da..d86f887 100644
--- a/include/libxml/parser.h
+++ b/include/libxml/parser.h
@@ -11,8 +11,9 @@
#include <libxml/tree.h>
#include <libxml/valid.h>
-#include <libxml/xmlIO.h>
#include <libxml/entities.h>
+#include <libxml/encoding.h>
+#include <libxml/xmlIO.h>
#ifdef __cplusplus
extern "C" {
@@ -38,8 +39,6 @@
typedef void (* xmlParserInputDeallocate)(xmlChar *);
-typedef struct _xmlParserInput xmlParserInput;
-typedef xmlParserInput *xmlParserInputPtr;
struct _xmlParserInput {
/* Input buffer */
xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */
@@ -141,8 +140,6 @@
* takes as the only argument the parser context pointer, so migrating
* to a state based parser for progressive parsing shouldn't be too hard.
*/
-typedef struct _xmlParserCtxt xmlParserCtxt;
-typedef xmlParserCtxt *xmlParserCtxtPtr;
struct _xmlParserCtxt {
struct _xmlSAXHandler *sax; /* The SAX handler */
void *userData; /* For SAX interface only, used by DOM build */
diff --git a/include/libxml/tree.h b/include/libxml/tree.h
index b2e466b..6195c71 100644
--- a/include/libxml/tree.h
+++ b/include/libxml/tree.h
@@ -25,6 +25,20 @@
extern "C" {
#endif
+/*
+ * Some of the basic types pointer to structures:
+ */
+/* xmlIO.h */
+typedef struct _xmlParserInputBuffer xmlParserInputBuffer;
+typedef xmlParserInputBuffer *xmlParserInputBufferPtr;
+
+/* parser.h */
+typedef struct _xmlParserInput xmlParserInput;
+typedef xmlParserInput *xmlParserInputPtr;
+
+typedef struct _xmlParserCtxt xmlParserCtxt;
+typedef xmlParserCtxt *xmlParserCtxtPtr;
+
#define BASE_BUFFER_SIZE 4000
/**
diff --git a/include/libxml/xmlIO.h b/include/libxml/xmlIO.h
index f99c2c5..7fc43e0 100644
--- a/include/libxml/xmlIO.h
+++ b/include/libxml/xmlIO.h
@@ -35,8 +35,6 @@
typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
typedef int (*xmlInputCloseCallback) (void * context);
-typedef struct _xmlParserInputBuffer xmlParserInputBuffer;
-typedef xmlParserInputBuffer *xmlParserInputBufferPtr;
struct _xmlParserInputBuffer {
void* context;
xmlInputReadCallback readcallback;
@@ -189,6 +187,13 @@
void htmlDocContentDumpOutput(xmlOutputBufferPtr buf,
xmlDocPtr cur,
const char *encoding);
+/*
+ * A predefined entity loader disabling network accesses
+ */
+xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL,
+ const char *ID,
+ xmlParserCtxtPtr ctxt);
+
#ifdef __cplusplus
}
#endif
diff --git a/threads.c b/threads.c
index 4f1b0b8..cde26f4 100644
--- a/threads.c
+++ b/threads.c
@@ -248,6 +248,7 @@
* *
************************************************************************/
+#ifdef LIBXML_THREAD_ENABLED
/**
* xmlFreeGlobalState:
* @state: a thread global state
@@ -283,6 +284,7 @@
xmlInitializeGlobalState(gs);
return (gs);
}
+#endif /* LIBXML_THREAD_ENABLED */
/**
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);
+}
+