|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define IN_LIBXML |
|
|
#include "libxml.h" |
|
|
|
|
|
#include <stdlib.h> |
|
|
#include <string.h> |
|
|
|
|
|
#define XML_GLOBALS_NO_REDEFINITION |
|
|
#include <libxml/globals.h> |
|
|
#include <libxml/xmlerror.h> |
|
|
#include <libxml/xmlmemory.h> |
|
|
#include <libxml/xmlIO.h> |
|
|
#include <libxml/parser.h> |
|
|
#include <libxml/threads.h> |
|
|
#include <libxml/tree.h> |
|
|
#include <libxml/SAX.h> |
|
|
#include <libxml/SAX2.h> |
|
|
|
|
|
#include "private/dict.h" |
|
|
#include "private/error.h" |
|
|
#include "private/globals.h" |
|
|
#include "private/threads.h" |
|
|
#include "private/tree.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlMutex xmlThrDefMutex; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef LIBXML_THREAD_ENABLED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if defined(XML_THREAD_LOCAL) && \ |
|
|
!defined(__APPLE__) && \ |
|
|
!defined(USE_WAIT_DTOR) |
|
|
#define USE_TLS |
|
|
#endif |
|
|
|
|
|
#ifdef HAVE_WIN32_THREADS |
|
|
#if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL) |
|
|
#define USE_WAIT_DTOR |
|
|
#else |
|
|
#define USE_DLL_MAIN |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
#define XML_DECLARE_MEMBER(name, type, attrs) \ |
|
|
type gs_##name; |
|
|
|
|
|
struct _xmlGlobalState { |
|
|
#ifdef USE_TLS |
|
|
int initialized; |
|
|
#endif |
|
|
|
|
|
#ifdef USE_WAIT_DTOR |
|
|
void *threadHandle; |
|
|
void *waitHandle; |
|
|
#endif |
|
|
|
|
|
unsigned localRngState[2]; |
|
|
|
|
|
xmlError lastError; |
|
|
|
|
|
#define XML_OP XML_DECLARE_MEMBER |
|
|
XML_GLOBALS_ALLOC |
|
|
XML_GLOBALS_PARSER |
|
|
XML_GLOBALS_ERROR |
|
|
XML_GLOBALS_TREE |
|
|
XML_GLOBALS_IO |
|
|
#undef XML_OP |
|
|
}; |
|
|
|
|
|
#ifdef USE_TLS |
|
|
static XML_THREAD_LOCAL xmlGlobalState globalState; |
|
|
#endif |
|
|
|
|
|
#ifdef HAVE_POSIX_THREADS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static pthread_key_t globalkey; |
|
|
|
|
|
#elif defined HAVE_WIN32_THREADS |
|
|
|
|
|
#ifndef USE_TLS |
|
|
static DWORD globalkey = TLS_OUT_OF_INDEXES; |
|
|
#endif |
|
|
|
|
|
#endif |
|
|
|
|
|
static void |
|
|
xmlFreeGlobalState(void *state); |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlFreeFunc xmlFree = free; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlMallocFunc xmlMalloc = malloc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlMallocFunc xmlMallocAtomic = malloc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlReallocFunc xmlRealloc = realloc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static char * |
|
|
xmlPosixStrdup(const char *cur) { |
|
|
return((char*) xmlCharStrdup(cur)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlStrdupFunc xmlMemStrdup = xmlPosixStrdup; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int xmlDefaultBufferSize = BASE_BUFFER_SIZE; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int oldXMLWDcompatibility = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const int xmlParserDebugEntities = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlDoValidityCheckingDefaultValue = 0; |
|
|
#endif |
|
|
static int xmlDoValidityCheckingDefaultValueThrDef = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlGetWarningsDefaultValue = 1; |
|
|
#endif |
|
|
static int xmlGetWarningsDefaultValueThrDef = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlLoadExtDtdDefaultValue = 0; |
|
|
#endif |
|
|
static int xmlLoadExtDtdDefaultValueThrDef = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlPedanticParserDefaultValue = 0; |
|
|
#endif |
|
|
static int xmlPedanticParserDefaultValueThrDef = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlLineNumbersDefaultValue = 0; |
|
|
#endif |
|
|
static int xmlLineNumbersDefaultValueThrDef = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlKeepBlanksDefaultValue = 1; |
|
|
#endif |
|
|
static int xmlKeepBlanksDefaultValueThrDef = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlSubstituteEntitiesDefaultValue = 0; |
|
|
#endif |
|
|
static int xmlSubstituteEntitiesDefaultValueThrDef = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL; |
|
|
#endif |
|
|
static xmlRegisterNodeFunc xmlRegisterNodeDefaultValueThrDef = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL; |
|
|
#endif |
|
|
static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlParserInputBufferCreateFilenameFunc |
|
|
xmlParserInputBufferCreateFilenameValue = NULL; |
|
|
#endif |
|
|
static xmlParserInputBufferCreateFilenameFunc |
|
|
xmlParserInputBufferCreateFilenameValueThrDef = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue = NULL; |
|
|
#endif |
|
|
static xmlOutputBufferCreateFilenameFunc |
|
|
xmlOutputBufferCreateFilenameValueThrDef = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; |
|
|
#endif |
|
|
static xmlGenericErrorFunc xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlStructuredErrorFunc xmlStructuredError = NULL; |
|
|
#endif |
|
|
static xmlStructuredErrorFunc xmlStructuredErrorThrDef = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
void *xmlGenericErrorContext = NULL; |
|
|
#endif |
|
|
static void *xmlGenericErrorContextThrDef = NULL; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
void *xmlStructuredErrorContext = NULL; |
|
|
#endif |
|
|
static void *xmlStructuredErrorContextThrDef = NULL; |
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
xmlError xmlLastError; |
|
|
#endif |
|
|
|
|
|
#ifdef LIBXML_OUTPUT_ENABLED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlIndentTreeOutput = 1; |
|
|
#endif |
|
|
static int xmlIndentTreeOutputThrDef = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
const char *xmlTreeIndentString = " "; |
|
|
#endif |
|
|
static const char *xmlTreeIndentStringThrDef = " "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#if !defined(LIBXML_THREAD_ENABLED) || defined(LIBXML_LEGACY_ENABLED) |
|
|
int xmlSaveNoEmptyTags = 0; |
|
|
#endif |
|
|
static int xmlSaveNoEmptyTagsThrDef = 0; |
|
|
#endif |
|
|
|
|
|
#ifdef LIBXML_SAX1_ENABLED |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const xmlSAXHandlerV1 xmlDefaultSAXHandler = { |
|
|
xmlSAX2InternalSubset, |
|
|
xmlSAX2IsStandalone, |
|
|
xmlSAX2HasInternalSubset, |
|
|
xmlSAX2HasExternalSubset, |
|
|
xmlSAX2ResolveEntity, |
|
|
xmlSAX2GetEntity, |
|
|
xmlSAX2EntityDecl, |
|
|
xmlSAX2NotationDecl, |
|
|
xmlSAX2AttributeDecl, |
|
|
xmlSAX2ElementDecl, |
|
|
xmlSAX2UnparsedEntityDecl, |
|
|
xmlSAX2SetDocumentLocator, |
|
|
xmlSAX2StartDocument, |
|
|
xmlSAX2EndDocument, |
|
|
xmlSAX2StartElement, |
|
|
xmlSAX2EndElement, |
|
|
xmlSAX2Reference, |
|
|
xmlSAX2Characters, |
|
|
xmlSAX2Characters, |
|
|
xmlSAX2ProcessingInstruction, |
|
|
xmlSAX2Comment, |
|
|
xmlParserWarning, |
|
|
xmlParserError, |
|
|
xmlParserError, |
|
|
xmlSAX2GetParameterEntity, |
|
|
xmlSAX2CDataBlock, |
|
|
xmlSAX2ExternalSubset, |
|
|
1, |
|
|
}; |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const xmlSAXLocator xmlDefaultSAXLocator = { |
|
|
xmlSAX2GetPublicId, |
|
|
xmlSAX2GetSystemId, |
|
|
xmlSAX2GetLineNumber, |
|
|
xmlSAX2GetColumnNumber |
|
|
}; |
|
|
|
|
|
#if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_SAX1_ENABLED) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const xmlSAXHandlerV1 htmlDefaultSAXHandler = { |
|
|
xmlSAX2InternalSubset, |
|
|
NULL, |
|
|
NULL, |
|
|
NULL, |
|
|
NULL, |
|
|
xmlSAX2GetEntity, |
|
|
NULL, |
|
|
NULL, |
|
|
NULL, |
|
|
NULL, |
|
|
NULL, |
|
|
xmlSAX2SetDocumentLocator, |
|
|
xmlSAX2StartDocument, |
|
|
xmlSAX2EndDocument, |
|
|
xmlSAX2StartElement, |
|
|
xmlSAX2EndElement, |
|
|
NULL, |
|
|
xmlSAX2Characters, |
|
|
xmlSAX2IgnorableWhitespace, |
|
|
xmlSAX2ProcessingInstruction, |
|
|
xmlSAX2Comment, |
|
|
xmlParserWarning, |
|
|
xmlParserError, |
|
|
xmlParserError, |
|
|
NULL, |
|
|
xmlSAX2CDataBlock, |
|
|
NULL, |
|
|
1, |
|
|
}; |
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void xmlInitGlobals(void) { |
|
|
xmlInitParser(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void xmlInitGlobalsInternal(void) { |
|
|
xmlInitMutex(&xmlThrDefMutex); |
|
|
|
|
|
#ifdef HAVE_POSIX_THREADS |
|
|
pthread_key_create(&globalkey, xmlFreeGlobalState); |
|
|
#elif defined(HAVE_WIN32_THREADS) |
|
|
#ifndef USE_TLS |
|
|
if (globalkey == TLS_OUT_OF_INDEXES) |
|
|
globalkey = TlsAlloc(); |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void xmlCleanupGlobals(void) { |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void xmlCleanupGlobalsInternal(void) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_POSIX_THREADS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlGlobalState *gs = pthread_getspecific(globalkey); |
|
|
if (gs != NULL) |
|
|
xmlFreeGlobalState(gs); |
|
|
pthread_key_delete(globalkey); |
|
|
#elif defined(HAVE_WIN32_THREADS) |
|
|
#if defined(USE_WAIT_DTOR) && !defined(USE_TLS) |
|
|
if (globalkey != TLS_OUT_OF_INDEXES) { |
|
|
TlsFree(globalkey); |
|
|
globalkey = TLS_OUT_OF_INDEXES; |
|
|
} |
|
|
#endif |
|
|
#else |
|
|
xmlResetError(&xmlLastError); |
|
|
#endif |
|
|
|
|
|
xmlCleanupMutex(&xmlThrDefMutex); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void |
|
|
xmlInitializeGlobalState(xmlGlobalStatePtr gs ATTRIBUTE_UNUSED) |
|
|
{ |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlGlobalStatePtr |
|
|
xmlGetGlobalState(void) |
|
|
{ |
|
|
return(NULL); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
xmlIsMainThread(void) { |
|
|
return(0); |
|
|
} |
|
|
|
|
|
#ifdef LIBXML_THREAD_ENABLED |
|
|
|
|
|
static void |
|
|
xmlFreeGlobalState(void *state) |
|
|
{ |
|
|
xmlGlobalState *gs = (xmlGlobalState *) state; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlResetError(&gs->lastError); |
|
|
#ifndef USE_TLS |
|
|
free(state); |
|
|
#endif |
|
|
} |
|
|
|
|
|
#if defined(USE_WAIT_DTOR) |
|
|
static void WINAPI |
|
|
xmlGlobalStateDtor(void *ctxt, unsigned char timedOut ATTRIBUTE_UNUSED) { |
|
|
xmlGlobalStatePtr gs = ctxt; |
|
|
|
|
|
UnregisterWait(gs->waitHandle); |
|
|
CloseHandle(gs->threadHandle); |
|
|
xmlFreeGlobalState(gs); |
|
|
} |
|
|
|
|
|
static int |
|
|
xmlRegisterGlobalStateDtor(xmlGlobalState *gs) { |
|
|
void *processHandle = GetCurrentProcess(); |
|
|
void *threadHandle; |
|
|
void *waitHandle; |
|
|
|
|
|
if (DuplicateHandle(processHandle, GetCurrentThread(), processHandle, |
|
|
&threadHandle, 0, FALSE, DUPLICATE_SAME_ACCESS) == 0) { |
|
|
return(-1); |
|
|
} |
|
|
|
|
|
if (RegisterWaitForSingleObject(&waitHandle, threadHandle, |
|
|
xmlGlobalStateDtor, gs, INFINITE, WT_EXECUTEONLYONCE) == 0) { |
|
|
CloseHandle(threadHandle); |
|
|
return(-1); |
|
|
} |
|
|
|
|
|
gs->threadHandle = threadHandle; |
|
|
gs->waitHandle = waitHandle; |
|
|
return(0); |
|
|
} |
|
|
#endif |
|
|
|
|
|
static void |
|
|
xmlInitGlobalState(xmlGlobalStatePtr gs) { |
|
|
gs->localRngState[0] = xmlGlobalRandom(); |
|
|
gs->localRngState[1] = xmlGlobalRandom(); |
|
|
|
|
|
memset(&gs->lastError, 0, sizeof(xmlError)); |
|
|
|
|
|
#ifdef LIBXML_THREAD_ALLOC_ENABLED |
|
|
|
|
|
gs->gs_xmlFree = free; |
|
|
gs->gs_xmlMalloc = malloc; |
|
|
gs->gs_xmlMallocAtomic = malloc; |
|
|
gs->gs_xmlRealloc = realloc; |
|
|
gs->gs_xmlMemStrdup = xmlPosixStrdup; |
|
|
#endif |
|
|
|
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
|
|
|
|
|
|
gs->gs_xmlDoValidityCheckingDefaultValue = |
|
|
xmlDoValidityCheckingDefaultValueThrDef; |
|
|
gs->gs_xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef; |
|
|
gs->gs_xmlKeepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef; |
|
|
gs->gs_xmlLineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef; |
|
|
gs->gs_xmlLoadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef; |
|
|
gs->gs_xmlPedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef; |
|
|
gs->gs_xmlSubstituteEntitiesDefaultValue = |
|
|
xmlSubstituteEntitiesDefaultValueThrDef; |
|
|
#ifdef LIBXML_OUTPUT_ENABLED |
|
|
gs->gs_xmlIndentTreeOutput = xmlIndentTreeOutputThrDef; |
|
|
gs->gs_xmlTreeIndentString = xmlTreeIndentStringThrDef; |
|
|
gs->gs_xmlSaveNoEmptyTags = xmlSaveNoEmptyTagsThrDef; |
|
|
#endif |
|
|
|
|
|
|
|
|
gs->gs_xmlGenericError = xmlGenericErrorThrDef; |
|
|
gs->gs_xmlStructuredError = xmlStructuredErrorThrDef; |
|
|
gs->gs_xmlGenericErrorContext = xmlGenericErrorContextThrDef; |
|
|
gs->gs_xmlStructuredErrorContext = xmlStructuredErrorContextThrDef; |
|
|
|
|
|
|
|
|
gs->gs_xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef; |
|
|
gs->gs_xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef; |
|
|
|
|
|
|
|
|
gs->gs_xmlParserInputBufferCreateFilenameValue = |
|
|
xmlParserInputBufferCreateFilenameValueThrDef; |
|
|
gs->gs_xmlOutputBufferCreateFilenameValue = |
|
|
xmlOutputBufferCreateFilenameValueThrDef; |
|
|
|
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
|
|
|
#ifdef USE_TLS |
|
|
gs->initialized = 1; |
|
|
#endif |
|
|
|
|
|
#ifdef HAVE_POSIX_THREADS |
|
|
pthread_setspecific(globalkey, gs); |
|
|
#elif defined HAVE_WIN32_THREADS |
|
|
#ifndef USE_TLS |
|
|
TlsSetValue(globalkey, gs); |
|
|
#endif |
|
|
#ifdef USE_WAIT_DTOR |
|
|
xmlRegisterGlobalStateDtor(gs); |
|
|
#endif |
|
|
#endif |
|
|
} |
|
|
|
|
|
#ifndef USE_TLS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static xmlGlobalStatePtr |
|
|
xmlNewGlobalState(int allowFailure) |
|
|
{ |
|
|
xmlGlobalState *gs; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gs = malloc(sizeof(xmlGlobalState)); |
|
|
if (gs == NULL) { |
|
|
if (allowFailure) |
|
|
return(NULL); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlAbort("libxml2: Failed to allocate globals for thread\n" |
|
|
"libxml2: See xmlCheckThreadLocalStorage\n"); |
|
|
} |
|
|
|
|
|
memset(gs, 0, sizeof(xmlGlobalState)); |
|
|
xmlInitGlobalState(gs); |
|
|
return (gs); |
|
|
} |
|
|
#endif |
|
|
|
|
|
static xmlGlobalStatePtr |
|
|
xmlGetThreadLocalStorage(int allowFailure) { |
|
|
xmlGlobalState *gs; |
|
|
|
|
|
(void) allowFailure; |
|
|
|
|
|
xmlInitParser(); |
|
|
|
|
|
#ifdef USE_TLS |
|
|
gs = &globalState; |
|
|
if (gs->initialized == 0) |
|
|
xmlInitGlobalState(gs); |
|
|
#elif defined(HAVE_POSIX_THREADS) |
|
|
gs = (xmlGlobalState *) pthread_getspecific(globalkey); |
|
|
if (gs == NULL) |
|
|
gs = xmlNewGlobalState(allowFailure); |
|
|
#elif defined(HAVE_WIN32_THREADS) |
|
|
gs = (xmlGlobalState *) TlsGetValue(globalkey); |
|
|
if (gs == NULL) |
|
|
gs = xmlNewGlobalState(allowFailure); |
|
|
#else |
|
|
gs = NULL; |
|
|
#endif |
|
|
|
|
|
return(gs); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#define XML_DEFINE_GLOBAL_WRAPPER(name, type, attrs) \ |
|
|
type *__##name(void) { \ |
|
|
return (&xmlGetThreadLocalStorage(0)->gs_##name); \ |
|
|
} |
|
|
|
|
|
#define XML_OP XML_DEFINE_GLOBAL_WRAPPER |
|
|
XML_GLOBALS_ALLOC |
|
|
XML_GLOBALS_PARSER |
|
|
XML_GLOBALS_ERROR |
|
|
XML_GLOBALS_TREE |
|
|
XML_GLOBALS_IO |
|
|
#undef XML_OP |
|
|
|
|
|
const xmlError * |
|
|
__xmlLastError(void) { |
|
|
return(&xmlGetThreadLocalStorage(0)->lastError); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
unsigned * |
|
|
xmlGetLocalRngState(void) { |
|
|
return(xmlGetThreadLocalStorage(0)->localRngState); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const char *const * |
|
|
__xmlParserVersion(void) { |
|
|
return &xmlParserVersion; |
|
|
} |
|
|
|
|
|
const int * |
|
|
__oldXMLWDcompatibility(void) { |
|
|
return &oldXMLWDcompatibility; |
|
|
} |
|
|
|
|
|
const int * |
|
|
__xmlParserDebugEntities(void) { |
|
|
return &xmlParserDebugEntities; |
|
|
} |
|
|
|
|
|
const xmlSAXLocator * |
|
|
__xmlDefaultSAXLocator(void) { |
|
|
return &xmlDefaultSAXLocator; |
|
|
} |
|
|
|
|
|
#ifdef LIBXML_SAX1_ENABLED |
|
|
const xmlSAXHandlerV1 * |
|
|
__xmlDefaultSAXHandler(void) { |
|
|
return &xmlDefaultSAXHandler; |
|
|
} |
|
|
|
|
|
#ifdef LIBXML_HTML_ENABLED |
|
|
const xmlSAXHandlerV1 * |
|
|
__htmlDefaultSAXHandler(void) { |
|
|
return &htmlDefaultSAXHandler; |
|
|
} |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int |
|
|
xmlCheckThreadLocalStorage(void) { |
|
|
#if defined(LIBXML_THREAD_ENABLED) && !defined(USE_TLS) |
|
|
if (xmlGetThreadLocalStorage(1) == NULL) |
|
|
return(-1); |
|
|
#endif |
|
|
return(0); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
xmlError * |
|
|
xmlGetLastErrorInternal(void) { |
|
|
#ifdef LIBXML_THREAD_ENABLED |
|
|
return(&xmlGetThreadLocalStorage(0)->lastError); |
|
|
#else |
|
|
return(&xmlLastError); |
|
|
#endif |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef USE_DLL_MAIN |
|
|
#if defined(LIBXML_STATIC_FOR_DLL) |
|
|
int |
|
|
xmlDllMain(ATTRIBUTE_UNUSED void *hinstDLL, unsigned long fdwReason, |
|
|
ATTRIBUTE_UNUSED void *lpvReserved) |
|
|
#else |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
XMLPUBFUN BOOL WINAPI |
|
|
DllMain (HINSTANCE hinstDLL, |
|
|
DWORD fdwReason, |
|
|
LPVOID lpvReserved); |
|
|
|
|
|
BOOL WINAPI |
|
|
DllMain(ATTRIBUTE_UNUSED HINSTANCE hinstDLL, DWORD fdwReason, |
|
|
ATTRIBUTE_UNUSED LPVOID lpvReserved) |
|
|
#endif |
|
|
{ |
|
|
switch (fdwReason) { |
|
|
case DLL_THREAD_DETACH: |
|
|
#ifdef USE_TLS |
|
|
xmlFreeGlobalState(&globalState); |
|
|
#else |
|
|
if (globalkey != TLS_OUT_OF_INDEXES) { |
|
|
xmlGlobalState *globalval; |
|
|
|
|
|
globalval = (xmlGlobalState *) TlsGetValue(globalkey); |
|
|
if (globalval) { |
|
|
xmlFreeGlobalState(globalval); |
|
|
TlsSetValue(globalkey, NULL); |
|
|
} |
|
|
} |
|
|
#endif |
|
|
break; |
|
|
|
|
|
#ifndef LIBXML_THREAD_ALLOC_ENABLED |
|
|
case DLL_PROCESS_DETACH: |
|
|
if (xmlFree == free) |
|
|
xmlCleanupParser(); |
|
|
if (globalkey != TLS_OUT_OF_INDEXES) { |
|
|
TlsFree(globalkey); |
|
|
globalkey = TLS_OUT_OF_INDEXES; |
|
|
} |
|
|
break; |
|
|
#endif |
|
|
} |
|
|
return TRUE; |
|
|
} |
|
|
#endif |
|
|
|
|
|
void |
|
|
xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler) { |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
xmlGenericErrorContextThrDef = ctx; |
|
|
if (handler != NULL) |
|
|
xmlGenericErrorThrDef = handler; |
|
|
else |
|
|
xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
} |
|
|
|
|
|
void |
|
|
xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler) { |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
xmlStructuredErrorContextThrDef = ctx; |
|
|
xmlStructuredErrorThrDef = handler; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
} |
|
|
|
|
|
xmlBufferAllocationScheme |
|
|
xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v ATTRIBUTE_UNUSED) { |
|
|
return xmlBufferAllocScheme; |
|
|
} |
|
|
|
|
|
int |
|
|
xmlThrDefDefaultBufferSize(int v ATTRIBUTE_UNUSED) { |
|
|
return xmlDefaultBufferSize; |
|
|
} |
|
|
|
|
|
int xmlThrDefDoValidityCheckingDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlDoValidityCheckingDefaultValueThrDef; |
|
|
xmlDoValidityCheckingDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
int xmlThrDefGetWarningsDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlGetWarningsDefaultValueThrDef; |
|
|
xmlGetWarningsDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
#ifdef LIBXML_OUTPUT_ENABLED |
|
|
int xmlThrDefIndentTreeOutput(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlIndentTreeOutputThrDef; |
|
|
xmlIndentTreeOutputThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
const char * xmlThrDefTreeIndentString(const char * v) { |
|
|
const char * ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlTreeIndentStringThrDef; |
|
|
xmlTreeIndentStringThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
int xmlThrDefSaveNoEmptyTags(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlSaveNoEmptyTagsThrDef; |
|
|
xmlSaveNoEmptyTagsThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
#endif |
|
|
|
|
|
int xmlThrDefKeepBlanksDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlKeepBlanksDefaultValueThrDef; |
|
|
xmlKeepBlanksDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
int xmlThrDefLineNumbersDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlLineNumbersDefaultValueThrDef; |
|
|
xmlLineNumbersDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
int xmlThrDefLoadExtDtdDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlLoadExtDtdDefaultValueThrDef; |
|
|
xmlLoadExtDtdDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
int xmlThrDefParserDebugEntities(int v ATTRIBUTE_UNUSED) { |
|
|
return(xmlParserDebugEntities); |
|
|
} |
|
|
|
|
|
int xmlThrDefPedanticParserDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlPedanticParserDefaultValueThrDef; |
|
|
xmlPedanticParserDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
int xmlThrDefSubstituteEntitiesDefaultValue(int v) { |
|
|
int ret; |
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
ret = xmlSubstituteEntitiesDefaultValueThrDef; |
|
|
xmlSubstituteEntitiesDefaultValueThrDef = v; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
return ret; |
|
|
} |
|
|
|
|
|
xmlRegisterNodeFunc |
|
|
xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func) |
|
|
{ |
|
|
xmlRegisterNodeFunc old; |
|
|
|
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
old = xmlRegisterNodeDefaultValueThrDef; |
|
|
|
|
|
xmlRegisterCallbacks = 1; |
|
|
xmlRegisterNodeDefaultValueThrDef = func; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
|
|
|
return(old); |
|
|
} |
|
|
|
|
|
xmlDeregisterNodeFunc |
|
|
xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func) |
|
|
{ |
|
|
xmlDeregisterNodeFunc old; |
|
|
|
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
old = xmlDeregisterNodeDefaultValueThrDef; |
|
|
|
|
|
xmlRegisterCallbacks = 1; |
|
|
xmlDeregisterNodeDefaultValueThrDef = func; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
|
|
|
return(old); |
|
|
} |
|
|
|
|
|
xmlParserInputBufferCreateFilenameFunc |
|
|
xmlThrDefParserInputBufferCreateFilenameDefault(xmlParserInputBufferCreateFilenameFunc func) |
|
|
{ |
|
|
xmlParserInputBufferCreateFilenameFunc old; |
|
|
|
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
old = xmlParserInputBufferCreateFilenameValueThrDef; |
|
|
if (old == NULL) { |
|
|
old = __xmlParserInputBufferCreateFilename; |
|
|
} |
|
|
|
|
|
xmlParserInputBufferCreateFilenameValueThrDef = func; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
|
|
|
return(old); |
|
|
} |
|
|
|
|
|
xmlOutputBufferCreateFilenameFunc |
|
|
xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func) |
|
|
{ |
|
|
xmlOutputBufferCreateFilenameFunc old; |
|
|
|
|
|
xmlMutexLock(&xmlThrDefMutex); |
|
|
old = xmlOutputBufferCreateFilenameValueThrDef; |
|
|
#ifdef LIBXML_OUTPUT_ENABLED |
|
|
if (old == NULL) { |
|
|
old = __xmlOutputBufferCreateFilename; |
|
|
} |
|
|
#endif |
|
|
xmlOutputBufferCreateFilenameValueThrDef = func; |
|
|
xmlMutexUnlock(&xmlThrDefMutex); |
|
|
|
|
|
return(old); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|