Initial revision
[TestXSLT.git] / libxml2 / globals.c
1 /*
2  * globals.c: definition and handling of the set of global variables
3  *            of the library
4  *
5  * The bottom of this file is automatically generated by build_glob.py
6  * based on the description file global.data
7  *
8  * See Copyright for the status of this software.
9  *
10  * Gary Pennington <Gary.Pennington@uk.sun.com>
11  * daniel@veillard.com
12  */
13
14 #define IN_LIBXML
15 #include "libxml.h"
16
17 #ifdef HAVE_STDLIB_H
18 #include <stdlib.h>
19 #endif
20 #include <string.h>
21
22 #include <libxml/globals.h>
23 #include <libxml/xmlmemory.h>
24
25 /* #define DEBUG_GLOBALS */
26
27 /*
28  * Helpful Macro
29  */
30 #ifdef LIBXML_THREAD_ENABLED
31 #define IS_MAIN_THREAD (xmlIsMainThread())
32 #else
33 #define IS_MAIN_THREAD 1
34 #endif
35
36 /************************************************************************
37  *                                                                      *
38  *      All the user accessible global variables of the library         *
39  *                                                                      *
40  ************************************************************************/
41
42 /*
43  * Memory allocation routines
44  */
45 #if defined(DEBUG_MEMORY_LOCATION) || defined(DEBUG_MEMORY)
46 extern void xmlMemFree(void *ptr);
47 extern void * xmlMemMalloc(size_t size);
48 extern void * xmlMemRealloc(void *ptr,size_t size);
49 extern char * xmlMemoryStrdup(const char *str);
50
51 xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
52 xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
53 xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
54 xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
55 #else
56 /**
57  * xmlFree:
58  * @mem: an already allocated block of memory
59  *
60  * The variable holding the libxml free() implementation
61  */
62 xmlFreeFunc xmlFree = (xmlFreeFunc) free;
63 /**
64  * xmlMalloc:
65  * @size:  the size requested in bytes
66  *
67  * The variable holding the libxml malloc() implementation
68  *
69  * Returns a pointer to the newly allocated block or NULL in case of error
70  */
71 xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
72 /**
73  * xmlRealloc:
74  * @mem: an already allocated block of memory
75  * @size:  the new size requested in bytes
76  *
77  * The variable holding the libxml realloc() implementation
78  *
79  * Returns a pointer to the newly reallocated block or NULL in case of error
80  */
81 xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
82 /**
83  * xmlMemStrdup:
84  * @str: a zero terminated string
85  *
86  * The variable holding the libxml strdup() implementation
87  *
88  * Returns the copy of the string or NULL in case of error
89  */
90 xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
91 #endif
92
93 #include <libxml/threads.h>
94 #include <libxml/globals.h>
95 #include <libxml/SAX.h>
96
97 #undef  docbDefaultSAXHandler
98 #undef  htmlDefaultSAXHandler
99 #undef  oldXMLWDcompatibility
100 #undef  xmlBufferAllocScheme
101 #undef  xmlDefaultBufferSize
102 #undef  xmlDefaultSAXHandler
103 #undef  xmlDefaultSAXLocator
104 #undef  xmlDoValidityCheckingDefaultValue
105 #undef  xmlGenericError
106 #undef  xmlGenericErrorContext
107 #undef  xmlGetWarningsDefaultValue
108 #undef  xmlIndentTreeOutput
109 #undef  xmlTreeIndentString
110 #undef  xmlKeepBlanksDefaultValue
111 #undef  xmlLineNumbersDefaultValue
112 #undef  xmlLoadExtDtdDefaultValue
113 #undef  xmlParserDebugEntities
114 #undef  xmlParserVersion
115 #undef  xmlPedanticParserDefaultValue
116 #undef  xmlSaveNoEmptyTags
117 #undef  xmlSubstituteEntitiesDefaultValue
118 #undef  xmlRegisterNodeDefaultValue
119 #undef  xmlDeregisterNodeDefaultValue
120
121 #undef  xmlFree
122 #undef  xmlMalloc
123 #undef  xmlMemStrdup
124 #undef  xmlRealloc
125
126 /**
127  * xmlParserVersion:
128  *
129  * Constant string describing the internal version of the library
130  */
131 const char *xmlParserVersion = LIBXML_VERSION_STRING;
132
133 /**
134  * xmlBufferAllocScheme:
135  *
136  * Global setting, default allocation policy for buffers, default is
137  * XML_BUFFER_ALLOC_EXACT
138  */
139 xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
140 /**
141  * xmlDefaultBufferSize:
142  *
143  * Global setting, default buffer size. Default value is BASE_BUFFER_SIZE
144  */
145 int xmlDefaultBufferSize = BASE_BUFFER_SIZE;
146
147 /*
148  * Parser defaults
149  */
150
151 /**
152  * oldXMLWDcompatibility:
153  *
154  * Global setting, DEPRECATED.
155  */
156 int oldXMLWDcompatibility = 0; /* DEPRECATED */
157 /**
158  * xmlParserDebugEntities:
159  *
160  * Global setting, asking the parser to print out debugging informations.
161  * while handling entities.
162  * Disabled by default
163  */
164 int xmlParserDebugEntities = 0;
165 /**
166  * xmlDoValidityCheckingDefaultValue:
167  *
168  * Global setting, indicate that the parser should work in validating mode.
169  * Disabled by default.
170  */
171 int xmlDoValidityCheckingDefaultValue = 0;
172 /**
173  * xmlGetWarningsDefaultValue:
174  *
175  * Global setting, indicate that the parser should provide warnings.
176  * Activated by default.
177  */
178 int xmlGetWarningsDefaultValue = 1;
179 /**
180  * xmlLoadExtDtdDefaultValue:
181  *
182  * Global setting, indicate that the parser should load DTD while not
183  * validating.
184  * Disabled by default.
185  */
186 int xmlLoadExtDtdDefaultValue = 0;
187 /**
188  * xmlPedanticParserDefaultValue:
189  *
190  * Global setting, indicate that the parser be pedantic
191  * Disabled by default.
192  */
193 int xmlPedanticParserDefaultValue = 0;
194 /**
195  * xmlLineNumbersDefaultValue:
196  *
197  * Global setting, indicate that the parser should store the line number
198  * in the content field of elements in the DOM tree. 
199  * Disabled by default since this may not be safe for old classes of
200  * applicaton.
201  */
202 int xmlLineNumbersDefaultValue = 0;
203 /**
204  * xmlKeepBlanksDefaultValue:
205  *
206  * Global setting, indicate that the parser should keep all blanks
207  * nodes found in the content
208  * Activated by default, this is actually needed to have the parser
209  * conformant to the XML Recommendation, however the option is kept
210  * for some applications since this was libxml1 default behaviour.
211  */
212 int xmlKeepBlanksDefaultValue = 1;
213 /**
214  * xmlSubstituteEntitiesDefaultValue:
215  *
216  * Global setting, indicate that the parser should not generate entity
217  * references but replace them with the actual content of the entity
218  * Disabled by default, this should be activated when using XPath since
219  * the XPath data model requires entities replacement and the XPath
220  * engine does not handle entities references transparently.
221  */
222 int xmlSubstituteEntitiesDefaultValue = 0;
223
224 xmlRegisterNodeFunc xmlRegisterNodeDefaultValue = NULL;
225 xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue = NULL;
226
227 /*
228  * Error handling
229  */
230
231 /* xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; */
232 /* Must initialize xmlGenericError in xmlInitParser */
233 void xmlGenericErrorDefaultFunc (void *ctx ATTRIBUTE_UNUSED,
234                                  const char *msg,
235                                  ...);
236 /**
237  * xmlGenericError:
238  *
239  * Global setting: function used for generic error callbacks
240  */
241 xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
242 /**
243  * xmlGenericErrorContext:
244  *
245  * Global setting passed to generic error callbacks
246  */
247 void *xmlGenericErrorContext = NULL;
248
249 /*
250  * output defaults
251  */
252 /**
253  * xmlIndentTreeOutput:
254  *
255  * Global setting, asking the serializer to indent the output tree by default
256  * Enabled by default
257  */
258 int xmlIndentTreeOutput = 1;
259
260 /**
261  * xmlTreeIndentString:
262  *
263  * The string used to do one-level indent. By default is equal to "  " (two spaces)
264  */
265 const char *xmlTreeIndentString = "  ";
266
267 /**
268  * xmlSaveNoEmptyTags:
269  *
270  * Global setting, asking the serializer to not output empty tags
271  * as <empty/> but <empty></empty>. those two forms are undistinguishable
272  * once parsed.
273  * Disabled by default
274  */
275 int xmlSaveNoEmptyTags = 0;
276
277 /**
278  * xmlDefaultSAXHandler:
279  *
280  * Default handler for XML, builds the DOM tree
281  */
282 xmlSAXHandler xmlDefaultSAXHandler = {
283     internalSubset,
284     isStandalone,
285     hasInternalSubset,
286     hasExternalSubset,
287     resolveEntity,
288     getEntity,
289     entityDecl,
290     notationDecl,
291     attributeDecl,
292     elementDecl,
293     unparsedEntityDecl,
294     setDocumentLocator,
295     startDocument,
296     endDocument,
297     startElement,
298     endElement,
299     reference,
300     characters,
301     characters,
302     processingInstruction,
303     comment,
304     xmlParserWarning,
305     xmlParserError,
306     xmlParserError,
307     getParameterEntity,
308     cdataBlock,
309     externalSubset,
310     0
311 };
312
313 /**
314  * xmlDefaultSAXLocator:
315  *
316  * The default SAX Locator
317  * { getPublicId, getSystemId, getLineNumber, getColumnNumber}
318  */
319 xmlSAXLocator xmlDefaultSAXLocator = {
320     getPublicId, getSystemId, getLineNumber, getColumnNumber
321 };
322
323 #ifdef LIBXML_HTML_ENABLED
324 /**
325  * htmlDefaultSAXHandler:
326  *
327  * Default handler for HTML, builds the DOM tree
328  */
329 xmlSAXHandler htmlDefaultSAXHandler = {
330     internalSubset,
331     NULL,
332     NULL,
333     NULL,
334     NULL,
335     getEntity,
336     NULL,
337     NULL,
338     NULL,
339     NULL,
340     NULL,
341     setDocumentLocator,
342     startDocument,
343     endDocument,
344     startElement,
345     endElement,
346     NULL,
347     characters,
348     ignorableWhitespace,
349     NULL,
350     comment,
351     xmlParserWarning,
352     xmlParserError,
353     xmlParserError,
354     getParameterEntity,
355     cdataBlock,
356     NULL,
357     0
358 };
359 #endif /* LIBXML_HTML_ENABLED */
360
361 #ifdef LIBXML_DOCB_ENABLED
362 /**
363  * docbDefaultSAXHandler:
364  *
365  * Default handler for SGML DocBook, builds the DOM tree
366  */
367 xmlSAXHandler docbDefaultSAXHandler = {
368     internalSubset,
369     isStandalone,
370     hasInternalSubset,
371     hasExternalSubset,
372     resolveEntity,
373     getEntity,
374     entityDecl,
375     NULL,
376     NULL,
377     NULL,
378     NULL,
379     setDocumentLocator,
380     startDocument,
381     endDocument,
382     startElement,
383     endElement,
384     reference,
385     characters,
386     ignorableWhitespace,
387     NULL,
388     comment,
389     xmlParserWarning,
390     xmlParserError,
391     xmlParserError,
392     getParameterEntity,
393     NULL,
394     NULL,
395     0
396 };
397 #endif /* LIBXML_DOCB_ENABLED */
398
399 /**
400  * xmlInitializeGlobalState:
401  * @gs: a pointer to a newly allocated global state
402  *
403  * xmlInitializeGlobalState() initialize a global state with all the
404  * default values of the library.
405  */
406 void
407 xmlInitializeGlobalState(xmlGlobalStatePtr gs)
408 {
409 #ifdef DEBUG_GLOBALS
410     fprintf(stderr, "Initializing globals at %lu for thread %d\n",
411             (unsigned long) gs, xmlGetThreadId());
412 #endif
413
414     /*
415      * Perform initialization as required by libxml
416      */
417
418 #ifdef LIBXML_DOCB_ENABLED
419     initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
420 #endif
421 #ifdef LIBXML_HTML_ENABLED
422     inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
423 #endif
424     initGenericErrorDefaultFunc(&gs->xmlGenericError);
425
426     gs->oldXMLWDcompatibility = 0;
427     gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
428     gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
429     initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
430     gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
431     gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
432     gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
433     gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
434     gs->xmlDoValidityCheckingDefaultValue = 0;
435 #if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
436     gs->xmlFree = (xmlFreeFunc) xmlMemFree;
437     gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
438     gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
439     gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
440 #else
441     gs->xmlFree = (xmlFreeFunc) free;
442     gs->xmlMalloc = (xmlMallocFunc) malloc;
443     gs->xmlRealloc = (xmlReallocFunc) realloc;
444     gs->xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
445 #endif
446     gs->xmlGenericErrorContext = NULL;
447     gs->xmlGetWarningsDefaultValue = 1;
448     gs->xmlIndentTreeOutput = 1;
449     gs->xmlTreeIndentString = "  ";
450     gs->xmlKeepBlanksDefaultValue = 1;
451     gs->xmlLineNumbersDefaultValue = 0;
452     gs->xmlLoadExtDtdDefaultValue = 0;
453     gs->xmlParserDebugEntities = 0;
454     gs->xmlParserVersion = LIBXML_VERSION_STRING;
455     gs->xmlPedanticParserDefaultValue = 0;
456     gs->xmlSaveNoEmptyTags = 0;
457     gs->xmlSubstituteEntitiesDefaultValue = 0;
458
459     gs->xmlRegisterNodeDefaultValue = NULL;
460     gs->xmlDeregisterNodeDefaultValue = NULL;
461 }
462
463 /**
464  * xmlRegisterNodeDefault:
465  * @func: function pointer to the new RegisterNodeFunc
466  *
467  * Registers a callback for node creation
468  *
469  * Returns the old value of the registration function
470  */
471 xmlRegisterNodeFunc
472 xmlRegisterNodeDefault(xmlRegisterNodeFunc func)
473 {
474     xmlRegisterNodeFunc old = xmlRegisterNodeDefaultValue;
475     
476     xmlRegisterNodeDefaultValue = func;
477     return(old);
478 }
479
480 /**
481  * xmlDeregisterNodeDefault:
482  * @func: function pointer to the new DeregisterNodeFunc
483  *
484  * Registers a callback for node destruction
485  *
486  * Returns the previous value of the deregistration function
487  */
488 xmlDeregisterNodeFunc
489 xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func)
490 {
491     xmlDeregisterNodeFunc old = xmlDeregisterNodeDefaultValue;
492     
493     xmlDeregisterNodeDefaultValue = func;
494     return(old);
495 }
496
497
498 #ifdef LIBXML_DOCB_ENABLED
499 #undef  docbDefaultSAXHandler
500 xmlSAXHandler *
501 __docbDefaultSAXHandler(void) {
502     if (IS_MAIN_THREAD)
503         return (&docbDefaultSAXHandler);
504     else
505         return (&xmlGetGlobalState()->docbDefaultSAXHandler);
506 }
507 #endif
508
509 #ifdef LIBXML_HTML_ENABLED
510 #undef  htmlDefaultSAXHandler
511 xmlSAXHandler *
512 __htmlDefaultSAXHandler(void) {
513     if (IS_MAIN_THREAD)
514         return (&htmlDefaultSAXHandler);
515     else
516         return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
517 }
518 #endif
519
520 /*
521  * Everything starting from the line below is
522  * Automatically generated by build_glob.py.
523  * Do not modify the previous line.
524  */
525
526
527 #undef  oldXMLWDcompatibility
528 int *
529 __oldXMLWDcompatibility(void) {
530     if (IS_MAIN_THREAD)
531         return (&oldXMLWDcompatibility);
532     else
533         return (&xmlGetGlobalState()->oldXMLWDcompatibility);
534 }
535
536 #undef  xmlBufferAllocScheme
537 xmlBufferAllocationScheme *
538 __xmlBufferAllocScheme(void) {
539     if (IS_MAIN_THREAD)
540         return (&xmlBufferAllocScheme);
541     else
542         return (&xmlGetGlobalState()->xmlBufferAllocScheme);
543 }
544
545 #undef  xmlDefaultBufferSize
546 int *
547 __xmlDefaultBufferSize(void) {
548     if (IS_MAIN_THREAD)
549         return (&xmlDefaultBufferSize);
550     else
551         return (&xmlGetGlobalState()->xmlDefaultBufferSize);
552 }
553
554 #undef  xmlDefaultSAXHandler
555 xmlSAXHandler *
556 __xmlDefaultSAXHandler(void) {
557     if (IS_MAIN_THREAD)
558         return (&xmlDefaultSAXHandler);
559     else
560         return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
561 }
562
563 #undef  xmlDefaultSAXLocator
564 xmlSAXLocator *
565 __xmlDefaultSAXLocator(void) {
566     if (IS_MAIN_THREAD)
567         return (&xmlDefaultSAXLocator);
568     else
569         return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
570 }
571
572 #undef  xmlDoValidityCheckingDefaultValue
573 int *
574 __xmlDoValidityCheckingDefaultValue(void) {
575     if (IS_MAIN_THREAD)
576         return (&xmlDoValidityCheckingDefaultValue);
577     else
578         return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
579 }
580
581 #undef  xmlGenericError
582 xmlGenericErrorFunc *
583 __xmlGenericError(void) {
584     if (IS_MAIN_THREAD)
585         return (&xmlGenericError);
586     else
587         return (&xmlGetGlobalState()->xmlGenericError);
588 }
589
590 #undef  xmlGenericErrorContext
591 void * *
592 __xmlGenericErrorContext(void) {
593     if (IS_MAIN_THREAD)
594         return (&xmlGenericErrorContext);
595     else
596         return (&xmlGetGlobalState()->xmlGenericErrorContext);
597 }
598
599 #undef  xmlGetWarningsDefaultValue
600 int *
601 __xmlGetWarningsDefaultValue(void) {
602     if (IS_MAIN_THREAD)
603         return (&xmlGetWarningsDefaultValue);
604     else
605         return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
606 }
607
608 #undef  xmlIndentTreeOutput
609 int *
610 __xmlIndentTreeOutput(void) {
611     if (IS_MAIN_THREAD)
612         return (&xmlIndentTreeOutput);
613     else
614         return (&xmlGetGlobalState()->xmlIndentTreeOutput);
615 }
616
617 #undef xmlTreeIndentString
618 const char * *
619 __xmlTreeIndentString(void) {
620     if (IS_MAIN_THREAD)
621         return (&xmlTreeIndentString);
622     else
623         return (&xmlGetGlobalState()->xmlTreeIndentString);
624 }
625
626 #undef  xmlKeepBlanksDefaultValue
627 int *
628 __xmlKeepBlanksDefaultValue(void) {
629     if (IS_MAIN_THREAD)
630         return (&xmlKeepBlanksDefaultValue);
631     else
632         return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
633 }
634
635 #undef  xmlLineNumbersDefaultValue
636 int *
637 __xmlLineNumbersDefaultValue(void) {
638     if (IS_MAIN_THREAD)
639         return (&xmlLineNumbersDefaultValue);
640     else
641         return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
642 }
643
644 #undef  xmlLoadExtDtdDefaultValue
645 int *
646 __xmlLoadExtDtdDefaultValue(void) {
647     if (IS_MAIN_THREAD)
648         return (&xmlLoadExtDtdDefaultValue);
649     else
650         return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
651 }
652
653 #undef  xmlParserDebugEntities
654 int *
655 __xmlParserDebugEntities(void) {
656     if (IS_MAIN_THREAD)
657         return (&xmlParserDebugEntities);
658     else
659         return (&xmlGetGlobalState()->xmlParserDebugEntities);
660 }
661
662 #undef  xmlParserVersion
663 const char * *
664 __xmlParserVersion(void) {
665     if (IS_MAIN_THREAD)
666         return (&xmlParserVersion);
667     else
668         return (&xmlGetGlobalState()->xmlParserVersion);
669 }
670
671 #undef  xmlPedanticParserDefaultValue
672 int *
673 __xmlPedanticParserDefaultValue(void) {
674     if (IS_MAIN_THREAD)
675         return (&xmlPedanticParserDefaultValue);
676     else
677         return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
678 }
679
680 #undef  xmlSaveNoEmptyTags
681 int *
682 __xmlSaveNoEmptyTags(void) {
683     if (IS_MAIN_THREAD)
684         return (&xmlSaveNoEmptyTags);
685     else
686         return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
687 }
688
689 #undef  xmlSubstituteEntitiesDefaultValue
690 int *
691 __xmlSubstituteEntitiesDefaultValue(void) {
692     if (IS_MAIN_THREAD)
693         return (&xmlSubstituteEntitiesDefaultValue);
694     else
695         return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
696 }
697
698 #undef  xmlRegisterNodeDefaultValue
699 xmlRegisterNodeFunc *
700 __xmlRegisterNodeDefaultValue(void) {
701     if (IS_MAIN_THREAD)
702         return (&xmlRegisterNodeDefaultValue);
703     else
704         return (&xmlGetGlobalState()->xmlRegisterNodeDefaultValue);
705 }
706
707 #undef  xmlDeregisterNodeDefaultValue
708 xmlDeregisterNodeFunc *
709 __xmlDeregisterNodeDefaultValue(void) {
710     if (IS_MAIN_THREAD)
711         return (&xmlDeregisterNodeDefaultValue);
712     else
713         return (&xmlGetGlobalState()->xmlDeregisterNodeDefaultValue);
714 }