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