/*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-2025 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]>21Copyright (c) 2025 Matthew Fernandez <[email protected]>22Licensed under the MIT license:2324Permission is hereby granted, free of charge, to any person obtaining25a copy of this software and associated documentation files (the26"Software"), to deal in the Software without restriction, including27without limitation the rights to use, copy, modify, merge, publish,28distribute, sublicense, and/or sell copies of the Software, and to permit29persons to whom the Software is furnished to do so, subject to the30following conditions:3132The above copyright notice and this permission notice shall be included33in all copies or substantial portions of the Software.3435THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,36EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF37MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN38NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,39DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR40OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE41USE OR OTHER DEALINGS IN THE SOFTWARE.42*/4344#ifndef Expat_INCLUDED45# define Expat_INCLUDED 14647# include <stdlib.h>48# include "expat_external.h"4950# ifdef __cplusplus51extern "C" {52# endif5354struct XML_ParserStruct;55typedef struct XML_ParserStruct *XML_Parser;5657typedef unsigned char XML_Bool;58# define XML_TRUE ((XML_Bool)1)59# define XML_FALSE ((XML_Bool)0)6061/* The XML_Status enum gives the possible return values for several62API functions. The preprocessor #defines are included so this63stanza can be added to code that still needs to support older64versions of Expat 1.95.x:6566#ifndef XML_STATUS_OK67#define XML_STATUS_OK 168#define XML_STATUS_ERROR 069#endif7071Otherwise, the #define hackery is quite ugly and would have been72dropped.73*/74enum XML_Status {75XML_STATUS_ERROR = 0,76# define XML_STATUS_ERROR XML_STATUS_ERROR77XML_STATUS_OK = 1,78# define XML_STATUS_OK XML_STATUS_OK79XML_STATUS_SUSPENDED = 280# define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED81};8283enum XML_Error {84XML_ERROR_NONE,85XML_ERROR_NO_MEMORY,86XML_ERROR_SYNTAX,87XML_ERROR_NO_ELEMENTS,88XML_ERROR_INVALID_TOKEN,89XML_ERROR_UNCLOSED_TOKEN,90XML_ERROR_PARTIAL_CHAR,91XML_ERROR_TAG_MISMATCH,92XML_ERROR_DUPLICATE_ATTRIBUTE,93XML_ERROR_JUNK_AFTER_DOC_ELEMENT,94XML_ERROR_PARAM_ENTITY_REF,95XML_ERROR_UNDEFINED_ENTITY,96XML_ERROR_RECURSIVE_ENTITY_REF,97XML_ERROR_ASYNC_ENTITY,98XML_ERROR_BAD_CHAR_REF,99XML_ERROR_BINARY_ENTITY_REF,100XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,101XML_ERROR_MISPLACED_XML_PI,102XML_ERROR_UNKNOWN_ENCODING,103XML_ERROR_INCORRECT_ENCODING,104XML_ERROR_UNCLOSED_CDATA_SECTION,105XML_ERROR_EXTERNAL_ENTITY_HANDLING,106XML_ERROR_NOT_STANDALONE,107XML_ERROR_UNEXPECTED_STATE,108XML_ERROR_ENTITY_DECLARED_IN_PE,109XML_ERROR_FEATURE_REQUIRES_XML_DTD,110XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,111/* Added in 1.95.7. */112XML_ERROR_UNBOUND_PREFIX,113/* Added in 1.95.8. */114XML_ERROR_UNDECLARING_PREFIX,115XML_ERROR_INCOMPLETE_PE,116XML_ERROR_XML_DECL,117XML_ERROR_TEXT_DECL,118XML_ERROR_PUBLICID,119XML_ERROR_SUSPENDED,120XML_ERROR_NOT_SUSPENDED,121XML_ERROR_ABORTED,122XML_ERROR_FINISHED,123XML_ERROR_SUSPEND_PE,124/* Added in 2.0. */125XML_ERROR_RESERVED_PREFIX_XML,126XML_ERROR_RESERVED_PREFIX_XMLNS,127XML_ERROR_RESERVED_NAMESPACE_URI,128/* Added in 2.2.1. */129XML_ERROR_INVALID_ARGUMENT,130/* Added in 2.3.0. */131XML_ERROR_NO_BUFFER,132/* Added in 2.4.0. */133XML_ERROR_AMPLIFICATION_LIMIT_BREACH,134/* Added in 2.6.4. */135XML_ERROR_NOT_STARTED,136};137138enum XML_Content_Type {139XML_CTYPE_EMPTY = 1,140XML_CTYPE_ANY,141XML_CTYPE_MIXED,142XML_CTYPE_NAME,143XML_CTYPE_CHOICE,144XML_CTYPE_SEQ145};146147enum XML_Content_Quant {148XML_CQUANT_NONE,149XML_CQUANT_OPT,150XML_CQUANT_REP,151XML_CQUANT_PLUS152};153154/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be155XML_CQUANT_NONE, and the other fields will be zero or NULL.156If type == XML_CTYPE_MIXED, then quant will be NONE or REP and157numchildren will contain number of elements that may be mixed in158and children point to an array of XML_Content cells that will be159all of XML_CTYPE_NAME type with no quantification.160161If type == XML_CTYPE_NAME, then the name points to the name, and162the numchildren field will be zero and children will be NULL. The163quant fields indicates any quantifiers placed on the name.164165CHOICE and SEQ will have name NULL, the number of children in166numchildren and children will point, recursively, to an array167of XML_Content cells.168169The EMPTY, ANY, and MIXED types will only occur at top level.170*/171172typedef struct XML_cp XML_Content;173174struct XML_cp {175enum XML_Content_Type type;176enum XML_Content_Quant quant;177XML_Char *name;178unsigned int numchildren;179XML_Content *children;180};181182/* This is called for an element declaration. See above for183description of the model argument. It's the user code's responsibility184to free model when finished with it. See XML_FreeContentModel.185There is no need to free the model from the handler, it can be kept186around and freed at a later stage.187*/188typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData,189const XML_Char *name,190XML_Content *model);191192XMLPARSEAPI(void)193XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl);194195/* The Attlist declaration handler is called for *each* attribute. So196a single Attlist declaration with multiple attributes declared will197generate multiple calls to this handler. The "default" parameter198may be NULL in the case of the "#IMPLIED" or "#REQUIRED"199keyword. The "isrequired" parameter will be true and the default200value will be NULL in the case of "#REQUIRED". If "isrequired" is201true and default is non-NULL, then this is a "#FIXED" default.202*/203typedef void(XMLCALL *XML_AttlistDeclHandler)(204void *userData, const XML_Char *elname, const XML_Char *attname,205const XML_Char *att_type, const XML_Char *dflt, int isrequired);206207XMLPARSEAPI(void)208XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl);209210/* The XML declaration handler is called for *both* XML declarations211and text declarations. The way to distinguish is that the version212parameter will be NULL for text declarations. The encoding213parameter may be NULL for XML declarations. The standalone214parameter will be -1, 0, or 1 indicating respectively that there215was no standalone parameter in the declaration, that it was given216as no, or that it was given as yes.217*/218typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData,219const XML_Char *version,220const XML_Char *encoding,221int standalone);222223XMLPARSEAPI(void)224XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl);225226typedef struct {227void *(*malloc_fcn)(size_t size);228void *(*realloc_fcn)(void *ptr, size_t size);229void (*free_fcn)(void *ptr);230} XML_Memory_Handling_Suite;231232/* Constructs a new parser; encoding is the encoding specified by the233external protocol or NULL if there is none specified.234*/235XMLPARSEAPI(XML_Parser)236XML_ParserCreate(const XML_Char *encoding);237238/* Constructs a new parser and namespace processor. Element type239names and attribute names that belong to a namespace will be240expanded; unprefixed attribute names are never expanded; unprefixed241element type names are expanded only if there is a default242namespace. The expanded name is the concatenation of the namespace243URI, the namespace separator character, and the local part of the244name. If the namespace separator is '\0' then the namespace URI245and the local part will be concatenated without any separator.246It is a programming error to use the separator '\0' with namespace247triplets (see XML_SetReturnNSTriplet).248If a namespace separator is chosen that can be part of a URI or249part of an XML name, splitting an expanded name back into its2501, 2 or 3 original parts on application level in the element handler251may end up vulnerable, so these are advised against; sane choices for252a namespace separator are e.g. '\n' (line feed) and '|' (pipe).253254Note that Expat does not validate namespace URIs (beyond encoding)255against RFC 3986 today (and is not required to do so with regard to256the XML 1.0 namespaces specification) but it may start doing that257in future releases. Before that, an application using Expat must258be ready to receive namespace URIs containing non-URI characters.259*/260XMLPARSEAPI(XML_Parser)261XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);262263/* Constructs a new parser using the memory management suite referred to264by memsuite. If memsuite is NULL, then use the standard library memory265suite. If namespaceSeparator is non-NULL it creates a parser with266namespace processing as described above. The character pointed at267will serve as the namespace separator.268269All further memory operations used for the created parser will come from270the given suite.271*/272XMLPARSEAPI(XML_Parser)273XML_ParserCreate_MM(const XML_Char *encoding,274const XML_Memory_Handling_Suite *memsuite,275const XML_Char *namespaceSeparator);276277/* Prepare a parser object to be reused. This is particularly278valuable when memory allocation overhead is disproportionately high,279such as when a large number of small documents need to be parsed.280All handlers are cleared from the parser, except for the281unknownEncodingHandler. The parser's external state is re-initialized282except for the values of ns and ns_triplets.283284Added in Expat 1.95.3.285*/286XMLPARSEAPI(XML_Bool)287XML_ParserReset(XML_Parser parser, const XML_Char *encoding);288289/* atts is array of name/value pairs, terminated by 0;290names and values are 0 terminated.291*/292typedef void(XMLCALL *XML_StartElementHandler)(void *userData,293const XML_Char *name,294const XML_Char **atts);295296typedef void(XMLCALL *XML_EndElementHandler)(void *userData,297const XML_Char *name);298299/* s is not 0 terminated. */300typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData,301const XML_Char *s, int len);302303/* target and data are 0 terminated */304typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,305const XML_Char *target,306const XML_Char *data);307308/* data is 0 terminated */309typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data);310311typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData);312typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData);313314/* This is called for any characters in the XML document for which315there is no applicable handler. This includes both characters that316are part of markup which is of a kind that is not reported317(comments, markup declarations), or characters that are part of a318construct which could be reported but for which no handler has been319supplied. The characters are passed exactly as they were in the XML320document except that they will be encoded in UTF-8 or UTF-16.321Line boundaries are not normalized. Note that a byte order mark322character is not passed to the default handler. There are no323guarantees about how characters are divided between calls to the324default handler: for example, a comment might be split between325multiple calls.326*/327typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s,328int len);329330/* This is called for the start of the DOCTYPE declaration, before331any DTD or internal subset is parsed.332*/333typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,334const XML_Char *doctypeName,335const XML_Char *sysid,336const XML_Char *pubid,337int has_internal_subset);338339/* This is called for the end of the DOCTYPE declaration when the340closing > is encountered, but after processing any external341subset.342*/343typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);344345/* This is called for entity declarations. The is_parameter_entity346argument will be non-zero if the entity is a parameter entity, zero347otherwise.348349For internal entities (<!ENTITY foo "bar">), value will350be non-NULL and systemId, publicID, and notationName will be NULL.351The value string is NOT null-terminated; the length is provided in352the value_length argument. Since it is legal to have zero-length353values, do not use this argument to test for internal entities.354355For external entities, value will be NULL and systemId will be356non-NULL. The publicId argument will be NULL unless a public357identifier was provided. The notationName argument will have a358non-NULL value only for unparsed entity declarations.359360Note that is_parameter_entity can't be changed to XML_Bool, since361that would break binary compatibility.362*/363typedef void(XMLCALL *XML_EntityDeclHandler)(364void *userData, const XML_Char *entityName, int is_parameter_entity,365const XML_Char *value, int value_length, const XML_Char *base,366const XML_Char *systemId, const XML_Char *publicId,367const XML_Char *notationName);368369XMLPARSEAPI(void)370XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler);371372/* OBSOLETE -- OBSOLETE -- OBSOLETE373This handler has been superseded by the EntityDeclHandler above.374It is provided here for backward compatibility.375376This is called for a declaration of an unparsed (NDATA) entity.377The base argument is whatever was set by XML_SetBase. The378entityName, systemId and notationName arguments will never be379NULL. The other arguments may be.380*/381typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)(382void *userData, const XML_Char *entityName, const XML_Char *base,383const XML_Char *systemId, const XML_Char *publicId,384const XML_Char *notationName);385386/* This is called for a declaration of notation. The base argument is387whatever was set by XML_SetBase. The notationName will never be388NULL. The other arguments can be.389*/390typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData,391const XML_Char *notationName,392const XML_Char *base,393const XML_Char *systemId,394const XML_Char *publicId);395396/* When namespace processing is enabled, these are called once for397each namespace declaration. The call to the start and end element398handlers occur between the calls to the start and end namespace399declaration handlers. For an xmlns attribute, prefix will be400NULL. For an xmlns="" attribute, uri will be NULL.401*/402typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,403const XML_Char *prefix,404const XML_Char *uri);405406typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,407const XML_Char *prefix);408409/* This is called if the document is not standalone, that is, it has an410external subset or a reference to a parameter entity, but does not411have standalone="yes". If this handler returns XML_STATUS_ERROR,412then processing will not continue, and the parser will return a413XML_ERROR_NOT_STANDALONE error.414If parameter entity parsing is enabled, then in addition to the415conditions above this handler will only be called if the referenced416entity was actually read.417*/418typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData);419420/* This is called for a reference to an external parsed general421entity. The referenced entity is not automatically parsed. The422application can parse it immediately or later using423XML_ExternalEntityParserCreate.424425The parser argument is the parser parsing the entity containing the426reference; it can be passed as the parser argument to427XML_ExternalEntityParserCreate. The systemId argument is the428system identifier as specified in the entity declaration; it will429not be NULL.430431The base argument is the system identifier that should be used as432the base for resolving systemId if systemId was relative; this is433set by XML_SetBase; it may be NULL.434435The publicId argument is the public identifier as specified in the436entity declaration, or NULL if none was specified; the whitespace437in the public identifier will have been normalized as required by438the XML spec.439440The context argument specifies the parsing context in the format441expected by the context argument to XML_ExternalEntityParserCreate;442context is valid only until the handler returns, so if the443referenced entity is to be parsed later, it must be copied.444context is NULL only when the entity is a parameter entity.445446The handler should return XML_STATUS_ERROR if processing should not447continue because of a fatal error in the handling of the external448entity. In this case the calling parser will return an449XML_ERROR_EXTERNAL_ENTITY_HANDLING error.450451Note that unlike other handlers the first argument is the parser,452not userData.453*/454typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser,455const XML_Char *context,456const XML_Char *base,457const XML_Char *systemId,458const XML_Char *publicId);459460/* This is called in two situations:4611) An entity reference is encountered for which no declaration462has been read *and* this is not an error.4632) An internal entity reference is read, but not expanded, because464XML_SetDefaultHandler has been called.465Note: skipped parameter entities in declarations and skipped general466entities in attribute values cannot be reported, because467the event would be out of sync with the reporting of the468declarations or attribute values469*/470typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData,471const XML_Char *entityName,472int is_parameter_entity);473474/* This structure is filled in by the XML_UnknownEncodingHandler to475provide information to the parser about encodings that are unknown476to the parser.477478The map[b] member gives information about byte sequences whose479first byte is b.480481If map[b] is c where c is >= 0, then b by itself encodes the482Unicode scalar value c.483484If map[b] is -1, then the byte sequence is malformed.485486If map[b] is -n, where n >= 2, then b is the first byte of an487n-byte sequence that encodes a single Unicode scalar value.488489The data member will be passed as the first argument to the convert490function.491492The convert function is used to convert multibyte sequences; s will493point to a n-byte sequence where map[(unsigned char)*s] == -n. The494convert function must return the Unicode scalar value represented495by this byte sequence or -1 if the byte sequence is malformed.496497The convert function may be NULL if the encoding is a single-byte498encoding, that is if map[b] >= -1 for all bytes b.499500When the parser is finished with the encoding, then if release is501not NULL, it will call release passing it the data member; once502release has been called, the convert function will not be called503again.504505Expat places certain restrictions on the encodings that are supported506using this mechanism.5075081. Every ASCII character that can appear in a well-formed XML document,509other than the characters510511$@\^`{}~512513must be represented by a single byte, and that byte must be the514same byte that represents that character in ASCII.5155162. No character may require more than 4 bytes to encode.5175183. All characters encoded must have Unicode scalar values <=5190xFFFF, (i.e., characters that would be encoded by surrogates in520UTF-16 are not allowed). Note that this restriction doesn't521apply to the built-in support for UTF-8 and UTF-16.5225234. No Unicode character may be encoded by more than one distinct524sequence of bytes.525*/526typedef struct {527int map[256];528void *data;529int(XMLCALL *convert)(void *data, const char *s);530void(XMLCALL *release)(void *data);531} XML_Encoding;532533/* This is called for an encoding that is unknown to the parser.534535The encodingHandlerData argument is that which was passed as the536second argument to XML_SetUnknownEncodingHandler.537538The name argument gives the name of the encoding as specified in539the encoding declaration.540541If the callback can provide information about the encoding, it must542fill in the XML_Encoding structure, and return XML_STATUS_OK.543Otherwise it must return XML_STATUS_ERROR.544545If info does not describe a suitable encoding, then the parser will546return an XML_ERROR_UNKNOWN_ENCODING error.547*/548typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,549const XML_Char *name,550XML_Encoding *info);551552XMLPARSEAPI(void)553XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start,554XML_EndElementHandler end);555556XMLPARSEAPI(void)557XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler);558559XMLPARSEAPI(void)560XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler);561562XMLPARSEAPI(void)563XML_SetCharacterDataHandler(XML_Parser parser,564XML_CharacterDataHandler handler);565566XMLPARSEAPI(void)567XML_SetProcessingInstructionHandler(XML_Parser parser,568XML_ProcessingInstructionHandler handler);569XMLPARSEAPI(void)570XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler);571572XMLPARSEAPI(void)573XML_SetCdataSectionHandler(XML_Parser parser,574XML_StartCdataSectionHandler start,575XML_EndCdataSectionHandler end);576577XMLPARSEAPI(void)578XML_SetStartCdataSectionHandler(XML_Parser parser,579XML_StartCdataSectionHandler start);580581XMLPARSEAPI(void)582XML_SetEndCdataSectionHandler(XML_Parser parser,583XML_EndCdataSectionHandler end);584585/* This sets the default handler and also inhibits expansion of586internal entities. These entity references will be passed to the587default handler, or to the skipped entity handler, if one is set.588*/589XMLPARSEAPI(void)590XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler);591592/* This sets the default handler but does not inhibit expansion of593internal entities. The entity reference will not be passed to the594default handler.595*/596XMLPARSEAPI(void)597XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler);598599XMLPARSEAPI(void)600XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start,601XML_EndDoctypeDeclHandler end);602603XMLPARSEAPI(void)604XML_SetStartDoctypeDeclHandler(XML_Parser parser,605XML_StartDoctypeDeclHandler start);606607XMLPARSEAPI(void)608XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end);609610XMLPARSEAPI(void)611XML_SetUnparsedEntityDeclHandler(XML_Parser parser,612XML_UnparsedEntityDeclHandler handler);613614XMLPARSEAPI(void)615XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler);616617XMLPARSEAPI(void)618XML_SetNamespaceDeclHandler(XML_Parser parser,619XML_StartNamespaceDeclHandler start,620XML_EndNamespaceDeclHandler end);621622XMLPARSEAPI(void)623XML_SetStartNamespaceDeclHandler(XML_Parser parser,624XML_StartNamespaceDeclHandler start);625626XMLPARSEAPI(void)627XML_SetEndNamespaceDeclHandler(XML_Parser parser,628XML_EndNamespaceDeclHandler end);629630XMLPARSEAPI(void)631XML_SetNotStandaloneHandler(XML_Parser parser,632XML_NotStandaloneHandler handler);633634XMLPARSEAPI(void)635XML_SetExternalEntityRefHandler(XML_Parser parser,636XML_ExternalEntityRefHandler handler);637638/* If a non-NULL value for arg is specified here, then it will be639passed as the first argument to the external entity ref handler640instead of the parser object.641*/642XMLPARSEAPI(void)643XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg);644645XMLPARSEAPI(void)646XML_SetSkippedEntityHandler(XML_Parser parser,647XML_SkippedEntityHandler handler);648649XMLPARSEAPI(void)650XML_SetUnknownEncodingHandler(XML_Parser parser,651XML_UnknownEncodingHandler handler,652void *encodingHandlerData);653654/* This can be called within a handler for a start element, end655element, processing instruction or character data. It causes the656corresponding markup to be passed to the default handler.657*/658XMLPARSEAPI(void)659XML_DefaultCurrent(XML_Parser parser);660661/* If do_nst is non-zero, and namespace processing is in effect, and662a name has a prefix (i.e. an explicit namespace qualifier) then663that name is returned as a triplet in a single string separated by664the separator character specified when the parser was created: URI665+ sep + local_name + sep + prefix.666667If do_nst is zero, then namespace information is returned in the668default manner (URI + sep + local_name) whether or not the name669has a prefix.670671Note: Calling XML_SetReturnNSTriplet after XML_Parse or672XML_ParseBuffer has no effect.673*/674675XMLPARSEAPI(void)676XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);677678/* This value is passed as the userData argument to callbacks. */679XMLPARSEAPI(void)680XML_SetUserData(XML_Parser parser, void *userData);681682/* Returns the last value set by XML_SetUserData or NULL. */683# define XML_GetUserData(parser) (*(void **)(parser))684685/* This is equivalent to supplying an encoding argument to686XML_ParserCreate. On success XML_SetEncoding returns non-zero,687zero otherwise.688Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer689has no effect and returns XML_STATUS_ERROR.690*/691XMLPARSEAPI(enum XML_Status)692XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);693694/* If this function is called, then the parser will be passed as the695first argument to callbacks instead of userData. The userData will696still be accessible using XML_GetUserData.697*/698XMLPARSEAPI(void)699XML_UseParserAsHandlerArg(XML_Parser parser);700701/* If useDTD == XML_TRUE is passed to this function, then the parser702will assume that there is an external subset, even if none is703specified in the document. In such a case the parser will call the704externalEntityRefHandler with a value of NULL for the systemId705argument (the publicId and context arguments will be NULL as well).706Note: For the purpose of checking WFC: Entity Declared, passing707useDTD == XML_TRUE will make the parser behave as if the document708had a DTD with an external subset.709Note: If this function is called, then this must be done before710the first call to XML_Parse or XML_ParseBuffer, since it will711have no effect after that. Returns712XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.713Note: If the document does not have a DOCTYPE declaration at all,714then startDoctypeDeclHandler and endDoctypeDeclHandler will not715be called, despite an external subset being parsed.716Note: If XML_DTD is not defined when Expat is compiled, returns717XML_ERROR_FEATURE_REQUIRES_XML_DTD.718Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT.719*/720XMLPARSEAPI(enum XML_Error)721XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);722723/* Sets the base to be used for resolving relative URIs in system724identifiers in declarations. Resolving relative identifiers is725left to the application: this value will be passed through as the726base argument to the XML_ExternalEntityRefHandler,727XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base728argument will be copied. Returns XML_STATUS_ERROR if out of memory,729XML_STATUS_OK otherwise.730*/731XMLPARSEAPI(enum XML_Status)732XML_SetBase(XML_Parser parser, const XML_Char *base);733734XMLPARSEAPI(const XML_Char *)735XML_GetBase(XML_Parser parser);736737/* Returns the number of the attribute/value pairs passed in last call738to the XML_StartElementHandler that were specified in the start-tag739rather than defaulted. Each attribute/value pair counts as 2; thus740this corresponds to an index into the atts array passed to the741XML_StartElementHandler. Returns -1 if parser == NULL.742*/743XMLPARSEAPI(int)744XML_GetSpecifiedAttributeCount(XML_Parser parser);745746/* Returns the index of the ID attribute passed in the last call to747XML_StartElementHandler, or -1 if there is no ID attribute or748parser == NULL. Each attribute/value pair counts as 2; thus this749corresponds to an index into the atts array passed to the750XML_StartElementHandler.751*/752XMLPARSEAPI(int)753XML_GetIdAttributeIndex(XML_Parser parser);754755# ifdef XML_ATTR_INFO756/* Source file byte offsets for the start and end of attribute names and values.757The value indices are exclusive of surrounding quotes; thus in a UTF-8 source758file an attribute value of "blah" will yield:759info->valueEnd - info->valueStart = 4 bytes.760*/761typedef struct {762XML_Index nameStart; /* Offset to beginning of the attribute name. */763XML_Index nameEnd; /* Offset after the attribute name's last byte. */764XML_Index valueStart; /* Offset to beginning of the attribute value. */765XML_Index valueEnd; /* Offset after the attribute value's last byte. */766} XML_AttrInfo;767768/* Returns an array of XML_AttrInfo structures for the attribute/value pairs769passed in last call to the XML_StartElementHandler that were specified770in the start-tag rather than defaulted. Each attribute/value pair counts771as 1; thus the number of entries in the array is772XML_GetSpecifiedAttributeCount(parser) / 2.773*/774XMLPARSEAPI(const XML_AttrInfo *)775XML_GetAttributeInfo(XML_Parser parser);776# endif777778/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is779detected. The last call to XML_Parse must have isFinal true; len780may be zero for this call (or any other).781782Though the return values for these functions has always been783described as a Boolean value, the implementation, at least for the7841.95.x series, has always returned exactly one of the XML_Status785values.786*/787XMLPARSEAPI(enum XML_Status)788XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);789790XMLPARSEAPI(void *)791XML_GetBuffer(XML_Parser parser, int len);792793XMLPARSEAPI(enum XML_Status)794XML_ParseBuffer(XML_Parser parser, int len, int isFinal);795796/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.797Must be called from within a call-back handler, except when aborting798(resumable = 0) an already suspended parser. Some call-backs may799still follow because they would otherwise get lost. Examples:800- endElementHandler() for empty elements when stopped in801startElementHandler(),802- endNameSpaceDeclHandler() when stopped in endElementHandler(),803and possibly others.804805Can be called from most handlers, including DTD related call-backs,806except when parsing an external parameter entity and resumable != 0.807Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.808Possible error codes:809- XML_ERROR_SUSPENDED: when suspending an already suspended parser.810- XML_ERROR_FINISHED: when the parser has already finished.811- XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.812813When resumable != 0 (true) then parsing is suspended, that is,814XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.815Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()816return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.817818*Note*:819This will be applied to the current parser instance only, that is, if820there is a parent parser then it will continue parsing when the821externalEntityRefHandler() returns. It is up to the implementation of822the externalEntityRefHandler() to call XML_StopParser() on the parent823parser (recursively), if one wants to stop parsing altogether.824825When suspended, parsing can be resumed by calling XML_ResumeParser().826*/827XMLPARSEAPI(enum XML_Status)828XML_StopParser(XML_Parser parser, XML_Bool resumable);829830/* Resumes parsing after it has been suspended with XML_StopParser().831Must not be called from within a handler call-back. Returns same832status codes as XML_Parse() or XML_ParseBuffer().833Additional error code XML_ERROR_NOT_SUSPENDED possible.834835*Note*:836This must be called on the most deeply nested child parser instance837first, and on its parent parser only after the child parser has finished,838to be applied recursively until the document entity's parser is restarted.839That is, the parent parser will not resume by itself and it is up to the840application to call XML_ResumeParser() on it at the appropriate moment.841*/842XMLPARSEAPI(enum XML_Status)843XML_ResumeParser(XML_Parser parser);844845enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED };846847typedef struct {848enum XML_Parsing parsing;849XML_Bool finalBuffer;850} XML_ParsingStatus;851852/* Returns status of parser with respect to being initialized, parsing,853finished, or suspended and processing the final buffer.854XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,855XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED856*/857XMLPARSEAPI(void)858XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);859860/* Creates an XML_Parser object that can parse an external general861entity; context is a '\0'-terminated string specifying the parse862context; encoding is a '\0'-terminated string giving the name of863the externally specified encoding, or NULL if there is no864externally specified encoding. The context string consists of a865sequence of tokens separated by formfeeds (\f); a token consisting866of a name specifies that the general entity of the name is open; a867token of the form prefix=uri specifies the namespace for a868particular prefix; a token of the form =uri specifies the default869namespace. This can be called at any point after the first call to870an ExternalEntityRefHandler so longer as the parser has not yet871been freed. The new parser is completely independent and may872safely be used in a separate thread. The handlers and userData are873initialized from the parser argument. Returns NULL if out of memory.874Otherwise returns a new XML_Parser object.875*/876XMLPARSEAPI(XML_Parser)877XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context,878const XML_Char *encoding);879880enum XML_ParamEntityParsing {881XML_PARAM_ENTITY_PARSING_NEVER,882XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,883XML_PARAM_ENTITY_PARSING_ALWAYS884};885886/* Controls parsing of parameter entities (including the external DTD887subset). If parsing of parameter entities is enabled, then888references to external parameter entities (including the external889DTD subset) will be passed to the handler set with890XML_SetExternalEntityRefHandler. The context passed will be 0.891892Unlike external general entities, external parameter entities can893only be parsed synchronously. If the external parameter entity is894to be parsed, it must be parsed during the call to the external895entity ref handler: the complete sequence of896XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and897XML_ParserFree calls must be made during this call. After898XML_ExternalEntityParserCreate has been called to create the parser899for the external parameter entity (context must be 0 for this900call), it is illegal to make any calls on the old parser until901XML_ParserFree has been called on the newly created parser.902If the library has been compiled without support for parameter903entity parsing (ie without XML_DTD being defined), then904XML_SetParamEntityParsing will return 0 if parsing of parameter905entities is requested; otherwise it will return non-zero.906Note: If XML_SetParamEntityParsing is called after XML_Parse or907XML_ParseBuffer, then it has no effect and will always return 0.908Note: If parser == NULL, the function will do nothing and return 0.909*/910XMLPARSEAPI(int)911XML_SetParamEntityParsing(XML_Parser parser,912enum XML_ParamEntityParsing parsing);913914/* Sets the hash salt to use for internal hash calculations.915Helps in preventing DoS attacks based on predicting hash916function behavior. This must be called before parsing is started.917Returns 1 if successful, 0 when called after parsing has started.918Note: If parser == NULL, the function will do nothing and return 0.919*/920XMLPARSEAPI(int)921XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt);922923/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then924XML_GetErrorCode returns information about the error.925*/926XMLPARSEAPI(enum XML_Error)927XML_GetErrorCode(XML_Parser parser);928929/* These functions return information about the current parse930location. They may be called from any callback called to report931some parse event; in this case the location is the location of the932first of the sequence of characters that generated the event. When933called from callbacks generated by declarations in the document934prologue, the location identified isn't as neatly defined, but will935be within the relevant markup. When called outside of the callback936functions, the position indicated will be just past the last parse937event (regardless of whether there was an associated callback).938939They may also be called after returning from a call to XML_Parse940or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then941the location is the location of the character at which the error942was detected; otherwise the location is the location of the last943parse event, as described above.944945Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber946return 0 to indicate an error.947Note: XML_GetCurrentByteIndex returns -1 to indicate an error.948*/949XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);950XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);951XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);952953/* Return the number of bytes in the current event.954Returns 0 if the event is in an internal entity.955*/956XMLPARSEAPI(int)957XML_GetCurrentByteCount(XML_Parser parser);958959/* If XML_CONTEXT_BYTES is >=1, returns the input buffer, sets960the integer pointed to by offset to the offset within this buffer961of the current parse position, and sets the integer pointed to by size962to the size of this buffer (the number of input bytes). Otherwise963returns a NULL pointer. Also returns a NULL pointer if a parse isn't964active.965966NOTE: The character pointer returned should not be used outside967the handler that makes the call.968*/969XMLPARSEAPI(const char *)970XML_GetInputContext(XML_Parser parser, int *offset, int *size);971972/* For backwards compatibility with previous versions. */973# define XML_GetErrorLineNumber XML_GetCurrentLineNumber974# define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber975# define XML_GetErrorByteIndex XML_GetCurrentByteIndex976977/* Frees the content model passed to the element declaration handler */978XMLPARSEAPI(void)979XML_FreeContentModel(XML_Parser parser, XML_Content *model);980981/* Exposing the memory handling functions used in Expat */982XMLPARSEAPI(void *)983XML_ATTR_MALLOC984XML_ATTR_ALLOC_SIZE(2)985XML_MemMalloc(XML_Parser parser, size_t size);986987XMLPARSEAPI(void *)988XML_ATTR_ALLOC_SIZE(3)989XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);990991XMLPARSEAPI(void)992XML_MemFree(XML_Parser parser, void *ptr);993994/* Frees memory used by the parser. */995XMLPARSEAPI(void)996XML_ParserFree(XML_Parser parser);997998/* Returns a string describing the error. */999XMLPARSEAPI(const XML_LChar *)1000XML_ErrorString(enum XML_Error code);10011002/* Return a string containing the version number of this expat */1003XMLPARSEAPI(const XML_LChar *)1004XML_ExpatVersion(void);10051006typedef struct {1007int major;1008int minor;1009int micro;1010} XML_Expat_Version;10111012/* Return an XML_Expat_Version structure containing numeric version1013number information for this version of expat.1014*/1015XMLPARSEAPI(XML_Expat_Version)1016XML_ExpatVersionInfo(void);10171018/* Added in Expat 1.95.5. */1019enum XML_FeatureEnum {1020XML_FEATURE_END = 0,1021XML_FEATURE_UNICODE,1022XML_FEATURE_UNICODE_WCHAR_T,1023XML_FEATURE_DTD,1024XML_FEATURE_CONTEXT_BYTES,1025XML_FEATURE_MIN_SIZE,1026XML_FEATURE_SIZEOF_XML_CHAR,1027XML_FEATURE_SIZEOF_XML_LCHAR,1028XML_FEATURE_NS,1029XML_FEATURE_LARGE_SIZE,1030XML_FEATURE_ATTR_INFO,1031/* Added in Expat 2.4.0. */1032XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,1033XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT,1034/* Added in Expat 2.6.0. */1035XML_FEATURE_GE,1036/* Added in Expat 2.7.2. */1037XML_FEATURE_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT,1038XML_FEATURE_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT,1039/* Additional features must be added to the end of this enum. */1040};10411042typedef struct {1043enum XML_FeatureEnum feature;1044const XML_LChar *name;1045long int value;1046} XML_Feature;10471048XMLPARSEAPI(const XML_Feature *)1049XML_GetFeatureList(void);10501051# if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1)1052/* 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_SetBillionLaughsAttackProtectionMaximumAmplification(1056XML_Parser parser, float maximumAmplificationFactor);10571058/* Added in Expat 2.4.0 for XML_DTD defined and1059* added in Expat 2.6.0 for XML_GE == 1. */1060XMLPARSEAPI(XML_Bool)1061XML_SetBillionLaughsAttackProtectionActivationThreshold(1062XML_Parser parser, unsigned long long activationThresholdBytes);10631064/* Added in Expat 2.7.2. */1065XMLPARSEAPI(XML_Bool)1066XML_SetAllocTrackerMaximumAmplification(XML_Parser parser,1067float maximumAmplificationFactor);10681069/* Added in Expat 2.7.2. */1070XMLPARSEAPI(XML_Bool)1071XML_SetAllocTrackerActivationThreshold(1072XML_Parser parser, unsigned long long activationThresholdBytes);1073# endif10741075/* Added in Expat 2.6.0. */1076XMLPARSEAPI(XML_Bool)1077XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);10781079/* Expat follows the semantic versioning convention.1080See https://semver.org1081*/1082# define XML_MAJOR_VERSION 21083# define XML_MINOR_VERSION 71084# define XML_MICRO_VERSION 310851086# ifdef __cplusplus1087}1088# endif10891090#endif /* not Expat_INCLUDED */109110921093