1 /* 2 __ __ _ 3 ___\ \/ /_ __ __ _| |_ 4 / _ \\ /| '_ \ / _` | __| 5 | __// \| |_) | (_| | |_ 6 \___/_/\_\ .__/ \__,_|\__| 7 |_| XML parser 8 9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd 10 Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> 11 Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> 12 Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net> 13 Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net> 14 Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org> 15 Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org> 16 Copyright (c) 2016 Thomas Beutlich <tc@tbeu.de> 17 Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> 18 Licensed under the MIT license: 19 20 Permission is hereby granted, free of charge, to any person obtaining 21 a copy of this software and associated documentation files (the 22 "Software"), to deal in the Software without restriction, including 23 without limitation the rights to use, copy, modify, merge, publish, 24 distribute, sublicense, and/or sell copies of the Software, and to permit 25 persons to whom the Software is furnished to do so, subject to the 26 following conditions: 27 28 The above copyright notice and this permission notice shall be included 29 in all copies or substantial portions of the Software. 30 31 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 32 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 33 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 34 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 35 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 36 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 37 USE OR OTHER DEALINGS IN THE SOFTWARE. 38 */ 39 40 #ifndef Expat_INCLUDED 41 #define Expat_INCLUDED 1 42 43 #include <stdlib.h> 44 #include "expat_external.h" 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 struct XML_ParserStruct; 51 typedef struct XML_ParserStruct *XML_Parser; 52 53 typedef unsigned char XML_Bool; 54 #define XML_TRUE ((XML_Bool)1) 55 #define XML_FALSE ((XML_Bool)0) 56 57 /* The XML_Status enum gives the possible return values for several 58 API functions. The preprocessor #defines are included so this 59 stanza can be added to code that still needs to support older 60 versions of Expat 1.95.x: 61 62 #ifndef XML_STATUS_OK 63 #define XML_STATUS_OK 1 64 #define XML_STATUS_ERROR 0 65 #endif 66 67 Otherwise, the #define hackery is quite ugly and would have been 68 dropped. 69 */ 70 enum XML_Status { 71 XML_STATUS_ERROR = 0, 72 #define XML_STATUS_ERROR XML_STATUS_ERROR 73 XML_STATUS_OK = 1, 74 #define XML_STATUS_OK XML_STATUS_OK 75 XML_STATUS_SUSPENDED = 2 76 #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED 77 }; 78 79 enum XML_Error { 80 XML_ERROR_NONE, 81 XML_ERROR_NO_MEMORY, 82 XML_ERROR_SYNTAX, 83 XML_ERROR_NO_ELEMENTS, 84 XML_ERROR_INVALID_TOKEN, 85 XML_ERROR_UNCLOSED_TOKEN, 86 XML_ERROR_PARTIAL_CHAR, 87 XML_ERROR_TAG_MISMATCH, 88 XML_ERROR_DUPLICATE_ATTRIBUTE, 89 XML_ERROR_JUNK_AFTER_DOC_ELEMENT, 90 XML_ERROR_PARAM_ENTITY_REF, 91 XML_ERROR_UNDEFINED_ENTITY, 92 XML_ERROR_RECURSIVE_ENTITY_REF, 93 XML_ERROR_ASYNC_ENTITY, 94 XML_ERROR_BAD_CHAR_REF, 95 XML_ERROR_BINARY_ENTITY_REF, 96 XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, 97 XML_ERROR_MISPLACED_XML_PI, 98 XML_ERROR_UNKNOWN_ENCODING, 99 XML_ERROR_INCORRECT_ENCODING, 100 XML_ERROR_UNCLOSED_CDATA_SECTION, 101 XML_ERROR_EXTERNAL_ENTITY_HANDLING, 102 XML_ERROR_NOT_STANDALONE, 103 XML_ERROR_UNEXPECTED_STATE, 104 XML_ERROR_ENTITY_DECLARED_IN_PE, 105 XML_ERROR_FEATURE_REQUIRES_XML_DTD, 106 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, 107 /* Added in 1.95.7. */ 108 XML_ERROR_UNBOUND_PREFIX, 109 /* Added in 1.95.8. */ 110 XML_ERROR_UNDECLARING_PREFIX, 111 XML_ERROR_INCOMPLETE_PE, 112 XML_ERROR_XML_DECL, 113 XML_ERROR_TEXT_DECL, 114 XML_ERROR_PUBLICID, 115 XML_ERROR_SUSPENDED, 116 XML_ERROR_NOT_SUSPENDED, 117 XML_ERROR_ABORTED, 118 XML_ERROR_FINISHED, 119 XML_ERROR_SUSPEND_PE, 120 /* Added in 2.0. */ 121 XML_ERROR_RESERVED_PREFIX_XML, 122 XML_ERROR_RESERVED_PREFIX_XMLNS, 123 XML_ERROR_RESERVED_NAMESPACE_URI, 124 /* Added in 2.2.1. */ 125 XML_ERROR_INVALID_ARGUMENT, 126 /* Added in 2.3.0. */ 127 XML_ERROR_NO_BUFFER, 128 /* Added in 2.4.0. */ 129 XML_ERROR_AMPLIFICATION_LIMIT_BREACH 130 }; 131 132 enum XML_Content_Type { 133 XML_CTYPE_EMPTY = 1, 134 XML_CTYPE_ANY, 135 XML_CTYPE_MIXED, 136 XML_CTYPE_NAME, 137 XML_CTYPE_CHOICE, 138 XML_CTYPE_SEQ 139 }; 140 141 enum XML_Content_Quant { 142 XML_CQUANT_NONE, 143 XML_CQUANT_OPT, 144 XML_CQUANT_REP, 145 XML_CQUANT_PLUS 146 }; 147 148 /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be 149 XML_CQUANT_NONE, and the other fields will be zero or NULL. 150 If type == XML_CTYPE_MIXED, then quant will be NONE or REP and 151 numchildren will contain number of elements that may be mixed in 152 and children point to an array of XML_Content cells that will be 153 all of XML_CTYPE_NAME type with no quantification. 154 155 If type == XML_CTYPE_NAME, then the name points to the name, and 156 the numchildren field will be zero and children will be NULL. The 157 quant fields indicates any quantifiers placed on the name. 158 159 CHOICE and SEQ will have name NULL, the number of children in 160 numchildren and children will point, recursively, to an array 161 of XML_Content cells. 162 163 The EMPTY, ANY, and MIXED types will only occur at top level. 164 */ 165 166 typedef struct XML_cp XML_Content; 167 168 struct XML_cp { 169 enum XML_Content_Type type; 170 enum XML_Content_Quant quant; 171 XML_Char *name; 172 unsigned int numchildren; 173 XML_Content *children; 174 }; 175 176 /* This is called for an element declaration. See above for 177 description of the model argument. It's the caller's responsibility 178 to free model when finished with it. 179 */ 180 typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData, 181 const XML_Char *name, 182 XML_Content *model); 183 184 XMLPARSEAPI(void) 185 XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl); 186 187 /* The Attlist declaration handler is called for *each* attribute. So 188 a single Attlist declaration with multiple attributes declared will 189 generate multiple calls to this handler. The "default" parameter 190 may be NULL in the case of the "#IMPLIED" or "#REQUIRED" 191 keyword. The "isrequired" parameter will be true and the default 192 value will be NULL in the case of "#REQUIRED". If "isrequired" is 193 true and default is non-NULL, then this is a "#FIXED" default. 194 */ 195 typedef void(XMLCALL *XML_AttlistDeclHandler)( 196 void *userData, const XML_Char *elname, const XML_Char *attname, 197 const XML_Char *att_type, const XML_Char *dflt, int isrequired); 198 199 XMLPARSEAPI(void) 200 XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl); 201 202 /* The XML declaration handler is called for *both* XML declarations 203 and text declarations. The way to distinguish is that the version 204 parameter will be NULL for text declarations. The encoding 205 parameter may be NULL for XML declarations. The standalone 206 parameter will be -1, 0, or 1 indicating respectively that there 207 was no standalone parameter in the declaration, that it was given 208 as no, or that it was given as yes. 209 */ 210 typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData, 211 const XML_Char *version, 212 const XML_Char *encoding, 213 int standalone); 214 215 XMLPARSEAPI(void) 216 XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl); 217 218 typedef struct { 219 void *(*malloc_fcn)(size_t size); 220 void *(*realloc_fcn)(void *ptr, size_t size); 221 void (*free_fcn)(void *ptr); 222 } XML_Memory_Handling_Suite; 223 224 /* Constructs a new parser; encoding is the encoding specified by the 225 external protocol or NULL if there is none specified. 226 */ 227 XMLPARSEAPI(XML_Parser) 228 XML_ParserCreate(const XML_Char *encoding); 229 230 /* Constructs a new parser and namespace processor. Element type 231 names and attribute names that belong to a namespace will be 232 expanded; unprefixed attribute names are never expanded; unprefixed 233 element type names are expanded only if there is a default 234 namespace. The expanded name is the concatenation of the namespace 235 URI, the namespace separator character, and the local part of the 236 name. If the namespace separator is '\0' then the namespace URI 237 and the local part will be concatenated without any separator. 238 It is a programming error to use the separator '\0' with namespace 239 triplets (see XML_SetReturnNSTriplet). 240 */ 241 XMLPARSEAPI(XML_Parser) 242 XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); 243 244 /* Constructs a new parser using the memory management suite referred to 245 by memsuite. If memsuite is NULL, then use the standard library memory 246 suite. If namespaceSeparator is non-NULL it creates a parser with 247 namespace processing as described above. The character pointed at 248 will serve as the namespace separator. 249 250 All further memory operations used for the created parser will come from 251 the given suite. 252 */ 253 XMLPARSEAPI(XML_Parser) 254 XML_ParserCreate_MM(const XML_Char *encoding, 255 const XML_Memory_Handling_Suite *memsuite, 256 const XML_Char *namespaceSeparator); 257 258 /* Prepare a parser object to be re-used. This is particularly 259 valuable when memory allocation overhead is disproportionately high, 260 such as when a large number of small documnents need to be parsed. 261 All handlers are cleared from the parser, except for the 262 unknownEncodingHandler. The parser's external state is re-initialized 263 except for the values of ns and ns_triplets. 264 265 Added in Expat 1.95.3. 266 */ 267 XMLPARSEAPI(XML_Bool) 268 XML_ParserReset(XML_Parser parser, const XML_Char *encoding); 269 270 /* atts is array of name/value pairs, terminated by 0; 271 names and values are 0 terminated. 272 */ 273 typedef void(XMLCALL *XML_StartElementHandler)(void *userData, 274 const XML_Char *name, 275 const XML_Char **atts); 276 277 typedef void(XMLCALL *XML_EndElementHandler)(void *userData, 278 const XML_Char *name); 279 280 /* s is not 0 terminated. */ 281 typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData, 282 const XML_Char *s, int len); 283 284 /* target and data are 0 terminated */ 285 typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData, 286 const XML_Char *target, 287 const XML_Char *data); 288 289 /* data is 0 terminated */ 290 typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data); 291 292 typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData); 293 typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData); 294 295 /* This is called for any characters in the XML document for which 296 there is no applicable handler. This includes both characters that 297 are part of markup which is of a kind that is not reported 298 (comments, markup declarations), or characters that are part of a 299 construct which could be reported but for which no handler has been 300 supplied. The characters are passed exactly as they were in the XML 301 document except that they will be encoded in UTF-8 or UTF-16. 302 Line boundaries are not normalized. Note that a byte order mark 303 character is not passed to the default handler. There are no 304 guarantees about how characters are divided between calls to the 305 default handler: for example, a comment might be split between 306 multiple calls. 307 */ 308 typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s, 309 int len); 310 311 /* This is called for the start of the DOCTYPE declaration, before 312 any DTD or internal subset is parsed. 313 */ 314 typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, 315 const XML_Char *doctypeName, 316 const XML_Char *sysid, 317 const XML_Char *pubid, 318 int has_internal_subset); 319 320 /* This is called for the start of the DOCTYPE declaration when the 321 closing > is encountered, but after processing any external 322 subset. 323 */ 324 typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); 325 326 /* This is called for entity declarations. The is_parameter_entity 327 argument will be non-zero if the entity is a parameter entity, zero 328 otherwise. 329 330 For internal entities (<!ENTITY foo "bar">), value will 331 be non-NULL and systemId, publicID, and notationName will be NULL. 332 The value string is NOT null-terminated; the length is provided in 333 the value_length argument. Since it is legal to have zero-length 334 values, do not use this argument to test for internal entities. 335 336 For external entities, value will be NULL and systemId will be 337 non-NULL. The publicId argument will be NULL unless a public 338 identifier was provided. The notationName argument will have a 339 non-NULL value only for unparsed entity declarations. 340 341 Note that is_parameter_entity can't be changed to XML_Bool, since 342 that would break binary compatibility. 343 */ 344 typedef void(XMLCALL *XML_EntityDeclHandler)( 345 void *userData, const XML_Char *entityName, int is_parameter_entity, 346 const XML_Char *value, int value_length, const XML_Char *base, 347 const XML_Char *systemId, const XML_Char *publicId, 348 const XML_Char *notationName); 349 350 XMLPARSEAPI(void) 351 XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); 352 353 /* OBSOLETE -- OBSOLETE -- OBSOLETE 354 This handler has been superseded by the EntityDeclHandler above. 355 It is provided here for backward compatibility. 356 357 This is called for a declaration of an unparsed (NDATA) entity. 358 The base argument is whatever was set by XML_SetBase. The 359 entityName, systemId and notationName arguments will never be 360 NULL. The other arguments may be. 361 */ 362 typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)( 363 void *userData, const XML_Char *entityName, const XML_Char *base, 364 const XML_Char *systemId, const XML_Char *publicId, 365 const XML_Char *notationName); 366 367 /* This is called for a declaration of notation. The base argument is 368 whatever was set by XML_SetBase. The notationName will never be 369 NULL. The other arguments can be. 370 */ 371 typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData, 372 const XML_Char *notationName, 373 const XML_Char *base, 374 const XML_Char *systemId, 375 const XML_Char *publicId); 376 377 /* When namespace processing is enabled, these are called once for 378 each namespace declaration. The call to the start and end element 379 handlers occur between the calls to the start and end namespace 380 declaration handlers. For an xmlns attribute, prefix will be 381 NULL. For an xmlns="" attribute, uri will be NULL. 382 */ 383 typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData, 384 const XML_Char *prefix, 385 const XML_Char *uri); 386 387 typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, 388 const XML_Char *prefix); 389 390 /* This is called if the document is not standalone, that is, it has an 391 external subset or a reference to a parameter entity, but does not 392 have standalone="yes". If this handler returns XML_STATUS_ERROR, 393 then processing will not continue, and the parser will return a 394 XML_ERROR_NOT_STANDALONE error. 395 If parameter entity parsing is enabled, then in addition to the 396 conditions above this handler will only be called if the referenced 397 entity was actually read. 398 */ 399 typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData); 400 401 /* This is called for a reference to an external parsed general 402 entity. The referenced entity is not automatically parsed. The 403 application can parse it immediately or later using 404 XML_ExternalEntityParserCreate. 405 406 The parser argument is the parser parsing the entity containing the 407 reference; it can be passed as the parser argument to 408 XML_ExternalEntityParserCreate. The systemId argument is the 409 system identifier as specified in the entity declaration; it will 410 not be NULL. 411 412 The base argument is the system identifier that should be used as 413 the base for resolving systemId if systemId was relative; this is 414 set by XML_SetBase; it may be NULL. 415 416 The publicId argument is the public identifier as specified in the 417 entity declaration, or NULL if none was specified; the whitespace 418 in the public identifier will have been normalized as required by 419 the XML spec. 420 421 The context argument specifies the parsing context in the format 422 expected by the context argument to XML_ExternalEntityParserCreate; 423 context is valid only until the handler returns, so if the 424 referenced entity is to be parsed later, it must be copied. 425 context is NULL only when the entity is a parameter entity. 426 427 The handler should return XML_STATUS_ERROR if processing should not 428 continue because of a fatal error in the handling of the external 429 entity. In this case the calling parser will return an 430 XML_ERROR_EXTERNAL_ENTITY_HANDLING error. 431 432 Note that unlike other handlers the first argument is the parser, 433 not userData. 434 */ 435 typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser, 436 const XML_Char *context, 437 const XML_Char *base, 438 const XML_Char *systemId, 439 const XML_Char *publicId); 440 441 /* This is called in two situations: 442 1) An entity reference is encountered for which no declaration 443 has been read *and* this is not an error. 444 2) An internal entity reference is read, but not expanded, because 445 XML_SetDefaultHandler has been called. 446 Note: skipped parameter entities in declarations and skipped general 447 entities in attribute values cannot be reported, because 448 the event would be out of sync with the reporting of the 449 declarations or attribute values 450 */ 451 typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData, 452 const XML_Char *entityName, 453 int is_parameter_entity); 454 455 /* This structure is filled in by the XML_UnknownEncodingHandler to 456 provide information to the parser about encodings that are unknown 457 to the parser. 458 459 The map[b] member gives information about byte sequences whose 460 first byte is b. 461 462 If map[b] is c where c is >= 0, then b by itself encodes the 463 Unicode scalar value c. 464 465 If map[b] is -1, then the byte sequence is malformed. 466 467 If map[b] is -n, where n >= 2, then b is the first byte of an 468 n-byte sequence that encodes a single Unicode scalar value. 469 470 The data member will be passed as the first argument to the convert 471 function. 472 473 The convert function is used to convert multibyte sequences; s will 474 point to a n-byte sequence where map[(unsigned char)*s] == -n. The 475 convert function must return the Unicode scalar value represented 476 by this byte sequence or -1 if the byte sequence is malformed. 477 478 The convert function may be NULL if the encoding is a single-byte 479 encoding, that is if map[b] >= -1 for all bytes b. 480 481 When the parser is finished with the encoding, then if release is 482 not NULL, it will call release passing it the data member; once 483 release has been called, the convert function will not be called 484 again. 485 486 Expat places certain restrictions on the encodings that are supported 487 using this mechanism. 488 489 1. Every ASCII character that can appear in a well-formed XML document, 490 other than the characters 491 492 $@\^`{}~ 493 494 must be represented by a single byte, and that byte must be the 495 same byte that represents that character in ASCII. 496 497 2. No character may require more than 4 bytes to encode. 498 499 3. All characters encoded must have Unicode scalar values <= 500 0xFFFF, (i.e., characters that would be encoded by surrogates in 501 UTF-16 are not allowed). Note that this restriction doesn't 502 apply to the built-in support for UTF-8 and UTF-16. 503 504 4. No Unicode character may be encoded by more than one distinct 505 sequence of bytes. 506 */ 507 typedef struct { 508 int map[256]; 509 void *data; 510 int(XMLCALL *convert)(void *data, const char *s); 511 void(XMLCALL *release)(void *data); 512 } XML_Encoding; 513 514 /* This is called for an encoding that is unknown to the parser. 515 516 The encodingHandlerData argument is that which was passed as the 517 second argument to XML_SetUnknownEncodingHandler. 518 519 The name argument gives the name of the encoding as specified in 520 the encoding declaration. 521 522 If the callback can provide information about the encoding, it must 523 fill in the XML_Encoding structure, and return XML_STATUS_OK. 524 Otherwise it must return XML_STATUS_ERROR. 525 526 If info does not describe a suitable encoding, then the parser will 527 return an XML_ERROR_UNKNOWN_ENCODING error. 528 */ 529 typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, 530 const XML_Char *name, 531 XML_Encoding *info); 532 533 XMLPARSEAPI(void) 534 XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, 535 XML_EndElementHandler end); 536 537 XMLPARSEAPI(void) 538 XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler); 539 540 XMLPARSEAPI(void) 541 XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler); 542 543 XMLPARSEAPI(void) 544 XML_SetCharacterDataHandler(XML_Parser parser, 545 XML_CharacterDataHandler handler); 546 547 XMLPARSEAPI(void) 548 XML_SetProcessingInstructionHandler(XML_Parser parser, 549 XML_ProcessingInstructionHandler handler); 550 XMLPARSEAPI(void) 551 XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler); 552 553 XMLPARSEAPI(void) 554 XML_SetCdataSectionHandler(XML_Parser parser, 555 XML_StartCdataSectionHandler start, 556 XML_EndCdataSectionHandler end); 557 558 XMLPARSEAPI(void) 559 XML_SetStartCdataSectionHandler(XML_Parser parser, 560 XML_StartCdataSectionHandler start); 561 562 XMLPARSEAPI(void) 563 XML_SetEndCdataSectionHandler(XML_Parser parser, 564 XML_EndCdataSectionHandler end); 565 566 /* This sets the default handler and also inhibits expansion of 567 internal entities. These entity references will be passed to the 568 default handler, or to the skipped entity handler, if one is set. 569 */ 570 XMLPARSEAPI(void) 571 XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler); 572 573 /* This sets the default handler but does not inhibit expansion of 574 internal entities. The entity reference will not be passed to the 575 default handler. 576 */ 577 XMLPARSEAPI(void) 578 XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); 579 580 XMLPARSEAPI(void) 581 XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, 582 XML_EndDoctypeDeclHandler end); 583 584 XMLPARSEAPI(void) 585 XML_SetStartDoctypeDeclHandler(XML_Parser parser, 586 XML_StartDoctypeDeclHandler start); 587 588 XMLPARSEAPI(void) 589 XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end); 590 591 XMLPARSEAPI(void) 592 XML_SetUnparsedEntityDeclHandler(XML_Parser parser, 593 XML_UnparsedEntityDeclHandler handler); 594 595 XMLPARSEAPI(void) 596 XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler); 597 598 XMLPARSEAPI(void) 599 XML_SetNamespaceDeclHandler(XML_Parser parser, 600 XML_StartNamespaceDeclHandler start, 601 XML_EndNamespaceDeclHandler end); 602 603 XMLPARSEAPI(void) 604 XML_SetStartNamespaceDeclHandler(XML_Parser parser, 605 XML_StartNamespaceDeclHandler start); 606 607 XMLPARSEAPI(void) 608 XML_SetEndNamespaceDeclHandler(XML_Parser parser, 609 XML_EndNamespaceDeclHandler end); 610 611 XMLPARSEAPI(void) 612 XML_SetNotStandaloneHandler(XML_Parser parser, 613 XML_NotStandaloneHandler handler); 614 615 XMLPARSEAPI(void) 616 XML_SetExternalEntityRefHandler(XML_Parser parser, 617 XML_ExternalEntityRefHandler handler); 618 619 /* If a non-NULL value for arg is specified here, then it will be 620 passed as the first argument to the external entity ref handler 621 instead of the parser object. 622 */ 623 XMLPARSEAPI(void) 624 XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg); 625 626 XMLPARSEAPI(void) 627 XML_SetSkippedEntityHandler(XML_Parser parser, 628 XML_SkippedEntityHandler handler); 629 630 XMLPARSEAPI(void) 631 XML_SetUnknownEncodingHandler(XML_Parser parser, 632 XML_UnknownEncodingHandler handler, 633 void *encodingHandlerData); 634 635 /* This can be called within a handler for a start element, end 636 element, processing instruction or character data. It causes the 637 corresponding markup to be passed to the default handler. 638 */ 639 XMLPARSEAPI(void) 640 XML_DefaultCurrent(XML_Parser parser); 641 642 /* If do_nst is non-zero, and namespace processing is in effect, and 643 a name has a prefix (i.e. an explicit namespace qualifier) then 644 that name is returned as a triplet in a single string separated by 645 the separator character specified when the parser was created: URI 646 + sep + local_name + sep + prefix. 647 648 If do_nst is zero, then namespace information is returned in the 649 default manner (URI + sep + local_name) whether or not the name 650 has a prefix. 651 652 Note: Calling XML_SetReturnNSTriplet after XML_Parse or 653 XML_ParseBuffer has no effect. 654 */ 655 656 XMLPARSEAPI(void) 657 XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); 658 659 /* This value is passed as the userData argument to callbacks. */ 660 XMLPARSEAPI(void) 661 XML_SetUserData(XML_Parser parser, void *userData); 662 663 /* Returns the last value set by XML_SetUserData or NULL. */ 664 #define XML_GetUserData(parser) (*(void **)(parser)) 665 666 /* This is equivalent to supplying an encoding argument to 667 XML_ParserCreate. On success XML_SetEncoding returns non-zero, 668 zero otherwise. 669 Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer 670 has no effect and returns XML_STATUS_ERROR. 671 */ 672 XMLPARSEAPI(enum XML_Status) 673 XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); 674 675 /* If this function is called, then the parser will be passed as the 676 first argument to callbacks instead of userData. The userData will 677 still be accessible using XML_GetUserData. 678 */ 679 XMLPARSEAPI(void) 680 XML_UseParserAsHandlerArg(XML_Parser parser); 681 682 /* If useDTD == XML_TRUE is passed to this function, then the parser 683 will assume that there is an external subset, even if none is 684 specified in the document. In such a case the parser will call the 685 externalEntityRefHandler with a value of NULL for the systemId 686 argument (the publicId and context arguments will be NULL as well). 687 Note: For the purpose of checking WFC: Entity Declared, passing 688 useDTD == XML_TRUE will make the parser behave as if the document 689 had a DTD with an external subset. 690 Note: If this function is called, then this must be done before 691 the first call to XML_Parse or XML_ParseBuffer, since it will 692 have no effect after that. Returns 693 XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. 694 Note: If the document does not have a DOCTYPE declaration at all, 695 then startDoctypeDeclHandler and endDoctypeDeclHandler will not 696 be called, despite an external subset being parsed. 697 Note: If XML_DTD is not defined when Expat is compiled, returns 698 XML_ERROR_FEATURE_REQUIRES_XML_DTD. 699 Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT. 700 */ 701 XMLPARSEAPI(enum XML_Error) 702 XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); 703 704 /* Sets the base to be used for resolving relative URIs in system 705 identifiers in declarations. Resolving relative identifiers is 706 left to the application: this value will be passed through as the 707 base argument to the XML_ExternalEntityRefHandler, 708 XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base 709 argument will be copied. Returns XML_STATUS_ERROR if out of memory, 710 XML_STATUS_OK otherwise. 711 */ 712 XMLPARSEAPI(enum XML_Status) 713 XML_SetBase(XML_Parser parser, const XML_Char *base); 714 715 XMLPARSEAPI(const XML_Char *) 716 XML_GetBase(XML_Parser parser); 717 718 /* Returns the number of the attribute/value pairs passed in last call 719 to the XML_StartElementHandler that were specified in the start-tag 720 rather than defaulted. Each attribute/value pair counts as 2; thus 721 this corresponds to an index into the atts array passed to the 722 XML_StartElementHandler. Returns -1 if parser == NULL. 723 */ 724 XMLPARSEAPI(int) 725 XML_GetSpecifiedAttributeCount(XML_Parser parser); 726 727 /* Returns the index of the ID attribute passed in the last call to 728 XML_StartElementHandler, or -1 if there is no ID attribute or 729 parser == NULL. Each attribute/value pair counts as 2; thus this 730 corresponds to an index into the atts array passed to the 731 XML_StartElementHandler. 732 */ 733 XMLPARSEAPI(int) 734 XML_GetIdAttributeIndex(XML_Parser parser); 735 736 #ifdef XML_ATTR_INFO 737 /* Source file byte offsets for the start and end of attribute names and values. 738 The value indices are exclusive of surrounding quotes; thus in a UTF-8 source 739 file an attribute value of "blah" will yield: 740 info->valueEnd - info->valueStart = 4 bytes. 741 */ 742 typedef struct { 743 XML_Index nameStart; /* Offset to beginning of the attribute name. */ 744 XML_Index nameEnd; /* Offset after the attribute name's last byte. */ 745 XML_Index valueStart; /* Offset to beginning of the attribute value. */ 746 XML_Index valueEnd; /* Offset after the attribute value's last byte. */ 747 } XML_AttrInfo; 748 749 /* Returns an array of XML_AttrInfo structures for the attribute/value pairs 750 passed in last call to the XML_StartElementHandler that were specified 751 in the start-tag rather than defaulted. Each attribute/value pair counts 752 as 1; thus the number of entries in the array is 753 XML_GetSpecifiedAttributeCount(parser) / 2. 754 */ 755 XMLPARSEAPI(const XML_AttrInfo *) 756 XML_GetAttributeInfo(XML_Parser parser); 757 #endif 758 759 /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is 760 detected. The last call to XML_Parse must have isFinal true; len 761 may be zero for this call (or any other). 762 763 Though the return values for these functions has always been 764 described as a Boolean value, the implementation, at least for the 765 1.95.x series, has always returned exactly one of the XML_Status 766 values. 767 */ 768 XMLPARSEAPI(enum XML_Status) 769 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); 770 771 XMLPARSEAPI(void *) 772 XML_GetBuffer(XML_Parser parser, int len); 773 774 XMLPARSEAPI(enum XML_Status) 775 XML_ParseBuffer(XML_Parser parser, int len, int isFinal); 776 777 /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. 778 Must be called from within a call-back handler, except when aborting 779 (resumable = 0) an already suspended parser. Some call-backs may 780 still follow because they would otherwise get lost. Examples: 781 - endElementHandler() for empty elements when stopped in 782 startElementHandler(), 783 - endNameSpaceDeclHandler() when stopped in endElementHandler(), 784 and possibly others. 785 786 Can be called from most handlers, including DTD related call-backs, 787 except when parsing an external parameter entity and resumable != 0. 788 Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. 789 Possible error codes: 790 - XML_ERROR_SUSPENDED: when suspending an already suspended parser. 791 - XML_ERROR_FINISHED: when the parser has already finished. 792 - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. 793 794 When resumable != 0 (true) then parsing is suspended, that is, 795 XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. 796 Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() 797 return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. 798 799 *Note*: 800 This will be applied to the current parser instance only, that is, if 801 there is a parent parser then it will continue parsing when the 802 externalEntityRefHandler() returns. It is up to the implementation of 803 the externalEntityRefHandler() to call XML_StopParser() on the parent 804 parser (recursively), if one wants to stop parsing altogether. 805 806 When suspended, parsing can be resumed by calling XML_ResumeParser(). 807 */ 808 XMLPARSEAPI(enum XML_Status) 809 XML_StopParser(XML_Parser parser, XML_Bool resumable); 810 811 /* Resumes parsing after it has been suspended with XML_StopParser(). 812 Must not be called from within a handler call-back. Returns same 813 status codes as XML_Parse() or XML_ParseBuffer(). 814 Additional error code XML_ERROR_NOT_SUSPENDED possible. 815 816 *Note*: 817 This must be called on the most deeply nested child parser instance 818 first, and on its parent parser only after the child parser has finished, 819 to be applied recursively until the document entity's parser is restarted. 820 That is, the parent parser will not resume by itself and it is up to the 821 application to call XML_ResumeParser() on it at the appropriate moment. 822 */ 823 XMLPARSEAPI(enum XML_Status) 824 XML_ResumeParser(XML_Parser parser); 825 826 enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED }; 827 828 typedef struct { 829 enum XML_Parsing parsing; 830 XML_Bool finalBuffer; 831 } XML_ParsingStatus; 832 833 /* Returns status of parser with respect to being initialized, parsing, 834 finished, or suspended and processing the final buffer. 835 XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, 836 XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED 837 */ 838 XMLPARSEAPI(void) 839 XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); 840 841 /* Creates an XML_Parser object that can parse an external general 842 entity; context is a '\0'-terminated string specifying the parse 843 context; encoding is a '\0'-terminated string giving the name of 844 the externally specified encoding, or NULL if there is no 845 externally specified encoding. The context string consists of a 846 sequence of tokens separated by formfeeds (\f); a token consisting 847 of a name specifies that the general entity of the name is open; a 848 token of the form prefix=uri specifies the namespace for a 849 particular prefix; a token of the form =uri specifies the default 850 namespace. This can be called at any point after the first call to 851 an ExternalEntityRefHandler so longer as the parser has not yet 852 been freed. The new parser is completely independent and may 853 safely be used in a separate thread. The handlers and userData are 854 initialized from the parser argument. Returns NULL if out of memory. 855 Otherwise returns a new XML_Parser object. 856 */ 857 XMLPARSEAPI(XML_Parser) 858 XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context, 859 const XML_Char *encoding); 860 861 enum XML_ParamEntityParsing { 862 XML_PARAM_ENTITY_PARSING_NEVER, 863 XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, 864 XML_PARAM_ENTITY_PARSING_ALWAYS 865 }; 866 867 /* Controls parsing of parameter entities (including the external DTD 868 subset). If parsing of parameter entities is enabled, then 869 references to external parameter entities (including the external 870 DTD subset) will be passed to the handler set with 871 XML_SetExternalEntityRefHandler. The context passed will be 0. 872 873 Unlike external general entities, external parameter entities can 874 only be parsed synchronously. If the external parameter entity is 875 to be parsed, it must be parsed during the call to the external 876 entity ref handler: the complete sequence of 877 XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and 878 XML_ParserFree calls must be made during this call. After 879 XML_ExternalEntityParserCreate has been called to create the parser 880 for the external parameter entity (context must be 0 for this 881 call), it is illegal to make any calls on the old parser until 882 XML_ParserFree has been called on the newly created parser. 883 If the library has been compiled without support for parameter 884 entity parsing (ie without XML_DTD being defined), then 885 XML_SetParamEntityParsing will return 0 if parsing of parameter 886 entities is requested; otherwise it will return non-zero. 887 Note: If XML_SetParamEntityParsing is called after XML_Parse or 888 XML_ParseBuffer, then it has no effect and will always return 0. 889 Note: If parser == NULL, the function will do nothing and return 0. 890 */ 891 XMLPARSEAPI(int) 892 XML_SetParamEntityParsing(XML_Parser parser, 893 enum XML_ParamEntityParsing parsing); 894 895 /* Sets the hash salt to use for internal hash calculations. 896 Helps in preventing DoS attacks based on predicting hash 897 function behavior. This must be called before parsing is started. 898 Returns 1 if successful, 0 when called after parsing has started. 899 Note: If parser == NULL, the function will do nothing and return 0. 900 */ 901 XMLPARSEAPI(int) 902 XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt); 903 904 /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then 905 XML_GetErrorCode returns information about the error. 906 */ 907 XMLPARSEAPI(enum XML_Error) 908 XML_GetErrorCode(XML_Parser parser); 909 910 /* These functions return information about the current parse 911 location. They may be called from any callback called to report 912 some parse event; in this case the location is the location of the 913 first of the sequence of characters that generated the event. When 914 called from callbacks generated by declarations in the document 915 prologue, the location identified isn't as neatly defined, but will 916 be within the relevant markup. When called outside of the callback 917 functions, the position indicated will be just past the last parse 918 event (regardless of whether there was an associated callback). 919 920 They may also be called after returning from a call to XML_Parse 921 or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then 922 the location is the location of the character at which the error 923 was detected; otherwise the location is the location of the last 924 parse event, as described above. 925 926 Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber 927 return 0 to indicate an error. 928 Note: XML_GetCurrentByteIndex returns -1 to indicate an error. 929 */ 930 XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); 931 XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); 932 XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); 933 934 /* Return the number of bytes in the current event. 935 Returns 0 if the event is in an internal entity. 936 */ 937 XMLPARSEAPI(int) 938 XML_GetCurrentByteCount(XML_Parser parser); 939 940 /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets 941 the integer pointed to by offset to the offset within this buffer 942 of the current parse position, and sets the integer pointed to by size 943 to the size of this buffer (the number of input bytes). Otherwise 944 returns a NULL pointer. Also returns a NULL pointer if a parse isn't 945 active. 946 947 NOTE: The character pointer returned should not be used outside 948 the handler that makes the call. 949 */ 950 XMLPARSEAPI(const char *) 951 XML_GetInputContext(XML_Parser parser, int *offset, int *size); 952 953 /* For backwards compatibility with previous versions. */ 954 #define XML_GetErrorLineNumber XML_GetCurrentLineNumber 955 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber 956 #define XML_GetErrorByteIndex XML_GetCurrentByteIndex 957 958 /* Frees the content model passed to the element declaration handler */ 959 XMLPARSEAPI(void) 960 XML_FreeContentModel(XML_Parser parser, XML_Content *model); 961 962 /* Exposing the memory handling functions used in Expat */ 963 XMLPARSEAPI(void *) 964 XML_ATTR_MALLOC 965 XML_ATTR_ALLOC_SIZE(2) 966 XML_MemMalloc(XML_Parser parser, size_t size); 967 968 XMLPARSEAPI(void *) 969 XML_ATTR_ALLOC_SIZE(3) 970 XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); 971 972 XMLPARSEAPI(void) 973 XML_MemFree(XML_Parser parser, void *ptr); 974 975 /* Frees memory used by the parser. */ 976 XMLPARSEAPI(void) 977 XML_ParserFree(XML_Parser parser); 978 979 /* Returns a string describing the error. */ 980 XMLPARSEAPI(const XML_LChar *) 981 XML_ErrorString(enum XML_Error code); 982 983 /* Return a string containing the version number of this expat */ 984 XMLPARSEAPI(const XML_LChar *) 985 XML_ExpatVersion(void); 986 987 typedef struct { 988 int major; 989 int minor; 990 int micro; 991 } XML_Expat_Version; 992 993 /* Return an XML_Expat_Version structure containing numeric version 994 number information for this version of expat. 995 */ 996 XMLPARSEAPI(XML_Expat_Version) 997 XML_ExpatVersionInfo(void); 998 999 /* Added in Expat 1.95.5. */ 1000 enum XML_FeatureEnum { 1001 XML_FEATURE_END = 0, 1002 XML_FEATURE_UNICODE, 1003 XML_FEATURE_UNICODE_WCHAR_T, 1004 XML_FEATURE_DTD, 1005 XML_FEATURE_CONTEXT_BYTES, 1006 XML_FEATURE_MIN_SIZE, 1007 XML_FEATURE_SIZEOF_XML_CHAR, 1008 XML_FEATURE_SIZEOF_XML_LCHAR, 1009 XML_FEATURE_NS, 1010 XML_FEATURE_LARGE_SIZE, 1011 XML_FEATURE_ATTR_INFO, 1012 /* Added in Expat 2.4.0. */ 1013 XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT, 1014 XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT 1015 /* Additional features must be added to the end of this enum. */ 1016 }; 1017 1018 typedef struct { 1019 enum XML_FeatureEnum feature; 1020 const XML_LChar *name; 1021 long int value; 1022 } XML_Feature; 1023 1024 XMLPARSEAPI(const XML_Feature *) 1025 XML_GetFeatureList(void); 1026 1027 #ifdef XML_DTD 1028 /* Added in Expat 2.4.0. */ 1029 XMLPARSEAPI(XML_Bool) 1030 XML_SetBillionLaughsAttackProtectionMaximumAmplification( 1031 XML_Parser parser, float maximumAmplificationFactor); 1032 1033 /* Added in Expat 2.4.0. */ 1034 XMLPARSEAPI(XML_Bool) 1035 XML_SetBillionLaughsAttackProtectionActivationThreshold( 1036 XML_Parser parser, unsigned long long activationThresholdBytes); 1037 #endif 1038 1039 /* Expat follows the semantic versioning convention. 1040 See http://semver.org. 1041 */ 1042 #define XML_MAJOR_VERSION 2 1043 #define XML_MINOR_VERSION 4 1044 #define XML_MICRO_VERSION 3 1045 1046 #ifdef __cplusplus 1047 } 1048 #endif 1049 1050 #endif /* not Expat_INCLUDED */ 1051