diff --git a/error.c b/error.c index 9ec02862..8556547d 100644 --- a/error.c +++ b/error.c @@ -132,7 +132,7 @@ xmlSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) { */ void xmlSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { - xmlGenericErrorContext = ctx; + xmlStructuredErrorContext = ctx; xmlStructuredError = handler; } @@ -471,7 +471,7 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, * if user has defined handler, change data ptr to user's choice */ if (schannel != NULL) - data = xmlGenericErrorContext; + data = xmlStructuredErrorContext; } if ((domain == XML_FROM_VALID) && ((channel == xmlParserValidityError) || @@ -593,20 +593,23 @@ __xmlRaiseError(xmlStructuredErrorFunc schannel, /* * Find the callback channel if channel param is NULL */ - if ((ctxt != NULL) && (channel == NULL) && (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { + if ((ctxt != NULL) && (channel == NULL) && + (xmlStructuredError == NULL) && (ctxt->sax != NULL)) { if (level == XML_ERR_WARNING) channel = ctxt->sax->warning; else channel = ctxt->sax->error; data = ctxt->userData; } else if (channel == NULL) { - if ((schannel == NULL) && (xmlStructuredError != NULL)) + if ((schannel == NULL) && (xmlStructuredError != NULL)) { schannel = xmlStructuredError; - else + data = xmlStructuredErrorContext; + } else { channel = xmlGenericError; - if (!data) { - data = xmlGenericErrorContext; - } + if (!data) { + data = xmlGenericErrorContext; + } + } } if (schannel != NULL) { schannel(data, to); diff --git a/global.data b/global.data index 1a8c8a7e..519519a4 100644 --- a/global.data +++ b/global.data @@ -2,11 +2,13 @@ int,oldXMLWDcompatibility,, xmlBufferAllocationScheme,xmlBufferAllocScheme,,1 int,xmlDefaultBufferSize,,1 -xmlSAXHandler,xmlDefaultSAXHandler,, +xmlSAXHandlerV1,xmlDefaultSAXHandler,, xmlSAXLocator,xmlDefaultSAXLocator,, int,xmlDoValidityCheckingDefaultValue,,1 xmlGenericErrorFunc,xmlGenericError,, +xmlStructuredErrorFunc,xmlStructuredError,, void *,xmlGenericErrorContext,, +void *,xmlStructuredErrorContext,, int,xmlGetWarningsDefaultValue,,1 int,xmlIndentTreeOutput,,1 const char *,xmlTreeIndentString,,1 @@ -23,3 +25,5 @@ int,xmlSaveNoEmptyTags,,1 int,xmlSubstituteEntitiesDefaultValue,,1 xmlRegisterNodeFunc,xmlRegisterNodeDefaultValue,, xmlDeregisterNodeFunc,xmlDeregisterNodeDefaultValue,, +xmlParserInputBufferCreateFilenameFunc,xmlParserInputBufferCreateFilenameValue,, +xmlOutputBufferCreateFilenameFunc,xmlOutputBufferCreateFilenameValue,, diff --git a/globals.c b/globals.c index cbc66253..9b4a5515 100644 --- a/globals.c +++ b/globals.c @@ -148,6 +148,7 @@ xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup; #undef xmlGenericError #undef xmlStructuredError #undef xmlGenericErrorContext +#undef xmlStructuredErrorContext #undef xmlGetWarningsDefaultValue #undef xmlIndentTreeOutput #undef xmlTreeIndentString @@ -314,6 +315,13 @@ static xmlStructuredErrorFunc xmlStructuredErrorThrDef = NULL; */ void *xmlGenericErrorContext = NULL; static void *xmlGenericErrorContextThrDef = NULL; +/** + * xmlStructuredErrorContext: + * + * Global setting passed to structured error callbacks + */ +void *xmlStructuredErrorContext = NULL; +static void *xmlStructuredErrorContextThrDef = NULL; xmlError xmlLastError; /* @@ -545,6 +553,7 @@ xmlInitializeGlobalState(xmlGlobalStatePtr gs) gs->xmlGenericError = xmlGenericErrorThrDef; gs->xmlStructuredError = xmlStructuredErrorThrDef; gs->xmlGenericErrorContext = xmlGenericErrorContextThrDef; + gs->xmlStructuredErrorContext = xmlStructuredErrorContextThrDef; gs->xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef; gs->xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef; @@ -573,7 +582,7 @@ xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) { void xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { xmlMutexLock(xmlThrDefMutex); - xmlGenericErrorContextThrDef = ctx; + xmlStructuredErrorContextThrDef = ctx; xmlStructuredErrorThrDef = handler; xmlMutexUnlock(xmlThrDefMutex); } @@ -876,6 +885,15 @@ __xmlGenericErrorContext(void) { return (&xmlGetGlobalState()->xmlGenericErrorContext); } +#undef xmlStructuredErrorContext +void * * +__xmlStructuredErrorContext(void) { + if (IS_MAIN_THREAD) + return (&xmlStructuredErrorContext); + else + return (&xmlGetGlobalState()->xmlStructuredErrorContext); +} + #undef xmlGetWarningsDefaultValue int * __xmlGetWarningsDefaultValue(void) { @@ -910,7 +928,7 @@ int xmlThrDefIndentTreeOutput(int v) { return ret; } -#undef xmlTreeIndentString +#undef xmlTreeIndentString const char * * __xmlTreeIndentString(void) { if (IS_MAIN_THREAD) diff --git a/include/libxml/globals.h b/include/libxml/globals.h index 57e25fa5..e74e1b15 100644 --- a/include/libxml/globals.h +++ b/include/libxml/globals.h @@ -76,6 +76,7 @@ XMLCALL xmlOutputBufferCreateFilenameDefault (xmlOutputBufferCreateFilenameFunc #undef xmlGenericError #undef xmlStructuredError #undef xmlGenericErrorContext +#undef xmlStructuredErrorContext #undef xmlGetWarningsDefaultValue #undef xmlIndentTreeOutput #undef xmlTreeIndentString @@ -158,6 +159,8 @@ struct _xmlGlobalState xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue; xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue; + + void *xmlStructuredErrorContext; }; #ifdef __cplusplus @@ -354,6 +357,14 @@ XMLPUBFUN void * * XMLCALL __xmlGenericErrorContext(void); XMLPUBVAR void * xmlGenericErrorContext; #endif +XMLPUBFUN void * * XMLCALL __xmlStructuredErrorContext(void); +#ifdef LIBXML_THREAD_ENABLED +#define xmlStructuredErrorContext \ +(*(__xmlStructuredErrorContext())) +#else +LIBXML_DLL_IMPORT extern void * xmlStructuredErrorContext; +#endif + XMLPUBFUN int * XMLCALL __xmlGetWarningsDefaultValue(void); #ifdef LIBXML_THREAD_ENABLED #define xmlGetWarningsDefaultValue \