From 0335a846ad62ce5b2394ea9c429c271391bd9ca7 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 2 Jun 2004 16:18:40 +0000 Subject: [PATCH] applied patch from Rob Richards for custom I/O BufferCreateFilenane fixes * globals.c xmlIO.c include/libxml/globals.h: applied patch from Rob Richards for custom I/O BufferCreateFilenane fixes bug #143366 Daniel --- ChangeLog | 6 +++ globals.c | 90 ++++++++++++++++++++++++++++++++++++++++ include/libxml/globals.h | 30 ++++++++++++++ xmlIO.c | 72 ++++++++++++++++++++------------ 4 files changed, 171 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 032897cb..00ebf9b0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Jun 2 18:15:51 CEST 2004 Daniel Veillard + + * globals.c xmlIO.c include/libxml/globals.h: applied patch from + Rob Richards for custom I/O BufferCreateFilenane fixes bug + #143366 + Wed Jun 02 16:25:32 HKT 2004 William Brack * xpath.c: fixed problem with predicate evaluation on an diff --git a/globals.c b/globals.c index f1aa1506..ffab8a7e 100644 --- a/globals.c +++ b/globals.c @@ -169,6 +169,8 @@ xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup; #undef xmlMemStrdup #undef xmlRealloc +#undef xmlParserInputBufferCreateFilenameValue +#undef xmlOutputBufferCreateFilenameValue /** * xmlParserVersion: * @@ -282,6 +284,12 @@ static xmlRegisterNodeFunc xmlRegisterNodeDefaultValueThrDef = NULL; xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL; static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL; +xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue = NULL; +static xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValueThrDef = NULL; + +xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue = NULL; +static xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValueThrDef = NULL; + /* * Error handling */ @@ -545,6 +553,9 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs) gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef; gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef; gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef; + + gs->xmlParserInputBufferCreateFilenameValue = xmlParserInputBufferCreateFilenameValueThrDef; + gs->xmlOutputBufferCreateFilenameValue = xmlOutputBufferCreateFilenameValueThrDef; memset(&gs->xmlLastError, 0, sizeof(xmlError)); xmlMutexUnlock(xmlThrDefMutex); @@ -639,6 +650,67 @@ xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func) return(old); } +/** + * xmlParserInputBufferCreateFilename: + * @func: function pointer to the new ParserInputBufferCreateFilenameFunc + * + * Registers a callback for URI input file handling + * + * Returns the old value of the registration function + */ +xmlParserInputBufferCreateFilenameFunc +xmlParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func) +{ + xmlParserInputBufferCreateFilenameFunc old = xmlParserInputBufferCreateFilenameValue; + + xmlParserInputBufferCreateFilenameValue = func; + return(old); +} + +xmlParserInputBufferCreateFilenameFunc +xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func) +{ + xmlParserInputBufferCreateFilenameFunc old; + + xmlMutexLock(xmlThrDefMutex); + old = xmlParserInputBufferCreateFilenameValueThrDef; + + xmlParserInputBufferCreateFilenameValueThrDef = func; + xmlMutexUnlock(xmlThrDefMutex); + + return(old); +} + +/** + * xmlOutputBufferCreateFilename: + * @func: function pointer to the new OutputBufferCreateFilenameFunc + * + * Registers a callback for URI output file handling + * + * Returns the old value of the registration function + */ +xmlOutputBufferCreateFilenameFunc +xmlOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func) +{ + xmlOutputBufferCreateFilenameFunc old = xmlOutputBufferCreateFilenameValue; + + xmlOutputBufferCreateFilenameValue = func; + return(old); +} + +xmlOutputBufferCreateFilenameFunc +xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func) +{ + xmlOutputBufferCreateFilenameFunc old; + + xmlMutexLock(xmlThrDefMutex); + old = xmlOutputBufferCreateFilenameValueThrDef; + + xmlOutputBufferCreateFilenameValueThrDef = func; + xmlMutexUnlock(xmlThrDefMutex); + + return(old); +} #ifdef LIBXML_DOCB_ENABLED #undef docbDefaultSAXHandler @@ -981,3 +1053,21 @@ __xmlDeregisterNodeDefaultValue(void) { else return (&xmlGetGlobalState()->xmlDeregisterNodeDefaultValue); } + +#undef xmlParserInputBufferCreateFilenameValue +xmlParserInputBufferCreateFilenameFunc * +__xmlParserInputBufferCreateFilenameValue(void) { + if (IS_MAIN_THREAD) + return (&xmlParserInputBufferCreateFilenameValue); + else + return (&xmlGetGlobalState()->xmlParserInputBufferCreateFilenameValue); +} + +#undef xmlOutputBufferCreateFilenameValue +xmlOutputBufferCreateFilenameFunc * +__xmlOutputBufferCreateFilenameValue(void) { + if (IS_MAIN_THREAD) + return (&xmlOutputBufferCreateFilenameValue); + else + return (&xmlGetGlobalState()->xmlOutputBufferCreateFilenameValue); +} \ No newline at end of file diff --git a/include/libxml/globals.h b/include/libxml/globals.h index 1be2d1fe..ebe16277 100644 --- a/include/libxml/globals.h +++ b/include/libxml/globals.h @@ -63,10 +63,15 @@ XMLPUBFUN void XMLCALL xmlCleanupGlobals(void); #undef xmlRegisterNodeDefaultValue #undef xmlDeregisterNodeDefaultValue #undef xmlLastError +#undef xmlParserInputBufferCreateFilenameValue +#undef xmlOutputBufferCreateFilenameValue typedef void (*xmlRegisterNodeFunc) (xmlNodePtr node); typedef void (*xmlDeregisterNodeFunc) (xmlNodePtr node); +typedef xmlParserInputBufferPtr (*xmlParserInputBufferCreateFilenameFunc) (const char *URI, xmlCharEncoding enc); +typedef xmlOutputBufferPtr (*xmlOutputBufferCreateFilenameFunc) (const char *URI, xmlCharEncodingHandlerPtr encoder, int compression); + typedef struct _xmlGlobalState xmlGlobalState; typedef xmlGlobalState *xmlGlobalStatePtr; struct _xmlGlobalState @@ -110,6 +115,9 @@ struct _xmlGlobalState xmlMallocFunc xmlMallocAtomic; xmlError xmlLastError; + + xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue; + xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue; }; #ifdef __cplusplus @@ -131,6 +139,12 @@ XMLPUBFUN xmlRegisterNodeFunc XMLCALL xmlThrDefRegisterNodeDefault(xmlRegisterNo XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func); XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func); +XMLPUBFUN xmlParserInputBufferCreateFilenameFunc XMLCALL xmlParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func); +XMLPUBFUN xmlParserInputBufferCreateFilenameFunc XMLCALL xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func); + +XMLPUBFUN xmlOutputBufferCreateFilenameFunc XMLCALL xmlOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func); +XMLPUBFUN xmlOutputBufferCreateFilenameFunc XMLCALL xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func); + /** DOC_DISABLE */ /* * In general the memory allocation entry points are not kept @@ -415,6 +429,22 @@ XMLPUBFUN xmlDeregisterNodeFunc * XMLCALL __xmlDeregisterNodeDefaultValue(void); XMLPUBVAR xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue; #endif +XMLPUBFUN xmlParserInputBufferCreateFilenameFunc * XMLCALL __xmlParserInputBufferCreateFilenameValue(void); +#ifdef LIBXML_THREAD_ENABLED +#define xmlParserInputBufferCreateFilenameValue \ +(*(__xmlParserInputBufferCreateFilenameValue())) +#else +XMLPUBVAR xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue; +#endif + +XMLPUBFUN xmlOutputBufferCreateFilenameFunc * XMLCALL __xmlOutputBufferCreateFilenameValue(void); +#ifdef LIBXML_THREAD_ENABLED +#define xmlOutputBufferCreateFilenameValue \ +(*(__xmlOutputBufferCreateFilenameValue())) +#else +XMLPUBVAR xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue; +#endif + #ifdef __cplusplus } #endif diff --git a/xmlIO.c b/xmlIO.c index 2f9874f4..6fddcfbf 100644 --- a/xmlIO.c +++ b/xmlIO.c @@ -2125,21 +2125,8 @@ xmlOutputBufferClose(xmlOutputBufferPtr out) } #endif /* LIBXML_OUTPUT_ENABLED */ -/** - * xmlParserInputBufferCreateFilename: - * @URI: a C string containing the URI or filename - * @enc: the charset encoding if known - * - * Create a buffered parser input for the progressive parsing of a file - * If filename is "-' then we use stdin as the input. - * Automatic support for ZLIB/Compress compressed document is provided - * by default if found at compile-time. - * Do an encoding check if enc == XML_CHAR_ENCODING_NONE - * - * Returns the new parser input or NULL - */ -xmlParserInputBufferPtr -xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { +static xmlParserInputBufferPtr +__xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { xmlParserInputBufferPtr ret; int i = 0; void *context = NULL; @@ -2196,26 +2183,32 @@ xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { return(ret); } -#ifdef LIBXML_OUTPUT_ENABLED /** - * xmlOutputBufferCreateFilename: + * xmlParserInputBufferCreateFilename: * @URI: a C string containing the URI or filename - * @encoder: the encoding converter or NULL - * @compression: the compression ration (0 none, 9 max). + * @enc: the charset encoding if known * - * Create a buffered output for the progressive saving of a file - * If filename is "-' then we use stdout as the output. + * Create a buffered parser input for the progressive parsing of a file + * If filename is "-' then we use stdin as the input. * Automatic support for ZLIB/Compress compressed document is provided * by default if found at compile-time. - * TODO: currently if compression is set, the library only support - * writing to a local file. + * Do an encoding check if enc == XML_CHAR_ENCODING_NONE * - * Returns the new output or NULL + * Returns the new parser input or NULL */ -xmlOutputBufferPtr -xmlOutputBufferCreateFilename(const char *URI, +xmlParserInputBufferPtr +xmlParserInputBufferCreateFilename(const char *URI, xmlCharEncoding enc) { + if ((xmlParserInputBufferCreateFilenameValue)) { + return xmlParserInputBufferCreateFilenameValue(URI, enc); + } + return __xmlParserInputBufferCreateFilename(URI, enc); +} + +#ifdef LIBXML_OUTPUT_ENABLED +static xmlOutputBufferPtr +__xmlOutputBufferCreateFilename(const char *URI, xmlCharEncodingHandlerPtr encoder, - int compression ATTRIBUTE_UNUSED) { + int compression ATTRIBUTE_UNUSED) { xmlOutputBufferPtr ret; xmlURIPtr puri; int i = 0; @@ -2329,6 +2322,31 @@ xmlOutputBufferCreateFilename(const char *URI, } return(ret); } + +/** + * xmlOutputBufferCreateFilename: + * @URI: a C string containing the URI or filename + * @encoder: the encoding converter or NULL + * @compression: the compression ration (0 none, 9 max). + * + * Create a buffered output for the progressive saving of a file + * If filename is "-' then we use stdout as the output. + * Automatic support for ZLIB/Compress compressed document is provided + * by default if found at compile-time. + * TODO: currently if compression is set, the library only support + * writing to a local file. + * + * Returns the new output or NULL + */ +xmlOutputBufferPtr +xmlOutputBufferCreateFilename(const char *URI, + xmlCharEncodingHandlerPtr encoder, + int compression ATTRIBUTE_UNUSED) { + if ((xmlOutputBufferCreateFilenameValue)) { + return xmlOutputBufferCreateFilenameValue(URI, encoder, compression); + } + return __xmlOutputBufferCreateFilename(URI, encoder, compression); +} #endif /* LIBXML_OUTPUT_ENABLED */ /**