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