2001-10-12 21:29:10 +04:00
/*
* globals . c : definition and handling of the set of global variables
* of the library
*
* See Copyright for the status of this software .
*
* Gary Pennington < Gary . Pennington @ uk . sun . com >
* daniel @ veillard . com
*/
2002-03-18 22:37:11 +03:00
# define IN_LIBXML
2001-10-12 21:29:10 +04:00
# include "libxml.h"
2023-09-20 14:30:01 +03:00
# include <stdio.h>
2001-10-13 16:06:09 +04:00
# include <stdlib.h>
# include <string.h>
2023-09-18 22:25:35 +03:00
# define XML_GLOBALS_NO_REDEFINITION
2001-10-17 19:58:35 +04:00
# include <libxml/globals.h>
2023-09-20 18:17:49 +03:00
# include <libxml/xmlerror.h>
2001-10-13 16:18:28 +04:00
# include <libxml/xmlmemory.h>
2023-09-20 18:54:48 +03:00
# include <libxml/xmlIO.h>
# include <libxml/parser.h>
2003-05-16 02:11:36 +04:00
# include <libxml/threads.h>
2023-09-20 18:54:48 +03:00
# include <libxml/tree.h>
2023-09-18 22:25:35 +03:00
# include <libxml/SAX.h>
2023-09-20 17:57:22 +03:00
# include <libxml/SAX2.h>
2001-10-13 16:18:28 +04:00
2023-12-24 17:33:12 +03:00
# include "private/dict.h"
2022-08-26 02:22:33 +03:00
# include "private/error.h"
2022-11-24 22:52:57 +03:00
# include "private/globals.h"
2022-08-26 02:22:33 +03:00
# include "private/threads.h"
# include "private/tree.h"
2023-09-20 13:45:14 +03:00
/*
* Thread - local storage emulation .
*
* This works by replacing a global variable
*
* extern xmlError xmlLastError ;
*
* with a macro that calls a function returning a pointer to the global in
* thread - local storage :
*
* xmlError * __xmlLastError ( void ) ;
* # define xmlError ( * __xmlLastError ( ) ) ;
*
* The code can operate in a multitude of ways depending on the environment .
* First we support POSIX and Windows threads . Then we support both thread - local
* storage provided by the compiler and older methods like thread - specific data
* ( pthreads ) or TlsAlloc ( Windows ) .
*
* To clean up thread - local storage , we use thread - specific data on POSIX .
* On Windows , we either use DllMain when compiling a DLL or a registered wait
* function for static builds .
*/
2001-10-12 21:29:10 +04:00
/*
* Helpful Macro
*/
2001-10-17 19:58:35 +04:00
# ifdef LIBXML_THREAD_ENABLED
2023-09-19 14:52:53 +03:00
# define IS_MAIN_THREAD (xmlIsMainThreadInternal())
2001-10-12 21:29:10 +04:00
# else
# define IS_MAIN_THREAD 1
# endif
2023-09-18 22:25:35 +03:00
# define XML_DECLARE_MEMBER(name, type, attrs) \
type gs_ # # name ;
2023-09-18 19:44:32 +03:00
2023-09-18 22:25:35 +03:00
struct _xmlGlobalState {
2023-09-19 14:17:00 +03:00
int initialized ;
2023-09-18 14:25:06 +03:00
# if defined(HAVE_WIN32_THREADS) && \
defined ( LIBXML_STATIC ) & & ! defined ( LIBXML_STATIC_FOR_DLL )
void * threadHandle ;
void * waitHandle ;
# endif
2023-12-24 17:33:12 +03:00
# ifdef LIBXML_THREAD_ENABLED
unsigned localRngState [ 2 ] ;
# endif
2023-09-18 22:25:35 +03:00
# define XML_OP XML_DECLARE_MEMBER
2023-09-20 18:00:50 +03:00
XML_GLOBALS_ALLOC
2023-09-20 18:17:49 +03:00
XML_GLOBALS_ERROR
2023-09-20 18:54:48 +03:00
XML_GLOBALS_IO
XML_GLOBALS_PARSER
XML_GLOBALS_TREE
2023-09-18 22:25:35 +03:00
# undef XML_OP
2023-09-18 19:44:32 +03:00
} ;
2023-09-22 14:37:28 +03:00
static int parserInitialized ;
/*
* Mutex to protect " ForNewThreads " variables
*/
static xmlMutex xmlThrDefMutex ;
2023-09-19 14:17:00 +03:00
# ifdef LIBXML_THREAD_ENABLED
2023-09-22 14:37:28 +03:00
/*
* On Darwin , thread - local storage destructors seem to be run before
* pthread thread - specific data destructors . This causes ASan to
* report a use - after - free .
2023-12-01 19:19:55 +03:00
*
* On Windows , we can ' t use TLS in static builds . The RegisterWait
* callback would run after TLS was deallocated .
2023-09-22 14:37:28 +03:00
*/
2023-12-01 19:19:55 +03:00
# if defined(XML_THREAD_LOCAL) && \
! defined ( __APPLE__ ) & & \
( ! defined ( HAVE_WIN32_THREADS ) | | \
! defined ( LIBXML_STATIC ) | | defined ( LIBXML_STATIC_FOR_DLL ) )
2023-09-22 14:37:28 +03:00
# define USE_TLS
# endif
# ifdef USE_TLS
2023-09-19 14:17:00 +03:00
static XML_THREAD_LOCAL xmlGlobalState globalState ;
# endif
2023-09-18 01:54:39 +03:00
# ifdef HAVE_POSIX_THREADS
/*
* Weak symbol hack , see threads . c
2003-12-20 05:10:28 +03:00
*/
2023-09-18 01:54:39 +03:00
# if defined(__GNUC__) && \
defined ( __GLIBC__ ) & & \
__GLIBC__ * 100 + __GLIBC_MINOR__ < 234
2023-11-18 20:21:38 +03:00
# pragma weak pthread_getspecific
# pragma weak pthread_setspecific
# pragma weak pthread_key_create
# pragma weak pthread_key_delete
2023-11-18 22:21:45 +03:00
# pragma weak pthread_equal
# pragma weak pthread_self
2023-11-18 20:21:38 +03:00
2023-09-18 01:54:39 +03:00
# define XML_PTHREAD_WEAK
static int libxml_is_threaded = - 1 ;
# endif
2023-09-20 13:45:14 +03:00
/*
* On POSIX , we need thread - specific data even with thread - local storage
* to destroy indirect references from global state ( xmlLastError ) at
* thread exit .
*/
2023-09-18 01:54:39 +03:00
static pthread_key_t globalkey ;
2023-09-19 14:52:53 +03:00
static pthread_t mainthread ;
2023-09-18 01:54:39 +03:00
# elif defined HAVE_WIN32_THREADS
2023-09-22 14:37:28 +03:00
# ifndef USE_TLS
2023-09-18 01:54:39 +03:00
static DWORD globalkey = TLS_OUT_OF_INDEXES ;
2023-09-19 14:17:00 +03:00
# endif
2023-09-19 14:52:53 +03:00
static DWORD mainthread ;
2023-09-18 01:54:39 +03:00
# endif /* HAVE_WIN32_THREADS */
2023-09-18 14:25:06 +03:00
static void
xmlFreeGlobalState ( void * state ) ;
2023-09-19 14:17:00 +03:00
# endif /* LIBXML_THREAD_ENABLED */
2023-09-18 14:25:06 +03:00
2001-10-12 21:29:10 +04:00
/************************************************************************
2012-09-11 09:26:36 +04:00
* *
2001-10-12 21:29:10 +04:00
* All the user accessible global variables of the library *
2012-09-11 09:26:36 +04:00
* *
2001-10-12 21:29:10 +04:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2023-12-24 17:33:12 +03:00
# ifdef LIBXML_THREAD_ENABLED
static unsigned xmlMainThreadRngState [ 2 ] ;
# endif
2001-10-12 21:29:10 +04:00
/*
* Memory allocation routines
*/
2004-06-10 17:00:15 +04:00
2002-01-22 21:15:52 +03:00
/**
* xmlFree :
* @ mem : an already allocated block of memory
*
* The variable holding the libxml free ( ) implementation
*/
2017-11-09 15:42:33 +03:00
xmlFreeFunc xmlFree = free ;
2002-01-22 21:15:52 +03:00
/**
* xmlMalloc :
* @ size : the size requested in bytes
*
* The variable holding the libxml malloc ( ) implementation
*
* Returns a pointer to the newly allocated block or NULL in case of error
*/
2017-11-09 15:42:33 +03:00
xmlMallocFunc xmlMalloc = malloc ;
2003-04-19 04:07:51 +04:00
/**
* xmlMallocAtomic :
* @ size : the size requested in bytes
*
* The variable holding the libxml malloc ( ) implementation for atomic
2019-09-30 18:04:54 +03:00
* data ( i . e . blocks not containing pointers ) , useful when using a
2003-04-19 04:07:51 +04:00
* garbage collecting allocator .
*
* Returns a pointer to the newly allocated block or NULL in case of error
*/
2017-11-09 15:42:33 +03:00
xmlMallocFunc xmlMallocAtomic = malloc ;
2002-01-22 21:15:52 +03:00
/**
* xmlRealloc :
* @ mem : an already allocated block of memory
* @ size : the new size requested in bytes
*
* The variable holding the libxml realloc ( ) implementation
*
* Returns a pointer to the newly reallocated block or NULL in case of error
*/
2017-11-09 15:42:33 +03:00
xmlReallocFunc xmlRealloc = realloc ;
/**
* xmlPosixStrdup
* @ cur : the input char *
*
* a strdup implementation with a type signature matching POSIX
*
* Returns a new xmlChar * or NULL
*/
static char *
xmlPosixStrdup ( const char * cur ) {
return ( ( char * ) xmlCharStrdup ( cur ) ) ;
}
2002-01-22 21:15:52 +03:00
/**
* xmlMemStrdup :
* @ str : a zero terminated string
*
* The variable holding the libxml strdup ( ) implementation
*
* Returns the copy of the string or NULL in case of error
*/
2017-11-09 15:42:33 +03:00
xmlStrdupFunc xmlMemStrdup = xmlPosixStrdup ;
2001-10-12 21:29:10 +04:00
2002-01-22 21:15:52 +03:00
/**
* xmlBufferAllocScheme :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : Don ' t use .
*
2002-01-22 21:15:52 +03:00
* Global setting , default allocation policy for buffers , default is
* XML_BUFFER_ALLOC_EXACT
2001-10-12 21:29:10 +04:00
*/
xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT ;
2003-05-16 02:11:36 +04:00
static xmlBufferAllocationScheme xmlBufferAllocSchemeThrDef = XML_BUFFER_ALLOC_EXACT ;
2002-01-22 21:15:52 +03:00
/**
* xmlDefaultBufferSize :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : Don ' t use .
*
2002-01-22 21:15:52 +03:00
* Global setting , default buffer size . Default value is BASE_BUFFER_SIZE
*/
2001-10-12 21:29:10 +04:00
int xmlDefaultBufferSize = BASE_BUFFER_SIZE ;
2003-05-16 02:11:36 +04:00
static int xmlDefaultBufferSizeThrDef = BASE_BUFFER_SIZE ;
2001-10-12 21:29:10 +04:00
/*
* Parser defaults
*/
2001-10-13 13:15:48 +04:00
2002-01-22 21:15:52 +03:00
/**
* oldXMLWDcompatibility :
*
* Global setting , DEPRECATED .
*/
2023-12-06 03:09:31 +03:00
const int oldXMLWDcompatibility = 0 ; /* DEPRECATED */
2002-01-22 21:15:52 +03:00
/**
* xmlParserDebugEntities :
*
2022-08-24 03:18:50 +03:00
* DEPRECATED : Don ' t use
*
2020-03-08 19:19:42 +03:00
* Global setting , asking the parser to print out debugging information .
2002-01-22 21:15:52 +03:00
* while handling entities .
* Disabled by default
*/
2023-12-18 21:31:29 +03:00
const int xmlParserDebugEntities = 0 ;
2002-01-22 21:15:52 +03:00
/**
* xmlDoValidityCheckingDefaultValue :
*
2022-08-24 03:18:50 +03:00
* DEPRECATED : Use the modern options API with XML_PARSE_DTDVALID .
*
2002-01-22 21:15:52 +03:00
* Global setting , indicate that the parser should work in validating mode .
* Disabled by default .
*/
2001-10-12 21:29:10 +04:00
int xmlDoValidityCheckingDefaultValue = 0 ;
2003-05-16 02:11:36 +04:00
static int xmlDoValidityCheckingDefaultValueThrDef = 0 ;
2002-01-22 21:15:52 +03:00
/**
* xmlGetWarningsDefaultValue :
*
2024-01-05 03:14:28 +03:00
* DEPRECATED : Use the modern options API with XML_PARSE_NOWARNING .
2022-08-24 03:18:50 +03:00
*
* Global setting , indicate that the DTD validation should provide warnings .
2002-01-22 21:15:52 +03:00
* Activated by default .
*/
2001-10-12 21:29:10 +04:00
int xmlGetWarningsDefaultValue = 1 ;
2003-05-16 02:11:36 +04:00
static int xmlGetWarningsDefaultValueThrDef = 1 ;
2002-01-22 21:15:52 +03:00
/**
* xmlLoadExtDtdDefaultValue :
*
2022-08-24 03:18:50 +03:00
* DEPRECATED : Use the modern options API with XML_PARSE_DTDLOAD .
*
2002-01-22 21:15:52 +03:00
* Global setting , indicate that the parser should load DTD while not
* validating .
* Disabled by default .
*/
2001-10-12 21:29:10 +04:00
int xmlLoadExtDtdDefaultValue = 0 ;
2003-05-16 02:11:36 +04:00
static int xmlLoadExtDtdDefaultValueThrDef = 0 ;
2002-01-22 21:15:52 +03:00
/**
* xmlPedanticParserDefaultValue :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : Use the modern options API with XML_PARSE_PEDANTIC .
*
2002-01-22 21:15:52 +03:00
* Global setting , indicate that the parser be pedantic
* Disabled by default .
*/
2001-10-12 21:29:10 +04:00
int xmlPedanticParserDefaultValue = 0 ;
2003-05-16 02:11:36 +04:00
static int xmlPedanticParserDefaultValueThrDef = 0 ;
2002-01-22 21:15:52 +03:00
/**
* xmlLineNumbersDefaultValue :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : The modern options API always enables line numbers .
*
2002-01-22 21:15:52 +03:00
* Global setting , indicate that the parser should store the line number
2012-09-11 09:26:36 +04:00
* in the content field of elements in the DOM tree .
2002-01-22 21:15:52 +03:00
* Disabled by default since this may not be safe for old classes of
2019-09-30 18:04:54 +03:00
* application .
2002-01-22 21:15:52 +03:00
*/
2001-10-12 21:29:10 +04:00
int xmlLineNumbersDefaultValue = 0 ;
2003-05-16 02:11:36 +04:00
static int xmlLineNumbersDefaultValueThrDef = 0 ;
2002-01-22 21:15:52 +03:00
/**
* xmlKeepBlanksDefaultValue :
*
2022-08-24 03:18:50 +03:00
* DEPRECATED : Use the modern options API with XML_PARSE_NOBLANKS .
*
2002-01-22 21:15:52 +03:00
* Global setting , indicate that the parser should keep all blanks
* nodes found in the content
* Activated by default , this is actually needed to have the parser
* conformant to the XML Recommendation , however the option is kept
* for some applications since this was libxml1 default behaviour .
*/
2001-10-12 21:29:10 +04:00
int xmlKeepBlanksDefaultValue = 1 ;
2003-05-16 02:11:36 +04:00
static int xmlKeepBlanksDefaultValueThrDef = 1 ;
2002-01-22 21:15:52 +03:00
/**
* xmlSubstituteEntitiesDefaultValue :
*
2022-08-24 03:18:50 +03:00
* DEPRECATED : Use the modern options API with XML_PARSE_NOENT .
*
2002-01-22 21:15:52 +03:00
* Global setting , indicate that the parser should not generate entity
* references but replace them with the actual content of the entity
* Disabled by default , this should be activated when using XPath since
* the XPath data model requires entities replacement and the XPath
* engine does not handle entities references transparently .
*/
2001-10-12 21:29:10 +04:00
int xmlSubstituteEntitiesDefaultValue = 0 ;
2003-05-16 02:11:36 +04:00
static int xmlSubstituteEntitiesDefaultValueThrDef = 0 ;
2001-10-12 21:29:10 +04:00
2022-08-24 03:18:50 +03:00
/**
* xmlRegisterNodeDefaultValue :
*
* DEPRECATED : Don ' t use
*/
2003-01-01 23:59:38 +03:00
xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL ;
2003-05-16 02:11:36 +04:00
static xmlRegisterNodeFunc xmlRegisterNodeDefaultValueThrDef = NULL ;
2022-08-24 03:18:50 +03:00
/**
* xmlDeregisterNodeDefaultValue :
*
* DEPRECATED : Don ' t use
*/
2003-01-01 23:59:38 +03:00
xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL ;
2003-05-16 02:11:36 +04:00
static xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValueThrDef = NULL ;
2003-01-01 23:59:38 +03:00
2022-08-24 03:18:50 +03:00
/**
* xmlParserInputBufferCreateFilenameValue :
*
* DEPRECATED : Don ' t use
*/
2004-06-02 20:18:40 +04:00
xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue = NULL ;
static xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValueThrDef = NULL ;
2022-08-24 03:18:50 +03:00
/**
* xmlOutputBufferCreateFilenameValue :
*
* DEPRECATED : Don ' t use
*/
2004-06-02 20:18:40 +04:00
xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue = NULL ;
static xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValueThrDef = NULL ;
2002-01-22 21:15:52 +03:00
/**
* xmlGenericError :
*
* Global setting : function used for generic error callbacks
*/
2001-10-29 14:48:19 +03:00
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc ;
2003-05-16 02:11:36 +04:00
static xmlGenericErrorFunc xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc ;
2003-10-10 18:10:40 +04:00
/**
* xmlStructuredError :
*
* Global setting : function used for structured error callbacks
*/
xmlStructuredErrorFunc xmlStructuredError = NULL ;
static xmlStructuredErrorFunc xmlStructuredErrorThrDef = NULL ;
2002-01-22 21:15:52 +03:00
/**
* xmlGenericErrorContext :
*
* Global setting passed to generic error callbacks
*/
2001-10-12 21:29:10 +04:00
void * xmlGenericErrorContext = NULL ;
2003-05-16 02:11:36 +04:00
static void * xmlGenericErrorContextThrDef = NULL ;
2009-08-24 19:34:25 +04:00
/**
* xmlStructuredErrorContext :
*
* Global setting passed to structured error callbacks
*/
void * xmlStructuredErrorContext = NULL ;
static void * xmlStructuredErrorContextThrDef = NULL ;
2003-10-03 02:28:19 +04:00
xmlError xmlLastError ;
2001-10-12 21:29:10 +04:00
2023-09-20 18:54:48 +03:00
# ifdef LIBXML_OUTPUT_ENABLED
2001-10-12 21:29:10 +04:00
/*
* output defaults
*/
2002-01-22 21:15:52 +03:00
/**
* xmlIndentTreeOutput :
*
* Global setting , asking the serializer to indent the output tree by default
2002-05-24 11:18:40 +04:00
* Enabled by default
*/
int xmlIndentTreeOutput = 1 ;
2003-05-16 02:11:36 +04:00
static int xmlIndentTreeOutputThrDef = 1 ;
2002-05-24 11:18:40 +04:00
/**
* xmlTreeIndentString :
*
* The string used to do one - level indent . By default is equal to " " ( two spaces )
2002-01-22 21:15:52 +03:00
*/
2002-05-24 11:18:40 +04:00
const char * xmlTreeIndentString = " " ;
2003-05-16 02:11:36 +04:00
static const char * xmlTreeIndentStringThrDef = " " ;
2002-05-24 11:18:40 +04:00
2002-01-22 21:15:52 +03:00
/**
* xmlSaveNoEmptyTags :
*
* Global setting , asking the serializer to not output empty tags
2019-09-30 18:04:54 +03:00
* as < empty / > but < empty > < / empty > . those two forms are indistinguishable
2002-01-22 21:15:52 +03:00
* once parsed .
* Disabled by default
*/
2001-10-12 21:29:10 +04:00
int xmlSaveNoEmptyTags = 0 ;
2005-07-29 03:49:35 +04:00
static int xmlSaveNoEmptyTagsThrDef = 0 ;
2023-09-20 18:54:48 +03:00
# endif /* LIBXML_OUTPUT_ENABLED */
2001-10-12 21:29:10 +04:00
2003-09-30 04:43:48 +04:00
# ifdef LIBXML_SAX1_ENABLED
2002-01-22 21:15:52 +03:00
/**
* xmlDefaultSAXHandler :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : This handler is unused and will be removed from future
* versions .
*
2003-09-25 18:29:29 +04:00
* Default SAX version1 handler for XML , builds the DOM tree
2001-10-12 21:29:10 +04:00
*/
2023-12-06 03:09:31 +03:00
const xmlSAXHandlerV1 xmlDefaultSAXHandler = {
2003-08-21 02:54:39 +04:00
xmlSAX2InternalSubset ,
xmlSAX2IsStandalone ,
xmlSAX2HasInternalSubset ,
xmlSAX2HasExternalSubset ,
xmlSAX2ResolveEntity ,
xmlSAX2GetEntity ,
xmlSAX2EntityDecl ,
xmlSAX2NotationDecl ,
xmlSAX2AttributeDecl ,
xmlSAX2ElementDecl ,
xmlSAX2UnparsedEntityDecl ,
xmlSAX2SetDocumentLocator ,
xmlSAX2StartDocument ,
xmlSAX2EndDocument ,
xmlSAX2StartElement ,
xmlSAX2EndElement ,
xmlSAX2Reference ,
xmlSAX2Characters ,
xmlSAX2Characters ,
xmlSAX2ProcessingInstruction ,
xmlSAX2Comment ,
2001-10-12 21:29:10 +04:00
xmlParserWarning ,
xmlParserError ,
xmlParserError ,
2003-08-21 02:54:39 +04:00
xmlSAX2GetParameterEntity ,
xmlSAX2CDataBlock ,
xmlSAX2ExternalSubset ,
2022-11-24 18:38:47 +03:00
1 ,
2001-10-12 21:29:10 +04:00
} ;
2003-09-30 04:43:48 +04:00
# endif /* LIBXML_SAX1_ENABLED */
2001-10-12 21:29:10 +04:00
2002-01-22 21:15:52 +03:00
/**
* xmlDefaultSAXLocator :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : Don ' t use
*
2002-01-22 21:15:52 +03:00
* The default SAX Locator
* { getPublicId , getSystemId , getLineNumber , getColumnNumber }
2001-10-12 21:29:10 +04:00
*/
2023-12-06 03:09:31 +03:00
const xmlSAXLocator xmlDefaultSAXLocator = {
2003-08-21 02:54:39 +04:00
xmlSAX2GetPublicId ,
xmlSAX2GetSystemId ,
xmlSAX2GetLineNumber ,
xmlSAX2GetColumnNumber
2001-10-12 21:29:10 +04:00
} ;
2022-08-22 15:11:15 +03:00
# if defined(LIBXML_HTML_ENABLED) && defined(LIBXML_SAX1_ENABLED)
2002-01-22 21:15:52 +03:00
/**
* htmlDefaultSAXHandler :
*
2022-08-23 21:57:49 +03:00
* DEPRECATED : This handler is unused and will be removed from future
* versions .
*
2003-09-25 18:29:29 +04:00
* Default old SAX v1 handler for HTML , builds the DOM tree
2001-10-12 21:29:10 +04:00
*/
2023-12-06 03:09:31 +03:00
const xmlSAXHandlerV1 htmlDefaultSAXHandler = {
2003-08-21 02:54:39 +04:00
xmlSAX2InternalSubset ,
2001-10-12 21:29:10 +04:00
NULL ,
NULL ,
NULL ,
NULL ,
2003-08-21 02:54:39 +04:00
xmlSAX2GetEntity ,
2001-10-12 21:29:10 +04:00
NULL ,
NULL ,
NULL ,
NULL ,
NULL ,
2003-08-21 02:54:39 +04:00
xmlSAX2SetDocumentLocator ,
xmlSAX2StartDocument ,
xmlSAX2EndDocument ,
xmlSAX2StartElement ,
xmlSAX2EndElement ,
2001-10-12 21:29:10 +04:00
NULL ,
2003-08-21 02:54:39 +04:00
xmlSAX2Characters ,
xmlSAX2IgnorableWhitespace ,
2004-10-22 18:34:23 +04:00
xmlSAX2ProcessingInstruction ,
2003-08-21 02:54:39 +04:00
xmlSAX2Comment ,
2001-10-12 21:29:10 +04:00
xmlParserWarning ,
xmlParserError ,
xmlParserError ,
2022-11-24 18:38:47 +03:00
NULL ,
2003-08-21 02:54:39 +04:00
xmlSAX2CDataBlock ,
NULL ,
2022-11-24 18:38:47 +03:00
1 ,
2001-10-12 21:29:10 +04:00
} ;
# endif /* LIBXML_HTML_ENABLED */
2023-09-18 01:54:39 +03:00
/************************************************************************
* *
* Per thread global state handling *
* *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* xmlInitGlobals :
*
* DEPRECATED : Alias for xmlInitParser .
*/
void xmlInitGlobals ( void ) {
xmlInitParser ( ) ;
}
/**
* xmlInitGlobalsInternal :
*
* Additional initialisation for multi - threading
*/
void xmlInitGlobalsInternal ( void ) {
xmlInitMutex ( & xmlThrDefMutex ) ;
# ifdef HAVE_POSIX_THREADS
# ifdef XML_PTHREAD_WEAK
if ( libxml_is_threaded = = - 1 )
libxml_is_threaded =
( pthread_getspecific ! = NULL ) & &
( pthread_setspecific ! = NULL ) & &
( pthread_key_create ! = NULL ) & &
2023-11-18 22:21:45 +03:00
( pthread_key_delete ! = NULL ) & &
/*
* pthread_equal can be inline , resuting in - Waddress warnings .
* Let ' s assume it ' s available if all the other functions are .
*/
/* (pthread_equal != NULL) && */
( pthread_self ! = NULL ) ;
2023-09-18 01:54:39 +03:00
if ( libxml_is_threaded = = 0 )
return ;
# endif /* XML_PTHREAD_WEAK */
pthread_key_create ( & globalkey , xmlFreeGlobalState ) ;
2023-09-19 14:52:53 +03:00
mainthread = pthread_self ( ) ;
2023-09-18 01:54:39 +03:00
# elif defined(HAVE_WIN32_THREADS)
2023-09-22 14:37:28 +03:00
# ifndef USE_TLS
2023-09-18 01:54:39 +03:00
globalkey = TlsAlloc ( ) ;
# endif
2023-09-19 14:52:53 +03:00
mainthread = GetCurrentThreadId ( ) ;
2023-09-18 01:54:39 +03:00
# endif
2023-12-24 17:33:12 +03:00
# ifdef LIBXML_THREAD_ENABLED
xmlMainThreadRngState [ 0 ] = xmlGlobalRandom ( ) ;
xmlMainThreadRngState [ 1 ] = xmlGlobalRandom ( ) ;
# endif
2023-09-18 01:54:39 +03:00
}
/**
* xmlCleanupGlobals :
*
* DEPRECATED : This function is a no - op . Call xmlCleanupParser
* to free global state but see the warnings there . xmlCleanupParser
* should be only called once at program exit . In most cases , you don ' t
* have call cleanup functions at all .
*/
void xmlCleanupGlobals ( void ) {
}
/**
* xmlCleanupGlobalsInternal :
*
* Additional cleanup for multi - threading
*/
void xmlCleanupGlobalsInternal ( void ) {
xmlResetError ( & xmlLastError ) ;
xmlCleanupMutex ( & xmlThrDefMutex ) ;
# ifdef HAVE_POSIX_THREADS
# ifdef XML_PTHREAD_WEAK
if ( libxml_is_threaded = = 0 )
return ;
# endif /* XML_PTHREAD_WEAK */
pthread_key_delete ( globalkey ) ;
# elif defined(HAVE_WIN32_THREADS)
2023-09-22 14:37:28 +03:00
# ifndef USE_TLS
2023-09-18 01:54:39 +03:00
if ( globalkey ! = TLS_OUT_OF_INDEXES ) {
TlsFree ( globalkey ) ;
globalkey = TLS_OUT_OF_INDEXES ;
}
# endif
# endif
2023-09-27 18:22:17 +03:00
parserInitialized = 0 ;
2023-09-18 01:54:39 +03:00
}
2001-10-12 21:29:10 +04:00
/**
* xmlInitializeGlobalState :
* @ gs : a pointer to a newly allocated global state
*
2023-09-18 14:25:06 +03:00
* DEPRECATED : No - op .
2001-10-12 21:29:10 +04:00
*/
void
2023-09-18 14:25:06 +03:00
xmlInitializeGlobalState ( xmlGlobalStatePtr gs ATTRIBUTE_UNUSED )
{
}
/**
* xmlGetGlobalState :
*
2023-09-21 23:57:33 +03:00
* DEPRECATED
*
* Returns NULL .
2023-09-18 14:25:06 +03:00
*/
xmlGlobalStatePtr
xmlGetGlobalState ( void )
{
return ( NULL ) ;
}
2023-09-19 14:52:53 +03:00
static int
xmlIsMainThreadInternal ( void ) {
if ( parserInitialized = = 0 ) {
xmlInitParser ( ) ;
parserInitialized = 1 ;
}
# ifdef HAVE_POSIX_THREADS
# ifdef XML_PTHREAD_WEAK
if ( libxml_is_threaded = = 0 )
return ( 1 ) ;
# endif
return ( pthread_equal ( mainthread , pthread_self ( ) ) ) ;
# elif defined HAVE_WIN32_THREADS
return ( mainthread = = GetCurrentThreadId ( ) ) ;
# else
return ( 1 ) ;
# endif
}
/**
* xmlIsMainThread :
*
* DEPRECATED : Internal function , do not use .
*
* Check whether the current thread is the main thread .
*
* Returns 1 if the current thread is the main thread , 0 otherwise
*/
int
xmlIsMainThread ( void ) {
return ( xmlIsMainThreadInternal ( ) ) ;
}
2023-09-18 14:25:06 +03:00
# ifdef LIBXML_THREAD_ENABLED
2023-09-21 00:07:58 +03:00
2023-09-18 14:25:06 +03:00
static void
xmlFreeGlobalState ( void * state )
2001-10-12 21:29:10 +04:00
{
2023-09-18 14:25:06 +03:00
xmlGlobalState * gs = ( xmlGlobalState * ) state ;
2023-09-20 13:45:14 +03:00
/*
* Free any memory allocated in the thread ' s xmlLastError . If it
* weren ' t for this indirect allocation , we wouldn ' t need
* a destructor with thread - local storage at all !
*
* It would be nice if we could make xmlLastError a special error
* type which uses statically allocated , fixed - size buffers .
* But the xmlError struct is fully public and widely used ,
* so changes are dangerous .
*/
2023-09-18 14:25:06 +03:00
xmlResetError ( & ( gs - > gs_xmlLastError ) ) ;
2023-09-22 14:37:28 +03:00
# ifndef USE_TLS
2023-09-18 14:25:06 +03:00
free ( state ) ;
# endif
}
# if defined(HAVE_WIN32_THREADS) && \
defined ( LIBXML_STATIC ) & & ! defined ( LIBXML_STATIC_FOR_DLL )
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 /* LIBXML_STATIC */
static void
xmlInitGlobalState ( xmlGlobalStatePtr gs ) {
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2002-11-22 08:07:29 +03:00
2023-12-24 17:33:12 +03:00
# ifdef LIBXML_THREAD_ENABLED
gs - > localRngState [ 0 ] = xmlGlobalRandom ( ) ;
gs - > localRngState [ 1 ] = xmlGlobalRandom ( ) ;
# endif
2023-09-18 22:25:35 +03:00
gs - > gs_xmlBufferAllocScheme = xmlBufferAllocSchemeThrDef ;
gs - > gs_xmlDefaultBufferSize = xmlDefaultBufferSizeThrDef ;
gs - > gs_xmlDoValidityCheckingDefaultValue =
2003-05-16 02:11:36 +04:00
xmlDoValidityCheckingDefaultValueThrDef ;
2023-10-18 21:06:35 +03:00
# 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 ;
2001-10-12 21:29:10 +04:00
# endif
2023-09-18 22:25:35 +03:00
gs - > gs_xmlGetWarningsDefaultValue = xmlGetWarningsDefaultValueThrDef ;
2023-09-21 21:40:32 +03:00
# ifdef LIBXML_OUTPUT_ENABLED
2023-09-18 22:25:35 +03:00
gs - > gs_xmlIndentTreeOutput = xmlIndentTreeOutputThrDef ;
gs - > gs_xmlTreeIndentString = xmlTreeIndentStringThrDef ;
2023-09-21 21:40:32 +03:00
gs - > gs_xmlSaveNoEmptyTags = xmlSaveNoEmptyTagsThrDef ;
# endif
2023-09-18 22:25:35 +03:00
gs - > gs_xmlKeepBlanksDefaultValue = xmlKeepBlanksDefaultValueThrDef ;
gs - > gs_xmlLineNumbersDefaultValue = xmlLineNumbersDefaultValueThrDef ;
gs - > gs_xmlLoadExtDtdDefaultValue = xmlLoadExtDtdDefaultValueThrDef ;
gs - > gs_xmlPedanticParserDefaultValue = xmlPedanticParserDefaultValueThrDef ;
gs - > gs_xmlSubstituteEntitiesDefaultValue =
2003-05-16 02:11:36 +04:00
xmlSubstituteEntitiesDefaultValueThrDef ;
2023-09-18 22:25:35 +03:00
gs - > gs_xmlGenericError = xmlGenericErrorThrDef ;
gs - > gs_xmlStructuredError = xmlStructuredErrorThrDef ;
gs - > gs_xmlGenericErrorContext = xmlGenericErrorContextThrDef ;
gs - > gs_xmlStructuredErrorContext = xmlStructuredErrorContextThrDef ;
gs - > gs_xmlRegisterNodeDefaultValue = xmlRegisterNodeDefaultValueThrDef ;
gs - > gs_xmlDeregisterNodeDefaultValue = xmlDeregisterNodeDefaultValueThrDef ;
2004-06-02 20:18:40 +04:00
2023-09-18 22:25:35 +03:00
gs - > gs_xmlParserInputBufferCreateFilenameValue =
xmlParserInputBufferCreateFilenameValueThrDef ;
gs - > gs_xmlOutputBufferCreateFilenameValue =
xmlOutputBufferCreateFilenameValueThrDef ;
memset ( & gs - > gs_xmlLastError , 0 , sizeof ( xmlError ) ) ;
2003-01-01 23:59:38 +03:00
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2023-09-18 01:54:39 +03:00
2023-09-18 14:25:06 +03:00
# ifdef HAVE_POSIX_THREADS
pthread_setspecific ( globalkey , gs ) ;
# elif defined HAVE_WIN32_THREADS
2023-09-22 14:37:28 +03:00
# ifndef USE_TLS
2023-09-18 14:25:06 +03:00
TlsSetValue ( globalkey , gs ) ;
# endif
# if defined(LIBXML_STATIC) && !defined(LIBXML_STATIC_FOR_DLL)
xmlRegisterGlobalStateDtor ( gs ) ;
# endif
# endif
2023-09-19 14:17:00 +03:00
gs - > initialized = 1 ;
2022-11-24 22:52:57 +03:00
}
2023-09-22 14:37:28 +03:00
# ifndef USE_TLS
2022-11-24 22:52:57 +03:00
/**
2023-09-18 01:54:39 +03:00
* xmlNewGlobalState :
2022-03-06 15:55:48 +03:00
*
2023-09-18 01:54:39 +03:00
* xmlNewGlobalState ( ) allocates a global state . This structure is used to
* hold all data for use by a thread when supporting backwards compatibility
* of libxml2 to pre - thread - safe behaviour .
*
* Returns the newly allocated xmlGlobalStatePtr or NULL in case of error
2022-03-02 04:14:39 +03:00
*/
2023-09-18 01:54:39 +03:00
static xmlGlobalStatePtr
2023-09-20 14:30:01 +03:00
xmlNewGlobalState ( int allowFailure )
2023-09-18 01:54:39 +03:00
{
xmlGlobalState * gs ;
gs = malloc ( sizeof ( xmlGlobalState ) ) ;
2023-09-20 14:30:01 +03:00
if ( gs = = NULL ) {
if ( allowFailure )
return ( NULL ) ;
/*
* If an application didn ' t call xmlCheckThreadLocalStorage to make
* sure that global state could be allocated , it ' s too late to
* handle the error .
*/
fprintf ( stderr , " libxml2: Failed to allocate globals for thread \n "
" libxml2: See xmlCheckThreadLocalStorage \n " ) ;
abort ( ) ;
}
2023-09-18 01:54:39 +03:00
memset ( gs , 0 , sizeof ( xmlGlobalState ) ) ;
2023-09-18 14:25:06 +03:00
xmlInitGlobalState ( gs ) ;
2023-09-18 01:54:39 +03:00
return ( gs ) ;
}
2023-09-19 14:17:00 +03:00
# endif
2023-09-18 14:25:06 +03:00
static xmlGlobalStatePtr
2023-09-20 14:30:01 +03:00
xmlGetThreadLocalStorage ( int allowFailure ) {
2023-09-18 14:25:06 +03:00
xmlGlobalState * gs ;
2023-09-19 14:17:00 +03:00
2023-09-20 14:30:01 +03:00
( void ) allowFailure ;
2023-09-22 14:37:28 +03:00
# ifdef USE_TLS
2023-09-19 14:17:00 +03:00
gs = & globalState ;
if ( gs - > initialized = = 0 )
xmlInitGlobalState ( gs ) ;
# elif defined(HAVE_POSIX_THREADS)
2023-09-18 14:25:06 +03:00
gs = ( xmlGlobalState * ) pthread_getspecific ( globalkey ) ;
if ( gs = = NULL )
2023-09-20 14:30:01 +03:00
gs = xmlNewGlobalState ( allowFailure ) ;
2023-09-19 14:17:00 +03:00
# elif defined(HAVE_WIN32_THREADS)
2023-09-18 14:25:06 +03:00
gs = ( xmlGlobalState * ) TlsGetValue ( globalkey ) ;
if ( gs = = NULL )
2023-09-20 14:30:01 +03:00
gs = xmlNewGlobalState ( allowFailure ) ;
2023-09-18 14:25:06 +03:00
# else
2023-09-19 14:17:00 +03:00
gs = NULL ;
2023-09-18 14:25:06 +03:00
# endif
2023-09-19 14:17:00 +03:00
return ( gs ) ;
2023-09-18 14:25:06 +03:00
}
2023-09-21 00:07:58 +03:00
/* Define thread-local storage accessors with macro magic */
# define XML_DEFINE_GLOBAL_WRAPPER(name, type, attrs) \
type * __ # # name ( void ) { \
if ( IS_MAIN_THREAD ) \
return ( & name ) ; \
else \
return ( & xmlGetThreadLocalStorage ( 0 ) - > gs_ # # name ) ; \
}
# define XML_OP XML_DEFINE_GLOBAL_WRAPPER
XML_GLOBALS_ALLOC
XML_GLOBALS_ERROR
XML_GLOBALS_IO
XML_GLOBALS_PARSER
XML_GLOBALS_TREE
# undef XML_OP
2023-12-24 17:33:12 +03:00
# ifdef LIBXML_THREAD_ENABLED
unsigned *
xmlGetLocalRngState ( void ) {
if ( IS_MAIN_THREAD )
return ( xmlMainThreadRngState ) ;
else
return ( xmlGetThreadLocalStorage ( 0 ) - > localRngState ) ;
}
# endif
2023-09-21 00:07:58 +03:00
/* For backward compatibility */
const char * const *
__xmlParserVersion ( void ) {
return & xmlParserVersion ;
}
2023-12-06 03:09:31 +03:00
const int *
__oldXMLWDcompatibility ( void ) {
return & oldXMLWDcompatibility ;
}
2023-12-18 21:31:29 +03:00
const int *
__xmlParserDebugEntities ( void ) {
return & xmlParserDebugEntities ;
}
2023-12-06 03:09:31 +03:00
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 /* LIBXML_HTML_ENABLED */
# endif /* LIBXML_SAX1_ENABLED */
2023-09-18 01:54:39 +03:00
# endif /* LIBXML_THREAD_ENABLED */
2022-03-02 04:14:39 +03:00
2023-09-18 20:53:31 +03:00
/**
* xmlCheckThreadLocalStorage :
*
* Check whether thread - local storage could be allocated .
*
2023-09-20 13:45:14 +03:00
* In cross - platform code running in multithreaded environments , this
* function should be called once in each thread before calling other
* library functions to make sure that thread - local storage was
* allocated properly .
2023-09-18 20:53:31 +03:00
*
* Returns 0 on success or - 1 if a memory allocation failed . A failed
* allocation signals a typically fatal and irrecoverable out - of - memory
* situation . Don ' t call any library functions in this case .
*
2023-09-20 13:45:14 +03:00
* This function never fails if the library is compiled with support
* for thread - local storage .
*
2023-09-18 20:53:31 +03:00
* This function never fails for the " main " thread which is the first
* thread calling xmlInitParser .
*
* Available since v2 .12 .0 .
*/
int
xmlCheckThreadLocalStorage ( void ) {
2023-09-22 14:37:28 +03:00
# if defined(LIBXML_THREAD_ENABLED) && !defined(USE_TLS)
2023-09-20 14:30:01 +03:00
if ( ( ! xmlIsMainThreadInternal ( ) ) & & ( xmlGetThreadLocalStorage ( 1 ) = = NULL ) )
2023-09-18 14:25:06 +03:00
return ( - 1 ) ;
2023-09-18 01:54:39 +03:00
# endif
2023-09-18 14:25:06 +03:00
return ( 0 ) ;
2023-09-18 01:54:39 +03:00
}
/**
* DllMain :
* @ hinstDLL : handle to DLL instance
* @ fdwReason : Reason code for entry
* @ lpvReserved : generic pointer ( depends upon reason code )
*
* Entry point for Windows library . It is being used to free thread - specific
* storage .
*
* Returns TRUE always
*/
2023-09-21 00:07:58 +03:00
# if defined(HAVE_WIN32_THREADS) && \
( ! defined ( LIBXML_STATIC ) | | defined ( LIBXML_STATIC_FOR_DLL ) )
2023-09-18 01:54:39 +03:00
# if defined(LIBXML_STATIC_FOR_DLL)
int
xmlDllMain ( ATTRIBUTE_UNUSED void * hinstDLL , unsigned long fdwReason ,
ATTRIBUTE_UNUSED void * lpvReserved )
# else
/* declare to avoid "no previous prototype for 'DllMain'" warning */
/* Note that we do NOT want to include this function declaration in
a public header because it ' s meant to be called by Windows itself ,
not a program that uses this library . This also has to be exported . */
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 :
2023-09-22 14:37:28 +03:00
# ifdef USE_TLS
2023-09-19 14:17:00 +03:00
xmlFreeGlobalState ( & globalState ) ;
# else
2023-09-18 01:54:39 +03:00
if ( globalkey ! = TLS_OUT_OF_INDEXES ) {
2023-09-18 14:25:06 +03:00
xmlGlobalState * globalval ;
globalval = ( xmlGlobalState * ) TlsGetValue ( globalkey ) ;
2023-09-18 01:54:39 +03:00
if ( globalval ) {
xmlFreeGlobalState ( globalval ) ;
TlsSetValue ( globalkey , NULL ) ;
}
}
2023-09-19 14:17:00 +03:00
# endif
2023-09-18 01:54:39 +03:00
break ;
}
return TRUE ;
2022-03-02 04:14:39 +03:00
}
2023-09-18 01:54:39 +03:00
# endif
2022-03-02 04:14:39 +03:00
2003-05-16 02:11:36 +04:00
void
xmlThrDefSetGenericErrorFunc ( void * ctx , xmlGenericErrorFunc handler ) {
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
xmlGenericErrorContextThrDef = ctx ;
if ( handler ! = NULL )
xmlGenericErrorThrDef = handler ;
else
xmlGenericErrorThrDef = xmlGenericErrorDefaultFunc ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-01-01 23:59:38 +03:00
}
2003-10-10 18:10:40 +04:00
void
xmlThrDefSetStructuredErrorFunc ( void * ctx , xmlStructuredErrorFunc handler ) {
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2009-08-24 19:34:25 +04:00
xmlStructuredErrorContextThrDef = ctx ;
2003-10-10 18:10:40 +04:00
xmlStructuredErrorThrDef = handler ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-10-10 18:10:40 +04:00
}
2003-05-16 02:11:36 +04:00
xmlBufferAllocationScheme xmlThrDefBufferAllocScheme ( xmlBufferAllocationScheme v ) {
xmlBufferAllocationScheme ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlBufferAllocSchemeThrDef ;
xmlBufferAllocSchemeThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefDefaultBufferSize ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlDefaultBufferSizeThrDef ;
xmlDefaultBufferSizeThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefDoValidityCheckingDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlDoValidityCheckingDefaultValueThrDef ;
xmlDoValidityCheckingDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefGetWarningsDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlGetWarningsDefaultValueThrDef ;
xmlGetWarningsDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2023-09-20 18:54:48 +03:00
# ifdef LIBXML_OUTPUT_ENABLED
2003-05-16 02:11:36 +04:00
int xmlThrDefIndentTreeOutput ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlIndentTreeOutputThrDef ;
xmlIndentTreeOutputThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
const char * xmlThrDefTreeIndentString ( const char * v ) {
const char * ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlTreeIndentStringThrDef ;
xmlTreeIndentStringThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2002-05-24 11:18:40 +04:00
2023-09-20 18:54:48 +03:00
int xmlThrDefSaveNoEmptyTags ( int v ) {
int ret ;
xmlMutexLock ( & xmlThrDefMutex ) ;
ret = xmlSaveNoEmptyTagsThrDef ;
xmlSaveNoEmptyTagsThrDef = v ;
xmlMutexUnlock ( & xmlThrDefMutex ) ;
return ret ;
}
# endif
2003-05-16 02:11:36 +04:00
int xmlThrDefKeepBlanksDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlKeepBlanksDefaultValueThrDef ;
xmlKeepBlanksDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefLineNumbersDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlLineNumbersDefaultValueThrDef ;
xmlLineNumbersDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefLoadExtDtdDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlLoadExtDtdDefaultValueThrDef ;
xmlLoadExtDtdDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2023-12-18 21:31:29 +03:00
int xmlThrDefParserDebugEntities ( int v ATTRIBUTE_UNUSED ) {
return ( xmlParserDebugEntities ) ;
2003-05-16 02:11:36 +04:00
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefPedanticParserDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlPedanticParserDefaultValueThrDef ;
xmlPedanticParserDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2001-10-12 21:29:10 +04:00
2003-05-16 02:11:36 +04:00
int xmlThrDefSubstituteEntitiesDefaultValue ( int v ) {
int ret ;
2022-11-24 22:54:18 +03:00
xmlMutexLock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
ret = xmlSubstituteEntitiesDefaultValueThrDef ;
xmlSubstituteEntitiesDefaultValueThrDef = v ;
2022-11-24 22:54:18 +03:00
xmlMutexUnlock ( & xmlThrDefMutex ) ;
2003-05-16 02:11:36 +04:00
return ret ;
}
2003-01-01 23:59:38 +03:00
2023-09-18 22:25:35 +03:00
xmlRegisterNodeFunc
xmlThrDefRegisterNodeDefault ( xmlRegisterNodeFunc func )
{
xmlRegisterNodeFunc old ;
xmlMutexLock ( & xmlThrDefMutex ) ;
old = xmlRegisterNodeDefaultValueThrDef ;
__xmlRegisterCallbacks = 1 ;
xmlRegisterNodeDefaultValueThrDef = func ;
xmlMutexUnlock ( & xmlThrDefMutex ) ;
return ( old ) ;
2003-01-01 23:59:38 +03:00
}
2004-06-02 20:18:40 +04:00
2023-09-18 22:25:35 +03:00
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 ) ;
2004-06-03 06:11:24 +04:00
}
2005-04-01 17:11:58 +04:00