10a48773fSEric van Gyzen /* 20a48773fSEric van Gyzen __ __ _ 30a48773fSEric van Gyzen ___\ \/ /_ __ __ _| |_ 40a48773fSEric van Gyzen / _ \\ /| '_ \ / _` | __| 50a48773fSEric van Gyzen | __// \| |_) | (_| | |_ 60a48773fSEric van Gyzen \___/_/\_\ .__/ \__,_|\__| 70a48773fSEric van Gyzen |_| XML parser 80a48773fSEric van Gyzen 90a48773fSEric van Gyzen Copyright (c) 1997-2000 Thai Open Source Software Center Ltd 10cc68614dSXin LI Copyright (c) 2000 Clark Cooper <coopercc@users.sourceforge.net> 11cc68614dSXin LI Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net> 12cc68614dSXin LI Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net> 13cc68614dSXin LI Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net> 144543ef51SXin LI Copyright (c) 2016-2024 Sebastian Pipping <sebastian@pipping.org> 15cc68614dSXin LI Copyright (c) 2016 Cristian Rodríguez <crrodriguez@opensuse.org> 16cc68614dSXin LI Copyright (c) 2016 Thomas Beutlich <tc@tbeu.de> 17cc68614dSXin LI Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk> 187ed8e142SXin LI Copyright (c) 2022 Thijs Schreijer <thijs@thijsschreijer.nl> 194543ef51SXin LI Copyright (c) 2023 Hanno Böck <hanno@gentoo.org> 204543ef51SXin LI Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com> 21*ffd294a1SEnji Cooper Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> 220a48773fSEric van Gyzen Licensed under the MIT license: 230a48773fSEric van Gyzen 240a48773fSEric van Gyzen Permission is hereby granted, free of charge, to any person obtaining 250a48773fSEric van Gyzen a copy of this software and associated documentation files (the 260a48773fSEric van Gyzen "Software"), to deal in the Software without restriction, including 270a48773fSEric van Gyzen without limitation the rights to use, copy, modify, merge, publish, 280a48773fSEric van Gyzen distribute, sublicense, and/or sell copies of the Software, and to permit 290a48773fSEric van Gyzen persons to whom the Software is furnished to do so, subject to the 300a48773fSEric van Gyzen following conditions: 310a48773fSEric van Gyzen 320a48773fSEric van Gyzen The above copyright notice and this permission notice shall be included 330a48773fSEric van Gyzen in all copies or substantial portions of the Software. 340a48773fSEric van Gyzen 350a48773fSEric van Gyzen THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 360a48773fSEric van Gyzen EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 370a48773fSEric van Gyzen MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN 380a48773fSEric van Gyzen NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 390a48773fSEric van Gyzen DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 400a48773fSEric van Gyzen OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 410a48773fSEric van Gyzen USE OR OTHER DEALINGS IN THE SOFTWARE. 425bb6a25fSPoul-Henning Kamp */ 435bb6a25fSPoul-Henning Kamp 44220ed979SColeman Kane #ifndef Expat_INCLUDED 45220ed979SColeman Kane #define Expat_INCLUDED 1 465bb6a25fSPoul-Henning Kamp 475bb6a25fSPoul-Henning Kamp #include <stdlib.h> 48220ed979SColeman Kane #include "expat_external.h" 495bb6a25fSPoul-Henning Kamp 505bb6a25fSPoul-Henning Kamp #ifdef __cplusplus 515bb6a25fSPoul-Henning Kamp extern "C" { 525bb6a25fSPoul-Henning Kamp #endif 535bb6a25fSPoul-Henning Kamp 545bb6a25fSPoul-Henning Kamp struct XML_ParserStruct; 555bb6a25fSPoul-Henning Kamp typedef struct XML_ParserStruct *XML_Parser; 565bb6a25fSPoul-Henning Kamp 575bb6a25fSPoul-Henning Kamp typedef unsigned char XML_Bool; 585bb6a25fSPoul-Henning Kamp #define XML_TRUE ((XML_Bool)1) 595bb6a25fSPoul-Henning Kamp #define XML_FALSE ((XML_Bool)0) 605bb6a25fSPoul-Henning Kamp 61220ed979SColeman Kane /* The XML_Status enum gives the possible return values for several 62220ed979SColeman Kane API functions. The preprocessor #defines are included so this 63220ed979SColeman Kane stanza can be added to code that still needs to support older 64220ed979SColeman Kane versions of Expat 1.95.x: 65220ed979SColeman Kane 66220ed979SColeman Kane #ifndef XML_STATUS_OK 67220ed979SColeman Kane #define XML_STATUS_OK 1 68220ed979SColeman Kane #define XML_STATUS_ERROR 0 69220ed979SColeman Kane #endif 70220ed979SColeman Kane 71220ed979SColeman Kane Otherwise, the #define hackery is quite ugly and would have been 72220ed979SColeman Kane dropped. 73220ed979SColeman Kane */ 74220ed979SColeman Kane enum XML_Status { 75220ed979SColeman Kane XML_STATUS_ERROR = 0, 76220ed979SColeman Kane #define XML_STATUS_ERROR XML_STATUS_ERROR 77220ed979SColeman Kane XML_STATUS_OK = 1, 78220ed979SColeman Kane #define XML_STATUS_OK XML_STATUS_OK 79220ed979SColeman Kane XML_STATUS_SUSPENDED = 2 80220ed979SColeman Kane #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED 81220ed979SColeman Kane }; 82220ed979SColeman Kane 835bb6a25fSPoul-Henning Kamp enum XML_Error { 845bb6a25fSPoul-Henning Kamp XML_ERROR_NONE, 855bb6a25fSPoul-Henning Kamp XML_ERROR_NO_MEMORY, 865bb6a25fSPoul-Henning Kamp XML_ERROR_SYNTAX, 875bb6a25fSPoul-Henning Kamp XML_ERROR_NO_ELEMENTS, 885bb6a25fSPoul-Henning Kamp XML_ERROR_INVALID_TOKEN, 895bb6a25fSPoul-Henning Kamp XML_ERROR_UNCLOSED_TOKEN, 905bb6a25fSPoul-Henning Kamp XML_ERROR_PARTIAL_CHAR, 915bb6a25fSPoul-Henning Kamp XML_ERROR_TAG_MISMATCH, 925bb6a25fSPoul-Henning Kamp XML_ERROR_DUPLICATE_ATTRIBUTE, 935bb6a25fSPoul-Henning Kamp XML_ERROR_JUNK_AFTER_DOC_ELEMENT, 945bb6a25fSPoul-Henning Kamp XML_ERROR_PARAM_ENTITY_REF, 955bb6a25fSPoul-Henning Kamp XML_ERROR_UNDEFINED_ENTITY, 965bb6a25fSPoul-Henning Kamp XML_ERROR_RECURSIVE_ENTITY_REF, 975bb6a25fSPoul-Henning Kamp XML_ERROR_ASYNC_ENTITY, 985bb6a25fSPoul-Henning Kamp XML_ERROR_BAD_CHAR_REF, 995bb6a25fSPoul-Henning Kamp XML_ERROR_BINARY_ENTITY_REF, 1005bb6a25fSPoul-Henning Kamp XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF, 1015bb6a25fSPoul-Henning Kamp XML_ERROR_MISPLACED_XML_PI, 1025bb6a25fSPoul-Henning Kamp XML_ERROR_UNKNOWN_ENCODING, 1035bb6a25fSPoul-Henning Kamp XML_ERROR_INCORRECT_ENCODING, 1045bb6a25fSPoul-Henning Kamp XML_ERROR_UNCLOSED_CDATA_SECTION, 1055bb6a25fSPoul-Henning Kamp XML_ERROR_EXTERNAL_ENTITY_HANDLING, 1065bb6a25fSPoul-Henning Kamp XML_ERROR_NOT_STANDALONE, 1075bb6a25fSPoul-Henning Kamp XML_ERROR_UNEXPECTED_STATE, 1085bb6a25fSPoul-Henning Kamp XML_ERROR_ENTITY_DECLARED_IN_PE, 1095bb6a25fSPoul-Henning Kamp XML_ERROR_FEATURE_REQUIRES_XML_DTD, 110220ed979SColeman Kane XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING, 111220ed979SColeman Kane /* Added in 1.95.7. */ 112220ed979SColeman Kane XML_ERROR_UNBOUND_PREFIX, 113220ed979SColeman Kane /* Added in 1.95.8. */ 114220ed979SColeman Kane XML_ERROR_UNDECLARING_PREFIX, 115220ed979SColeman Kane XML_ERROR_INCOMPLETE_PE, 116220ed979SColeman Kane XML_ERROR_XML_DECL, 117220ed979SColeman Kane XML_ERROR_TEXT_DECL, 118220ed979SColeman Kane XML_ERROR_PUBLICID, 119220ed979SColeman Kane XML_ERROR_SUSPENDED, 120220ed979SColeman Kane XML_ERROR_NOT_SUSPENDED, 121220ed979SColeman Kane XML_ERROR_ABORTED, 122220ed979SColeman Kane XML_ERROR_FINISHED, 123220ed979SColeman Kane XML_ERROR_SUSPEND_PE, 124220ed979SColeman Kane /* Added in 2.0. */ 125220ed979SColeman Kane XML_ERROR_RESERVED_PREFIX_XML, 126220ed979SColeman Kane XML_ERROR_RESERVED_PREFIX_XMLNS, 1270a48773fSEric van Gyzen XML_ERROR_RESERVED_NAMESPACE_URI, 1280a48773fSEric van Gyzen /* Added in 2.2.1. */ 129cc68614dSXin LI XML_ERROR_INVALID_ARGUMENT, 130cc68614dSXin LI /* Added in 2.3.0. */ 131cc68614dSXin LI XML_ERROR_NO_BUFFER, 132cc68614dSXin LI /* Added in 2.4.0. */ 133cc68614dSXin LI XML_ERROR_AMPLIFICATION_LIMIT_BREACH 1345bb6a25fSPoul-Henning Kamp }; 1355bb6a25fSPoul-Henning Kamp 1365bb6a25fSPoul-Henning Kamp enum XML_Content_Type { 1375bb6a25fSPoul-Henning Kamp XML_CTYPE_EMPTY = 1, 1385bb6a25fSPoul-Henning Kamp XML_CTYPE_ANY, 1395bb6a25fSPoul-Henning Kamp XML_CTYPE_MIXED, 1405bb6a25fSPoul-Henning Kamp XML_CTYPE_NAME, 1415bb6a25fSPoul-Henning Kamp XML_CTYPE_CHOICE, 1425bb6a25fSPoul-Henning Kamp XML_CTYPE_SEQ 1435bb6a25fSPoul-Henning Kamp }; 1445bb6a25fSPoul-Henning Kamp 1455bb6a25fSPoul-Henning Kamp enum XML_Content_Quant { 1465bb6a25fSPoul-Henning Kamp XML_CQUANT_NONE, 1475bb6a25fSPoul-Henning Kamp XML_CQUANT_OPT, 1485bb6a25fSPoul-Henning Kamp XML_CQUANT_REP, 1495bb6a25fSPoul-Henning Kamp XML_CQUANT_PLUS 1505bb6a25fSPoul-Henning Kamp }; 1515bb6a25fSPoul-Henning Kamp 1525bb6a25fSPoul-Henning Kamp /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be 1535bb6a25fSPoul-Henning Kamp XML_CQUANT_NONE, and the other fields will be zero or NULL. 1545bb6a25fSPoul-Henning Kamp If type == XML_CTYPE_MIXED, then quant will be NONE or REP and 1555bb6a25fSPoul-Henning Kamp numchildren will contain number of elements that may be mixed in 1565bb6a25fSPoul-Henning Kamp and children point to an array of XML_Content cells that will be 1575bb6a25fSPoul-Henning Kamp all of XML_CTYPE_NAME type with no quantification. 1585bb6a25fSPoul-Henning Kamp 1595bb6a25fSPoul-Henning Kamp If type == XML_CTYPE_NAME, then the name points to the name, and 1605bb6a25fSPoul-Henning Kamp the numchildren field will be zero and children will be NULL. The 1615bb6a25fSPoul-Henning Kamp quant fields indicates any quantifiers placed on the name. 1625bb6a25fSPoul-Henning Kamp 1635bb6a25fSPoul-Henning Kamp CHOICE and SEQ will have name NULL, the number of children in 1645bb6a25fSPoul-Henning Kamp numchildren and children will point, recursively, to an array 1655bb6a25fSPoul-Henning Kamp of XML_Content cells. 1665bb6a25fSPoul-Henning Kamp 1675bb6a25fSPoul-Henning Kamp The EMPTY, ANY, and MIXED types will only occur at top level. 1685bb6a25fSPoul-Henning Kamp */ 1695bb6a25fSPoul-Henning Kamp 1705bb6a25fSPoul-Henning Kamp typedef struct XML_cp XML_Content; 1715bb6a25fSPoul-Henning Kamp 1725bb6a25fSPoul-Henning Kamp struct XML_cp { 1735bb6a25fSPoul-Henning Kamp enum XML_Content_Type type; 1745bb6a25fSPoul-Henning Kamp enum XML_Content_Quant quant; 1755bb6a25fSPoul-Henning Kamp XML_Char *name; 1765bb6a25fSPoul-Henning Kamp unsigned int numchildren; 1775bb6a25fSPoul-Henning Kamp XML_Content *children; 1785bb6a25fSPoul-Henning Kamp }; 1795bb6a25fSPoul-Henning Kamp 1805bb6a25fSPoul-Henning Kamp /* This is called for an element declaration. See above for 1817ed8e142SXin LI description of the model argument. It's the user code's responsibility 1827ed8e142SXin LI to free model when finished with it. See XML_FreeContentModel. 1837ed8e142SXin LI There is no need to free the model from the handler, it can be kept 1847ed8e142SXin LI around and freed at a later stage. 1855bb6a25fSPoul-Henning Kamp */ 186220ed979SColeman Kane typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData, 1875bb6a25fSPoul-Henning Kamp const XML_Char *name, 1885bb6a25fSPoul-Henning Kamp XML_Content *model); 1895bb6a25fSPoul-Henning Kamp 1905bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 1916b2c1e49SXin LI XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl); 1925bb6a25fSPoul-Henning Kamp 1935bb6a25fSPoul-Henning Kamp /* The Attlist declaration handler is called for *each* attribute. So 1945bb6a25fSPoul-Henning Kamp a single Attlist declaration with multiple attributes declared will 1955bb6a25fSPoul-Henning Kamp generate multiple calls to this handler. The "default" parameter 1965bb6a25fSPoul-Henning Kamp may be NULL in the case of the "#IMPLIED" or "#REQUIRED" 1975bb6a25fSPoul-Henning Kamp keyword. The "isrequired" parameter will be true and the default 1985bb6a25fSPoul-Henning Kamp value will be NULL in the case of "#REQUIRED". If "isrequired" is 1995bb6a25fSPoul-Henning Kamp true and default is non-NULL, then this is a "#FIXED" default. 2005bb6a25fSPoul-Henning Kamp */ 201220ed979SColeman Kane typedef void(XMLCALL *XML_AttlistDeclHandler)( 2026b2c1e49SXin LI void *userData, const XML_Char *elname, const XML_Char *attname, 2036b2c1e49SXin LI const XML_Char *att_type, const XML_Char *dflt, int isrequired); 2045bb6a25fSPoul-Henning Kamp 2055bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 2066b2c1e49SXin LI XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl); 2075bb6a25fSPoul-Henning Kamp 2085bb6a25fSPoul-Henning Kamp /* The XML declaration handler is called for *both* XML declarations 2095bb6a25fSPoul-Henning Kamp and text declarations. The way to distinguish is that the version 2105bb6a25fSPoul-Henning Kamp parameter will be NULL for text declarations. The encoding 2115bb6a25fSPoul-Henning Kamp parameter may be NULL for XML declarations. The standalone 2125bb6a25fSPoul-Henning Kamp parameter will be -1, 0, or 1 indicating respectively that there 2135bb6a25fSPoul-Henning Kamp was no standalone parameter in the declaration, that it was given 2145bb6a25fSPoul-Henning Kamp as no, or that it was given as yes. 2155bb6a25fSPoul-Henning Kamp */ 216220ed979SColeman Kane typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData, 2175bb6a25fSPoul-Henning Kamp const XML_Char *version, 2185bb6a25fSPoul-Henning Kamp const XML_Char *encoding, 2195bb6a25fSPoul-Henning Kamp int standalone); 2205bb6a25fSPoul-Henning Kamp 2215bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 2226b2c1e49SXin LI XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl); 2235bb6a25fSPoul-Henning Kamp 2245bb6a25fSPoul-Henning Kamp typedef struct { 2255bb6a25fSPoul-Henning Kamp void *(*malloc_fcn)(size_t size); 2265bb6a25fSPoul-Henning Kamp void *(*realloc_fcn)(void *ptr, size_t size); 2275bb6a25fSPoul-Henning Kamp void (*free_fcn)(void *ptr); 2285bb6a25fSPoul-Henning Kamp } XML_Memory_Handling_Suite; 2295bb6a25fSPoul-Henning Kamp 2305bb6a25fSPoul-Henning Kamp /* Constructs a new parser; encoding is the encoding specified by the 2315bb6a25fSPoul-Henning Kamp external protocol or NULL if there is none specified. 2325bb6a25fSPoul-Henning Kamp */ 2335bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser) 2345bb6a25fSPoul-Henning Kamp XML_ParserCreate(const XML_Char *encoding); 2355bb6a25fSPoul-Henning Kamp 2365bb6a25fSPoul-Henning Kamp /* Constructs a new parser and namespace processor. Element type 2375bb6a25fSPoul-Henning Kamp names and attribute names that belong to a namespace will be 2385bb6a25fSPoul-Henning Kamp expanded; unprefixed attribute names are never expanded; unprefixed 2395bb6a25fSPoul-Henning Kamp element type names are expanded only if there is a default 2405bb6a25fSPoul-Henning Kamp namespace. The expanded name is the concatenation of the namespace 2415bb6a25fSPoul-Henning Kamp URI, the namespace separator character, and the local part of the 2425bb6a25fSPoul-Henning Kamp name. If the namespace separator is '\0' then the namespace URI 2435bb6a25fSPoul-Henning Kamp and the local part will be concatenated without any separator. 244220ed979SColeman Kane It is a programming error to use the separator '\0' with namespace 245220ed979SColeman Kane triplets (see XML_SetReturnNSTriplet). 2467ed8e142SXin LI If a namespace separator is chosen that can be part of a URI or 2477ed8e142SXin LI part of an XML name, splitting an expanded name back into its 2487ed8e142SXin LI 1, 2 or 3 original parts on application level in the element handler 2497ed8e142SXin LI may end up vulnerable, so these are advised against; sane choices for 2507ed8e142SXin LI a namespace separator are e.g. '\n' (line feed) and '|' (pipe). 2517ed8e142SXin LI 2527ed8e142SXin LI Note that Expat does not validate namespace URIs (beyond encoding) 2537ed8e142SXin LI against RFC 3986 today (and is not required to do so with regard to 2547ed8e142SXin LI the XML 1.0 namespaces specification) but it may start doing that 2557ed8e142SXin LI in future releases. Before that, an application using Expat must 2567ed8e142SXin LI be ready to receive namespace URIs containing non-URI characters. 2575bb6a25fSPoul-Henning Kamp */ 2585bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser) 2595bb6a25fSPoul-Henning Kamp XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator); 2605bb6a25fSPoul-Henning Kamp 261220ed979SColeman Kane /* Constructs a new parser using the memory management suite referred to 2625bb6a25fSPoul-Henning Kamp by memsuite. If memsuite is NULL, then use the standard library memory 2635bb6a25fSPoul-Henning Kamp suite. If namespaceSeparator is non-NULL it creates a parser with 2645bb6a25fSPoul-Henning Kamp namespace processing as described above. The character pointed at 2655bb6a25fSPoul-Henning Kamp will serve as the namespace separator. 2665bb6a25fSPoul-Henning Kamp 2675bb6a25fSPoul-Henning Kamp All further memory operations used for the created parser will come from 2685bb6a25fSPoul-Henning Kamp the given suite. 2695bb6a25fSPoul-Henning Kamp */ 2705bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser) 2715bb6a25fSPoul-Henning Kamp XML_ParserCreate_MM(const XML_Char *encoding, 2725bb6a25fSPoul-Henning Kamp const XML_Memory_Handling_Suite *memsuite, 2735bb6a25fSPoul-Henning Kamp const XML_Char *namespaceSeparator); 2745bb6a25fSPoul-Henning Kamp 2754543ef51SXin LI /* Prepare a parser object to be reused. This is particularly 2760a48773fSEric van Gyzen valuable when memory allocation overhead is disproportionately high, 2775bb6a25fSPoul-Henning Kamp such as when a large number of small documnents need to be parsed. 2785bb6a25fSPoul-Henning Kamp All handlers are cleared from the parser, except for the 2795bb6a25fSPoul-Henning Kamp unknownEncodingHandler. The parser's external state is re-initialized 2805bb6a25fSPoul-Henning Kamp except for the values of ns and ns_triplets. 2815bb6a25fSPoul-Henning Kamp 2825bb6a25fSPoul-Henning Kamp Added in Expat 1.95.3. 2835bb6a25fSPoul-Henning Kamp */ 2845bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Bool) 2855bb6a25fSPoul-Henning Kamp XML_ParserReset(XML_Parser parser, const XML_Char *encoding); 2865bb6a25fSPoul-Henning Kamp 2875bb6a25fSPoul-Henning Kamp /* atts is array of name/value pairs, terminated by 0; 2885bb6a25fSPoul-Henning Kamp names and values are 0 terminated. 2895bb6a25fSPoul-Henning Kamp */ 290220ed979SColeman Kane typedef void(XMLCALL *XML_StartElementHandler)(void *userData, 2915bb6a25fSPoul-Henning Kamp const XML_Char *name, 2925bb6a25fSPoul-Henning Kamp const XML_Char **atts); 2935bb6a25fSPoul-Henning Kamp 294220ed979SColeman Kane typedef void(XMLCALL *XML_EndElementHandler)(void *userData, 2955bb6a25fSPoul-Henning Kamp const XML_Char *name); 2965bb6a25fSPoul-Henning Kamp 2975bb6a25fSPoul-Henning Kamp /* s is not 0 terminated. */ 298220ed979SColeman Kane typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData, 2996b2c1e49SXin LI const XML_Char *s, int len); 3005bb6a25fSPoul-Henning Kamp 3015bb6a25fSPoul-Henning Kamp /* target and data are 0 terminated */ 3026b2c1e49SXin LI typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData, 3035bb6a25fSPoul-Henning Kamp const XML_Char *target, 3045bb6a25fSPoul-Henning Kamp const XML_Char *data); 3055bb6a25fSPoul-Henning Kamp 3065bb6a25fSPoul-Henning Kamp /* data is 0 terminated */ 3076b2c1e49SXin LI typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data); 3085bb6a25fSPoul-Henning Kamp 309220ed979SColeman Kane typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData); 310220ed979SColeman Kane typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData); 3115bb6a25fSPoul-Henning Kamp 3125bb6a25fSPoul-Henning Kamp /* This is called for any characters in the XML document for which 3135bb6a25fSPoul-Henning Kamp there is no applicable handler. This includes both characters that 3145bb6a25fSPoul-Henning Kamp are part of markup which is of a kind that is not reported 3155bb6a25fSPoul-Henning Kamp (comments, markup declarations), or characters that are part of a 3165bb6a25fSPoul-Henning Kamp construct which could be reported but for which no handler has been 3175bb6a25fSPoul-Henning Kamp supplied. The characters are passed exactly as they were in the XML 3185bb6a25fSPoul-Henning Kamp document except that they will be encoded in UTF-8 or UTF-16. 3195bb6a25fSPoul-Henning Kamp Line boundaries are not normalized. Note that a byte order mark 3205bb6a25fSPoul-Henning Kamp character is not passed to the default handler. There are no 3215bb6a25fSPoul-Henning Kamp guarantees about how characters are divided between calls to the 3225bb6a25fSPoul-Henning Kamp default handler: for example, a comment might be split between 3235bb6a25fSPoul-Henning Kamp multiple calls. 3245bb6a25fSPoul-Henning Kamp */ 3256b2c1e49SXin LI typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s, 3265bb6a25fSPoul-Henning Kamp int len); 3275bb6a25fSPoul-Henning Kamp 3285bb6a25fSPoul-Henning Kamp /* This is called for the start of the DOCTYPE declaration, before 3295bb6a25fSPoul-Henning Kamp any DTD or internal subset is parsed. 3305bb6a25fSPoul-Henning Kamp */ 3316b2c1e49SXin LI typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData, 3325bb6a25fSPoul-Henning Kamp const XML_Char *doctypeName, 3335bb6a25fSPoul-Henning Kamp const XML_Char *sysid, 3345bb6a25fSPoul-Henning Kamp const XML_Char *pubid, 3355bb6a25fSPoul-Henning Kamp int has_internal_subset); 3365bb6a25fSPoul-Henning Kamp 3377ed8e142SXin LI /* This is called for the end of the DOCTYPE declaration when the 3385bb6a25fSPoul-Henning Kamp closing > is encountered, but after processing any external 3395bb6a25fSPoul-Henning Kamp subset. 3405bb6a25fSPoul-Henning Kamp */ 341220ed979SColeman Kane typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData); 3425bb6a25fSPoul-Henning Kamp 3435bb6a25fSPoul-Henning Kamp /* This is called for entity declarations. The is_parameter_entity 3445bb6a25fSPoul-Henning Kamp argument will be non-zero if the entity is a parameter entity, zero 3455bb6a25fSPoul-Henning Kamp otherwise. 3465bb6a25fSPoul-Henning Kamp 3475bb6a25fSPoul-Henning Kamp For internal entities (<!ENTITY foo "bar">), value will 3485bb6a25fSPoul-Henning Kamp be non-NULL and systemId, publicID, and notationName will be NULL. 349cc68614dSXin LI The value string is NOT null-terminated; the length is provided in 3505bb6a25fSPoul-Henning Kamp the value_length argument. Since it is legal to have zero-length 3515bb6a25fSPoul-Henning Kamp values, do not use this argument to test for internal entities. 3525bb6a25fSPoul-Henning Kamp 3535bb6a25fSPoul-Henning Kamp For external entities, value will be NULL and systemId will be 3545bb6a25fSPoul-Henning Kamp non-NULL. The publicId argument will be NULL unless a public 3555bb6a25fSPoul-Henning Kamp identifier was provided. The notationName argument will have a 3565bb6a25fSPoul-Henning Kamp non-NULL value only for unparsed entity declarations. 3575bb6a25fSPoul-Henning Kamp 3585bb6a25fSPoul-Henning Kamp Note that is_parameter_entity can't be changed to XML_Bool, since 3595bb6a25fSPoul-Henning Kamp that would break binary compatibility. 3605bb6a25fSPoul-Henning Kamp */ 361220ed979SColeman Kane typedef void(XMLCALL *XML_EntityDeclHandler)( 3626b2c1e49SXin LI void *userData, const XML_Char *entityName, int is_parameter_entity, 3636b2c1e49SXin LI const XML_Char *value, int value_length, const XML_Char *base, 3646b2c1e49SXin LI const XML_Char *systemId, const XML_Char *publicId, 3655bb6a25fSPoul-Henning Kamp const XML_Char *notationName); 3665bb6a25fSPoul-Henning Kamp 3675bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 3686b2c1e49SXin LI XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler); 3695bb6a25fSPoul-Henning Kamp 3705bb6a25fSPoul-Henning Kamp /* OBSOLETE -- OBSOLETE -- OBSOLETE 371be8aff81SXin LI This handler has been superseded by the EntityDeclHandler above. 3725bb6a25fSPoul-Henning Kamp It is provided here for backward compatibility. 3735bb6a25fSPoul-Henning Kamp 3745bb6a25fSPoul-Henning Kamp This is called for a declaration of an unparsed (NDATA) entity. 3755bb6a25fSPoul-Henning Kamp The base argument is whatever was set by XML_SetBase. The 3765bb6a25fSPoul-Henning Kamp entityName, systemId and notationName arguments will never be 3775bb6a25fSPoul-Henning Kamp NULL. The other arguments may be. 3785bb6a25fSPoul-Henning Kamp */ 379220ed979SColeman Kane typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)( 3806b2c1e49SXin LI void *userData, const XML_Char *entityName, const XML_Char *base, 3816b2c1e49SXin LI const XML_Char *systemId, const XML_Char *publicId, 3825bb6a25fSPoul-Henning Kamp const XML_Char *notationName); 3835bb6a25fSPoul-Henning Kamp 3845bb6a25fSPoul-Henning Kamp /* This is called for a declaration of notation. The base argument is 3855bb6a25fSPoul-Henning Kamp whatever was set by XML_SetBase. The notationName will never be 3865bb6a25fSPoul-Henning Kamp NULL. The other arguments can be. 3875bb6a25fSPoul-Henning Kamp */ 3886b2c1e49SXin LI typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData, 3895bb6a25fSPoul-Henning Kamp const XML_Char *notationName, 3905bb6a25fSPoul-Henning Kamp const XML_Char *base, 3915bb6a25fSPoul-Henning Kamp const XML_Char *systemId, 3925bb6a25fSPoul-Henning Kamp const XML_Char *publicId); 3935bb6a25fSPoul-Henning Kamp 3945bb6a25fSPoul-Henning Kamp /* When namespace processing is enabled, these are called once for 3955bb6a25fSPoul-Henning Kamp each namespace declaration. The call to the start and end element 3965bb6a25fSPoul-Henning Kamp handlers occur between the calls to the start and end namespace 3975bb6a25fSPoul-Henning Kamp declaration handlers. For an xmlns attribute, prefix will be 3985bb6a25fSPoul-Henning Kamp NULL. For an xmlns="" attribute, uri will be NULL. 3995bb6a25fSPoul-Henning Kamp */ 4006b2c1e49SXin LI typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData, 4015bb6a25fSPoul-Henning Kamp const XML_Char *prefix, 4025bb6a25fSPoul-Henning Kamp const XML_Char *uri); 4035bb6a25fSPoul-Henning Kamp 4046b2c1e49SXin LI typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData, 4055bb6a25fSPoul-Henning Kamp const XML_Char *prefix); 4065bb6a25fSPoul-Henning Kamp 4075bb6a25fSPoul-Henning Kamp /* This is called if the document is not standalone, that is, it has an 4085bb6a25fSPoul-Henning Kamp external subset or a reference to a parameter entity, but does not 409220ed979SColeman Kane have standalone="yes". If this handler returns XML_STATUS_ERROR, 410220ed979SColeman Kane then processing will not continue, and the parser will return a 4115bb6a25fSPoul-Henning Kamp XML_ERROR_NOT_STANDALONE error. 4125bb6a25fSPoul-Henning Kamp If parameter entity parsing is enabled, then in addition to the 4135bb6a25fSPoul-Henning Kamp conditions above this handler will only be called if the referenced 4145bb6a25fSPoul-Henning Kamp entity was actually read. 4155bb6a25fSPoul-Henning Kamp */ 416220ed979SColeman Kane typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData); 4175bb6a25fSPoul-Henning Kamp 4185bb6a25fSPoul-Henning Kamp /* This is called for a reference to an external parsed general 4195bb6a25fSPoul-Henning Kamp entity. The referenced entity is not automatically parsed. The 4205bb6a25fSPoul-Henning Kamp application can parse it immediately or later using 4215bb6a25fSPoul-Henning Kamp XML_ExternalEntityParserCreate. 4225bb6a25fSPoul-Henning Kamp 4235bb6a25fSPoul-Henning Kamp The parser argument is the parser parsing the entity containing the 4245bb6a25fSPoul-Henning Kamp reference; it can be passed as the parser argument to 4255bb6a25fSPoul-Henning Kamp XML_ExternalEntityParserCreate. The systemId argument is the 4265bb6a25fSPoul-Henning Kamp system identifier as specified in the entity declaration; it will 4275bb6a25fSPoul-Henning Kamp not be NULL. 4285bb6a25fSPoul-Henning Kamp 4295bb6a25fSPoul-Henning Kamp The base argument is the system identifier that should be used as 4305bb6a25fSPoul-Henning Kamp the base for resolving systemId if systemId was relative; this is 4315bb6a25fSPoul-Henning Kamp set by XML_SetBase; it may be NULL. 4325bb6a25fSPoul-Henning Kamp 4335bb6a25fSPoul-Henning Kamp The publicId argument is the public identifier as specified in the 4345bb6a25fSPoul-Henning Kamp entity declaration, or NULL if none was specified; the whitespace 4355bb6a25fSPoul-Henning Kamp in the public identifier will have been normalized as required by 4365bb6a25fSPoul-Henning Kamp the XML spec. 4375bb6a25fSPoul-Henning Kamp 4385bb6a25fSPoul-Henning Kamp The context argument specifies the parsing context in the format 4395bb6a25fSPoul-Henning Kamp expected by the context argument to XML_ExternalEntityParserCreate; 4405bb6a25fSPoul-Henning Kamp context is valid only until the handler returns, so if the 4415bb6a25fSPoul-Henning Kamp referenced entity is to be parsed later, it must be copied. 442220ed979SColeman Kane context is NULL only when the entity is a parameter entity. 4435bb6a25fSPoul-Henning Kamp 444220ed979SColeman Kane The handler should return XML_STATUS_ERROR if processing should not 445220ed979SColeman Kane continue because of a fatal error in the handling of the external 446220ed979SColeman Kane entity. In this case the calling parser will return an 4475bb6a25fSPoul-Henning Kamp XML_ERROR_EXTERNAL_ENTITY_HANDLING error. 4485bb6a25fSPoul-Henning Kamp 4495bb6a25fSPoul-Henning Kamp Note that unlike other handlers the first argument is the parser, 4505bb6a25fSPoul-Henning Kamp not userData. 4515bb6a25fSPoul-Henning Kamp */ 4526b2c1e49SXin LI typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser, 4535bb6a25fSPoul-Henning Kamp const XML_Char *context, 4545bb6a25fSPoul-Henning Kamp const XML_Char *base, 4555bb6a25fSPoul-Henning Kamp const XML_Char *systemId, 4565bb6a25fSPoul-Henning Kamp const XML_Char *publicId); 4575bb6a25fSPoul-Henning Kamp 4585bb6a25fSPoul-Henning Kamp /* This is called in two situations: 4595bb6a25fSPoul-Henning Kamp 1) An entity reference is encountered for which no declaration 4605bb6a25fSPoul-Henning Kamp has been read *and* this is not an error. 4615bb6a25fSPoul-Henning Kamp 2) An internal entity reference is read, but not expanded, because 4625bb6a25fSPoul-Henning Kamp XML_SetDefaultHandler has been called. 4635bb6a25fSPoul-Henning Kamp Note: skipped parameter entities in declarations and skipped general 4645bb6a25fSPoul-Henning Kamp entities in attribute values cannot be reported, because 4655bb6a25fSPoul-Henning Kamp the event would be out of sync with the reporting of the 4665bb6a25fSPoul-Henning Kamp declarations or attribute values 4675bb6a25fSPoul-Henning Kamp */ 4686b2c1e49SXin LI typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData, 4695bb6a25fSPoul-Henning Kamp const XML_Char *entityName, 4705bb6a25fSPoul-Henning Kamp int is_parameter_entity); 4715bb6a25fSPoul-Henning Kamp 4725bb6a25fSPoul-Henning Kamp /* This structure is filled in by the XML_UnknownEncodingHandler to 4735bb6a25fSPoul-Henning Kamp provide information to the parser about encodings that are unknown 4745bb6a25fSPoul-Henning Kamp to the parser. 4755bb6a25fSPoul-Henning Kamp 4765bb6a25fSPoul-Henning Kamp The map[b] member gives information about byte sequences whose 4775bb6a25fSPoul-Henning Kamp first byte is b. 4785bb6a25fSPoul-Henning Kamp 4795bb6a25fSPoul-Henning Kamp If map[b] is c where c is >= 0, then b by itself encodes the 4805bb6a25fSPoul-Henning Kamp Unicode scalar value c. 4815bb6a25fSPoul-Henning Kamp 4825bb6a25fSPoul-Henning Kamp If map[b] is -1, then the byte sequence is malformed. 4835bb6a25fSPoul-Henning Kamp 4845bb6a25fSPoul-Henning Kamp If map[b] is -n, where n >= 2, then b is the first byte of an 4855bb6a25fSPoul-Henning Kamp n-byte sequence that encodes a single Unicode scalar value. 4865bb6a25fSPoul-Henning Kamp 4875bb6a25fSPoul-Henning Kamp The data member will be passed as the first argument to the convert 4885bb6a25fSPoul-Henning Kamp function. 4895bb6a25fSPoul-Henning Kamp 4905bb6a25fSPoul-Henning Kamp The convert function is used to convert multibyte sequences; s will 4915bb6a25fSPoul-Henning Kamp point to a n-byte sequence where map[(unsigned char)*s] == -n. The 4925bb6a25fSPoul-Henning Kamp convert function must return the Unicode scalar value represented 4935bb6a25fSPoul-Henning Kamp by this byte sequence or -1 if the byte sequence is malformed. 4945bb6a25fSPoul-Henning Kamp 4955bb6a25fSPoul-Henning Kamp The convert function may be NULL if the encoding is a single-byte 4965bb6a25fSPoul-Henning Kamp encoding, that is if map[b] >= -1 for all bytes b. 4975bb6a25fSPoul-Henning Kamp 4985bb6a25fSPoul-Henning Kamp When the parser is finished with the encoding, then if release is 4995bb6a25fSPoul-Henning Kamp not NULL, it will call release passing it the data member; once 5005bb6a25fSPoul-Henning Kamp release has been called, the convert function will not be called 5015bb6a25fSPoul-Henning Kamp again. 5025bb6a25fSPoul-Henning Kamp 5035bb6a25fSPoul-Henning Kamp Expat places certain restrictions on the encodings that are supported 5045bb6a25fSPoul-Henning Kamp using this mechanism. 5055bb6a25fSPoul-Henning Kamp 5065bb6a25fSPoul-Henning Kamp 1. Every ASCII character that can appear in a well-formed XML document, 5075bb6a25fSPoul-Henning Kamp other than the characters 5085bb6a25fSPoul-Henning Kamp 5095bb6a25fSPoul-Henning Kamp $@\^`{}~ 5105bb6a25fSPoul-Henning Kamp 5115bb6a25fSPoul-Henning Kamp must be represented by a single byte, and that byte must be the 5125bb6a25fSPoul-Henning Kamp same byte that represents that character in ASCII. 5135bb6a25fSPoul-Henning Kamp 5145bb6a25fSPoul-Henning Kamp 2. No character may require more than 4 bytes to encode. 5155bb6a25fSPoul-Henning Kamp 5165bb6a25fSPoul-Henning Kamp 3. All characters encoded must have Unicode scalar values <= 5175bb6a25fSPoul-Henning Kamp 0xFFFF, (i.e., characters that would be encoded by surrogates in 5185bb6a25fSPoul-Henning Kamp UTF-16 are not allowed). Note that this restriction doesn't 5195bb6a25fSPoul-Henning Kamp apply to the built-in support for UTF-8 and UTF-16. 5205bb6a25fSPoul-Henning Kamp 5215bb6a25fSPoul-Henning Kamp 4. No Unicode character may be encoded by more than one distinct 5225bb6a25fSPoul-Henning Kamp sequence of bytes. 5235bb6a25fSPoul-Henning Kamp */ 5245bb6a25fSPoul-Henning Kamp typedef struct { 5255bb6a25fSPoul-Henning Kamp int map[256]; 5265bb6a25fSPoul-Henning Kamp void *data; 527220ed979SColeman Kane int(XMLCALL *convert)(void *data, const char *s); 528220ed979SColeman Kane void(XMLCALL *release)(void *data); 5295bb6a25fSPoul-Henning Kamp } XML_Encoding; 5305bb6a25fSPoul-Henning Kamp 5315bb6a25fSPoul-Henning Kamp /* This is called for an encoding that is unknown to the parser. 5325bb6a25fSPoul-Henning Kamp 5335bb6a25fSPoul-Henning Kamp The encodingHandlerData argument is that which was passed as the 5345bb6a25fSPoul-Henning Kamp second argument to XML_SetUnknownEncodingHandler. 5355bb6a25fSPoul-Henning Kamp 5365bb6a25fSPoul-Henning Kamp The name argument gives the name of the encoding as specified in 5375bb6a25fSPoul-Henning Kamp the encoding declaration. 5385bb6a25fSPoul-Henning Kamp 5395bb6a25fSPoul-Henning Kamp If the callback can provide information about the encoding, it must 540220ed979SColeman Kane fill in the XML_Encoding structure, and return XML_STATUS_OK. 541220ed979SColeman Kane Otherwise it must return XML_STATUS_ERROR. 5425bb6a25fSPoul-Henning Kamp 5435bb6a25fSPoul-Henning Kamp If info does not describe a suitable encoding, then the parser will 544cc68614dSXin LI return an XML_ERROR_UNKNOWN_ENCODING error. 5455bb6a25fSPoul-Henning Kamp */ 5466b2c1e49SXin LI typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData, 5475bb6a25fSPoul-Henning Kamp const XML_Char *name, 5485bb6a25fSPoul-Henning Kamp XML_Encoding *info); 5495bb6a25fSPoul-Henning Kamp 5505bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5516b2c1e49SXin LI XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, 5525bb6a25fSPoul-Henning Kamp XML_EndElementHandler end); 5535bb6a25fSPoul-Henning Kamp 5545bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5556b2c1e49SXin LI XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler); 5565bb6a25fSPoul-Henning Kamp 5575bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5586b2c1e49SXin LI XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler); 5595bb6a25fSPoul-Henning Kamp 5605bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5615bb6a25fSPoul-Henning Kamp XML_SetCharacterDataHandler(XML_Parser parser, 5625bb6a25fSPoul-Henning Kamp XML_CharacterDataHandler handler); 5635bb6a25fSPoul-Henning Kamp 5645bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5655bb6a25fSPoul-Henning Kamp XML_SetProcessingInstructionHandler(XML_Parser parser, 5665bb6a25fSPoul-Henning Kamp XML_ProcessingInstructionHandler handler); 5675bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5686b2c1e49SXin LI XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler); 5695bb6a25fSPoul-Henning Kamp 5705bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5715bb6a25fSPoul-Henning Kamp XML_SetCdataSectionHandler(XML_Parser parser, 5725bb6a25fSPoul-Henning Kamp XML_StartCdataSectionHandler start, 5735bb6a25fSPoul-Henning Kamp XML_EndCdataSectionHandler end); 5745bb6a25fSPoul-Henning Kamp 5755bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5765bb6a25fSPoul-Henning Kamp XML_SetStartCdataSectionHandler(XML_Parser parser, 5775bb6a25fSPoul-Henning Kamp XML_StartCdataSectionHandler start); 5785bb6a25fSPoul-Henning Kamp 5795bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5805bb6a25fSPoul-Henning Kamp XML_SetEndCdataSectionHandler(XML_Parser parser, 5815bb6a25fSPoul-Henning Kamp XML_EndCdataSectionHandler end); 5825bb6a25fSPoul-Henning Kamp 5835bb6a25fSPoul-Henning Kamp /* This sets the default handler and also inhibits expansion of 5845bb6a25fSPoul-Henning Kamp internal entities. These entity references will be passed to the 5855bb6a25fSPoul-Henning Kamp default handler, or to the skipped entity handler, if one is set. 5865bb6a25fSPoul-Henning Kamp */ 5875bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5886b2c1e49SXin LI XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler); 5895bb6a25fSPoul-Henning Kamp 5905bb6a25fSPoul-Henning Kamp /* This sets the default handler but does not inhibit expansion of 5915bb6a25fSPoul-Henning Kamp internal entities. The entity reference will not be passed to the 5925bb6a25fSPoul-Henning Kamp default handler. 5935bb6a25fSPoul-Henning Kamp */ 5945bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5956b2c1e49SXin LI XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler); 5965bb6a25fSPoul-Henning Kamp 5975bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 5986b2c1e49SXin LI XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start, 5995bb6a25fSPoul-Henning Kamp XML_EndDoctypeDeclHandler end); 6005bb6a25fSPoul-Henning Kamp 6015bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6025bb6a25fSPoul-Henning Kamp XML_SetStartDoctypeDeclHandler(XML_Parser parser, 6035bb6a25fSPoul-Henning Kamp XML_StartDoctypeDeclHandler start); 6045bb6a25fSPoul-Henning Kamp 6055bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6066b2c1e49SXin LI XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end); 6075bb6a25fSPoul-Henning Kamp 6085bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6095bb6a25fSPoul-Henning Kamp XML_SetUnparsedEntityDeclHandler(XML_Parser parser, 6105bb6a25fSPoul-Henning Kamp XML_UnparsedEntityDeclHandler handler); 6115bb6a25fSPoul-Henning Kamp 6125bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6136b2c1e49SXin LI XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler); 6145bb6a25fSPoul-Henning Kamp 6155bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6165bb6a25fSPoul-Henning Kamp XML_SetNamespaceDeclHandler(XML_Parser parser, 6175bb6a25fSPoul-Henning Kamp XML_StartNamespaceDeclHandler start, 6185bb6a25fSPoul-Henning Kamp XML_EndNamespaceDeclHandler end); 6195bb6a25fSPoul-Henning Kamp 6205bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6215bb6a25fSPoul-Henning Kamp XML_SetStartNamespaceDeclHandler(XML_Parser parser, 6225bb6a25fSPoul-Henning Kamp XML_StartNamespaceDeclHandler start); 6235bb6a25fSPoul-Henning Kamp 6245bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6255bb6a25fSPoul-Henning Kamp XML_SetEndNamespaceDeclHandler(XML_Parser parser, 6265bb6a25fSPoul-Henning Kamp XML_EndNamespaceDeclHandler end); 6275bb6a25fSPoul-Henning Kamp 6285bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6295bb6a25fSPoul-Henning Kamp XML_SetNotStandaloneHandler(XML_Parser parser, 6305bb6a25fSPoul-Henning Kamp XML_NotStandaloneHandler handler); 6315bb6a25fSPoul-Henning Kamp 6325bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6335bb6a25fSPoul-Henning Kamp XML_SetExternalEntityRefHandler(XML_Parser parser, 6345bb6a25fSPoul-Henning Kamp XML_ExternalEntityRefHandler handler); 6355bb6a25fSPoul-Henning Kamp 6365bb6a25fSPoul-Henning Kamp /* If a non-NULL value for arg is specified here, then it will be 6375bb6a25fSPoul-Henning Kamp passed as the first argument to the external entity ref handler 6385bb6a25fSPoul-Henning Kamp instead of the parser object. 6395bb6a25fSPoul-Henning Kamp */ 6405bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6416b2c1e49SXin LI XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg); 6425bb6a25fSPoul-Henning Kamp 6435bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6445bb6a25fSPoul-Henning Kamp XML_SetSkippedEntityHandler(XML_Parser parser, 6455bb6a25fSPoul-Henning Kamp XML_SkippedEntityHandler handler); 6465bb6a25fSPoul-Henning Kamp 6475bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6485bb6a25fSPoul-Henning Kamp XML_SetUnknownEncodingHandler(XML_Parser parser, 6495bb6a25fSPoul-Henning Kamp XML_UnknownEncodingHandler handler, 6505bb6a25fSPoul-Henning Kamp void *encodingHandlerData); 6515bb6a25fSPoul-Henning Kamp 6525bb6a25fSPoul-Henning Kamp /* This can be called within a handler for a start element, end 6535bb6a25fSPoul-Henning Kamp element, processing instruction or character data. It causes the 6545bb6a25fSPoul-Henning Kamp corresponding markup to be passed to the default handler. 6555bb6a25fSPoul-Henning Kamp */ 6565bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6575bb6a25fSPoul-Henning Kamp XML_DefaultCurrent(XML_Parser parser); 6585bb6a25fSPoul-Henning Kamp 6595bb6a25fSPoul-Henning Kamp /* If do_nst is non-zero, and namespace processing is in effect, and 6605bb6a25fSPoul-Henning Kamp a name has a prefix (i.e. an explicit namespace qualifier) then 6615bb6a25fSPoul-Henning Kamp that name is returned as a triplet in a single string separated by 6625bb6a25fSPoul-Henning Kamp the separator character specified when the parser was created: URI 6635bb6a25fSPoul-Henning Kamp + sep + local_name + sep + prefix. 6645bb6a25fSPoul-Henning Kamp 6655bb6a25fSPoul-Henning Kamp If do_nst is zero, then namespace information is returned in the 6665bb6a25fSPoul-Henning Kamp default manner (URI + sep + local_name) whether or not the name 6675bb6a25fSPoul-Henning Kamp has a prefix. 6685bb6a25fSPoul-Henning Kamp 6695bb6a25fSPoul-Henning Kamp Note: Calling XML_SetReturnNSTriplet after XML_Parse or 6705bb6a25fSPoul-Henning Kamp XML_ParseBuffer has no effect. 6715bb6a25fSPoul-Henning Kamp */ 6725bb6a25fSPoul-Henning Kamp 6735bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6745bb6a25fSPoul-Henning Kamp XML_SetReturnNSTriplet(XML_Parser parser, int do_nst); 6755bb6a25fSPoul-Henning Kamp 6765bb6a25fSPoul-Henning Kamp /* This value is passed as the userData argument to callbacks. */ 6775bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6785bb6a25fSPoul-Henning Kamp XML_SetUserData(XML_Parser parser, void *userData); 6795bb6a25fSPoul-Henning Kamp 6805bb6a25fSPoul-Henning Kamp /* Returns the last value set by XML_SetUserData or NULL. */ 6815bb6a25fSPoul-Henning Kamp #define XML_GetUserData(parser) (*(void **)(parser)) 6825bb6a25fSPoul-Henning Kamp 6835bb6a25fSPoul-Henning Kamp /* This is equivalent to supplying an encoding argument to 6845bb6a25fSPoul-Henning Kamp XML_ParserCreate. On success XML_SetEncoding returns non-zero, 6855bb6a25fSPoul-Henning Kamp zero otherwise. 6865bb6a25fSPoul-Henning Kamp Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer 687220ed979SColeman Kane has no effect and returns XML_STATUS_ERROR. 6885bb6a25fSPoul-Henning Kamp */ 689220ed979SColeman Kane XMLPARSEAPI(enum XML_Status) 6905bb6a25fSPoul-Henning Kamp XML_SetEncoding(XML_Parser parser, const XML_Char *encoding); 6915bb6a25fSPoul-Henning Kamp 6925bb6a25fSPoul-Henning Kamp /* If this function is called, then the parser will be passed as the 6935bb6a25fSPoul-Henning Kamp first argument to callbacks instead of userData. The userData will 6945bb6a25fSPoul-Henning Kamp still be accessible using XML_GetUserData. 6955bb6a25fSPoul-Henning Kamp */ 6965bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 6975bb6a25fSPoul-Henning Kamp XML_UseParserAsHandlerArg(XML_Parser parser); 6985bb6a25fSPoul-Henning Kamp 6995bb6a25fSPoul-Henning Kamp /* If useDTD == XML_TRUE is passed to this function, then the parser 7005bb6a25fSPoul-Henning Kamp will assume that there is an external subset, even if none is 7015bb6a25fSPoul-Henning Kamp specified in the document. In such a case the parser will call the 7025bb6a25fSPoul-Henning Kamp externalEntityRefHandler with a value of NULL for the systemId 7035bb6a25fSPoul-Henning Kamp argument (the publicId and context arguments will be NULL as well). 704220ed979SColeman Kane Note: For the purpose of checking WFC: Entity Declared, passing 705220ed979SColeman Kane useDTD == XML_TRUE will make the parser behave as if the document 706220ed979SColeman Kane had a DTD with an external subset. 7075bb6a25fSPoul-Henning Kamp Note: If this function is called, then this must be done before 7085bb6a25fSPoul-Henning Kamp the first call to XML_Parse or XML_ParseBuffer, since it will 7095bb6a25fSPoul-Henning Kamp have no effect after that. Returns 7105bb6a25fSPoul-Henning Kamp XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING. 7115bb6a25fSPoul-Henning Kamp Note: If the document does not have a DOCTYPE declaration at all, 7125bb6a25fSPoul-Henning Kamp then startDoctypeDeclHandler and endDoctypeDeclHandler will not 7135bb6a25fSPoul-Henning Kamp be called, despite an external subset being parsed. 7145bb6a25fSPoul-Henning Kamp Note: If XML_DTD is not defined when Expat is compiled, returns 7155bb6a25fSPoul-Henning Kamp XML_ERROR_FEATURE_REQUIRES_XML_DTD. 7160a48773fSEric van Gyzen Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT. 7175bb6a25fSPoul-Henning Kamp */ 7185bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Error) 7195bb6a25fSPoul-Henning Kamp XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD); 7205bb6a25fSPoul-Henning Kamp 7215bb6a25fSPoul-Henning Kamp /* Sets the base to be used for resolving relative URIs in system 7225bb6a25fSPoul-Henning Kamp identifiers in declarations. Resolving relative identifiers is 7235bb6a25fSPoul-Henning Kamp left to the application: this value will be passed through as the 7245bb6a25fSPoul-Henning Kamp base argument to the XML_ExternalEntityRefHandler, 7255bb6a25fSPoul-Henning Kamp XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base 726220ed979SColeman Kane argument will be copied. Returns XML_STATUS_ERROR if out of memory, 727220ed979SColeman Kane XML_STATUS_OK otherwise. 7285bb6a25fSPoul-Henning Kamp */ 729220ed979SColeman Kane XMLPARSEAPI(enum XML_Status) 7305bb6a25fSPoul-Henning Kamp XML_SetBase(XML_Parser parser, const XML_Char *base); 7315bb6a25fSPoul-Henning Kamp 7325bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_Char *) 7335bb6a25fSPoul-Henning Kamp XML_GetBase(XML_Parser parser); 7345bb6a25fSPoul-Henning Kamp 7355bb6a25fSPoul-Henning Kamp /* Returns the number of the attribute/value pairs passed in last call 7365bb6a25fSPoul-Henning Kamp to the XML_StartElementHandler that were specified in the start-tag 7375bb6a25fSPoul-Henning Kamp rather than defaulted. Each attribute/value pair counts as 2; thus 738cc68614dSXin LI this corresponds to an index into the atts array passed to the 7390a48773fSEric van Gyzen XML_StartElementHandler. Returns -1 if parser == NULL. 7405bb6a25fSPoul-Henning Kamp */ 7415bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int) 7425bb6a25fSPoul-Henning Kamp XML_GetSpecifiedAttributeCount(XML_Parser parser); 7435bb6a25fSPoul-Henning Kamp 7445bb6a25fSPoul-Henning Kamp /* Returns the index of the ID attribute passed in the last call to 7450a48773fSEric van Gyzen XML_StartElementHandler, or -1 if there is no ID attribute or 7460a48773fSEric van Gyzen parser == NULL. Each attribute/value pair counts as 2; thus this 747cc68614dSXin LI corresponds to an index into the atts array passed to the 7480a48773fSEric van Gyzen XML_StartElementHandler. 7495bb6a25fSPoul-Henning Kamp */ 7505bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int) 7515bb6a25fSPoul-Henning Kamp XML_GetIdAttributeIndex(XML_Parser parser); 7525bb6a25fSPoul-Henning Kamp 753e3466a89SXin LI #ifdef XML_ATTR_INFO 754e3466a89SXin LI /* Source file byte offsets for the start and end of attribute names and values. 755e3466a89SXin LI The value indices are exclusive of surrounding quotes; thus in a UTF-8 source 756e3466a89SXin LI file an attribute value of "blah" will yield: 757e3466a89SXin LI info->valueEnd - info->valueStart = 4 bytes. 758e3466a89SXin LI */ 759e3466a89SXin LI typedef struct { 760e3466a89SXin LI XML_Index nameStart; /* Offset to beginning of the attribute name. */ 761e3466a89SXin LI XML_Index nameEnd; /* Offset after the attribute name's last byte. */ 762e3466a89SXin LI XML_Index valueStart; /* Offset to beginning of the attribute value. */ 763e3466a89SXin LI XML_Index valueEnd; /* Offset after the attribute value's last byte. */ 764e3466a89SXin LI } XML_AttrInfo; 765e3466a89SXin LI 766e3466a89SXin LI /* Returns an array of XML_AttrInfo structures for the attribute/value pairs 767e3466a89SXin LI passed in last call to the XML_StartElementHandler that were specified 768e3466a89SXin LI in the start-tag rather than defaulted. Each attribute/value pair counts 769e3466a89SXin LI as 1; thus the number of entries in the array is 770e3466a89SXin LI XML_GetSpecifiedAttributeCount(parser) / 2. 771e3466a89SXin LI */ 772e3466a89SXin LI XMLPARSEAPI(const XML_AttrInfo *) 773e3466a89SXin LI XML_GetAttributeInfo(XML_Parser parser); 774e3466a89SXin LI #endif 775e3466a89SXin LI 7765bb6a25fSPoul-Henning Kamp /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is 7775bb6a25fSPoul-Henning Kamp detected. The last call to XML_Parse must have isFinal true; len 7785bb6a25fSPoul-Henning Kamp may be zero for this call (or any other). 7795bb6a25fSPoul-Henning Kamp 780220ed979SColeman Kane Though the return values for these functions has always been 781220ed979SColeman Kane described as a Boolean value, the implementation, at least for the 782220ed979SColeman Kane 1.95.x series, has always returned exactly one of the XML_Status 783220ed979SColeman Kane values. 7845bb6a25fSPoul-Henning Kamp */ 7855bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Status) 7865bb6a25fSPoul-Henning Kamp XML_Parse(XML_Parser parser, const char *s, int len, int isFinal); 7875bb6a25fSPoul-Henning Kamp 7885bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void *) 7895bb6a25fSPoul-Henning Kamp XML_GetBuffer(XML_Parser parser, int len); 7905bb6a25fSPoul-Henning Kamp 7915bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Status) 7925bb6a25fSPoul-Henning Kamp XML_ParseBuffer(XML_Parser parser, int len, int isFinal); 7935bb6a25fSPoul-Henning Kamp 794220ed979SColeman Kane /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return. 795220ed979SColeman Kane Must be called from within a call-back handler, except when aborting 796220ed979SColeman Kane (resumable = 0) an already suspended parser. Some call-backs may 797220ed979SColeman Kane still follow because they would otherwise get lost. Examples: 798220ed979SColeman Kane - endElementHandler() for empty elements when stopped in 799220ed979SColeman Kane startElementHandler(), 800220ed979SColeman Kane - endNameSpaceDeclHandler() when stopped in endElementHandler(), 801220ed979SColeman Kane and possibly others. 802220ed979SColeman Kane 803220ed979SColeman Kane Can be called from most handlers, including DTD related call-backs, 804220ed979SColeman Kane except when parsing an external parameter entity and resumable != 0. 805220ed979SColeman Kane Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise. 806220ed979SColeman Kane Possible error codes: 807220ed979SColeman Kane - XML_ERROR_SUSPENDED: when suspending an already suspended parser. 808220ed979SColeman Kane - XML_ERROR_FINISHED: when the parser has already finished. 809220ed979SColeman Kane - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE. 810220ed979SColeman Kane 811220ed979SColeman Kane When resumable != 0 (true) then parsing is suspended, that is, 812220ed979SColeman Kane XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED. 813220ed979SColeman Kane Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer() 814220ed979SColeman Kane return XML_STATUS_ERROR with error code XML_ERROR_ABORTED. 815220ed979SColeman Kane 816220ed979SColeman Kane *Note*: 817220ed979SColeman Kane This will be applied to the current parser instance only, that is, if 818220ed979SColeman Kane there is a parent parser then it will continue parsing when the 819220ed979SColeman Kane externalEntityRefHandler() returns. It is up to the implementation of 820220ed979SColeman Kane the externalEntityRefHandler() to call XML_StopParser() on the parent 821220ed979SColeman Kane parser (recursively), if one wants to stop parsing altogether. 822220ed979SColeman Kane 823220ed979SColeman Kane When suspended, parsing can be resumed by calling XML_ResumeParser(). 824220ed979SColeman Kane */ 825220ed979SColeman Kane XMLPARSEAPI(enum XML_Status) 826220ed979SColeman Kane XML_StopParser(XML_Parser parser, XML_Bool resumable); 827220ed979SColeman Kane 828220ed979SColeman Kane /* Resumes parsing after it has been suspended with XML_StopParser(). 829220ed979SColeman Kane Must not be called from within a handler call-back. Returns same 830220ed979SColeman Kane status codes as XML_Parse() or XML_ParseBuffer(). 831220ed979SColeman Kane Additional error code XML_ERROR_NOT_SUSPENDED possible. 832220ed979SColeman Kane 833220ed979SColeman Kane *Note*: 834220ed979SColeman Kane This must be called on the most deeply nested child parser instance 835220ed979SColeman Kane first, and on its parent parser only after the child parser has finished, 836220ed979SColeman Kane to be applied recursively until the document entity's parser is restarted. 837220ed979SColeman Kane That is, the parent parser will not resume by itself and it is up to the 838220ed979SColeman Kane application to call XML_ResumeParser() on it at the appropriate moment. 839220ed979SColeman Kane */ 840220ed979SColeman Kane XMLPARSEAPI(enum XML_Status) 841220ed979SColeman Kane XML_ResumeParser(XML_Parser parser); 842220ed979SColeman Kane 8436b2c1e49SXin LI enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED }; 844220ed979SColeman Kane 845220ed979SColeman Kane typedef struct { 846220ed979SColeman Kane enum XML_Parsing parsing; 847220ed979SColeman Kane XML_Bool finalBuffer; 848220ed979SColeman Kane } XML_ParsingStatus; 849220ed979SColeman Kane 850220ed979SColeman Kane /* Returns status of parser with respect to being initialized, parsing, 851220ed979SColeman Kane finished, or suspended and processing the final buffer. 852220ed979SColeman Kane XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus, 853220ed979SColeman Kane XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED 854220ed979SColeman Kane */ 855220ed979SColeman Kane XMLPARSEAPI(void) 856220ed979SColeman Kane XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status); 857220ed979SColeman Kane 8585bb6a25fSPoul-Henning Kamp /* Creates an XML_Parser object that can parse an external general 8595bb6a25fSPoul-Henning Kamp entity; context is a '\0'-terminated string specifying the parse 8605bb6a25fSPoul-Henning Kamp context; encoding is a '\0'-terminated string giving the name of 8615bb6a25fSPoul-Henning Kamp the externally specified encoding, or NULL if there is no 8625bb6a25fSPoul-Henning Kamp externally specified encoding. The context string consists of a 8635bb6a25fSPoul-Henning Kamp sequence of tokens separated by formfeeds (\f); a token consisting 8645bb6a25fSPoul-Henning Kamp of a name specifies that the general entity of the name is open; a 8655bb6a25fSPoul-Henning Kamp token of the form prefix=uri specifies the namespace for a 8665bb6a25fSPoul-Henning Kamp particular prefix; a token of the form =uri specifies the default 8675bb6a25fSPoul-Henning Kamp namespace. This can be called at any point after the first call to 8685bb6a25fSPoul-Henning Kamp an ExternalEntityRefHandler so longer as the parser has not yet 8695bb6a25fSPoul-Henning Kamp been freed. The new parser is completely independent and may 8705bb6a25fSPoul-Henning Kamp safely be used in a separate thread. The handlers and userData are 871220ed979SColeman Kane initialized from the parser argument. Returns NULL if out of memory. 8725bb6a25fSPoul-Henning Kamp Otherwise returns a new XML_Parser object. 8735bb6a25fSPoul-Henning Kamp */ 8745bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser) 8756b2c1e49SXin LI XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context, 8765bb6a25fSPoul-Henning Kamp const XML_Char *encoding); 8775bb6a25fSPoul-Henning Kamp 8785bb6a25fSPoul-Henning Kamp enum XML_ParamEntityParsing { 8795bb6a25fSPoul-Henning Kamp XML_PARAM_ENTITY_PARSING_NEVER, 8805bb6a25fSPoul-Henning Kamp XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE, 8815bb6a25fSPoul-Henning Kamp XML_PARAM_ENTITY_PARSING_ALWAYS 8825bb6a25fSPoul-Henning Kamp }; 8835bb6a25fSPoul-Henning Kamp 8845bb6a25fSPoul-Henning Kamp /* Controls parsing of parameter entities (including the external DTD 8855bb6a25fSPoul-Henning Kamp subset). If parsing of parameter entities is enabled, then 8865bb6a25fSPoul-Henning Kamp references to external parameter entities (including the external 8875bb6a25fSPoul-Henning Kamp DTD subset) will be passed to the handler set with 8885bb6a25fSPoul-Henning Kamp XML_SetExternalEntityRefHandler. The context passed will be 0. 8895bb6a25fSPoul-Henning Kamp 8905bb6a25fSPoul-Henning Kamp Unlike external general entities, external parameter entities can 8915bb6a25fSPoul-Henning Kamp only be parsed synchronously. If the external parameter entity is 8925bb6a25fSPoul-Henning Kamp to be parsed, it must be parsed during the call to the external 8935bb6a25fSPoul-Henning Kamp entity ref handler: the complete sequence of 8945bb6a25fSPoul-Henning Kamp XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and 8955bb6a25fSPoul-Henning Kamp XML_ParserFree calls must be made during this call. After 8965bb6a25fSPoul-Henning Kamp XML_ExternalEntityParserCreate has been called to create the parser 8975bb6a25fSPoul-Henning Kamp for the external parameter entity (context must be 0 for this 8985bb6a25fSPoul-Henning Kamp call), it is illegal to make any calls on the old parser until 8995bb6a25fSPoul-Henning Kamp XML_ParserFree has been called on the newly created parser. 9005bb6a25fSPoul-Henning Kamp If the library has been compiled without support for parameter 9015bb6a25fSPoul-Henning Kamp entity parsing (ie without XML_DTD being defined), then 9025bb6a25fSPoul-Henning Kamp XML_SetParamEntityParsing will return 0 if parsing of parameter 9035bb6a25fSPoul-Henning Kamp entities is requested; otherwise it will return non-zero. 9045bb6a25fSPoul-Henning Kamp Note: If XML_SetParamEntityParsing is called after XML_Parse or 9055bb6a25fSPoul-Henning Kamp XML_ParseBuffer, then it has no effect and will always return 0. 9060a48773fSEric van Gyzen Note: If parser == NULL, the function will do nothing and return 0. 9075bb6a25fSPoul-Henning Kamp */ 9085bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int) 9095bb6a25fSPoul-Henning Kamp XML_SetParamEntityParsing(XML_Parser parser, 9105bb6a25fSPoul-Henning Kamp enum XML_ParamEntityParsing parsing); 9115bb6a25fSPoul-Henning Kamp 912e3466a89SXin LI /* Sets the hash salt to use for internal hash calculations. 913e3466a89SXin LI Helps in preventing DoS attacks based on predicting hash 914e3466a89SXin LI function behavior. This must be called before parsing is started. 915e3466a89SXin LI Returns 1 if successful, 0 when called after parsing has started. 9160a48773fSEric van Gyzen Note: If parser == NULL, the function will do nothing and return 0. 917e3466a89SXin LI */ 918e3466a89SXin LI XMLPARSEAPI(int) 9196b2c1e49SXin LI XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt); 920e3466a89SXin LI 921220ed979SColeman Kane /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then 9225bb6a25fSPoul-Henning Kamp XML_GetErrorCode returns information about the error. 9235bb6a25fSPoul-Henning Kamp */ 9245bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Error) 9255bb6a25fSPoul-Henning Kamp XML_GetErrorCode(XML_Parser parser); 9265bb6a25fSPoul-Henning Kamp 9275bb6a25fSPoul-Henning Kamp /* These functions return information about the current parse 928220ed979SColeman Kane location. They may be called from any callback called to report 929220ed979SColeman Kane some parse event; in this case the location is the location of the 930220ed979SColeman Kane first of the sequence of characters that generated the event. When 931220ed979SColeman Kane called from callbacks generated by declarations in the document 932220ed979SColeman Kane prologue, the location identified isn't as neatly defined, but will 933220ed979SColeman Kane be within the relevant markup. When called outside of the callback 934220ed979SColeman Kane functions, the position indicated will be just past the last parse 935220ed979SColeman Kane event (regardless of whether there was an associated callback). 9365bb6a25fSPoul-Henning Kamp 937220ed979SColeman Kane They may also be called after returning from a call to XML_Parse 938220ed979SColeman Kane or XML_ParseBuffer. If the return value is XML_STATUS_ERROR then 939220ed979SColeman Kane the location is the location of the character at which the error 940220ed979SColeman Kane was detected; otherwise the location is the location of the last 941220ed979SColeman Kane parse event, as described above. 9420a48773fSEric van Gyzen 9430a48773fSEric van Gyzen Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber 9440a48773fSEric van Gyzen return 0 to indicate an error. 9450a48773fSEric van Gyzen Note: XML_GetCurrentByteIndex returns -1 to indicate an error. 9465bb6a25fSPoul-Henning Kamp */ 947220ed979SColeman Kane XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser); 948220ed979SColeman Kane XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser); 949220ed979SColeman Kane XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser); 9505bb6a25fSPoul-Henning Kamp 9515bb6a25fSPoul-Henning Kamp /* Return the number of bytes in the current event. 9525bb6a25fSPoul-Henning Kamp Returns 0 if the event is in an internal entity. 9535bb6a25fSPoul-Henning Kamp */ 9545bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int) 9555bb6a25fSPoul-Henning Kamp XML_GetCurrentByteCount(XML_Parser parser); 9565bb6a25fSPoul-Henning Kamp 9574543ef51SXin LI /* If XML_CONTEXT_BYTES is >=1, returns the input buffer, sets 9585bb6a25fSPoul-Henning Kamp the integer pointed to by offset to the offset within this buffer 9595bb6a25fSPoul-Henning Kamp of the current parse position, and sets the integer pointed to by size 9605bb6a25fSPoul-Henning Kamp to the size of this buffer (the number of input bytes). Otherwise 9615bb6a25fSPoul-Henning Kamp returns a NULL pointer. Also returns a NULL pointer if a parse isn't 9625bb6a25fSPoul-Henning Kamp active. 9635bb6a25fSPoul-Henning Kamp 9645bb6a25fSPoul-Henning Kamp NOTE: The character pointer returned should not be used outside 9655bb6a25fSPoul-Henning Kamp the handler that makes the call. 9665bb6a25fSPoul-Henning Kamp */ 9675bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const char *) 9686b2c1e49SXin LI XML_GetInputContext(XML_Parser parser, int *offset, int *size); 9695bb6a25fSPoul-Henning Kamp 9705bb6a25fSPoul-Henning Kamp /* For backwards compatibility with previous versions. */ 9715bb6a25fSPoul-Henning Kamp #define XML_GetErrorLineNumber XML_GetCurrentLineNumber 9725bb6a25fSPoul-Henning Kamp #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber 9735bb6a25fSPoul-Henning Kamp #define XML_GetErrorByteIndex XML_GetCurrentByteIndex 9745bb6a25fSPoul-Henning Kamp 975220ed979SColeman Kane /* Frees the content model passed to the element declaration handler */ 976220ed979SColeman Kane XMLPARSEAPI(void) 977220ed979SColeman Kane XML_FreeContentModel(XML_Parser parser, XML_Content *model); 978220ed979SColeman Kane 979220ed979SColeman Kane /* Exposing the memory handling functions used in Expat */ 980220ed979SColeman Kane XMLPARSEAPI(void *) 981be8aff81SXin LI XML_ATTR_MALLOC 982be8aff81SXin LI XML_ATTR_ALLOC_SIZE(2) 983220ed979SColeman Kane XML_MemMalloc(XML_Parser parser, size_t size); 984220ed979SColeman Kane 985220ed979SColeman Kane XMLPARSEAPI(void *) 986be8aff81SXin LI XML_ATTR_ALLOC_SIZE(3) 987220ed979SColeman Kane XML_MemRealloc(XML_Parser parser, void *ptr, size_t size); 988220ed979SColeman Kane 989220ed979SColeman Kane XMLPARSEAPI(void) 990220ed979SColeman Kane XML_MemFree(XML_Parser parser, void *ptr); 991220ed979SColeman Kane 9925bb6a25fSPoul-Henning Kamp /* Frees memory used by the parser. */ 9935bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void) 9945bb6a25fSPoul-Henning Kamp XML_ParserFree(XML_Parser parser); 9955bb6a25fSPoul-Henning Kamp 9965bb6a25fSPoul-Henning Kamp /* Returns a string describing the error. */ 9975bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_LChar *) 9985bb6a25fSPoul-Henning Kamp XML_ErrorString(enum XML_Error code); 9995bb6a25fSPoul-Henning Kamp 10005bb6a25fSPoul-Henning Kamp /* Return a string containing the version number of this expat */ 10015bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_LChar *) 10025bb6a25fSPoul-Henning Kamp XML_ExpatVersion(void); 10035bb6a25fSPoul-Henning Kamp 10045bb6a25fSPoul-Henning Kamp typedef struct { 10055bb6a25fSPoul-Henning Kamp int major; 10065bb6a25fSPoul-Henning Kamp int minor; 10075bb6a25fSPoul-Henning Kamp int micro; 10085bb6a25fSPoul-Henning Kamp } XML_Expat_Version; 10095bb6a25fSPoul-Henning Kamp 10105bb6a25fSPoul-Henning Kamp /* Return an XML_Expat_Version structure containing numeric version 10115bb6a25fSPoul-Henning Kamp number information for this version of expat. 10125bb6a25fSPoul-Henning Kamp */ 10135bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Expat_Version) 10145bb6a25fSPoul-Henning Kamp XML_ExpatVersionInfo(void); 10155bb6a25fSPoul-Henning Kamp 10165bb6a25fSPoul-Henning Kamp /* Added in Expat 1.95.5. */ 10175bb6a25fSPoul-Henning Kamp enum XML_FeatureEnum { 10185bb6a25fSPoul-Henning Kamp XML_FEATURE_END = 0, 10195bb6a25fSPoul-Henning Kamp XML_FEATURE_UNICODE, 10205bb6a25fSPoul-Henning Kamp XML_FEATURE_UNICODE_WCHAR_T, 10215bb6a25fSPoul-Henning Kamp XML_FEATURE_DTD, 10225bb6a25fSPoul-Henning Kamp XML_FEATURE_CONTEXT_BYTES, 10235bb6a25fSPoul-Henning Kamp XML_FEATURE_MIN_SIZE, 10245bb6a25fSPoul-Henning Kamp XML_FEATURE_SIZEOF_XML_CHAR, 1025220ed979SColeman Kane XML_FEATURE_SIZEOF_XML_LCHAR, 1026220ed979SColeman Kane XML_FEATURE_NS, 1027e3466a89SXin LI XML_FEATURE_LARGE_SIZE, 1028cc68614dSXin LI XML_FEATURE_ATTR_INFO, 1029cc68614dSXin LI /* Added in Expat 2.4.0. */ 1030cc68614dSXin LI XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT, 10314543ef51SXin LI XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT, 10324543ef51SXin LI /* Added in Expat 2.6.0. */ 10334543ef51SXin LI XML_FEATURE_GE 10345bb6a25fSPoul-Henning Kamp /* Additional features must be added to the end of this enum. */ 10355bb6a25fSPoul-Henning Kamp }; 10365bb6a25fSPoul-Henning Kamp 10375bb6a25fSPoul-Henning Kamp typedef struct { 10385bb6a25fSPoul-Henning Kamp enum XML_FeatureEnum feature; 1039220ed979SColeman Kane const XML_LChar *name; 10405bb6a25fSPoul-Henning Kamp long int value; 10415bb6a25fSPoul-Henning Kamp } XML_Feature; 10425bb6a25fSPoul-Henning Kamp 10435bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_Feature *) 10445bb6a25fSPoul-Henning Kamp XML_GetFeatureList(void); 10455bb6a25fSPoul-Henning Kamp 1046*ffd294a1SEnji Cooper #if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1) 10474543ef51SXin LI /* Added in Expat 2.4.0 for XML_DTD defined and 10484543ef51SXin LI * added in Expat 2.6.0 for XML_GE == 1. */ 1049cc68614dSXin LI XMLPARSEAPI(XML_Bool) 1050cc68614dSXin LI XML_SetBillionLaughsAttackProtectionMaximumAmplification( 1051cc68614dSXin LI XML_Parser parser, float maximumAmplificationFactor); 1052cc68614dSXin LI 10534543ef51SXin LI /* Added in Expat 2.4.0 for XML_DTD defined and 10544543ef51SXin LI * added in Expat 2.6.0 for XML_GE == 1. */ 1055cc68614dSXin LI XMLPARSEAPI(XML_Bool) 1056cc68614dSXin LI XML_SetBillionLaughsAttackProtectionActivationThreshold( 1057cc68614dSXin LI XML_Parser parser, unsigned long long activationThresholdBytes); 1058cc68614dSXin LI #endif 1059cc68614dSXin LI 10604543ef51SXin LI /* Added in Expat 2.6.0. */ 10614543ef51SXin LI XMLPARSEAPI(XML_Bool) 10624543ef51SXin LI XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled); 10634543ef51SXin LI 1064be8aff81SXin LI /* Expat follows the semantic versioning convention. 10654543ef51SXin LI See https://semver.org 10665bb6a25fSPoul-Henning Kamp */ 1067220ed979SColeman Kane #define XML_MAJOR_VERSION 2 10684543ef51SXin LI #define XML_MINOR_VERSION 6 1069*ffd294a1SEnji Cooper #define XML_MICRO_VERSION 3 10705bb6a25fSPoul-Henning Kamp 10715bb6a25fSPoul-Henning Kamp #ifdef __cplusplus 10725bb6a25fSPoul-Henning Kamp } 10735bb6a25fSPoul-Henning Kamp #endif 10745bb6a25fSPoul-Henning Kamp 1075220ed979SColeman Kane #endif /* not Expat_INCLUDED */ 1076