mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-29 11:41:22 +03:00
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
This commit is contained in:
@ -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>
|
Tue Oct 30 18:38:53 CET 2001 Daniel Veillard <daniel@veillard.com>
|
||||||
|
|
||||||
* catalog.c: Justin Fletcher pointed out that xmlParseXMLCatalog
|
* catalog.c: Justin Fletcher pointed out that xmlParseXMLCatalog
|
||||||
|
@ -443,7 +443,7 @@ Threadtests : testThreads
|
|||||||
@echo "##"
|
@echo "##"
|
||||||
@echo "## Threaded regression tests"
|
@echo "## Threaded regression tests"
|
||||||
@echo "##"
|
@echo "##"
|
||||||
testThreads
|
$(top_builddir)/testThreads
|
||||||
|
|
||||||
SAXtests : testSAX
|
SAXtests : testSAX
|
||||||
@(echo > .memdump)
|
@(echo > .memdump)
|
||||||
|
@ -11,8 +11,9 @@
|
|||||||
|
|
||||||
#include <libxml/tree.h>
|
#include <libxml/tree.h>
|
||||||
#include <libxml/valid.h>
|
#include <libxml/valid.h>
|
||||||
#include <libxml/xmlIO.h>
|
|
||||||
#include <libxml/entities.h>
|
#include <libxml/entities.h>
|
||||||
|
#include <libxml/encoding.h>
|
||||||
|
#include <libxml/xmlIO.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
@ -38,8 +39,6 @@ extern "C" {
|
|||||||
|
|
||||||
typedef void (* xmlParserInputDeallocate)(xmlChar *);
|
typedef void (* xmlParserInputDeallocate)(xmlChar *);
|
||||||
|
|
||||||
typedef struct _xmlParserInput xmlParserInput;
|
|
||||||
typedef xmlParserInput *xmlParserInputPtr;
|
|
||||||
struct _xmlParserInput {
|
struct _xmlParserInput {
|
||||||
/* Input buffer */
|
/* Input buffer */
|
||||||
xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */
|
xmlParserInputBufferPtr buf; /* UTF-8 encoded buffer */
|
||||||
@ -141,8 +140,6 @@ typedef enum {
|
|||||||
* takes as the only argument the parser context pointer, so migrating
|
* takes as the only argument the parser context pointer, so migrating
|
||||||
* to a state based parser for progressive parsing shouldn't be too hard.
|
* to a state based parser for progressive parsing shouldn't be too hard.
|
||||||
*/
|
*/
|
||||||
typedef struct _xmlParserCtxt xmlParserCtxt;
|
|
||||||
typedef xmlParserCtxt *xmlParserCtxtPtr;
|
|
||||||
struct _xmlParserCtxt {
|
struct _xmlParserCtxt {
|
||||||
struct _xmlSAXHandler *sax; /* The SAX handler */
|
struct _xmlSAXHandler *sax; /* The SAX handler */
|
||||||
void *userData; /* For SAX interface only, used by DOM build */
|
void *userData; /* For SAX interface only, used by DOM build */
|
||||||
|
@ -25,6 +25,20 @@
|
|||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
#define BASE_BUFFER_SIZE 4000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,8 +35,6 @@ typedef void * (*xmlInputOpenCallback) (char const *filename);
|
|||||||
typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
|
typedef int (*xmlInputReadCallback) (void * context, char * buffer, int len);
|
||||||
typedef int (*xmlInputCloseCallback) (void * context);
|
typedef int (*xmlInputCloseCallback) (void * context);
|
||||||
|
|
||||||
typedef struct _xmlParserInputBuffer xmlParserInputBuffer;
|
|
||||||
typedef xmlParserInputBuffer *xmlParserInputBufferPtr;
|
|
||||||
struct _xmlParserInputBuffer {
|
struct _xmlParserInputBuffer {
|
||||||
void* context;
|
void* context;
|
||||||
xmlInputReadCallback readcallback;
|
xmlInputReadCallback readcallback;
|
||||||
@ -189,6 +187,13 @@ void xmlNodeDumpOutput (xmlOutputBufferPtr buf,
|
|||||||
void htmlDocContentDumpOutput(xmlOutputBufferPtr buf,
|
void htmlDocContentDumpOutput(xmlOutputBufferPtr buf,
|
||||||
xmlDocPtr cur,
|
xmlDocPtr cur,
|
||||||
const char *encoding);
|
const char *encoding);
|
||||||
|
/*
|
||||||
|
* A predefined entity loader disabling network accesses
|
||||||
|
*/
|
||||||
|
xmlParserInputPtr xmlNoNetExternalEntityLoader(const char *URL,
|
||||||
|
const char *ID,
|
||||||
|
xmlParserCtxtPtr ctxt);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -248,6 +248,7 @@ xmlRMutexUnlock(xmlRMutexPtr tok)
|
|||||||
* *
|
* *
|
||||||
************************************************************************/
|
************************************************************************/
|
||||||
|
|
||||||
|
#ifdef LIBXML_THREAD_ENABLED
|
||||||
/**
|
/**
|
||||||
* xmlFreeGlobalState:
|
* xmlFreeGlobalState:
|
||||||
* @state: a thread global state
|
* @state: a thread global state
|
||||||
@ -283,6 +284,7 @@ xmlNewGlobalState(void)
|
|||||||
xmlInitializeGlobalState(gs);
|
xmlInitializeGlobalState(gs);
|
||||||
return (gs);
|
return (gs);
|
||||||
}
|
}
|
||||||
|
#endif /* LIBXML_THREAD_ENABLED */
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
131
xmlIO.c
131
xmlIO.c
@ -2596,3 +2596,134 @@ xmlLoadExternalEntity(const char *URL, const char *ID,
|
|||||||
return(xmlCurrentExternalEntityLoader(URL, ID, ctxt));
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user