globals.c 15 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/*
 * globals.c: definition and handling of the set of global variables
 *            of the library
 *
 * The bottom of this file is automatically generated by build_glob.py
 * based on the description file global.data
 *
 * See Copyright for the status of this software.
 *
 * Gary Pennington <Gary.Pennington@uk.sun.com>
 * daniel@veillard.com
 */

14
#define IN_LIBXML
15 16
#include "libxml.h"

17
#ifdef HAVE_STDLIB_H
18
#include <stdlib.h>
19
#endif
20 21
#include <string.h>

22
#include <libxml/globals.h>
23 24
#include <libxml/xmlmemory.h>

25 26
/* #define DEBUG_GLOBALS */

27 28 29
/*
 * Helpful Macro
 */
30 31
#ifdef LIBXML_THREAD_ENABLED
#define IS_MAIN_THREAD (xmlIsMainThread())
32 33 34 35 36 37 38 39 40 41 42 43 44 45
#else
#define IS_MAIN_THREAD 1
#endif

/************************************************************************
 * 									*
 *	All the user accessible global variables of the library		*
 * 									*
 ************************************************************************/

/*
 * Memory allocation routines
 */
#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
46 47 48 49 50
extern void xmlMemFree(void *ptr);
extern void * xmlMemMalloc(size_t size);
extern void * xmlMemRealloc(void *ptr,size_t size);
extern char * xmlMemoryStrdup(const char *str);

51 52 53 54 55
xmlFreeFunc xmlFree = (xmlFreeFunc) xmlMemFree;
xmlMallocFunc xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
xmlReallocFunc xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
#else
56 57 58 59 60 61
/**
 * xmlFree:
 * @mem: an already allocated block of memory
 *
 * The variable holding the libxml free() implementation
 */
62
xmlFreeFunc xmlFree = (xmlFreeFunc) free;
63 64 65 66 67 68 69 70
/**
 * 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
 */
71
xmlMallocFunc xmlMalloc = (xmlMallocFunc) malloc;
72 73 74 75 76 77 78 79 80
/**
 * 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
 */
81
xmlReallocFunc xmlRealloc = (xmlReallocFunc) realloc;
82 83 84 85 86 87 88 89
/**
 * 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
 */
90
xmlStrdupFunc xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
91 92
#endif

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
#include <libxml/threads.h>
#include <libxml/globals.h>
#include <libxml/SAX.h>

#undef	docbDefaultSAXHandler
#undef	htmlDefaultSAXHandler
#undef	oldXMLWDcompatibility
#undef	xmlBufferAllocScheme
#undef	xmlDefaultBufferSize
#undef	xmlDefaultSAXHandler
#undef	xmlDefaultSAXLocator
#undef	xmlDoValidityCheckingDefaultValue
#undef	xmlGenericError
#undef	xmlGenericErrorContext
#undef	xmlGetWarningsDefaultValue
#undef	xmlIndentTreeOutput
#undef	xmlKeepBlanksDefaultValue
#undef	xmlLineNumbersDefaultValue
#undef	xmlLoadExtDtdDefaultValue
#undef	xmlParserDebugEntities
#undef	xmlParserVersion
#undef	xmlPedanticParserDefaultValue
#undef	xmlSaveNoEmptyTags
#undef	xmlSubstituteEntitiesDefaultValue

#undef	xmlFree
#undef	xmlMalloc
#undef	xmlMemStrdup
#undef	xmlRealloc

123 124 125 126 127
/**
 * xmlParserVersion:
 *
 * Constant string describing the internal version of the library
 */
128 129
const char *xmlParserVersion = LIBXML_VERSION_STRING;

130 131 132 133 134
/**
 * xmlBufferAllocScheme:
 *
 * Global setting, default allocation policy for buffers, default is
 * XML_BUFFER_ALLOC_EXACT
135 136
 */
xmlBufferAllocationScheme xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
137 138 139 140 141
/**
 * xmlDefaultBufferSize:
 *
 * Global setting, default buffer size. Default value is BASE_BUFFER_SIZE
 */
142 143 144 145 146
int xmlDefaultBufferSize = BASE_BUFFER_SIZE;

/*
 * Parser defaults
 */
147

148 149 150 151 152
/**
 * oldXMLWDcompatibility:
 *
 * Global setting, DEPRECATED.
 */
153
int oldXMLWDcompatibility = 0; /* DEPRECATED */
154 155 156 157 158 159 160
/**
 * xmlParserDebugEntities:
 *
 * Global setting, asking the parser to print out debugging informations.
 * while handling entities.
 * Disabled by default
 */
161
int xmlParserDebugEntities = 0;
162 163 164 165 166 167
/**
 * xmlDoValidityCheckingDefaultValue:
 *
 * Global setting, indicate that the parser should work in validating mode.
 * Disabled by default.
 */
168
int xmlDoValidityCheckingDefaultValue = 0;
169 170 171 172 173 174
/**
 * xmlGetWarningsDefaultValue:
 *
 * Global setting, indicate that the parser should provide warnings.
 * Activated by default.
 */
175
int xmlGetWarningsDefaultValue = 1;
176 177 178 179 180 181 182
/**
 * xmlLoadExtDtdDefaultValue:
 *
 * Global setting, indicate that the parser should load DTD while not
 * validating.
 * Disabled by default.
 */
183
int xmlLoadExtDtdDefaultValue = 0;
184 185 186 187 188 189
/**
 * xmlPedanticParserDefaultValue:
 *
 * Global setting, indicate that the parser be pedantic
 * Disabled by default.
 */
190
int xmlPedanticParserDefaultValue = 0;
191 192 193 194 195 196 197 198
/**
 * xmlLineNumbersDefaultValue:
 *
 * Global setting, indicate that the parser should store the line number
 * in the content field of elements in the DOM tree. 
 * Disabled by default since this may not be safe for old classes of
 * applicaton.
 */
199
int xmlLineNumbersDefaultValue = 0;
200 201 202 203 204 205 206 207 208
/**
 * xmlKeepBlanksDefaultValue:
 *
 * 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.
 */
209
int xmlKeepBlanksDefaultValue = 1;
210 211 212 213 214 215 216 217 218
/**
 * xmlSubstituteEntitiesDefaultValue:
 *
 * 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.
 */
219 220 221 222 223 224 225 226
int xmlSubstituteEntitiesDefaultValue = 0;

/*
 * Error handling
 */

/* xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc; */
/* Must initialize xmlGenericError in xmlInitParser */
227 228 229
void xmlGenericErrorDefaultFunc	(void *ctx ATTRIBUTE_UNUSED,
				 const char *msg,
				 ...);
230 231 232 233 234
/**
 * xmlGenericError:
 *
 * Global setting: function used for generic error callbacks
 */
235
xmlGenericErrorFunc xmlGenericError = xmlGenericErrorDefaultFunc;
236 237 238 239 240
/**
 * xmlGenericErrorContext:
 *
 * Global setting passed to generic error callbacks
 */
241 242 243 244 245
void *xmlGenericErrorContext = NULL;

/*
 * output defaults
 */
246 247 248 249 250 251
/**
 * xmlIndentTreeOutput:
 *
 * Global setting, asking the serializer to indent the output tree by default
 * Disabled by default
 */
252
int xmlIndentTreeOutput = 0;
253 254 255 256 257 258 259 260
/**
 * xmlSaveNoEmptyTags:
 *
 * Global setting, asking the serializer to not output empty tags
 * as <empty/> but <empty></empty>. those two forms are undistinguishable
 * once parsed.
 * Disabled by default
 */
261 262
int xmlSaveNoEmptyTags = 0;

263 264 265
/**
 * xmlDefaultSAXHandler:
 *
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
 * Default handler for XML, builds the DOM tree
 */
xmlSAXHandler xmlDefaultSAXHandler = {
    internalSubset,
    isStandalone,
    hasInternalSubset,
    hasExternalSubset,
    resolveEntity,
    getEntity,
    entityDecl,
    notationDecl,
    attributeDecl,
    elementDecl,
    unparsedEntityDecl,
    setDocumentLocator,
    startDocument,
    endDocument,
    startElement,
    endElement,
    reference,
    characters,
    characters,
    processingInstruction,
    comment,
    xmlParserWarning,
    xmlParserError,
    xmlParserError,
    getParameterEntity,
    cdataBlock,
    externalSubset,
    0
};

299 300 301 302 303
/**
 * xmlDefaultSAXLocator:
 *
 * The default SAX Locator
 * { getPublicId, getSystemId, getLineNumber, getColumnNumber}
304 305 306 307 308 309
 */
xmlSAXLocator xmlDefaultSAXLocator = {
    getPublicId, getSystemId, getLineNumber, getColumnNumber
};

#ifdef LIBXML_HTML_ENABLED
310 311 312
/**
 * htmlDefaultSAXHandler:
 *
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
 * Default handler for HTML, builds the DOM tree
 */
xmlSAXHandler htmlDefaultSAXHandler = {
    internalSubset,
    NULL,
    NULL,
    NULL,
    NULL,
    getEntity,
    NULL,
    NULL,
    NULL,
    NULL,
    NULL,
    setDocumentLocator,
    startDocument,
    endDocument,
    startElement,
    endElement,
    NULL,
    characters,
    ignorableWhitespace,
    NULL,
    comment,
    xmlParserWarning,
    xmlParserError,
    xmlParserError,
    getParameterEntity,
    cdataBlock,
    NULL,
    0
};
#endif /* LIBXML_HTML_ENABLED */

#ifdef LIBXML_DOCB_ENABLED
348 349 350
/**
 * docbDefaultSAXHandler:
 *
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394
 * Default handler for SGML DocBook, builds the DOM tree
 */
xmlSAXHandler docbDefaultSAXHandler = {
    internalSubset,
    isStandalone,
    hasInternalSubset,
    hasExternalSubset,
    resolveEntity,
    getEntity,
    entityDecl,
    NULL,
    NULL,
    NULL,
    NULL,
    setDocumentLocator,
    startDocument,
    endDocument,
    startElement,
    endElement,
    reference,
    characters,
    ignorableWhitespace,
    NULL,
    comment,
    xmlParserWarning,
    xmlParserError,
    xmlParserError,
    getParameterEntity,
    NULL,
    NULL,
    0
};
#endif /* LIBXML_DOCB_ENABLED */

/**
 * xmlInitializeGlobalState:
 * @gs: a pointer to a newly allocated global state
 *
 * xmlInitializeGlobalState() initialize a global state with all the
 * default values of the library.
 */
void
xmlInitializeGlobalState(xmlGlobalStatePtr gs)
{
395 396 397 398 399
#ifdef DEBUG_GLOBALS
    fprintf(stderr, "Initializing globals at %lu for thread %d\n",
	    (unsigned long) gs, xmlGetThreadId());
#endif

400
    /*
401
     * Perform initialization as required by libxml
402
     */
403
    initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
404
#ifdef LIBXML_DOCB_ENABLED
405
    initdocbDefaultSAXHandler(&gs->docbDefaultSAXHandler);
406 407
#endif
#ifdef LIBXML_HTML_ENABLED
408
    inithtmlDefaultSAXHandler(&gs->htmlDefaultSAXHandler);
409
#endif
410 411
    initGenericErrorDefaultFunc(&gs->xmlGenericError);

412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429
    gs->oldXMLWDcompatibility = 0;
    gs->xmlBufferAllocScheme = XML_BUFFER_ALLOC_EXACT;
    gs->xmlDefaultBufferSize = BASE_BUFFER_SIZE;
    initxmlDefaultSAXHandler(&gs->xmlDefaultSAXHandler, 1);
    gs->xmlDefaultSAXLocator.getPublicId = getPublicId;
    gs->xmlDefaultSAXLocator.getSystemId = getSystemId;
    gs->xmlDefaultSAXLocator.getLineNumber = getLineNumber;
    gs->xmlDefaultSAXLocator.getColumnNumber = getColumnNumber;
    gs->xmlDoValidityCheckingDefaultValue = 0;
#if defined(DEBUG_MEMORY_LOCATION) | defined(DEBUG_MEMORY)
    gs->xmlFree = (xmlFreeFunc) xmlMemFree;
    gs->xmlMalloc = (xmlMallocFunc) xmlMemMalloc;
    gs->xmlRealloc = (xmlReallocFunc) xmlMemRealloc;
    gs->xmlMemStrdup = (xmlStrdupFunc) xmlMemoryStrdup;
#else
    gs->xmlFree = (xmlFreeFunc) free;
    gs->xmlMalloc = (xmlMallocFunc) malloc;
    gs->xmlRealloc = (xmlReallocFunc) realloc;
430
    gs->xmlMemStrdup = (xmlStrdupFunc) xmlStrdup;
431 432 433 434 435 436 437 438 439 440 441 442 443 444
#endif
    gs->xmlGenericErrorContext = NULL;
    gs->xmlGetWarningsDefaultValue = 1;
    gs->xmlIndentTreeOutput = 0;
    gs->xmlKeepBlanksDefaultValue = 1;
    gs->xmlLineNumbersDefaultValue = 0;
    gs->xmlLoadExtDtdDefaultValue = 0;
    gs->xmlParserDebugEntities = 0;
    gs->xmlParserVersion = LIBXML_VERSION_STRING;
    gs->xmlPedanticParserDefaultValue = 0;
    gs->xmlSaveNoEmptyTags = 0;
    gs->xmlSubstituteEntitiesDefaultValue = 0;
}

445
#ifdef LIBXML_DOCB_ENABLED
446 447 448 449 450 451
#undef	docbDefaultSAXHandler
xmlSAXHandler *
__docbDefaultSAXHandler(void) {
    if (IS_MAIN_THREAD)
	return (&docbDefaultSAXHandler);
    else
452
	return (&xmlGetGlobalState()->docbDefaultSAXHandler);
453
}
454
#endif
455

456
#ifdef LIBXML_HTML_ENABLED
457 458 459 460 461 462
#undef	htmlDefaultSAXHandler
xmlSAXHandler *
__htmlDefaultSAXHandler(void) {
    if (IS_MAIN_THREAD)
	return (&htmlDefaultSAXHandler);
    else
463
	return (&xmlGetGlobalState()->htmlDefaultSAXHandler);
464
}
465 466 467 468 469 470 471 472
#endif

/*
 * Everything starting from the line below is
 * Automatically generated by build_glob.py.
 * Do not modify the previous line.
 */

473 474 475 476 477 478 479

#undef	oldXMLWDcompatibility
int *
__oldXMLWDcompatibility(void) {
    if (IS_MAIN_THREAD)
	return (&oldXMLWDcompatibility);
    else
480
	return (&xmlGetGlobalState()->oldXMLWDcompatibility);
481 482 483 484 485 486 487 488
}

#undef	xmlBufferAllocScheme
xmlBufferAllocationScheme *
__xmlBufferAllocScheme(void) {
    if (IS_MAIN_THREAD)
	return (&xmlBufferAllocScheme);
    else
489
	return (&xmlGetGlobalState()->xmlBufferAllocScheme);
490 491 492 493 494 495 496 497
}

#undef	xmlDefaultBufferSize
int *
__xmlDefaultBufferSize(void) {
    if (IS_MAIN_THREAD)
	return (&xmlDefaultBufferSize);
    else
498
	return (&xmlGetGlobalState()->xmlDefaultBufferSize);
499 500 501 502 503 504 505 506
}

#undef	xmlDefaultSAXHandler
xmlSAXHandler *
__xmlDefaultSAXHandler(void) {
    if (IS_MAIN_THREAD)
	return (&xmlDefaultSAXHandler);
    else
507
	return (&xmlGetGlobalState()->xmlDefaultSAXHandler);
508 509 510 511 512 513 514 515
}

#undef	xmlDefaultSAXLocator
xmlSAXLocator *
__xmlDefaultSAXLocator(void) {
    if (IS_MAIN_THREAD)
	return (&xmlDefaultSAXLocator);
    else
516
	return (&xmlGetGlobalState()->xmlDefaultSAXLocator);
517 518 519 520 521 522 523 524
}

#undef	xmlDoValidityCheckingDefaultValue
int *
__xmlDoValidityCheckingDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlDoValidityCheckingDefaultValue);
    else
525
	return (&xmlGetGlobalState()->xmlDoValidityCheckingDefaultValue);
526 527 528 529 530 531 532 533
}

#undef	xmlGenericError
xmlGenericErrorFunc *
__xmlGenericError(void) {
    if (IS_MAIN_THREAD)
	return (&xmlGenericError);
    else
534
	return (&xmlGetGlobalState()->xmlGenericError);
535 536 537 538 539 540 541 542
}

#undef	xmlGenericErrorContext
void * *
__xmlGenericErrorContext(void) {
    if (IS_MAIN_THREAD)
	return (&xmlGenericErrorContext);
    else
543
	return (&xmlGetGlobalState()->xmlGenericErrorContext);
544 545 546 547 548 549 550 551
}

#undef	xmlGetWarningsDefaultValue
int *
__xmlGetWarningsDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlGetWarningsDefaultValue);
    else
552
	return (&xmlGetGlobalState()->xmlGetWarningsDefaultValue);
553 554 555 556 557 558 559 560
}

#undef	xmlIndentTreeOutput
int *
__xmlIndentTreeOutput(void) {
    if (IS_MAIN_THREAD)
	return (&xmlIndentTreeOutput);
    else
561
	return (&xmlGetGlobalState()->xmlIndentTreeOutput);
562 563 564 565 566 567 568 569
}

#undef	xmlKeepBlanksDefaultValue
int *
__xmlKeepBlanksDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlKeepBlanksDefaultValue);
    else
570
	return (&xmlGetGlobalState()->xmlKeepBlanksDefaultValue);
571 572 573 574 575 576 577 578
}

#undef	xmlLineNumbersDefaultValue
int *
__xmlLineNumbersDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlLineNumbersDefaultValue);
    else
579
	return (&xmlGetGlobalState()->xmlLineNumbersDefaultValue);
580 581 582 583 584 585 586 587
}

#undef	xmlLoadExtDtdDefaultValue
int *
__xmlLoadExtDtdDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlLoadExtDtdDefaultValue);
    else
588
	return (&xmlGetGlobalState()->xmlLoadExtDtdDefaultValue);
589 590 591 592 593 594 595 596
}

#undef	xmlParserDebugEntities
int *
__xmlParserDebugEntities(void) {
    if (IS_MAIN_THREAD)
	return (&xmlParserDebugEntities);
    else
597
	return (&xmlGetGlobalState()->xmlParserDebugEntities);
598 599 600 601 602 603 604 605
}

#undef	xmlParserVersion
const char * *
__xmlParserVersion(void) {
    if (IS_MAIN_THREAD)
	return (&xmlParserVersion);
    else
606
	return (&xmlGetGlobalState()->xmlParserVersion);
607 608 609 610 611 612 613 614
}

#undef	xmlPedanticParserDefaultValue
int *
__xmlPedanticParserDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlPedanticParserDefaultValue);
    else
615
	return (&xmlGetGlobalState()->xmlPedanticParserDefaultValue);
616 617 618 619 620 621 622 623
}

#undef	xmlSaveNoEmptyTags
int *
__xmlSaveNoEmptyTags(void) {
    if (IS_MAIN_THREAD)
	return (&xmlSaveNoEmptyTags);
    else
624
	return (&xmlGetGlobalState()->xmlSaveNoEmptyTags);
625 626 627 628 629 630 631 632
}

#undef	xmlSubstituteEntitiesDefaultValue
int *
__xmlSubstituteEntitiesDefaultValue(void) {
    if (IS_MAIN_THREAD)
	return (&xmlSubstituteEntitiesDefaultValue);
    else
633
	return (&xmlGetGlobalState()->xmlSubstituteEntitiesDefaultValue);
634
}