1355604Sdelphij/* 2355604Sdelphij __ __ _ 3355604Sdelphij ___\ \/ /_ __ __ _| |_ 4355604Sdelphij / _ \\ /| '_ \ / _` | __| 5355604Sdelphij | __// \| |_) | (_| | |_ 6355604Sdelphij \___/_/\_\ .__/ \__,_|\__| 7355604Sdelphij |_| XML parser 8355604Sdelphij 9355604Sdelphij Copyright (c) 1997-2000 Thai Open Source Software Center Ltd 10355604Sdelphij Copyright (c) 2000-2017 Expat development team 11355604Sdelphij Licensed under the MIT license: 12355604Sdelphij 13355604Sdelphij Permission is hereby granted, free of charge, to any person obtaining 14355604Sdelphij a copy of this software and associated documentation files (the 15355604Sdelphij "Software"), to deal in the Software without restriction, including 16355604Sdelphij without limitation the rights to use, copy, modify, merge, publish, 17355604Sdelphij distribute, sublicense, and/or sell copies of the Software, and to permit 18355604Sdelphij persons to whom the Software is furnished to do so, subject to the 19355604Sdelphij following conditions: 20355604Sdelphij 21355604Sdelphij The above copyright notice and this permission notice shall be included 22355604Sdelphij in all copies or substantial portions of the Software. 23355604Sdelphij 24355604Sdelphij THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 25355604Sdelphij EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 26355604Sdelphij MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 27355604Sdelphij NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 28355604Sdelphij DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 29355604Sdelphij OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 30355604Sdelphij USE OR OTHER DEALINGS IN THE SOFTWARE. 31104349Sphk*/ 32104349Sphk 33178848Scokane#ifndef Expat_INCLUDED 34178848Scokane#define Expat_INCLUDED 1 35104349Sphk 36104349Sphk#include <stdlib.h> 37178848Scokane#include "expat_external.h" 38104349Sphk 39104349Sphk#ifdef __cplusplus 40104349Sphkextern "C" { 41104349Sphk#endif 42104349Sphk 43104349Sphkstruct XML_ParserStruct; 44104349Sphktypedef struct XML_ParserStruct *XML_Parser; 45104349Sphk 46104349Sphktypedef unsigned char XML_Bool; 47355604Sdelphij#define XML_TRUE ((XML_Bool)1) 48355604Sdelphij#define XML_FALSE ((XML_Bool)0) 49104349Sphk 50178848Scokane/* The XML_Status enum gives the possible return values for several 51178848Scokane API functions. The preprocessor #defines are included so this 52178848Scokane stanza can be added to code that still needs to support older 53178848Scokane versions of Expat 1.95.x: 54178848Scokane 55178848Scokane #ifndef XML_STATUS_OK 56178848Scokane #define XML_STATUS_OK 1 57178848Scokane #define XML_STATUS_ERROR 0 58178848Scokane #endif 59178848Scokane 60178848Scokane Otherwise, the #define hackery is quite ugly and would have been 61178848Scokane dropped. 62178848Scokane*/ 63178848Scokaneenum XML_Status { 64178848Scokane XML_STATUS_ERROR = 0, 65178848Scokane#define XML_STATUS_ERROR XML_STATUS_ERROR 66178848Scokane XML_STATUS_OK = 1, 67178848Scokane#define XML_STATUS_OK XML_STATUS_OK 68178848Scokane XML_STATUS_SUSPENDED = 2 69178848Scokane#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED 70178848Scokane}; 71178848Scokane 72104349Sphkenum XML_Error { 73104349Sphk XML_ERROR_NONE, 74104349Sphk XML_ERROR_NO_MEMORY, 75104349Sphk XML_ERROR_SYNTAX, 76104349Sphk XML_ERROR_NO_ELEMENTS, 77104349Sphk XML_ERROR_INVALID_TOKEN, 78104349Sphk XML_ERROR_UNCLOSED_TOKEN, 79104349Sphk XML_ERROR_PARTIAL_CHAR, 80104349Sphk XML_ERROR_TAG_MISMATCH, 81104349Sphk XML_ERROR_DUPLICATE_ATTRIBUTE, 82104349Sphk XML_ERROR_JUNK_AFTER_DOC_ELEMENT, 83104349Sphk XML_ERROR_PARAM_ENTITY_REF, 84104349Sphk XML_ERROR_UNDEFINED_ENTITY, 85104349Sphk XML_ERROR_RECURSIVE_ENTITY_REF, 86104349Sphk XML_ERROR_ASYNC_ENTITY, 87104349Sphk XML_ERROR_BAD_CHAR_REF, 88104349Sphk XML_ERROR_BINARY_ENTITY_REF, 89104349Sphk XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, 90104349Sphk XML_ERROR_MISPLACED_XML_PI, 91104349Sphk XML_ERROR_UNKNOWN_ENCODING, 92104349Sphk XML_ERROR_INCORRECT_ENCODING, 93104349Sphk XML_ERROR_UNCLOSED_CDATA_SECTION, 94104349Sphk XML_ERROR_EXTERNAL_ENTITY_HANDLING, 95104349Sphk XML_ERROR_NOT_STANDALONE, 96104349Sphk XML_ERROR_UNEXPECTED_STATE, 97104349Sphk XML_ERROR_ENTITY_DECLARED_IN_PE, 98104349Sphk XML_ERROR_FEATURE_REQUIRES_XML_DTD, 99178848Scokane XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, 100178848Scokane /* Added in 1.95.7. */ 101178848Scokane XML_ERROR_UNBOUND_PREFIX, 102178848Scokane /* Added in 1.95.8. */ 103178848Scokane XML_ERROR_UNDECLARING_PREFIX, 104178848Scokane XML_ERROR_INCOMPLETE_PE, 105178848Scokane XML_ERROR_XML_DECL, 106178848Scokane XML_ERROR_TEXT_DECL, 107178848Scokane XML_ERROR_PUBLICID, 108178848Scokane XML_ERROR_SUSPENDED, 109178848Scokane XML_ERROR_NOT_SUSPENDED, 110178848Scokane XML_ERROR_ABORTED, 111178848Scokane XML_ERROR_FINISHED, 112178848Scokane XML_ERROR_SUSPEND_PE, 113178848Scokane /* Added in 2.0. */ 114178848Scokane XML_ERROR_RESERVED_PREFIX_XML, 115178848Scokane XML_ERROR_RESERVED_PREFIX_XMLNS, 116355604Sdelphij XML_ERROR_RESERVED_NAMESPACE_URI, 117355604Sdelphij /* Added in 2.2.1. */ 118355604Sdelphij XML_ERROR_INVALID_ARGUMENT 119104349Sphk}; 120104349Sphk 121104349Sphkenum XML_Content_Type { 122104349Sphk XML_CTYPE_EMPTY = 1, 123104349Sphk XML_CTYPE_ANY, 124104349Sphk XML_CTYPE_MIXED, 125104349Sphk XML_CTYPE_NAME, 126104349Sphk XML_CTYPE_CHOICE, 127104349Sphk XML_CTYPE_SEQ 128104349Sphk}; 129104349Sphk 130104349Sphkenum XML_Content_Quant { 131104349Sphk XML_CQUANT_NONE, 132104349Sphk XML_CQUANT_OPT, 133104349Sphk XML_CQUANT_REP, 134104349Sphk XML_CQUANT_PLUS 135104349Sphk}; 136104349Sphk 137104349Sphk/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be 138104349Sphk XML_CQUANT_NONE, and the other fields will be zero or NULL. 139104349Sphk If type == XML_CTYPE_MIXED, then quant will be NONE or REP and 140104349Sphk numchildren will contain number of elements that may be mixed in 141104349Sphk and children point to an array of XML_Content cells that will be 142104349Sphk all of XML_CTYPE_NAME type with no quantification. 143104349Sphk 144104349Sphk If type == XML_CTYPE_NAME, then the name points to the name, and 145104349Sphk the numchildren field will be zero and children will be NULL. The 146104349Sphk quant fields indicates any quantifiers placed on the name. 147104349Sphk 148104349Sphk CHOICE and SEQ will have name NULL, the number of children in 149104349Sphk numchildren and children will point, recursively, to an array 150104349Sphk of XML_Content cells. 151104349Sphk 152104349Sphk The EMPTY, ANY, and MIXED types will only occur at top level. 153104349Sphk*/ 154104349Sphk 155104349Sphktypedef struct XML_cp XML_Content; 156104349Sphk 157104349Sphkstruct XML_cp { 158355604Sdelphij enum XML_Content_Type type; 159355604Sdelphij enum XML_Content_Quant quant; 160355604Sdelphij XML_Char *name; 161355604Sdelphij unsigned int numchildren; 162355604Sdelphij XML_Content *children; 163104349Sphk}; 164104349Sphk 165104349Sphk/* This is called for an element declaration. See above for 166104349Sphk description of the model argument. It's the caller's responsibility 167104349Sphk to free model when finished with it. 168104349Sphk*/ 169355604Sdelphijtypedef void(XMLCALL *XML_ElementDeclHandler)(void *userData, 170355604Sdelphij const XML_Char *name, 171355604Sdelphij XML_Content *model); 172104349Sphk 173104349SphkXMLPARSEAPI(void) 174355604SdelphijXML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl); 175104349Sphk 176104349Sphk/* The Attlist declaration handler is called for *each* attribute. So 177104349Sphk a single Attlist declaration with multiple attributes declared will 178104349Sphk generate multiple calls to this handler. The "default" parameter 179104349Sphk may be NULL in the case of the "#IMPLIED" or "#REQUIRED" 180104349Sphk keyword. The "isrequired" parameter will be true and the default 181104349Sphk value will be NULL in the case of "#REQUIRED". If "isrequired" is 182104349Sphk true and default is non-NULL, then this is a "#FIXED" default. 183104349Sphk*/ 184355604Sdelphijtypedef void(XMLCALL *XML_AttlistDeclHandler)( 185355604Sdelphij void *userData, const XML_Char *elname, const XML_Char *attname, 186355604Sdelphij const XML_Char *att_type, const XML_Char *dflt, int isrequired); 187104349Sphk 188104349SphkXMLPARSEAPI(void) 189355604SdelphijXML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl); 190104349Sphk 191104349Sphk/* The XML declaration handler is called for *both* XML declarations 192104349Sphk and text declarations. The way to distinguish is that the version 193104349Sphk parameter will be NULL for text declarations. The encoding 194104349Sphk parameter may be NULL for XML declarations. The standalone 195104349Sphk parameter will be -1, 0, or 1 indicating respectively that there 196104349Sphk was no standalone parameter in the declaration, that it was given 197104349Sphk as no, or that it was given as yes. 198104349Sphk*/ 199355604Sdelphijtypedef void(XMLCALL *XML_XmlDeclHandler)(void *userData, 200355604Sdelphij const XML_Char *version, 201355604Sdelphij const XML_Char *encoding, 202355604Sdelphij int standalone); 203104349Sphk 204104349SphkXMLPARSEAPI(void) 205355604SdelphijXML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl); 206104349Sphk 207104349Sphktypedef struct { 208104349Sphk void *(*malloc_fcn)(size_t size); 209104349Sphk void *(*realloc_fcn)(void *ptr, size_t size); 210104349Sphk void (*free_fcn)(void *ptr); 211104349Sphk} XML_Memory_Handling_Suite; 212104349Sphk 213104349Sphk/* Constructs a new parser; encoding is the encoding specified by the 214104349Sphk external protocol or NULL if there is none specified. 215104349Sphk*/ 216104349SphkXMLPARSEAPI(XML_Parser) 217104349SphkXML_ParserCreate(const XML_Char *encoding); 218104349Sphk 219104349Sphk/* Constructs a new parser and namespace processor. Element type 220104349Sphk names and attribute names that belong to a namespace will be 221104349Sphk expanded; unprefixed attribute names are never expanded; unprefixed 222104349Sphk element type names are expanded only if there is a default 223104349Sphk namespace. The expanded name is the concatenation of the namespace 224104349Sphk URI, the namespace separator character, and the local part of the 225104349Sphk name. If the namespace separator is '\0' then the namespace URI 226104349Sphk and the local part will be concatenated without any separator. 227178848Scokane It is a programming error to use the separator '\0' with namespace 228178848Scokane triplets (see XML_SetReturnNSTriplet). 229104349Sphk*/ 230104349SphkXMLPARSEAPI(XML_Parser) 231104349SphkXML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); 232104349Sphk 233178848Scokane/* Constructs a new parser using the memory management suite referred to 234104349Sphk by memsuite. If memsuite is NULL, then use the standard library memory 235104349Sphk suite. If namespaceSeparator is non-NULL it creates a parser with 236104349Sphk namespace processing as described above. The character pointed at 237104349Sphk will serve as the namespace separator. 238104349Sphk 239104349Sphk All further memory operations used for the created parser will come from 240104349Sphk the given suite. 241104349Sphk*/ 242104349SphkXMLPARSEAPI(XML_Parser) 243104349SphkXML_ParserCreate_MM(const XML_Char *encoding, 244104349Sphk const XML_Memory_Handling_Suite *memsuite, 245104349Sphk const XML_Char *namespaceSeparator); 246104349Sphk 247104349Sphk/* Prepare a parser object to be re-used. This is particularly 248355604Sdelphij valuable when memory allocation overhead is disproportionately high, 249104349Sphk such as when a large number of small documnents need to be parsed. 250178848Scokane All handlers are cleared from the parser, except for the 251104349Sphk unknownEncodingHandler. The parser's external state is re-initialized 252104349Sphk except for the values of ns and ns_triplets. 253104349Sphk 254104349Sphk Added in Expat 1.95.3. 255104349Sphk*/ 256104349SphkXMLPARSEAPI(XML_Bool) 257104349SphkXML_ParserReset(XML_Parser parser, const XML_Char *encoding); 258104349Sphk 259104349Sphk/* atts is array of name/value pairs, terminated by 0; 260104349Sphk names and values are 0 terminated. 261104349Sphk*/ 262355604Sdelphijtypedef void(XMLCALL *XML_StartElementHandler)(void *userData, 263355604Sdelphij const XML_Char *name, 264355604Sdelphij const XML_Char **atts); 265104349Sphk 266355604Sdelphijtypedef void(XMLCALL *XML_EndElementHandler)(void *userData, 267355604Sdelphij const XML_Char *name); 268104349Sphk 269104349Sphk/* s is not 0 terminated. */ 270355604Sdelphijtypedef void(XMLCALL *XML_CharacterDataHandler)(void *userData, 271355604Sdelphij const XML_Char *s, int len); 272104349Sphk 273104349Sphk/* target and data are 0 terminated */ 274355604Sdelphijtypedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData, 275355604Sdelphij const XML_Char *target, 276355604Sdelphij const XML_Char *data); 277104349Sphk 278104349Sphk/* data is 0 terminated */ 279355604Sdelphijtypedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data); 280104349Sphk 281355604Sdelphijtypedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData); 282355604Sdelphijtypedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData); 283104349Sphk 284104349Sphk/* This is called for any characters in the XML document for which 285104349Sphk there is no applicable handler. This includes both characters that 286104349Sphk are part of markup which is of a kind that is not reported 287104349Sphk (comments, markup declarations), or characters that are part of a 288104349Sphk construct which could be reported but for which no handler has been 289104349Sphk supplied. The characters are passed exactly as they were in the XML 290178848Scokane document except that they will be encoded in UTF-8 or UTF-16. 291104349Sphk Line boundaries are not normalized. Note that a byte order mark 292104349Sphk character is not passed to the default handler. There are no 293104349Sphk guarantees about how characters are divided between calls to the 294104349Sphk default handler: for example, a comment might be split between 295104349Sphk multiple calls. 296104349Sphk*/ 297355604Sdelphijtypedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s, 298355604Sdelphij int len); 299104349Sphk 300104349Sphk/* This is called for the start of the DOCTYPE declaration, before 301104349Sphk any DTD or internal subset is parsed. 302104349Sphk*/ 303355604Sdelphijtypedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, 304355604Sdelphij const XML_Char *doctypeName, 305355604Sdelphij const XML_Char *sysid, 306355604Sdelphij const XML_Char *pubid, 307355604Sdelphij int has_internal_subset); 308104349Sphk 309104349Sphk/* This is called for the start of the DOCTYPE declaration when the 310104349Sphk closing > is encountered, but after processing any external 311104349Sphk subset. 312104349Sphk*/ 313355604Sdelphijtypedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); 314104349Sphk 315104349Sphk/* This is called for entity declarations. The is_parameter_entity 316104349Sphk argument will be non-zero if the entity is a parameter entity, zero 317104349Sphk otherwise. 318104349Sphk 319104349Sphk For internal entities (<!ENTITY foo "bar">), value will 320104349Sphk be non-NULL and systemId, publicID, and notationName will be NULL. 321104349Sphk The value string is NOT nul-terminated; the length is provided in 322104349Sphk the value_length argument. Since it is legal to have zero-length 323104349Sphk values, do not use this argument to test for internal entities. 324104349Sphk 325104349Sphk For external entities, value will be NULL and systemId will be 326104349Sphk non-NULL. The publicId argument will be NULL unless a public 327104349Sphk identifier was provided. The notationName argument will have a 328104349Sphk non-NULL value only for unparsed entity declarations. 329104349Sphk 330104349Sphk Note that is_parameter_entity can't be changed to XML_Bool, since 331104349Sphk that would break binary compatibility. 332104349Sphk*/ 333355604Sdelphijtypedef void(XMLCALL *XML_EntityDeclHandler)( 334355604Sdelphij void *userData, const XML_Char *entityName, int is_parameter_entity, 335355604Sdelphij const XML_Char *value, int value_length, const XML_Char *base, 336355604Sdelphij const XML_Char *systemId, const XML_Char *publicId, 337355604Sdelphij const XML_Char *notationName); 338178848Scokane 339104349SphkXMLPARSEAPI(void) 340355604SdelphijXML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); 341104349Sphk 342104349Sphk/* OBSOLETE -- OBSOLETE -- OBSOLETE 343302305Sdelphij This handler has been superseded by the EntityDeclHandler above. 344104349Sphk It is provided here for backward compatibility. 345104349Sphk 346104349Sphk This is called for a declaration of an unparsed (NDATA) entity. 347104349Sphk The base argument is whatever was set by XML_SetBase. The 348104349Sphk entityName, systemId and notationName arguments will never be 349104349Sphk NULL. The other arguments may be. 350104349Sphk*/ 351355604Sdelphijtypedef void(XMLCALL *XML_UnparsedEntityDeclHandler)( 352355604Sdelphij void *userData, const XML_Char *entityName, const XML_Char *base, 353355604Sdelphij const XML_Char *systemId, const XML_Char *publicId, 354355604Sdelphij const XML_Char *notationName); 355104349Sphk 356104349Sphk/* This is called for a declaration of notation. The base argument is 357104349Sphk whatever was set by XML_SetBase. The notationName will never be 358104349Sphk NULL. The other arguments can be. 359104349Sphk*/ 360355604Sdelphijtypedef void(XMLCALL *XML_NotationDeclHandler)(void *userData, 361355604Sdelphij const XML_Char *notationName, 362355604Sdelphij const XML_Char *base, 363355604Sdelphij const XML_Char *systemId, 364355604Sdelphij const XML_Char *publicId); 365104349Sphk 366104349Sphk/* When namespace processing is enabled, these are called once for 367104349Sphk each namespace declaration. The call to the start and end element 368104349Sphk handlers occur between the calls to the start and end namespace 369104349Sphk declaration handlers. For an xmlns attribute, prefix will be 370104349Sphk NULL. For an xmlns="" attribute, uri will be NULL. 371104349Sphk*/ 372355604Sdelphijtypedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData, 373355604Sdelphij const XML_Char *prefix, 374355604Sdelphij const XML_Char *uri); 375104349Sphk 376355604Sdelphijtypedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, 377355604Sdelphij const XML_Char *prefix); 378104349Sphk 379104349Sphk/* This is called if the document is not standalone, that is, it has an 380104349Sphk external subset or a reference to a parameter entity, but does not 381178848Scokane have standalone="yes". If this handler returns XML_STATUS_ERROR, 382178848Scokane then processing will not continue, and the parser will return a 383104349Sphk XML_ERROR_NOT_STANDALONE error. 384104349Sphk If parameter entity parsing is enabled, then in addition to the 385104349Sphk conditions above this handler will only be called if the referenced 386104349Sphk entity was actually read. 387104349Sphk*/ 388355604Sdelphijtypedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData); 389104349Sphk 390104349Sphk/* This is called for a reference to an external parsed general 391104349Sphk entity. The referenced entity is not automatically parsed. The 392104349Sphk application can parse it immediately or later using 393104349Sphk XML_ExternalEntityParserCreate. 394104349Sphk 395104349Sphk The parser argument is the parser parsing the entity containing the 396104349Sphk reference; it can be passed as the parser argument to 397104349Sphk XML_ExternalEntityParserCreate. The systemId argument is the 398104349Sphk system identifier as specified in the entity declaration; it will 399104349Sphk not be NULL. 400104349Sphk 401104349Sphk The base argument is the system identifier that should be used as 402104349Sphk the base for resolving systemId if systemId was relative; this is 403104349Sphk set by XML_SetBase; it may be NULL. 404104349Sphk 405104349Sphk The publicId argument is the public identifier as specified in the 406104349Sphk entity declaration, or NULL if none was specified; the whitespace 407104349Sphk in the public identifier will have been normalized as required by 408104349Sphk the XML spec. 409104349Sphk 410104349Sphk The context argument specifies the parsing context in the format 411104349Sphk expected by the context argument to XML_ExternalEntityParserCreate; 412104349Sphk context is valid only until the handler returns, so if the 413104349Sphk referenced entity is to be parsed later, it must be copied. 414178848Scokane context is NULL only when the entity is a parameter entity. 415104349Sphk 416178848Scokane The handler should return XML_STATUS_ERROR if processing should not 417178848Scokane continue because of a fatal error in the handling of the external 418178848Scokane entity. In this case the calling parser will return an 419104349Sphk XML_ERROR_EXTERNAL_ENTITY_HANDLING error. 420104349Sphk 421104349Sphk Note that unlike other handlers the first argument is the parser, 422104349Sphk not userData. 423104349Sphk*/ 424355604Sdelphijtypedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser, 425355604Sdelphij const XML_Char *context, 426355604Sdelphij const XML_Char *base, 427355604Sdelphij const XML_Char *systemId, 428355604Sdelphij const XML_Char *publicId); 429104349Sphk 430104349Sphk/* This is called in two situations: 431104349Sphk 1) An entity reference is encountered for which no declaration 432104349Sphk has been read *and* this is not an error. 433104349Sphk 2) An internal entity reference is read, but not expanded, because 434104349Sphk XML_SetDefaultHandler has been called. 435104349Sphk Note: skipped parameter entities in declarations and skipped general 436104349Sphk entities in attribute values cannot be reported, because 437104349Sphk the event would be out of sync with the reporting of the 438104349Sphk declarations or attribute values 439104349Sphk*/ 440355604Sdelphijtypedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData, 441355604Sdelphij const XML_Char *entityName, 442355604Sdelphij int is_parameter_entity); 443104349Sphk 444104349Sphk/* This structure is filled in by the XML_UnknownEncodingHandler to 445104349Sphk provide information to the parser about encodings that are unknown 446104349Sphk to the parser. 447104349Sphk 448104349Sphk The map[b] member gives information about byte sequences whose 449104349Sphk first byte is b. 450104349Sphk 451104349Sphk If map[b] is c where c is >= 0, then b by itself encodes the 452104349Sphk Unicode scalar value c. 453104349Sphk 454104349Sphk If map[b] is -1, then the byte sequence is malformed. 455104349Sphk 456104349Sphk If map[b] is -n, where n >= 2, then b is the first byte of an 457104349Sphk n-byte sequence that encodes a single Unicode scalar value. 458104349Sphk 459104349Sphk The data member will be passed as the first argument to the convert 460104349Sphk function. 461104349Sphk 462104349Sphk The convert function is used to convert multibyte sequences; s will 463104349Sphk point to a n-byte sequence where map[(unsigned char)*s] == -n. The 464104349Sphk convert function must return the Unicode scalar value represented 465104349Sphk by this byte sequence or -1 if the byte sequence is malformed. 466104349Sphk 467104349Sphk The convert function may be NULL if the encoding is a single-byte 468104349Sphk encoding, that is if map[b] >= -1 for all bytes b. 469104349Sphk 470104349Sphk When the parser is finished with the encoding, then if release is 471104349Sphk not NULL, it will call release passing it the data member; once 472104349Sphk release has been called, the convert function will not be called 473104349Sphk again. 474104349Sphk 475104349Sphk Expat places certain restrictions on the encodings that are supported 476104349Sphk using this mechanism. 477104349Sphk 478104349Sphk 1. Every ASCII character that can appear in a well-formed XML document, 479104349Sphk other than the characters 480104349Sphk 481104349Sphk $@\^`{}~ 482104349Sphk 483104349Sphk must be represented by a single byte, and that byte must be the 484104349Sphk same byte that represents that character in ASCII. 485104349Sphk 486104349Sphk 2. No character may require more than 4 bytes to encode. 487104349Sphk 488104349Sphk 3. All characters encoded must have Unicode scalar values <= 489104349Sphk 0xFFFF, (i.e., characters that would be encoded by surrogates in 490104349Sphk UTF-16 are not allowed). Note that this restriction doesn't 491104349Sphk apply to the built-in support for UTF-8 and UTF-16. 492104349Sphk 493104349Sphk 4. No Unicode character may be encoded by more than one distinct 494104349Sphk sequence of bytes. 495104349Sphk*/ 496104349Sphktypedef struct { 497104349Sphk int map[256]; 498104349Sphk void *data; 499355604Sdelphij int(XMLCALL *convert)(void *data, const char *s); 500355604Sdelphij void(XMLCALL *release)(void *data); 501104349Sphk} XML_Encoding; 502104349Sphk 503104349Sphk/* This is called for an encoding that is unknown to the parser. 504104349Sphk 505104349Sphk The encodingHandlerData argument is that which was passed as the 506104349Sphk second argument to XML_SetUnknownEncodingHandler. 507104349Sphk 508104349Sphk The name argument gives the name of the encoding as specified in 509104349Sphk the encoding declaration. 510104349Sphk 511104349Sphk If the callback can provide information about the encoding, it must 512178848Scokane fill in the XML_Encoding structure, and return XML_STATUS_OK. 513178848Scokane Otherwise it must return XML_STATUS_ERROR. 514104349Sphk 515104349Sphk If info does not describe a suitable encoding, then the parser will 516104349Sphk return an XML_UNKNOWN_ENCODING error. 517104349Sphk*/ 518355604Sdelphijtypedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, 519355604Sdelphij const XML_Char *name, 520355604Sdelphij XML_Encoding *info); 521104349Sphk 522104349SphkXMLPARSEAPI(void) 523355604SdelphijXML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, 524104349Sphk XML_EndElementHandler end); 525104349Sphk 526104349SphkXMLPARSEAPI(void) 527355604SdelphijXML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler); 528104349Sphk 529104349SphkXMLPARSEAPI(void) 530355604SdelphijXML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler); 531104349Sphk 532104349SphkXMLPARSEAPI(void) 533104349SphkXML_SetCharacterDataHandler(XML_Parser parser, 534104349Sphk XML_CharacterDataHandler handler); 535104349Sphk 536104349SphkXMLPARSEAPI(void) 537104349SphkXML_SetProcessingInstructionHandler(XML_Parser parser, 538104349Sphk XML_ProcessingInstructionHandler handler); 539104349SphkXMLPARSEAPI(void) 540355604SdelphijXML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler); 541104349Sphk 542104349SphkXMLPARSEAPI(void) 543104349SphkXML_SetCdataSectionHandler(XML_Parser parser, 544104349Sphk XML_StartCdataSectionHandler start, 545104349Sphk XML_EndCdataSectionHandler end); 546104349Sphk 547104349SphkXMLPARSEAPI(void) 548104349SphkXML_SetStartCdataSectionHandler(XML_Parser parser, 549104349Sphk XML_StartCdataSectionHandler start); 550104349Sphk 551104349SphkXMLPARSEAPI(void) 552104349SphkXML_SetEndCdataSectionHandler(XML_Parser parser, 553104349Sphk XML_EndCdataSectionHandler end); 554104349Sphk 555104349Sphk/* This sets the default handler and also inhibits expansion of 556104349Sphk internal entities. These entity references will be passed to the 557104349Sphk default handler, or to the skipped entity handler, if one is set. 558104349Sphk*/ 559104349SphkXMLPARSEAPI(void) 560355604SdelphijXML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler); 561104349Sphk 562104349Sphk/* This sets the default handler but does not inhibit expansion of 563104349Sphk internal entities. The entity reference will not be passed to the 564104349Sphk default handler. 565104349Sphk*/ 566104349SphkXMLPARSEAPI(void) 567355604SdelphijXML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); 568104349Sphk 569104349SphkXMLPARSEAPI(void) 570355604SdelphijXML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, 571104349Sphk XML_EndDoctypeDeclHandler end); 572104349Sphk 573104349SphkXMLPARSEAPI(void) 574104349SphkXML_SetStartDoctypeDeclHandler(XML_Parser parser, 575104349Sphk XML_StartDoctypeDeclHandler start); 576104349Sphk 577104349SphkXMLPARSEAPI(void) 578355604SdelphijXML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end); 579104349Sphk 580104349SphkXMLPARSEAPI(void) 581104349SphkXML_SetUnparsedEntityDeclHandler(XML_Parser parser, 582104349Sphk XML_UnparsedEntityDeclHandler handler); 583104349Sphk 584104349SphkXMLPARSEAPI(void) 585355604SdelphijXML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler); 586104349Sphk 587104349SphkXMLPARSEAPI(void) 588104349SphkXML_SetNamespaceDeclHandler(XML_Parser parser, 589104349Sphk XML_StartNamespaceDeclHandler start, 590104349Sphk XML_EndNamespaceDeclHandler end); 591104349Sphk 592104349SphkXMLPARSEAPI(void) 593104349SphkXML_SetStartNamespaceDeclHandler(XML_Parser parser, 594104349Sphk XML_StartNamespaceDeclHandler start); 595104349Sphk 596104349SphkXMLPARSEAPI(void) 597104349SphkXML_SetEndNamespaceDeclHandler(XML_Parser parser, 598104349Sphk XML_EndNamespaceDeclHandler end); 599104349Sphk 600104349SphkXMLPARSEAPI(void) 601104349SphkXML_SetNotStandaloneHandler(XML_Parser parser, 602104349Sphk XML_NotStandaloneHandler handler); 603104349Sphk 604104349SphkXMLPARSEAPI(void) 605104349SphkXML_SetExternalEntityRefHandler(XML_Parser parser, 606104349Sphk XML_ExternalEntityRefHandler handler); 607104349Sphk 608104349Sphk/* If a non-NULL value for arg is specified here, then it will be 609104349Sphk passed as the first argument to the external entity ref handler 610104349Sphk instead of the parser object. 611104349Sphk*/ 612104349SphkXMLPARSEAPI(void) 613355604SdelphijXML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg); 614104349Sphk 615104349SphkXMLPARSEAPI(void) 616104349SphkXML_SetSkippedEntityHandler(XML_Parser parser, 617104349Sphk XML_SkippedEntityHandler handler); 618104349Sphk 619104349SphkXMLPARSEAPI(void) 620104349SphkXML_SetUnknownEncodingHandler(XML_Parser parser, 621104349Sphk XML_UnknownEncodingHandler handler, 622104349Sphk void *encodingHandlerData); 623104349Sphk 624104349Sphk/* This can be called within a handler for a start element, end 625104349Sphk element, processing instruction or character data. It causes the 626104349Sphk corresponding markup to be passed to the default handler. 627104349Sphk*/ 628104349SphkXMLPARSEAPI(void) 629104349SphkXML_DefaultCurrent(XML_Parser parser); 630104349Sphk 631104349Sphk/* If do_nst is non-zero, and namespace processing is in effect, and 632104349Sphk a name has a prefix (i.e. an explicit namespace qualifier) then 633104349Sphk that name is returned as a triplet in a single string separated by 634104349Sphk the separator character specified when the parser was created: URI 635104349Sphk + sep + local_name + sep + prefix. 636104349Sphk 637104349Sphk If do_nst is zero, then namespace information is returned in the 638104349Sphk default manner (URI + sep + local_name) whether or not the name 639104349Sphk has a prefix. 640104349Sphk 641104349Sphk Note: Calling XML_SetReturnNSTriplet after XML_Parse or 642104349Sphk XML_ParseBuffer has no effect. 643104349Sphk*/ 644104349Sphk 645104349SphkXMLPARSEAPI(void) 646104349SphkXML_SetReturnNSTriplet(XML_Parser parser, int do_nst); 647104349Sphk 648104349Sphk/* This value is passed as the userData argument to callbacks. */ 649104349SphkXMLPARSEAPI(void) 650104349SphkXML_SetUserData(XML_Parser parser, void *userData); 651104349Sphk 652104349Sphk/* Returns the last value set by XML_SetUserData or NULL. */ 653104349Sphk#define XML_GetUserData(parser) (*(void **)(parser)) 654104349Sphk 655104349Sphk/* This is equivalent to supplying an encoding argument to 656104349Sphk XML_ParserCreate. On success XML_SetEncoding returns non-zero, 657104349Sphk zero otherwise. 658104349Sphk Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer 659178848Scokane has no effect and returns XML_STATUS_ERROR. 660104349Sphk*/ 661178848ScokaneXMLPARSEAPI(enum XML_Status) 662104349SphkXML_SetEncoding(XML_Parser parser, const XML_Char *encoding); 663104349Sphk 664104349Sphk/* If this function is called, then the parser will be passed as the 665104349Sphk first argument to callbacks instead of userData. The userData will 666104349Sphk still be accessible using XML_GetUserData. 667104349Sphk*/ 668104349SphkXMLPARSEAPI(void) 669104349SphkXML_UseParserAsHandlerArg(XML_Parser parser); 670104349Sphk 671104349Sphk/* If useDTD == XML_TRUE is passed to this function, then the parser 672104349Sphk will assume that there is an external subset, even if none is 673104349Sphk specified in the document. In such a case the parser will call the 674104349Sphk externalEntityRefHandler with a value of NULL for the systemId 675104349Sphk argument (the publicId and context arguments will be NULL as well). 676178848Scokane Note: For the purpose of checking WFC: Entity Declared, passing 677178848Scokane useDTD == XML_TRUE will make the parser behave as if the document 678178848Scokane had a DTD with an external subset. 679104349Sphk Note: If this function is called, then this must be done before 680104349Sphk the first call to XML_Parse or XML_ParseBuffer, since it will 681104349Sphk have no effect after that. Returns 682104349Sphk XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. 683104349Sphk Note: If the document does not have a DOCTYPE declaration at all, 684104349Sphk then startDoctypeDeclHandler and endDoctypeDeclHandler will not 685104349Sphk be called, despite an external subset being parsed. 686104349Sphk Note: If XML_DTD is not defined when Expat is compiled, returns 687104349Sphk XML_ERROR_FEATURE_REQUIRES_XML_DTD. 688355604Sdelphij Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT. 689104349Sphk*/ 690104349SphkXMLPARSEAPI(enum XML_Error) 691104349SphkXML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); 692104349Sphk 693104349Sphk/* Sets the base to be used for resolving relative URIs in system 694104349Sphk identifiers in declarations. Resolving relative identifiers is 695104349Sphk left to the application: this value will be passed through as the 696104349Sphk base argument to the XML_ExternalEntityRefHandler, 697104349Sphk XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base 698178848Scokane argument will be copied. Returns XML_STATUS_ERROR if out of memory, 699178848Scokane XML_STATUS_OK otherwise. 700104349Sphk*/ 701178848ScokaneXMLPARSEAPI(enum XML_Status) 702104349SphkXML_SetBase(XML_Parser parser, const XML_Char *base); 703104349Sphk 704104349SphkXMLPARSEAPI(const XML_Char *) 705104349SphkXML_GetBase(XML_Parser parser); 706104349Sphk 707104349Sphk/* Returns the number of the attribute/value pairs passed in last call 708104349Sphk to the XML_StartElementHandler that were specified in the start-tag 709104349Sphk rather than defaulted. Each attribute/value pair counts as 2; thus 710104349Sphk this correspondds to an index into the atts array passed to the 711355604Sdelphij XML_StartElementHandler. Returns -1 if parser == NULL. 712104349Sphk*/ 713104349SphkXMLPARSEAPI(int) 714104349SphkXML_GetSpecifiedAttributeCount(XML_Parser parser); 715104349Sphk 716104349Sphk/* Returns the index of the ID attribute passed in the last call to 717355604Sdelphij XML_StartElementHandler, or -1 if there is no ID attribute or 718355604Sdelphij parser == NULL. Each attribute/value pair counts as 2; thus this 719355604Sdelphij correspondds to an index into the atts array passed to the 720355604Sdelphij XML_StartElementHandler. 721104349Sphk*/ 722104349SphkXMLPARSEAPI(int) 723104349SphkXML_GetIdAttributeIndex(XML_Parser parser); 724104349Sphk 725247296Sdelphij#ifdef XML_ATTR_INFO 726247296Sdelphij/* Source file byte offsets for the start and end of attribute names and values. 727247296Sdelphij The value indices are exclusive of surrounding quotes; thus in a UTF-8 source 728247296Sdelphij file an attribute value of "blah" will yield: 729247296Sdelphij info->valueEnd - info->valueStart = 4 bytes. 730247296Sdelphij*/ 731247296Sdelphijtypedef struct { 732355604Sdelphij XML_Index nameStart; /* Offset to beginning of the attribute name. */ 733355604Sdelphij XML_Index nameEnd; /* Offset after the attribute name's last byte. */ 734355604Sdelphij XML_Index valueStart; /* Offset to beginning of the attribute value. */ 735355604Sdelphij XML_Index valueEnd; /* Offset after the attribute value's last byte. */ 736247296Sdelphij} XML_AttrInfo; 737247296Sdelphij 738247296Sdelphij/* Returns an array of XML_AttrInfo structures for the attribute/value pairs 739247296Sdelphij passed in last call to the XML_StartElementHandler that were specified 740247296Sdelphij in the start-tag rather than defaulted. Each attribute/value pair counts 741247296Sdelphij as 1; thus the number of entries in the array is 742247296Sdelphij XML_GetSpecifiedAttributeCount(parser) / 2. 743247296Sdelphij*/ 744247296SdelphijXMLPARSEAPI(const XML_AttrInfo *) 745247296SdelphijXML_GetAttributeInfo(XML_Parser parser); 746247296Sdelphij#endif 747247296Sdelphij 748104349Sphk/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is 749104349Sphk detected. The last call to XML_Parse must have isFinal true; len 750104349Sphk may be zero for this call (or any other). 751104349Sphk 752178848Scokane Though the return values for these functions has always been 753178848Scokane described as a Boolean value, the implementation, at least for the 754178848Scokane 1.95.x series, has always returned exactly one of the XML_Status 755178848Scokane values. 756104349Sphk*/ 757104349SphkXMLPARSEAPI(enum XML_Status) 758104349SphkXML_Parse(XML_Parser parser, const char *s, int len, int isFinal); 759104349Sphk 760104349SphkXMLPARSEAPI(void *) 761104349SphkXML_GetBuffer(XML_Parser parser, int len); 762104349Sphk 763104349SphkXMLPARSEAPI(enum XML_Status) 764104349SphkXML_ParseBuffer(XML_Parser parser, int len, int isFinal); 765104349Sphk 766178848Scokane/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. 767178848Scokane Must be called from within a call-back handler, except when aborting 768178848Scokane (resumable = 0) an already suspended parser. Some call-backs may 769178848Scokane still follow because they would otherwise get lost. Examples: 770178848Scokane - endElementHandler() for empty elements when stopped in 771355604Sdelphij startElementHandler(), 772355604Sdelphij - endNameSpaceDeclHandler() when stopped in endElementHandler(), 773178848Scokane and possibly others. 774178848Scokane 775178848Scokane Can be called from most handlers, including DTD related call-backs, 776178848Scokane except when parsing an external parameter entity and resumable != 0. 777178848Scokane Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. 778355604Sdelphij Possible error codes: 779178848Scokane - XML_ERROR_SUSPENDED: when suspending an already suspended parser. 780178848Scokane - XML_ERROR_FINISHED: when the parser has already finished. 781178848Scokane - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. 782178848Scokane 783355604Sdelphij When resumable != 0 (true) then parsing is suspended, that is, 784355604Sdelphij XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. 785178848Scokane Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() 786178848Scokane return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. 787178848Scokane 788178848Scokane *Note*: 789178848Scokane This will be applied to the current parser instance only, that is, if 790178848Scokane there is a parent parser then it will continue parsing when the 791178848Scokane externalEntityRefHandler() returns. It is up to the implementation of 792178848Scokane the externalEntityRefHandler() to call XML_StopParser() on the parent 793178848Scokane parser (recursively), if one wants to stop parsing altogether. 794178848Scokane 795355604Sdelphij When suspended, parsing can be resumed by calling XML_ResumeParser(). 796178848Scokane*/ 797178848ScokaneXMLPARSEAPI(enum XML_Status) 798178848ScokaneXML_StopParser(XML_Parser parser, XML_Bool resumable); 799178848Scokane 800178848Scokane/* Resumes parsing after it has been suspended with XML_StopParser(). 801178848Scokane Must not be called from within a handler call-back. Returns same 802178848Scokane status codes as XML_Parse() or XML_ParseBuffer(). 803355604Sdelphij Additional error code XML_ERROR_NOT_SUSPENDED possible. 804178848Scokane 805178848Scokane *Note*: 806178848Scokane This must be called on the most deeply nested child parser instance 807178848Scokane first, and on its parent parser only after the child parser has finished, 808178848Scokane to be applied recursively until the document entity's parser is restarted. 809178848Scokane That is, the parent parser will not resume by itself and it is up to the 810178848Scokane application to call XML_ResumeParser() on it at the appropriate moment. 811178848Scokane*/ 812178848ScokaneXMLPARSEAPI(enum XML_Status) 813178848ScokaneXML_ResumeParser(XML_Parser parser); 814178848Scokane 815355604Sdelphijenum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED }; 816178848Scokane 817178848Scokanetypedef struct { 818178848Scokane enum XML_Parsing parsing; 819178848Scokane XML_Bool finalBuffer; 820178848Scokane} XML_ParsingStatus; 821178848Scokane 822178848Scokane/* Returns status of parser with respect to being initialized, parsing, 823178848Scokane finished, or suspended and processing the final buffer. 824178848Scokane XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, 825178848Scokane XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED 826178848Scokane*/ 827178848ScokaneXMLPARSEAPI(void) 828178848ScokaneXML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); 829178848Scokane 830104349Sphk/* Creates an XML_Parser object that can parse an external general 831104349Sphk entity; context is a '\0'-terminated string specifying the parse 832104349Sphk context; encoding is a '\0'-terminated string giving the name of 833104349Sphk the externally specified encoding, or NULL if there is no 834104349Sphk externally specified encoding. The context string consists of a 835104349Sphk sequence of tokens separated by formfeeds (\f); a token consisting 836104349Sphk of a name specifies that the general entity of the name is open; a 837104349Sphk token of the form prefix=uri specifies the namespace for a 838104349Sphk particular prefix; a token of the form =uri specifies the default 839104349Sphk namespace. This can be called at any point after the first call to 840104349Sphk an ExternalEntityRefHandler so longer as the parser has not yet 841104349Sphk been freed. The new parser is completely independent and may 842104349Sphk safely be used in a separate thread. The handlers and userData are 843178848Scokane initialized from the parser argument. Returns NULL if out of memory. 844104349Sphk Otherwise returns a new XML_Parser object. 845104349Sphk*/ 846104349SphkXMLPARSEAPI(XML_Parser) 847355604SdelphijXML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context, 848104349Sphk const XML_Char *encoding); 849104349Sphk 850104349Sphkenum XML_ParamEntityParsing { 851104349Sphk XML_PARAM_ENTITY_PARSING_NEVER, 852104349Sphk XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, 853104349Sphk XML_PARAM_ENTITY_PARSING_ALWAYS 854104349Sphk}; 855104349Sphk 856104349Sphk/* Controls parsing of parameter entities (including the external DTD 857104349Sphk subset). If parsing of parameter entities is enabled, then 858104349Sphk references to external parameter entities (including the external 859104349Sphk DTD subset) will be passed to the handler set with 860104349Sphk XML_SetExternalEntityRefHandler. The context passed will be 0. 861104349Sphk 862104349Sphk Unlike external general entities, external parameter entities can 863104349Sphk only be parsed synchronously. If the external parameter entity is 864104349Sphk to be parsed, it must be parsed during the call to the external 865104349Sphk entity ref handler: the complete sequence of 866104349Sphk XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and 867104349Sphk XML_ParserFree calls must be made during this call. After 868104349Sphk XML_ExternalEntityParserCreate has been called to create the parser 869104349Sphk for the external parameter entity (context must be 0 for this 870104349Sphk call), it is illegal to make any calls on the old parser until 871104349Sphk XML_ParserFree has been called on the newly created parser. 872104349Sphk If the library has been compiled without support for parameter 873104349Sphk entity parsing (ie without XML_DTD being defined), then 874104349Sphk XML_SetParamEntityParsing will return 0 if parsing of parameter 875104349Sphk entities is requested; otherwise it will return non-zero. 876104349Sphk Note: If XML_SetParamEntityParsing is called after XML_Parse or 877104349Sphk XML_ParseBuffer, then it has no effect and will always return 0. 878355604Sdelphij Note: If parser == NULL, the function will do nothing and return 0. 879104349Sphk*/ 880104349SphkXMLPARSEAPI(int) 881104349SphkXML_SetParamEntityParsing(XML_Parser parser, 882104349Sphk enum XML_ParamEntityParsing parsing); 883104349Sphk 884247296Sdelphij/* Sets the hash salt to use for internal hash calculations. 885247296Sdelphij Helps in preventing DoS attacks based on predicting hash 886247296Sdelphij function behavior. This must be called before parsing is started. 887247296Sdelphij Returns 1 if successful, 0 when called after parsing has started. 888355604Sdelphij Note: If parser == NULL, the function will do nothing and return 0. 889247296Sdelphij*/ 890247296SdelphijXMLPARSEAPI(int) 891355604SdelphijXML_SetHashSalt(XML_Parser parser, unsigned long hash_salt); 892247296Sdelphij 893178848Scokane/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then 894104349Sphk XML_GetErrorCode returns information about the error. 895104349Sphk*/ 896104349SphkXMLPARSEAPI(enum XML_Error) 897104349SphkXML_GetErrorCode(XML_Parser parser); 898104349Sphk 899104349Sphk/* These functions return information about the current parse 900178848Scokane location. They may be called from any callback called to report 901178848Scokane some parse event; in this case the location is the location of the 902178848Scokane first of the sequence of characters that generated the event. When 903178848Scokane called from callbacks generated by declarations in the document 904178848Scokane prologue, the location identified isn't as neatly defined, but will 905178848Scokane be within the relevant markup. When called outside of the callback 906178848Scokane functions, the position indicated will be just past the last parse 907178848Scokane event (regardless of whether there was an associated callback). 908355604Sdelphij 909178848Scokane They may also be called after returning from a call to XML_Parse 910178848Scokane or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then 911178848Scokane the location is the location of the character at which the error 912178848Scokane was detected; otherwise the location is the location of the last 913178848Scokane parse event, as described above. 914355604Sdelphij 915355604Sdelphij Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber 916355604Sdelphij return 0 to indicate an error. 917355604Sdelphij Note: XML_GetCurrentByteIndex returns -1 to indicate an error. 918104349Sphk*/ 919178848ScokaneXMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); 920178848ScokaneXMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); 921178848ScokaneXMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); 922104349Sphk 923104349Sphk/* Return the number of bytes in the current event. 924104349Sphk Returns 0 if the event is in an internal entity. 925104349Sphk*/ 926104349SphkXMLPARSEAPI(int) 927104349SphkXML_GetCurrentByteCount(XML_Parser parser); 928104349Sphk 929104349Sphk/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets 930104349Sphk the integer pointed to by offset to the offset within this buffer 931104349Sphk of the current parse position, and sets the integer pointed to by size 932104349Sphk to the size of this buffer (the number of input bytes). Otherwise 933104349Sphk returns a NULL pointer. Also returns a NULL pointer if a parse isn't 934104349Sphk active. 935104349Sphk 936104349Sphk NOTE: The character pointer returned should not be used outside 937104349Sphk the handler that makes the call. 938104349Sphk*/ 939104349SphkXMLPARSEAPI(const char *) 940355604SdelphijXML_GetInputContext(XML_Parser parser, int *offset, int *size); 941104349Sphk 942104349Sphk/* For backwards compatibility with previous versions. */ 943355604Sdelphij#define XML_GetErrorLineNumber XML_GetCurrentLineNumber 944104349Sphk#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber 945355604Sdelphij#define XML_GetErrorByteIndex XML_GetCurrentByteIndex 946104349Sphk 947178848Scokane/* Frees the content model passed to the element declaration handler */ 948178848ScokaneXMLPARSEAPI(void) 949178848ScokaneXML_FreeContentModel(XML_Parser parser, XML_Content *model); 950178848Scokane 951178848Scokane/* Exposing the memory handling functions used in Expat */ 952178848ScokaneXMLPARSEAPI(void *) 953302305SdelphijXML_ATTR_MALLOC 954302305SdelphijXML_ATTR_ALLOC_SIZE(2) 955178848ScokaneXML_MemMalloc(XML_Parser parser, size_t size); 956178848Scokane 957178848ScokaneXMLPARSEAPI(void *) 958302305SdelphijXML_ATTR_ALLOC_SIZE(3) 959178848ScokaneXML_MemRealloc(XML_Parser parser, void *ptr, size_t size); 960178848Scokane 961178848ScokaneXMLPARSEAPI(void) 962178848ScokaneXML_MemFree(XML_Parser parser, void *ptr); 963178848Scokane 964104349Sphk/* Frees memory used by the parser. */ 965104349SphkXMLPARSEAPI(void) 966104349SphkXML_ParserFree(XML_Parser parser); 967104349Sphk 968104349Sphk/* Returns a string describing the error. */ 969104349SphkXMLPARSEAPI(const XML_LChar *) 970104349SphkXML_ErrorString(enum XML_Error code); 971104349Sphk 972104349Sphk/* Return a string containing the version number of this expat */ 973104349SphkXMLPARSEAPI(const XML_LChar *) 974104349SphkXML_ExpatVersion(void); 975104349Sphk 976104349Sphktypedef struct { 977104349Sphk int major; 978104349Sphk int minor; 979104349Sphk int micro; 980104349Sphk} XML_Expat_Version; 981104349Sphk 982104349Sphk/* Return an XML_Expat_Version structure containing numeric version 983104349Sphk number information for this version of expat. 984104349Sphk*/ 985104349SphkXMLPARSEAPI(XML_Expat_Version) 986104349SphkXML_ExpatVersionInfo(void); 987104349Sphk 988104349Sphk/* Added in Expat 1.95.5. */ 989104349Sphkenum XML_FeatureEnum { 990104349Sphk XML_FEATURE_END = 0, 991104349Sphk XML_FEATURE_UNICODE, 992104349Sphk XML_FEATURE_UNICODE_WCHAR_T, 993104349Sphk XML_FEATURE_DTD, 994104349Sphk XML_FEATURE_CONTEXT_BYTES, 995104349Sphk XML_FEATURE_MIN_SIZE, 996104349Sphk XML_FEATURE_SIZEOF_XML_CHAR, 997178848Scokane XML_FEATURE_SIZEOF_XML_LCHAR, 998178848Scokane XML_FEATURE_NS, 999247296Sdelphij XML_FEATURE_LARGE_SIZE, 1000247296Sdelphij XML_FEATURE_ATTR_INFO 1001104349Sphk /* Additional features must be added to the end of this enum. */ 1002104349Sphk}; 1003104349Sphk 1004104349Sphktypedef struct { 1005355604Sdelphij enum XML_FeatureEnum feature; 1006355604Sdelphij const XML_LChar *name; 1007355604Sdelphij long int value; 1008104349Sphk} XML_Feature; 1009104349Sphk 1010104349SphkXMLPARSEAPI(const XML_Feature *) 1011104349SphkXML_GetFeatureList(void); 1012104349Sphk 1013302305Sdelphij/* Expat follows the semantic versioning convention. 1014302305Sdelphij See http://semver.org. 1015104349Sphk*/ 1016178848Scokane#define XML_MAJOR_VERSION 2 1017302305Sdelphij#define XML_MINOR_VERSION 2 1018355604Sdelphij#define XML_MICRO_VERSION 9 1019104349Sphk 1020104349Sphk#ifdef __cplusplus 1021104349Sphk} 1022104349Sphk#endif 1023104349Sphk 1024178848Scokane#endif /* not Expat_INCLUDED */ 1025