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