/*1__ __ _2___\ \/ /_ __ __ _| |_3/ _ \\ /| '_ \ / _` | __|4| __// \| |_) | (_| | |_5\___/_/\_\ .__/ \__,_|\__|6|_| XML parser78Copyright (c) 1997-2000 Thai Open Source Software Center Ltd9Copyright (c) 2000 Clark Cooper <[email protected]>10Copyright (c) 2000-2005 Fred L. Drake, Jr. <[email protected]>11Copyright (c) 2001-2002 Greg Stein <[email protected]>12Copyright (c) 2002-2016 Karl Waclawek <[email protected]>13Copyright (c) 2016-2024 Sebastian Pipping <[email protected]>14Copyright (c) 2016 Cristian Rodríguez <[email protected]>15Copyright (c) 2016 Thomas Beutlich <[email protected]>16Copyright (c) 2017 Rhodri James <[email protected]>17Copyright (c) 2022 Thijs Schreijer <[email protected]>18Copyright (c) 2023 Hanno Böck <[email protected]>19Copyright (c) 2023 Sony Corporation / Snild Dolkow <[email protected]>20Copyright (c) 2024 Taichi Haradaguchi <[email protected]>21Licensed under the MIT license:2223Permission is hereby granted, free of charge, to any person obtaining24a copy of this software and associated documentation files (the25"Software"), to deal in the Software without restriction, including26without limitation the rights to use, copy, modify, merge, publish,27distribute, sublicense, and/or sell copies of the Software, and to permit28persons to whom the Software is furnished to do so, subject to the29following conditions:3031The above copyright notice and this permission notice shall be included32in all copies or substantial portions of the Software.3334THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,35EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF36MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN37NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,38DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR39OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE40USE OR OTHER DEALINGS IN THE SOFTWARE.41*/4243#ifndef Expat_INCLUDED44#define Expat_INCLUDED 14546#include <stdlib.h>47#include "expat_external.h"4849#ifdef __cplusplus50extern "C" {51#endif5253struct XML_ParserStruct;54typedef struct XML_ParserStruct *XML_Parser;5556typedef unsigned char XML_Bool;57#define XML_TRUE ((XML_Bool)1)58#define XML_FALSE ((XML_Bool)0)5960/* The XML_Status enum gives the possible return values for several61API functions. The preprocessor #defines are included so this62stanza can be added to code that still needs to support older63versions of Expat 1.95.x:6465#ifndef XML_STATUS_OK66#define XML_STATUS_OK 167#define XML_STATUS_ERROR 068#endif6970Otherwise, the #define hackery is quite ugly and would have been71dropped.72*/73enum XML_Status {74XML_STATUS_ERROR = 0,75#define XML_STATUS_ERROR XML_STATUS_ERROR76XML_STATUS_OK = 1,77#define XML_STATUS_OK XML_STATUS_OK78XML_STATUS_SUSPENDED = 279#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED80};8182enum XML_Error {83XML_ERROR_NONE,84XML_ERROR_NO_MEMORY,85XML_ERROR_SYNTAX,86XML_ERROR_NO_ELEMENTS,87XML_ERROR_INVALID_TOKEN,88XML_ERROR_UNCLOSED_TOKEN,89XML_ERROR_PARTIAL_CHAR,90XML_ERROR_TAG_MISMATCH,91XML_ERROR_DUPLICATE_ATTRIBUTE,92XML_ERROR_JUNK_AFTER_DOC_ELEMENT,93XML_ERROR_PARAM_ENTITY_REF,94XML_ERROR_UNDEFINED_ENTITY,95XML_ERROR_RECURSIVE_ENTITY_REF,96XML_ERROR_ASYNC_ENTITY,97XML_ERROR_BAD_CHAR_REF,98XML_ERROR_BINARY_ENTITY_REF,99XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,100XML_ERROR_MISPLACED_XML_PI,101XML_ERROR_UNKNOWN_ENCODING,102XML_ERROR_INCORRECT_ENCODING,103XML_ERROR_UNCLOSED_CDATA_SECTION,104XML_ERROR_EXTERNAL_ENTITY_HANDLING,105XML_ERROR_NOT_STANDALONE,106XML_ERROR_UNEXPECTED_STATE,107XML_ERROR_ENTITY_DECLARED_IN_PE,108XML_ERROR_FEATURE_REQUIRES_XML_DTD,109XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,110/* Added in 1.95.7. */111XML_ERROR_UNBOUND_PREFIX,112/* Added in 1.95.8. */113XML_ERROR_UNDECLARING_PREFIX,114XML_ERROR_INCOMPLETE_PE,115XML_ERROR_XML_DECL,116XML_ERROR_TEXT_DECL,117XML_ERROR_PUBLICID,118XML_ERROR_SUSPENDED,119XML_ERROR_NOT_SUSPENDED,120XML_ERROR_ABORTED,121XML_ERROR_FINISHED,122XML_ERROR_SUSPEND_PE,123/* Added in 2.0. */124XML_ERROR_RESERVED_PREFIX_XML,125XML_ERROR_RESERVED_PREFIX_XMLNS,126XML_ERROR_RESERVED_NAMESPACE_URI,127/* Added in 2.2.1. */128XML_ERROR_INVALID_ARGUMENT,129/* Added in 2.3.0. */130XML_ERROR_NO_BUFFER,131/* Added in 2.4.0. */132XML_ERROR_AMPLIFICATION_LIMIT_BREACH133};134135enum XML_Content_Type {136XML_CTYPE_EMPTY = 1,137XML_CTYPE_ANY,138XML_CTYPE_MIXED,139XML_CTYPE_NAME,140XML_CTYPE_CHOICE,141XML_CTYPE_SEQ142};143144enum XML_Content_Quant {145XML_CQUANT_NONE,146XML_CQUANT_OPT,147XML_CQUANT_REP,148XML_CQUANT_PLUS149};150151/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be152XML_CQUANT_NONE, and the other fields will be zero or NULL.153If type == XML_CTYPE_MIXED, then quant will be NONE or REP and154numchildren will contain number of elements that may be mixed in155and children point to an array of XML_Content cells that will be156all of XML_CTYPE_NAME type with no quantification.157158If type == XML_CTYPE_NAME, then the name points to the name, and159the numchildren field will be zero and children will be NULL. The160quant fields indicates any quantifiers placed on the name.161162CHOICE and SEQ will have name NULL, the number of children in163numchildren and children will point, recursively, to an array164of XML_Content cells.165166The EMPTY, ANY, and MIXED types will only occur at top level.167*/168169typedef struct XML_cp XML_Content;170171struct XML_cp {172enum XML_Content_Type type;173enum XML_Content_Quant quant;174XML_Char *name;175unsigned int numchildren;176XML_Content *children;177};178179/* This is called for an element declaration. See above for180description of the model argument. It's the user code's responsibility181to free model when finished with it. See XML_FreeContentModel.182There is no need to free the model from the handler, it can be kept183around and freed at a later stage.184*/185typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData,186const XML_Char *name,187XML_Content *model);188189XMLPARSEAPI(void)190XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl);191192/* The Attlist declaration handler is called for *each* attribute. So193a single Attlist declaration with multiple attributes declared will194generate multiple calls to this handler. The "default" parameter195may be NULL in the case of the "#IMPLIED" or "#REQUIRED"196keyword. The "isrequired" parameter will be true and the default197value will be NULL in the case of "#REQUIRED". If "isrequired" is198true and default is non-NULL, then this is a "#FIXED" default.199*/200typedef void(XMLCALL *XML_AttlistDeclHandler)(201void *userData, const XML_Char *elname, const XML_Char *attname,202const XML_Char *att_type, const XML_Char *dflt, int isrequired);203204XMLPARSEAPI(void)205XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl);206207/* The XML declaration handler is called for *both* XML declarations208and text declarations. The way to distinguish is that the version209parameter will be NULL for text declarations. The encoding210parameter may be NULL for XML declarations. The standalone211parameter will be -1, 0, or 1 indicating respectively that there212was no standalone parameter in the declaration, that it was given213as no, or that it was given as yes.214*/215typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData,216const XML_Char *version,217const XML_Char *encoding,218int standalone);219220XMLPARSEAPI(void)221XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl);222223typedef struct {224void *(*malloc_fcn)(size_t size);225void *(*realloc_fcn)(void *ptr, size_t size);226void (*free_fcn)(void *ptr);227} XML_Memory_Handling_Suite;228229/* Constructs a new parser; encoding is the encoding specified by the230external protocol or NULL if there is none specified.231*/232XMLPARSEAPI(XML_Parser)233XML_ParserCreate(const XML_Char *encoding);234235/* Constructs a new parser and namespace processor. Element type236names and attribute names that belong to a namespace will be237expanded; unprefixed attribute names are never expanded; unprefixed238element type names are expanded only if there is a default239namespace. The expanded name is the concatenation of the namespace240URI, the namespace separator character, and the local part of the241name. If the namespace separator is '\0' then the namespace URI242and the local part will be concatenated without any separator.243It is a programming error to use the separator '\0' with namespace244triplets (see XML_SetReturnNSTriplet).245If a namespace separator is chosen that can be part of a URI or246part of an XML name, splitting an expanded name back into its2471, 2 or 3 original parts on application level in the element handler248may end up vulnerable, so these are advised against; sane choices for249a namespace separator are e.g. '\n' (line feed) and '|' (pipe).250251Note that Expat does not validate namespace URIs (beyond encoding)252against RFC 3986 today (and is not required to do so with regard to253the XML 1.0 namespaces specification) but it may start doing that254in future releases. Before that, an application using Expat must255be ready to receive namespace URIs containing non-URI characters.256*/257XMLPARSEAPI(XML_Parser)258XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);259260/* Constructs a new parser using the memory management suite referred to261by memsuite. If memsuite is NULL, then use the standard library memory262suite. If namespaceSeparator is non-NULL it creates a parser with263namespace processing as described above. The character pointed at264will serve as the namespace separator.265266All further memory operations used for the created parser will come from267the given suite.268*/269XMLPARSEAPI(XML_Parser)270XML_ParserCreate_MM(const XML_Char *encoding,271const XML_Memory_Handling_Suite *memsuite,272const XML_Char *namespaceSeparator);273274/* Prepare a parser object to be reused. This is particularly275valuable when memory allocation overhead is disproportionately high,276such as when a large number of small documnents need to be parsed.277All handlers are cleared from the parser, except for the278unknownEncodingHandler. The parser's external state is re-initialized279except for the values of ns and ns_triplets.280281Added in Expat 1.95.3.282*/283XMLPARSEAPI(XML_Bool)284XML_ParserReset(XML_Parser parser, const XML_Char *encoding);285286/* atts is array of name/value pairs, terminated by 0;287names and values are 0 terminated.288*/289typedef void(XMLCALL *XML_StartElementHandler)(void *userData,290const XML_Char *name,291const XML_Char **atts);292293typedef void(XMLCALL *XML_EndElementHandler)(void *userData,294const XML_Char *name);295296/* s is not 0 terminated. */297typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData,298const XML_Char *s, int len);299300/* target and data are 0 terminated */301typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,302const XML_Char *target,303const XML_Char *data);304305/* data is 0 terminated */306typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data);307308typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData);309typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData);310311/* This is called for any characters in the XML document for which312there is no applicable handler. This includes both characters that313are part of markup which is of a kind that is not reported314(comments, markup declarations), or characters that are part of a315construct which could be reported but for which no handler has been316supplied. The characters are passed exactly as they were in the XML317document except that they will be encoded in UTF-8 or UTF-16.318Line boundaries are not normalized. Note that a byte order mark319character is not passed to the default handler. There are no320guarantees about how characters are divided between calls to the321default handler: for example, a comment might be split between322multiple calls.323*/324typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s,325int len);326327/* This is called for the start of the DOCTYPE declaration, before328any DTD or internal subset is parsed.329*/330typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,331const XML_Char *doctypeName,332const XML_Char *sysid,333const XML_Char *pubid,334int has_internal_subset);335336/* This is called for the end of the DOCTYPE declaration when the337closing > is encountered, but after processing any external338subset.339*/340typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);341342/* This is called for entity declarations. The is_parameter_entity343argument will be non-zero if the entity is a parameter entity, zero344otherwise.345346For internal entities (<!ENTITY foo "bar">), value will347be non-NULL and systemId, publicID, and notationName will be NULL.348The value string is NOT null-terminated; the length is provided in349the value_length argument. Since it is legal to have zero-length350values, do not use this argument to test for internal entities.351352For external entities, value will be NULL and systemId will be353non-NULL. The publicId argument will be NULL unless a public354identifier was provided. The notationName argument will have a355non-NULL value only for unparsed entity declarations.356357Note that is_parameter_entity can't be changed to XML_Bool, since358that would break binary compatibility.359*/360typedef void(XMLCALL *XML_EntityDeclHandler)(361void *userData, const XML_Char *entityName, int is_parameter_entity,362const XML_Char *value, int value_length, const XML_Char *base,363const XML_Char *systemId, const XML_Char *publicId,364const XML_Char *notationName);365366XMLPARSEAPI(void)367XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler);368369/* OBSOLETE -- OBSOLETE -- OBSOLETE370This handler has been superseded by the EntityDeclHandler above.371It is provided here for backward compatibility.372373This is called for a declaration of an unparsed (NDATA) entity.374The base argument is whatever was set by XML_SetBase. The375entityName, systemId and notationName arguments will never be376NULL. The other arguments may be.377*/378typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)(379void *userData, const XML_Char *entityName, const XML_Char *base,380const XML_Char *systemId, const XML_Char *publicId,381const XML_Char *notationName);382383/* This is called for a declaration of notation. The base argument is384whatever was set by XML_SetBase. The notationName will never be385NULL. The other arguments can be.386*/387typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData,388const XML_Char *notationName,389const XML_Char *base,390const XML_Char *systemId,391const XML_Char *publicId);392393/* When namespace processing is enabled, these are called once for394each namespace declaration. The call to the start and end element395handlers occur between the calls to the start and end namespace396declaration handlers. For an xmlns attribute, prefix will be397NULL. For an xmlns="" attribute, uri will be NULL.398*/399typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,400const XML_Char *prefix,401const XML_Char *uri);402403typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,404const XML_Char *prefix);405406/* This is called if the document is not standalone, that is, it has an407external subset or a reference to a parameter entity, but does not408have standalone="yes". If this handler returns XML_STATUS_ERROR,409then processing will not continue, and the parser will return a410XML_ERROR_NOT_STANDALONE error.411If parameter entity parsing is enabled, then in addition to the412conditions above this handler will only be called if the referenced413entity was actually read.414*/415typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData);416417/* This is called for a reference to an external parsed general418entity. The referenced entity is not automatically parsed. The419application can parse it immediately or later using420XML_ExternalEntityParserCreate.421422The parser argument is the parser parsing the entity containing the423reference; it can be passed as the parser argument to424XML_ExternalEntityParserCreate. The systemId argument is the425system identifier as specified in the entity declaration; it will426not be NULL.427428The base argument is the system identifier that should be used as429the base for resolving systemId if systemId was relative; this is430set by XML_SetBase; it may be NULL.431432The publicId argument is the public identifier as specified in the433entity declaration, or NULL if none was specified; the whitespace434in the public identifier will have been normalized as required by435the XML spec.436437The context argument specifies the parsing context in the format438expected by the context argument to XML_ExternalEntityParserCreate;439context is valid only until the handler returns, so if the440referenced entity is to be parsed later, it must be copied.441context is NULL only when the entity is a parameter entity.442443The handler should return XML_STATUS_ERROR if processing should not444continue because of a fatal error in the handling of the external445entity. In this case the calling parser will return an446XML_ERROR_EXTERNAL_ENTITY_HANDLING error.447448Note that unlike other handlers the first argument is the parser,449not userData.450*/451typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser,452const XML_Char *context,453const XML_Char *base,454const XML_Char *systemId,455const XML_Char *publicId);456457/* This is called in two situations:4581) An entity reference is encountered for which no declaration459has been read *and* this is not an error.4602) An internal entity reference is read, but not expanded, because461XML_SetDefaultHandler has been called.462Note: skipped parameter entities in declarations and skipped general463entities in attribute values cannot be reported, because464the event would be out of sync with the reporting of the465declarations or attribute values466*/467typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData,468const XML_Char *entityName,469int is_parameter_entity);470471/* This structure is filled in by the XML_UnknownEncodingHandler to472provide information to the parser about encodings that are unknown473to the parser.474475The map[b] member gives information about byte sequences whose476first byte is b.477478If map[b] is c where c is >= 0, then b by itself encodes the479Unicode scalar value c.480481If map[b] is -1, then the byte sequence is malformed.482483If map[b] is -n, where n >= 2, then b is the first byte of an484n-byte sequence that encodes a single Unicode scalar value.485486The data member will be passed as the first argument to the convert487function.488489The convert function is used to convert multibyte sequences; s will490point to a n-byte sequence where map[(unsigned char)*s] == -n. The491convert function must return the Unicode scalar value represented492by this byte sequence or -1 if the byte sequence is malformed.493494The convert function may be NULL if the encoding is a single-byte495encoding, that is if map[b] >= -1 for all bytes b.496497When the parser is finished with the encoding, then if release is498not NULL, it will call release passing it the data member; once499release has been called, the convert function will not be called500again.501502Expat places certain restrictions on the encodings that are supported503using this mechanism.5045051. Every ASCII character that can appear in a well-formed XML document,506other than the characters507508$@\^`{}~509510must be represented by a single byte, and that byte must be the511same byte that represents that character in ASCII.5125132. No character may require more than 4 bytes to encode.5145153. All characters encoded must have Unicode scalar values <=5160xFFFF, (i.e., characters that would be encoded by surrogates in517UTF-16 are not allowed). Note that this restriction doesn't518apply to the built-in support for UTF-8 and UTF-16.5195204. No Unicode character may be encoded by more than one distinct521sequence of bytes.522*/523typedef struct {524int map[256];525void *data;526int(XMLCALL *convert)(void *data, const char *s);527void(XMLCALL *release)(void *data);528} XML_Encoding;529530/* This is called for an encoding that is unknown to the parser.531532The encodingHandlerData argument is that which was passed as the533second argument to XML_SetUnknownEncodingHandler.534535The name argument gives the name of the encoding as specified in536the encoding declaration.537538If the callback can provide information about the encoding, it must539fill in the XML_Encoding structure, and return XML_STATUS_OK.540Otherwise it must return XML_STATUS_ERROR.541542If info does not describe a suitable encoding, then the parser will543return an XML_ERROR_UNKNOWN_ENCODING error.544*/545typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,546const XML_Char *name,547XML_Encoding *info);548549XMLPARSEAPI(void)550XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start,551XML_EndElementHandler end);552553XMLPARSEAPI(void)554XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler);555556XMLPARSEAPI(void)557XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler);558559XMLPARSEAPI(void)560XML_SetCharacterDataHandler(XML_Parser parser,561XML_CharacterDataHandler handler);562563XMLPARSEAPI(void)564XML_SetProcessingInstructionHandler(XML_Parser parser,565XML_ProcessingInstructionHandler handler);566XMLPARSEAPI(void)567XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler);568569XMLPARSEAPI(void)570XML_SetCdataSectionHandler(XML_Parser parser,571XML_StartCdataSectionHandler start,572XML_EndCdataSectionHandler end);573574XMLPARSEAPI(void)575XML_SetStartCdataSectionHandler(XML_Parser parser,576XML_StartCdataSectionHandler start);577578XMLPARSEAPI(void)579XML_SetEndCdataSectionHandler(XML_Parser parser,580XML_EndCdataSectionHandler end);581582/* This sets the default handler and also inhibits expansion of583internal entities. These entity references will be passed to the584default handler, or to the skipped entity handler, if one is set.585*/586XMLPARSEAPI(void)587XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler);588589/* This sets the default handler but does not inhibit expansion of590internal entities. The entity reference will not be passed to the591default handler.592*/593XMLPARSEAPI(void)594XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler);595596XMLPARSEAPI(void)597XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start,598XML_EndDoctypeDeclHandler end);599600XMLPARSEAPI(void)601XML_SetStartDoctypeDeclHandler(XML_Parser parser,602XML_StartDoctypeDeclHandler start);603604XMLPARSEAPI(void)605XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end);606607XMLPARSEAPI(void)608XML_SetUnparsedEntityDeclHandler(XML_Parser parser,609XML_UnparsedEntityDeclHandler handler);610611XMLPARSEAPI(void)612XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler);613614XMLPARSEAPI(void)615XML_SetNamespaceDeclHandler(XML_Parser parser,616XML_StartNamespaceDeclHandler start,617XML_EndNamespaceDeclHandler end);618619XMLPARSEAPI(void)620XML_SetStartNamespaceDeclHandler(XML_Parser parser,621XML_StartNamespaceDeclHandler start);622623XMLPARSEAPI(void)624XML_SetEndNamespaceDeclHandler(XML_Parser parser,625XML_EndNamespaceDeclHandler end);626627XMLPARSEAPI(void)628XML_SetNotStandaloneHandler(XML_Parser parser,629XML_NotStandaloneHandler handler);630631XMLPARSEAPI(void)632XML_SetExternalEntityRefHandler(XML_Parser parser,633XML_ExternalEntityRefHandler handler);634635/* If a non-NULL value for arg is specified here, then it will be636passed as the first argument to the external entity ref handler637instead of the parser object.638*/639XMLPARSEAPI(void)640XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg);641642XMLPARSEAPI(void)643XML_SetSkippedEntityHandler(XML_Parser parser,644XML_SkippedEntityHandler handler);645646XMLPARSEAPI(void)647XML_SetUnknownEncodingHandler(XML_Parser parser,648XML_UnknownEncodingHandler handler,649void *encodingHandlerData);650651/* This can be called within a handler for a start element, end652element, processing instruction or character data. It causes the653corresponding markup to be passed to the default handler.654*/655XMLPARSEAPI(void)656XML_DefaultCurrent(XML_Parser parser);657658/* If do_nst is non-zero, and namespace processing is in effect, and659a name has a prefix (i.e. an explicit namespace qualifier) then660that name is returned as a triplet in a single string separated by661the separator character specified when the parser was created: URI662+ sep + local_name + sep + prefix.663664If do_nst is zero, then namespace information is returned in the665default manner (URI + sep + local_name) whether or not the name666has a prefix.667668Note: Calling XML_SetReturnNSTriplet after XML_Parse or669XML_ParseBuffer has no effect.670*/671672XMLPARSEAPI(void)673XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);674675/* This value is passed as the userData argument to callbacks. */676XMLPARSEAPI(void)677XML_SetUserData(XML_Parser parser, void *userData);678679/* Returns the last value set by XML_SetUserData or NULL. */680#define XML_GetUserData(parser) (*(void **)(parser))681682/* This is equivalent to supplying an encoding argument to683XML_ParserCreate. On success XML_SetEncoding returns non-zero,684zero otherwise.685Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer686has no effect and returns XML_STATUS_ERROR.687*/688XMLPARSEAPI(enum XML_Status)689XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);690691/* If this function is called, then the parser will be passed as the692first argument to callbacks instead of userData. The userData will693still be accessible using XML_GetUserData.694*/695XMLPARSEAPI(void)696XML_UseParserAsHandlerArg(XML_Parser parser);697698/* If useDTD == XML_TRUE is passed to this function, then the parser699will assume that there is an external subset, even if none is700specified in the document. In such a case the parser will call the701externalEntityRefHandler with a value of NULL for the systemId702argument (the publicId and context arguments will be NULL as well).703Note: For the purpose of checking WFC: Entity Declared, passing704useDTD == XML_TRUE will make the parser behave as if the document705had a DTD with an external subset.706Note: If this function is called, then this must be done before707the first call to XML_Parse or XML_ParseBuffer, since it will708have no effect after that. Returns709XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.710Note: If the document does not have a DOCTYPE declaration at all,711then startDoctypeDeclHandler and endDoctypeDeclHandler will not712be called, despite an external subset being parsed.713Note: If XML_DTD is not defined when Expat is compiled, returns714XML_ERROR_FEATURE_REQUIRES_XML_DTD.715Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT.716*/717XMLPARSEAPI(enum XML_Error)718XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);719720/* Sets the base to be used for resolving relative URIs in system721identifiers in declarations. Resolving relative identifiers is722left to the application: this value will be passed through as the723base argument to the XML_ExternalEntityRefHandler,724XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base725argument will be copied. Returns XML_STATUS_ERROR if out of memory,726XML_STATUS_OK otherwise.727*/728XMLPARSEAPI(enum XML_Status)729XML_SetBase(XML_Parser parser, const XML_Char *base);730731XMLPARSEAPI(const XML_Char *)732XML_GetBase(XML_Parser parser);733734/* Returns the number of the attribute/value pairs passed in last call735to the XML_StartElementHandler that were specified in the start-tag736rather than defaulted. Each attribute/value pair counts as 2; thus737this corresponds to an index into the atts array passed to the738XML_StartElementHandler. Returns -1 if parser == NULL.739*/740XMLPARSEAPI(int)741XML_GetSpecifiedAttributeCount(XML_Parser parser);742743/* Returns the index of the ID attribute passed in the last call to744XML_StartElementHandler, or -1 if there is no ID attribute or745parser == NULL. Each attribute/value pair counts as 2; thus this746corresponds to an index into the atts array passed to the747XML_StartElementHandler.748*/749XMLPARSEAPI(int)750XML_GetIdAttributeIndex(XML_Parser parser);751752#ifdef XML_ATTR_INFO753/* Source file byte offsets for the start and end of attribute names and values.754The value indices are exclusive of surrounding quotes; thus in a UTF-8 source755file an attribute value of "blah" will yield:756info->valueEnd - info->valueStart = 4 bytes.757*/758typedef struct {759XML_Index nameStart; /* Offset to beginning of the attribute name. */760XML_Index nameEnd; /* Offset after the attribute name's last byte. */761XML_Index valueStart; /* Offset to beginning of the attribute value. */762XML_Index valueEnd; /* Offset after the attribute value's last byte. */763} XML_AttrInfo;764765/* Returns an array of XML_AttrInfo structures for the attribute/value pairs766passed in last call to the XML_StartElementHandler that were specified767in the start-tag rather than defaulted. Each attribute/value pair counts768as 1; thus the number of entries in the array is769XML_GetSpecifiedAttributeCount(parser) / 2.770*/771XMLPARSEAPI(const XML_AttrInfo *)772XML_GetAttributeInfo(XML_Parser parser);773#endif774775/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is776detected. The last call to XML_Parse must have isFinal true; len777may be zero for this call (or any other).778779Though the return values for these functions has always been780described as a Boolean value, the implementation, at least for the7811.95.x series, has always returned exactly one of the XML_Status782values.783*/784XMLPARSEAPI(enum XML_Status)785XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);786787XMLPARSEAPI(void *)788XML_GetBuffer(XML_Parser parser, int len);789790XMLPARSEAPI(enum XML_Status)791XML_ParseBuffer(XML_Parser parser, int len, int isFinal);792793/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.794Must be called from within a call-back handler, except when aborting795(resumable = 0) an already suspended parser. Some call-backs may796still follow because they would otherwise get lost. Examples:797- endElementHandler() for empty elements when stopped in798startElementHandler(),799- endNameSpaceDeclHandler() when stopped in endElementHandler(),800and possibly others.801802Can be called from most handlers, including DTD related call-backs,803except when parsing an external parameter entity and resumable != 0.804Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.805Possible error codes:806- XML_ERROR_SUSPENDED: when suspending an already suspended parser.807- XML_ERROR_FINISHED: when the parser has already finished.808- XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.809810When resumable != 0 (true) then parsing is suspended, that is,811XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.812Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()813return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.814815*Note*:816This will be applied to the current parser instance only, that is, if817there is a parent parser then it will continue parsing when the818externalEntityRefHandler() returns. It is up to the implementation of819the externalEntityRefHandler() to call XML_StopParser() on the parent820parser (recursively), if one wants to stop parsing altogether.821822When suspended, parsing can be resumed by calling XML_ResumeParser().823*/824XMLPARSEAPI(enum XML_Status)825XML_StopParser(XML_Parser parser, XML_Bool resumable);826827/* Resumes parsing after it has been suspended with XML_StopParser().828Must not be called from within a handler call-back. Returns same829status codes as XML_Parse() or XML_ParseBuffer().830Additional error code XML_ERROR_NOT_SUSPENDED possible.831832*Note*:833This must be called on the most deeply nested child parser instance834first, and on its parent parser only after the child parser has finished,835to be applied recursively until the document entity's parser is restarted.836That is, the parent parser will not resume by itself and it is up to the837application to call XML_ResumeParser() on it at the appropriate moment.838*/839XMLPARSEAPI(enum XML_Status)840XML_ResumeParser(XML_Parser parser);841842enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED };843844typedef struct {845enum XML_Parsing parsing;846XML_Bool finalBuffer;847} XML_ParsingStatus;848849/* Returns status of parser with respect to being initialized, parsing,850finished, or suspended and processing the final buffer.851XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,852XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED853*/854XMLPARSEAPI(void)855XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);856857/* Creates an XML_Parser object that can parse an external general858entity; context is a '\0'-terminated string specifying the parse859context; encoding is a '\0'-terminated string giving the name of860the externally specified encoding, or NULL if there is no861externally specified encoding. The context string consists of a862sequence of tokens separated by formfeeds (\f); a token consisting863of a name specifies that the general entity of the name is open; a864token of the form prefix=uri specifies the namespace for a865particular prefix; a token of the form =uri specifies the default866namespace. This can be called at any point after the first call to867an ExternalEntityRefHandler so longer as the parser has not yet868been freed. The new parser is completely independent and may869safely be used in a separate thread. The handlers and userData are870initialized from the parser argument. Returns NULL if out of memory.871Otherwise returns a new XML_Parser object.872*/873XMLPARSEAPI(XML_Parser)874XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context,875const XML_Char *encoding);876877enum XML_ParamEntityParsing {878XML_PARAM_ENTITY_PARSING_NEVER,879XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,880XML_PARAM_ENTITY_PARSING_ALWAYS881};882883/* Controls parsing of parameter entities (including the external DTD884subset). If parsing of parameter entities is enabled, then885references to external parameter entities (including the external886DTD subset) will be passed to the handler set with887XML_SetExternalEntityRefHandler. The context passed will be 0.888889Unlike external general entities, external parameter entities can890only be parsed synchronously. If the external parameter entity is891to be parsed, it must be parsed during the call to the external892entity ref handler: the complete sequence of893XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and894XML_ParserFree calls must be made during this call. After895XML_ExternalEntityParserCreate has been called to create the parser896for the external parameter entity (context must be 0 for this897call), it is illegal to make any calls on the old parser until898XML_ParserFree has been called on the newly created parser.899If the library has been compiled without support for parameter900entity parsing (ie without XML_DTD being defined), then901XML_SetParamEntityParsing will return 0 if parsing of parameter902entities is requested; otherwise it will return non-zero.903Note: If XML_SetParamEntityParsing is called after XML_Parse or904XML_ParseBuffer, then it has no effect and will always return 0.905Note: If parser == NULL, the function will do nothing and return 0.906*/907XMLPARSEAPI(int)908XML_SetParamEntityParsing(XML_Parser parser,909enum XML_ParamEntityParsing parsing);910911/* Sets the hash salt to use for internal hash calculations.912Helps in preventing DoS attacks based on predicting hash913function behavior. This must be called before parsing is started.914Returns 1 if successful, 0 when called after parsing has started.915Note: If parser == NULL, the function will do nothing and return 0.916*/917XMLPARSEAPI(int)918XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt);919920/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then921XML_GetErrorCode returns information about the error.922*/923XMLPARSEAPI(enum XML_Error)924XML_GetErrorCode(XML_Parser parser);925926/* These functions return information about the current parse927location. They may be called from any callback called to report928some parse event; in this case the location is the location of the929first of the sequence of characters that generated the event. When930called from callbacks generated by declarations in the document931prologue, the location identified isn't as neatly defined, but will932be within the relevant markup. When called outside of the callback933functions, the position indicated will be just past the last parse934event (regardless of whether there was an associated callback).935936They may also be called after returning from a call to XML_Parse937or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then938the location is the location of the character at which the error939was detected; otherwise the location is the location of the last940parse event, as described above.941942Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber943return 0 to indicate an error.944Note: XML_GetCurrentByteIndex returns -1 to indicate an error.945*/946XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);947XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);948XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);949950/* Return the number of bytes in the current event.951Returns 0 if the event is in an internal entity.952*/953XMLPARSEAPI(int)954XML_GetCurrentByteCount(XML_Parser parser);955956/* If XML_CONTEXT_BYTES is >=1, returns the input buffer, sets957the integer pointed to by offset to the offset within this buffer958of the current parse position, and sets the integer pointed to by size959to the size of this buffer (the number of input bytes). Otherwise960returns a NULL pointer. Also returns a NULL pointer if a parse isn't961active.962963NOTE: The character pointer returned should not be used outside964the handler that makes the call.965*/966XMLPARSEAPI(const char *)967XML_GetInputContext(XML_Parser parser, int *offset, int *size);968969/* For backwards compatibility with previous versions. */970#define XML_GetErrorLineNumber XML_GetCurrentLineNumber971#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber972#define XML_GetErrorByteIndex XML_GetCurrentByteIndex973974/* Frees the content model passed to the element declaration handler */975XMLPARSEAPI(void)976XML_FreeContentModel(XML_Parser parser, XML_Content *model);977978/* Exposing the memory handling functions used in Expat */979XMLPARSEAPI(void *)980XML_ATTR_MALLOC981XML_ATTR_ALLOC_SIZE(2)982XML_MemMalloc(XML_Parser parser, size_t size);983984XMLPARSEAPI(void *)985XML_ATTR_ALLOC_SIZE(3)986XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);987988XMLPARSEAPI(void)989XML_MemFree(XML_Parser parser, void *ptr);990991/* Frees memory used by the parser. */992XMLPARSEAPI(void)993XML_ParserFree(XML_Parser parser);994995/* Returns a string describing the error. */996XMLPARSEAPI(const XML_LChar *)997XML_ErrorString(enum XML_Error code);998999/* Return a string containing the version number of this expat */1000XMLPARSEAPI(const XML_LChar *)1001XML_ExpatVersion(void);10021003typedef struct {1004int major;1005int minor;1006int micro;1007} XML_Expat_Version;10081009/* Return an XML_Expat_Version structure containing numeric version1010number information for this version of expat.1011*/1012XMLPARSEAPI(XML_Expat_Version)1013XML_ExpatVersionInfo(void);10141015/* Added in Expat 1.95.5. */1016enum XML_FeatureEnum {1017XML_FEATURE_END = 0,1018XML_FEATURE_UNICODE,1019XML_FEATURE_UNICODE_WCHAR_T,1020XML_FEATURE_DTD,1021XML_FEATURE_CONTEXT_BYTES,1022XML_FEATURE_MIN_SIZE,1023XML_FEATURE_SIZEOF_XML_CHAR,1024XML_FEATURE_SIZEOF_XML_LCHAR,1025XML_FEATURE_NS,1026XML_FEATURE_LARGE_SIZE,1027XML_FEATURE_ATTR_INFO,1028/* Added in Expat 2.4.0. */1029XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,1030XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT,1031/* Added in Expat 2.6.0. */1032XML_FEATURE_GE1033/* Additional features must be added to the end of this enum. */1034};10351036typedef struct {1037enum XML_FeatureEnum feature;1038const XML_LChar *name;1039long int value;1040} XML_Feature;10411042XMLPARSEAPI(const XML_Feature *)1043XML_GetFeatureList(void);10441045#if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1)1046/* Added in Expat 2.4.0 for XML_DTD defined and1047* added in Expat 2.6.0 for XML_GE == 1. */1048XMLPARSEAPI(XML_Bool)1049XML_SetBillionLaughsAttackProtectionMaximumAmplification(1050XML_Parser parser, float maximumAmplificationFactor);10511052/* Added in Expat 2.4.0 for XML_DTD defined and1053* added in Expat 2.6.0 for XML_GE == 1. */1054XMLPARSEAPI(XML_Bool)1055XML_SetBillionLaughsAttackProtectionActivationThreshold(1056XML_Parser parser, unsigned long long activationThresholdBytes);1057#endif10581059/* Added in Expat 2.6.0. */1060XMLPARSEAPI(XML_Bool)1061XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);10621063/* Expat follows the semantic versioning convention.1064See https://semver.org1065*/1066#define XML_MAJOR_VERSION 21067#define XML_MINOR_VERSION 61068#define XML_MICRO_VERSION 210691070#ifdef __cplusplus1071}1072#endif10731074#endif /* not Expat_INCLUDED */107510761077