xref: /freebsd/contrib/expat/lib/expat.h (revision cc68614da8232d8baaca0ae0d0dd8f890f06623e)
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
10*cc68614dSXin LI    Copyright (c) 2000      Clark Cooper <coopercc@users.sourceforge.net>
11*cc68614dSXin LI    Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
12*cc68614dSXin LI    Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net>
13*cc68614dSXin LI    Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net>
14*cc68614dSXin LI    Copyright (c) 2016-2022 Sebastian Pipping <sebastian@pipping.org>
15*cc68614dSXin LI    Copyright (c) 2016      Cristian Rodríguez <crrodriguez@opensuse.org>
16*cc68614dSXin LI    Copyright (c) 2016      Thomas Beutlich <tc@tbeu.de>
17*cc68614dSXin LI    Copyright (c) 2017      Rhodri James <rhodri@wildebeest.org.uk>
180a48773fSEric van Gyzen    Licensed under the MIT license:
190a48773fSEric van Gyzen 
200a48773fSEric van Gyzen    Permission is  hereby granted,  free of charge,  to any  person obtaining
210a48773fSEric van Gyzen    a  copy  of  this  software   and  associated  documentation  files  (the
220a48773fSEric van Gyzen    "Software"),  to  deal in  the  Software  without restriction,  including
230a48773fSEric van Gyzen    without  limitation the  rights  to use,  copy,  modify, merge,  publish,
240a48773fSEric van Gyzen    distribute, sublicense, and/or sell copies of the Software, and to permit
250a48773fSEric van Gyzen    persons  to whom  the Software  is  furnished to  do so,  subject to  the
260a48773fSEric van Gyzen    following conditions:
270a48773fSEric van Gyzen 
280a48773fSEric van Gyzen    The above copyright  notice and this permission notice  shall be included
290a48773fSEric van Gyzen    in all copies or substantial portions of the Software.
300a48773fSEric van Gyzen 
310a48773fSEric van Gyzen    THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
320a48773fSEric van Gyzen    EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
330a48773fSEric van Gyzen    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
340a48773fSEric van Gyzen    NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
350a48773fSEric van Gyzen    DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
360a48773fSEric van Gyzen    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
370a48773fSEric van Gyzen    USE OR OTHER DEALINGS IN THE SOFTWARE.
385bb6a25fSPoul-Henning Kamp */
395bb6a25fSPoul-Henning Kamp 
40220ed979SColeman Kane #ifndef Expat_INCLUDED
41220ed979SColeman Kane #define Expat_INCLUDED 1
425bb6a25fSPoul-Henning Kamp 
435bb6a25fSPoul-Henning Kamp #include <stdlib.h>
44220ed979SColeman Kane #include "expat_external.h"
455bb6a25fSPoul-Henning Kamp 
465bb6a25fSPoul-Henning Kamp #ifdef __cplusplus
475bb6a25fSPoul-Henning Kamp extern "C" {
485bb6a25fSPoul-Henning Kamp #endif
495bb6a25fSPoul-Henning Kamp 
505bb6a25fSPoul-Henning Kamp struct XML_ParserStruct;
515bb6a25fSPoul-Henning Kamp typedef struct XML_ParserStruct *XML_Parser;
525bb6a25fSPoul-Henning Kamp 
535bb6a25fSPoul-Henning Kamp typedef unsigned char XML_Bool;
545bb6a25fSPoul-Henning Kamp #define XML_TRUE ((XML_Bool)1)
555bb6a25fSPoul-Henning Kamp #define XML_FALSE ((XML_Bool)0)
565bb6a25fSPoul-Henning Kamp 
57220ed979SColeman Kane /* The XML_Status enum gives the possible return values for several
58220ed979SColeman Kane    API functions.  The preprocessor #defines are included so this
59220ed979SColeman Kane    stanza can be added to code that still needs to support older
60220ed979SColeman Kane    versions of Expat 1.95.x:
61220ed979SColeman Kane 
62220ed979SColeman Kane    #ifndef XML_STATUS_OK
63220ed979SColeman Kane    #define XML_STATUS_OK    1
64220ed979SColeman Kane    #define XML_STATUS_ERROR 0
65220ed979SColeman Kane    #endif
66220ed979SColeman Kane 
67220ed979SColeman Kane    Otherwise, the #define hackery is quite ugly and would have been
68220ed979SColeman Kane    dropped.
69220ed979SColeman Kane */
70220ed979SColeman Kane enum XML_Status {
71220ed979SColeman Kane   XML_STATUS_ERROR = 0,
72220ed979SColeman Kane #define XML_STATUS_ERROR XML_STATUS_ERROR
73220ed979SColeman Kane   XML_STATUS_OK = 1,
74220ed979SColeman Kane #define XML_STATUS_OK XML_STATUS_OK
75220ed979SColeman Kane   XML_STATUS_SUSPENDED = 2
76220ed979SColeman Kane #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
77220ed979SColeman Kane };
78220ed979SColeman Kane 
795bb6a25fSPoul-Henning Kamp enum XML_Error {
805bb6a25fSPoul-Henning Kamp   XML_ERROR_NONE,
815bb6a25fSPoul-Henning Kamp   XML_ERROR_NO_MEMORY,
825bb6a25fSPoul-Henning Kamp   XML_ERROR_SYNTAX,
835bb6a25fSPoul-Henning Kamp   XML_ERROR_NO_ELEMENTS,
845bb6a25fSPoul-Henning Kamp   XML_ERROR_INVALID_TOKEN,
855bb6a25fSPoul-Henning Kamp   XML_ERROR_UNCLOSED_TOKEN,
865bb6a25fSPoul-Henning Kamp   XML_ERROR_PARTIAL_CHAR,
875bb6a25fSPoul-Henning Kamp   XML_ERROR_TAG_MISMATCH,
885bb6a25fSPoul-Henning Kamp   XML_ERROR_DUPLICATE_ATTRIBUTE,
895bb6a25fSPoul-Henning Kamp   XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
905bb6a25fSPoul-Henning Kamp   XML_ERROR_PARAM_ENTITY_REF,
915bb6a25fSPoul-Henning Kamp   XML_ERROR_UNDEFINED_ENTITY,
925bb6a25fSPoul-Henning Kamp   XML_ERROR_RECURSIVE_ENTITY_REF,
935bb6a25fSPoul-Henning Kamp   XML_ERROR_ASYNC_ENTITY,
945bb6a25fSPoul-Henning Kamp   XML_ERROR_BAD_CHAR_REF,
955bb6a25fSPoul-Henning Kamp   XML_ERROR_BINARY_ENTITY_REF,
965bb6a25fSPoul-Henning Kamp   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
975bb6a25fSPoul-Henning Kamp   XML_ERROR_MISPLACED_XML_PI,
985bb6a25fSPoul-Henning Kamp   XML_ERROR_UNKNOWN_ENCODING,
995bb6a25fSPoul-Henning Kamp   XML_ERROR_INCORRECT_ENCODING,
1005bb6a25fSPoul-Henning Kamp   XML_ERROR_UNCLOSED_CDATA_SECTION,
1015bb6a25fSPoul-Henning Kamp   XML_ERROR_EXTERNAL_ENTITY_HANDLING,
1025bb6a25fSPoul-Henning Kamp   XML_ERROR_NOT_STANDALONE,
1035bb6a25fSPoul-Henning Kamp   XML_ERROR_UNEXPECTED_STATE,
1045bb6a25fSPoul-Henning Kamp   XML_ERROR_ENTITY_DECLARED_IN_PE,
1055bb6a25fSPoul-Henning Kamp   XML_ERROR_FEATURE_REQUIRES_XML_DTD,
106220ed979SColeman Kane   XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
107220ed979SColeman Kane   /* Added in 1.95.7. */
108220ed979SColeman Kane   XML_ERROR_UNBOUND_PREFIX,
109220ed979SColeman Kane   /* Added in 1.95.8. */
110220ed979SColeman Kane   XML_ERROR_UNDECLARING_PREFIX,
111220ed979SColeman Kane   XML_ERROR_INCOMPLETE_PE,
112220ed979SColeman Kane   XML_ERROR_XML_DECL,
113220ed979SColeman Kane   XML_ERROR_TEXT_DECL,
114220ed979SColeman Kane   XML_ERROR_PUBLICID,
115220ed979SColeman Kane   XML_ERROR_SUSPENDED,
116220ed979SColeman Kane   XML_ERROR_NOT_SUSPENDED,
117220ed979SColeman Kane   XML_ERROR_ABORTED,
118220ed979SColeman Kane   XML_ERROR_FINISHED,
119220ed979SColeman Kane   XML_ERROR_SUSPEND_PE,
120220ed979SColeman Kane   /* Added in 2.0. */
121220ed979SColeman Kane   XML_ERROR_RESERVED_PREFIX_XML,
122220ed979SColeman Kane   XML_ERROR_RESERVED_PREFIX_XMLNS,
1230a48773fSEric van Gyzen   XML_ERROR_RESERVED_NAMESPACE_URI,
1240a48773fSEric van Gyzen   /* Added in 2.2.1. */
125*cc68614dSXin LI   XML_ERROR_INVALID_ARGUMENT,
126*cc68614dSXin LI   /* Added in 2.3.0. */
127*cc68614dSXin LI   XML_ERROR_NO_BUFFER,
128*cc68614dSXin LI   /* Added in 2.4.0. */
129*cc68614dSXin LI   XML_ERROR_AMPLIFICATION_LIMIT_BREACH
1305bb6a25fSPoul-Henning Kamp };
1315bb6a25fSPoul-Henning Kamp 
1325bb6a25fSPoul-Henning Kamp enum XML_Content_Type {
1335bb6a25fSPoul-Henning Kamp   XML_CTYPE_EMPTY = 1,
1345bb6a25fSPoul-Henning Kamp   XML_CTYPE_ANY,
1355bb6a25fSPoul-Henning Kamp   XML_CTYPE_MIXED,
1365bb6a25fSPoul-Henning Kamp   XML_CTYPE_NAME,
1375bb6a25fSPoul-Henning Kamp   XML_CTYPE_CHOICE,
1385bb6a25fSPoul-Henning Kamp   XML_CTYPE_SEQ
1395bb6a25fSPoul-Henning Kamp };
1405bb6a25fSPoul-Henning Kamp 
1415bb6a25fSPoul-Henning Kamp enum XML_Content_Quant {
1425bb6a25fSPoul-Henning Kamp   XML_CQUANT_NONE,
1435bb6a25fSPoul-Henning Kamp   XML_CQUANT_OPT,
1445bb6a25fSPoul-Henning Kamp   XML_CQUANT_REP,
1455bb6a25fSPoul-Henning Kamp   XML_CQUANT_PLUS
1465bb6a25fSPoul-Henning Kamp };
1475bb6a25fSPoul-Henning Kamp 
1485bb6a25fSPoul-Henning Kamp /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
1495bb6a25fSPoul-Henning Kamp    XML_CQUANT_NONE, and the other fields will be zero or NULL.
1505bb6a25fSPoul-Henning Kamp    If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
1515bb6a25fSPoul-Henning Kamp    numchildren will contain number of elements that may be mixed in
1525bb6a25fSPoul-Henning Kamp    and children point to an array of XML_Content cells that will be
1535bb6a25fSPoul-Henning Kamp    all of XML_CTYPE_NAME type with no quantification.
1545bb6a25fSPoul-Henning Kamp 
1555bb6a25fSPoul-Henning Kamp    If type == XML_CTYPE_NAME, then the name points to the name, and
1565bb6a25fSPoul-Henning Kamp    the numchildren field will be zero and children will be NULL. The
1575bb6a25fSPoul-Henning Kamp    quant fields indicates any quantifiers placed on the name.
1585bb6a25fSPoul-Henning Kamp 
1595bb6a25fSPoul-Henning Kamp    CHOICE and SEQ will have name NULL, the number of children in
1605bb6a25fSPoul-Henning Kamp    numchildren and children will point, recursively, to an array
1615bb6a25fSPoul-Henning Kamp    of XML_Content cells.
1625bb6a25fSPoul-Henning Kamp 
1635bb6a25fSPoul-Henning Kamp    The EMPTY, ANY, and MIXED types will only occur at top level.
1645bb6a25fSPoul-Henning Kamp */
1655bb6a25fSPoul-Henning Kamp 
1665bb6a25fSPoul-Henning Kamp typedef struct XML_cp XML_Content;
1675bb6a25fSPoul-Henning Kamp 
1685bb6a25fSPoul-Henning Kamp struct XML_cp {
1695bb6a25fSPoul-Henning Kamp   enum XML_Content_Type type;
1705bb6a25fSPoul-Henning Kamp   enum XML_Content_Quant quant;
1715bb6a25fSPoul-Henning Kamp   XML_Char *name;
1725bb6a25fSPoul-Henning Kamp   unsigned int numchildren;
1735bb6a25fSPoul-Henning Kamp   XML_Content *children;
1745bb6a25fSPoul-Henning Kamp };
1755bb6a25fSPoul-Henning Kamp 
1765bb6a25fSPoul-Henning Kamp /* This is called for an element declaration. See above for
1775bb6a25fSPoul-Henning Kamp    description of the model argument. It's the caller's responsibility
1785bb6a25fSPoul-Henning Kamp    to free model when finished with it.
1795bb6a25fSPoul-Henning Kamp */
180220ed979SColeman Kane typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData,
1815bb6a25fSPoul-Henning Kamp                                               const XML_Char *name,
1825bb6a25fSPoul-Henning Kamp                                               XML_Content *model);
1835bb6a25fSPoul-Henning Kamp 
1845bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
1856b2c1e49SXin LI XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl);
1865bb6a25fSPoul-Henning Kamp 
1875bb6a25fSPoul-Henning Kamp /* The Attlist declaration handler is called for *each* attribute. So
1885bb6a25fSPoul-Henning Kamp    a single Attlist declaration with multiple attributes declared will
1895bb6a25fSPoul-Henning Kamp    generate multiple calls to this handler. The "default" parameter
1905bb6a25fSPoul-Henning Kamp    may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
1915bb6a25fSPoul-Henning Kamp    keyword. The "isrequired" parameter will be true and the default
1925bb6a25fSPoul-Henning Kamp    value will be NULL in the case of "#REQUIRED". If "isrequired" is
1935bb6a25fSPoul-Henning Kamp    true and default is non-NULL, then this is a "#FIXED" default.
1945bb6a25fSPoul-Henning Kamp */
195220ed979SColeman Kane typedef void(XMLCALL *XML_AttlistDeclHandler)(
1966b2c1e49SXin LI     void *userData, const XML_Char *elname, const XML_Char *attname,
1976b2c1e49SXin LI     const XML_Char *att_type, const XML_Char *dflt, int isrequired);
1985bb6a25fSPoul-Henning Kamp 
1995bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
2006b2c1e49SXin LI XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl);
2015bb6a25fSPoul-Henning Kamp 
2025bb6a25fSPoul-Henning Kamp /* The XML declaration handler is called for *both* XML declarations
2035bb6a25fSPoul-Henning Kamp    and text declarations. The way to distinguish is that the version
2045bb6a25fSPoul-Henning Kamp    parameter will be NULL for text declarations. The encoding
2055bb6a25fSPoul-Henning Kamp    parameter may be NULL for XML declarations. The standalone
2065bb6a25fSPoul-Henning Kamp    parameter will be -1, 0, or 1 indicating respectively that there
2075bb6a25fSPoul-Henning Kamp    was no standalone parameter in the declaration, that it was given
2085bb6a25fSPoul-Henning Kamp    as no, or that it was given as yes.
2095bb6a25fSPoul-Henning Kamp */
210220ed979SColeman Kane typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData,
2115bb6a25fSPoul-Henning Kamp                                           const XML_Char *version,
2125bb6a25fSPoul-Henning Kamp                                           const XML_Char *encoding,
2135bb6a25fSPoul-Henning Kamp                                           int standalone);
2145bb6a25fSPoul-Henning Kamp 
2155bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
2166b2c1e49SXin LI XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl);
2175bb6a25fSPoul-Henning Kamp 
2185bb6a25fSPoul-Henning Kamp typedef struct {
2195bb6a25fSPoul-Henning Kamp   void *(*malloc_fcn)(size_t size);
2205bb6a25fSPoul-Henning Kamp   void *(*realloc_fcn)(void *ptr, size_t size);
2215bb6a25fSPoul-Henning Kamp   void (*free_fcn)(void *ptr);
2225bb6a25fSPoul-Henning Kamp } XML_Memory_Handling_Suite;
2235bb6a25fSPoul-Henning Kamp 
2245bb6a25fSPoul-Henning Kamp /* Constructs a new parser; encoding is the encoding specified by the
2255bb6a25fSPoul-Henning Kamp    external protocol or NULL if there is none specified.
2265bb6a25fSPoul-Henning Kamp */
2275bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
2285bb6a25fSPoul-Henning Kamp XML_ParserCreate(const XML_Char *encoding);
2295bb6a25fSPoul-Henning Kamp 
2305bb6a25fSPoul-Henning Kamp /* Constructs a new parser and namespace processor.  Element type
2315bb6a25fSPoul-Henning Kamp    names and attribute names that belong to a namespace will be
2325bb6a25fSPoul-Henning Kamp    expanded; unprefixed attribute names are never expanded; unprefixed
2335bb6a25fSPoul-Henning Kamp    element type names are expanded only if there is a default
2345bb6a25fSPoul-Henning Kamp    namespace. The expanded name is the concatenation of the namespace
2355bb6a25fSPoul-Henning Kamp    URI, the namespace separator character, and the local part of the
2365bb6a25fSPoul-Henning Kamp    name.  If the namespace separator is '\0' then the namespace URI
2375bb6a25fSPoul-Henning Kamp    and the local part will be concatenated without any separator.
238220ed979SColeman Kane    It is a programming error to use the separator '\0' with namespace
239220ed979SColeman Kane    triplets (see XML_SetReturnNSTriplet).
2405bb6a25fSPoul-Henning Kamp */
2415bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
2425bb6a25fSPoul-Henning Kamp XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
2435bb6a25fSPoul-Henning Kamp 
244220ed979SColeman Kane /* Constructs a new parser using the memory management suite referred to
2455bb6a25fSPoul-Henning Kamp    by memsuite. If memsuite is NULL, then use the standard library memory
2465bb6a25fSPoul-Henning Kamp    suite. If namespaceSeparator is non-NULL it creates a parser with
2475bb6a25fSPoul-Henning Kamp    namespace processing as described above. The character pointed at
2485bb6a25fSPoul-Henning Kamp    will serve as the namespace separator.
2495bb6a25fSPoul-Henning Kamp 
2505bb6a25fSPoul-Henning Kamp    All further memory operations used for the created parser will come from
2515bb6a25fSPoul-Henning Kamp    the given suite.
2525bb6a25fSPoul-Henning Kamp */
2535bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
2545bb6a25fSPoul-Henning Kamp XML_ParserCreate_MM(const XML_Char *encoding,
2555bb6a25fSPoul-Henning Kamp                     const XML_Memory_Handling_Suite *memsuite,
2565bb6a25fSPoul-Henning Kamp                     const XML_Char *namespaceSeparator);
2575bb6a25fSPoul-Henning Kamp 
2585bb6a25fSPoul-Henning Kamp /* Prepare a parser object to be re-used.  This is particularly
2590a48773fSEric van Gyzen    valuable when memory allocation overhead is disproportionately high,
2605bb6a25fSPoul-Henning Kamp    such as when a large number of small documnents need to be parsed.
2615bb6a25fSPoul-Henning Kamp    All handlers are cleared from the parser, except for the
2625bb6a25fSPoul-Henning Kamp    unknownEncodingHandler. The parser's external state is re-initialized
2635bb6a25fSPoul-Henning Kamp    except for the values of ns and ns_triplets.
2645bb6a25fSPoul-Henning Kamp 
2655bb6a25fSPoul-Henning Kamp    Added in Expat 1.95.3.
2665bb6a25fSPoul-Henning Kamp */
2675bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Bool)
2685bb6a25fSPoul-Henning Kamp XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
2695bb6a25fSPoul-Henning Kamp 
2705bb6a25fSPoul-Henning Kamp /* atts is array of name/value pairs, terminated by 0;
2715bb6a25fSPoul-Henning Kamp    names and values are 0 terminated.
2725bb6a25fSPoul-Henning Kamp */
273220ed979SColeman Kane typedef void(XMLCALL *XML_StartElementHandler)(void *userData,
2745bb6a25fSPoul-Henning Kamp                                                const XML_Char *name,
2755bb6a25fSPoul-Henning Kamp                                                const XML_Char **atts);
2765bb6a25fSPoul-Henning Kamp 
277220ed979SColeman Kane typedef void(XMLCALL *XML_EndElementHandler)(void *userData,
2785bb6a25fSPoul-Henning Kamp                                              const XML_Char *name);
2795bb6a25fSPoul-Henning Kamp 
2805bb6a25fSPoul-Henning Kamp /* s is not 0 terminated. */
281220ed979SColeman Kane typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData,
2826b2c1e49SXin LI                                                 const XML_Char *s, int len);
2835bb6a25fSPoul-Henning Kamp 
2845bb6a25fSPoul-Henning Kamp /* target and data are 0 terminated */
2856b2c1e49SXin LI typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,
2865bb6a25fSPoul-Henning Kamp                                                         const XML_Char *target,
2875bb6a25fSPoul-Henning Kamp                                                         const XML_Char *data);
2885bb6a25fSPoul-Henning Kamp 
2895bb6a25fSPoul-Henning Kamp /* data is 0 terminated */
2906b2c1e49SXin LI typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data);
2915bb6a25fSPoul-Henning Kamp 
292220ed979SColeman Kane typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData);
293220ed979SColeman Kane typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData);
2945bb6a25fSPoul-Henning Kamp 
2955bb6a25fSPoul-Henning Kamp /* This is called for any characters in the XML document for which
2965bb6a25fSPoul-Henning Kamp    there is no applicable handler.  This includes both characters that
2975bb6a25fSPoul-Henning Kamp    are part of markup which is of a kind that is not reported
2985bb6a25fSPoul-Henning Kamp    (comments, markup declarations), or characters that are part of a
2995bb6a25fSPoul-Henning Kamp    construct which could be reported but for which no handler has been
3005bb6a25fSPoul-Henning Kamp    supplied. The characters are passed exactly as they were in the XML
3015bb6a25fSPoul-Henning Kamp    document except that they will be encoded in UTF-8 or UTF-16.
3025bb6a25fSPoul-Henning Kamp    Line boundaries are not normalized. Note that a byte order mark
3035bb6a25fSPoul-Henning Kamp    character is not passed to the default handler. There are no
3045bb6a25fSPoul-Henning Kamp    guarantees about how characters are divided between calls to the
3055bb6a25fSPoul-Henning Kamp    default handler: for example, a comment might be split between
3065bb6a25fSPoul-Henning Kamp    multiple calls.
3075bb6a25fSPoul-Henning Kamp */
3086b2c1e49SXin LI typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s,
3095bb6a25fSPoul-Henning Kamp                                           int len);
3105bb6a25fSPoul-Henning Kamp 
3115bb6a25fSPoul-Henning Kamp /* This is called for the start of the DOCTYPE declaration, before
3125bb6a25fSPoul-Henning Kamp    any DTD or internal subset is parsed.
3135bb6a25fSPoul-Henning Kamp */
3146b2c1e49SXin LI typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,
3155bb6a25fSPoul-Henning Kamp                                                    const XML_Char *doctypeName,
3165bb6a25fSPoul-Henning Kamp                                                    const XML_Char *sysid,
3175bb6a25fSPoul-Henning Kamp                                                    const XML_Char *pubid,
3185bb6a25fSPoul-Henning Kamp                                                    int has_internal_subset);
3195bb6a25fSPoul-Henning Kamp 
3205bb6a25fSPoul-Henning Kamp /* This is called for the start of the DOCTYPE declaration when the
3215bb6a25fSPoul-Henning Kamp    closing > is encountered, but after processing any external
3225bb6a25fSPoul-Henning Kamp    subset.
3235bb6a25fSPoul-Henning Kamp */
324220ed979SColeman Kane typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
3255bb6a25fSPoul-Henning Kamp 
3265bb6a25fSPoul-Henning Kamp /* This is called for entity declarations. The is_parameter_entity
3275bb6a25fSPoul-Henning Kamp    argument will be non-zero if the entity is a parameter entity, zero
3285bb6a25fSPoul-Henning Kamp    otherwise.
3295bb6a25fSPoul-Henning Kamp 
3305bb6a25fSPoul-Henning Kamp    For internal entities (<!ENTITY foo "bar">), value will
3315bb6a25fSPoul-Henning Kamp    be non-NULL and systemId, publicID, and notationName will be NULL.
332*cc68614dSXin LI    The value string is NOT null-terminated; the length is provided in
3335bb6a25fSPoul-Henning Kamp    the value_length argument. Since it is legal to have zero-length
3345bb6a25fSPoul-Henning Kamp    values, do not use this argument to test for internal entities.
3355bb6a25fSPoul-Henning Kamp 
3365bb6a25fSPoul-Henning Kamp    For external entities, value will be NULL and systemId will be
3375bb6a25fSPoul-Henning Kamp    non-NULL. The publicId argument will be NULL unless a public
3385bb6a25fSPoul-Henning Kamp    identifier was provided. The notationName argument will have a
3395bb6a25fSPoul-Henning Kamp    non-NULL value only for unparsed entity declarations.
3405bb6a25fSPoul-Henning Kamp 
3415bb6a25fSPoul-Henning Kamp    Note that is_parameter_entity can't be changed to XML_Bool, since
3425bb6a25fSPoul-Henning Kamp    that would break binary compatibility.
3435bb6a25fSPoul-Henning Kamp */
344220ed979SColeman Kane typedef void(XMLCALL *XML_EntityDeclHandler)(
3456b2c1e49SXin LI     void *userData, const XML_Char *entityName, int is_parameter_entity,
3466b2c1e49SXin LI     const XML_Char *value, int value_length, const XML_Char *base,
3476b2c1e49SXin LI     const XML_Char *systemId, const XML_Char *publicId,
3485bb6a25fSPoul-Henning Kamp     const XML_Char *notationName);
3495bb6a25fSPoul-Henning Kamp 
3505bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
3516b2c1e49SXin LI XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler);
3525bb6a25fSPoul-Henning Kamp 
3535bb6a25fSPoul-Henning Kamp /* OBSOLETE -- OBSOLETE -- OBSOLETE
354be8aff81SXin LI    This handler has been superseded by the EntityDeclHandler above.
3555bb6a25fSPoul-Henning Kamp    It is provided here for backward compatibility.
3565bb6a25fSPoul-Henning Kamp 
3575bb6a25fSPoul-Henning Kamp    This is called for a declaration of an unparsed (NDATA) entity.
3585bb6a25fSPoul-Henning Kamp    The base argument is whatever was set by XML_SetBase. The
3595bb6a25fSPoul-Henning Kamp    entityName, systemId and notationName arguments will never be
3605bb6a25fSPoul-Henning Kamp    NULL. The other arguments may be.
3615bb6a25fSPoul-Henning Kamp */
362220ed979SColeman Kane typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)(
3636b2c1e49SXin LI     void *userData, const XML_Char *entityName, 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 /* This is called for a declaration of notation.  The base argument is
3685bb6a25fSPoul-Henning Kamp    whatever was set by XML_SetBase. The notationName will never be
3695bb6a25fSPoul-Henning Kamp    NULL.  The other arguments can be.
3705bb6a25fSPoul-Henning Kamp */
3716b2c1e49SXin LI typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData,
3725bb6a25fSPoul-Henning Kamp                                                const XML_Char *notationName,
3735bb6a25fSPoul-Henning Kamp                                                const XML_Char *base,
3745bb6a25fSPoul-Henning Kamp                                                const XML_Char *systemId,
3755bb6a25fSPoul-Henning Kamp                                                const XML_Char *publicId);
3765bb6a25fSPoul-Henning Kamp 
3775bb6a25fSPoul-Henning Kamp /* When namespace processing is enabled, these are called once for
3785bb6a25fSPoul-Henning Kamp    each namespace declaration. The call to the start and end element
3795bb6a25fSPoul-Henning Kamp    handlers occur between the calls to the start and end namespace
3805bb6a25fSPoul-Henning Kamp    declaration handlers. For an xmlns attribute, prefix will be
3815bb6a25fSPoul-Henning Kamp    NULL.  For an xmlns="" attribute, uri will be NULL.
3825bb6a25fSPoul-Henning Kamp */
3836b2c1e49SXin LI typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,
3845bb6a25fSPoul-Henning Kamp                                                      const XML_Char *prefix,
3855bb6a25fSPoul-Henning Kamp                                                      const XML_Char *uri);
3865bb6a25fSPoul-Henning Kamp 
3876b2c1e49SXin LI typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,
3885bb6a25fSPoul-Henning Kamp                                                    const XML_Char *prefix);
3895bb6a25fSPoul-Henning Kamp 
3905bb6a25fSPoul-Henning Kamp /* This is called if the document is not standalone, that is, it has an
3915bb6a25fSPoul-Henning Kamp    external subset or a reference to a parameter entity, but does not
392220ed979SColeman Kane    have standalone="yes". If this handler returns XML_STATUS_ERROR,
393220ed979SColeman Kane    then processing will not continue, and the parser will return a
3945bb6a25fSPoul-Henning Kamp    XML_ERROR_NOT_STANDALONE error.
3955bb6a25fSPoul-Henning Kamp    If parameter entity parsing is enabled, then in addition to the
3965bb6a25fSPoul-Henning Kamp    conditions above this handler will only be called if the referenced
3975bb6a25fSPoul-Henning Kamp    entity was actually read.
3985bb6a25fSPoul-Henning Kamp */
399220ed979SColeman Kane typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData);
4005bb6a25fSPoul-Henning Kamp 
4015bb6a25fSPoul-Henning Kamp /* This is called for a reference to an external parsed general
4025bb6a25fSPoul-Henning Kamp    entity.  The referenced entity is not automatically parsed.  The
4035bb6a25fSPoul-Henning Kamp    application can parse it immediately or later using
4045bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate.
4055bb6a25fSPoul-Henning Kamp 
4065bb6a25fSPoul-Henning Kamp    The parser argument is the parser parsing the entity containing the
4075bb6a25fSPoul-Henning Kamp    reference; it can be passed as the parser argument to
4085bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate.  The systemId argument is the
4095bb6a25fSPoul-Henning Kamp    system identifier as specified in the entity declaration; it will
4105bb6a25fSPoul-Henning Kamp    not be NULL.
4115bb6a25fSPoul-Henning Kamp 
4125bb6a25fSPoul-Henning Kamp    The base argument is the system identifier that should be used as
4135bb6a25fSPoul-Henning Kamp    the base for resolving systemId if systemId was relative; this is
4145bb6a25fSPoul-Henning Kamp    set by XML_SetBase; it may be NULL.
4155bb6a25fSPoul-Henning Kamp 
4165bb6a25fSPoul-Henning Kamp    The publicId argument is the public identifier as specified in the
4175bb6a25fSPoul-Henning Kamp    entity declaration, or NULL if none was specified; the whitespace
4185bb6a25fSPoul-Henning Kamp    in the public identifier will have been normalized as required by
4195bb6a25fSPoul-Henning Kamp    the XML spec.
4205bb6a25fSPoul-Henning Kamp 
4215bb6a25fSPoul-Henning Kamp    The context argument specifies the parsing context in the format
4225bb6a25fSPoul-Henning Kamp    expected by the context argument to XML_ExternalEntityParserCreate;
4235bb6a25fSPoul-Henning Kamp    context is valid only until the handler returns, so if the
4245bb6a25fSPoul-Henning Kamp    referenced entity is to be parsed later, it must be copied.
425220ed979SColeman Kane    context is NULL only when the entity is a parameter entity.
4265bb6a25fSPoul-Henning Kamp 
427220ed979SColeman Kane    The handler should return XML_STATUS_ERROR if processing should not
428220ed979SColeman Kane    continue because of a fatal error in the handling of the external
429220ed979SColeman Kane    entity.  In this case the calling parser will return an
4305bb6a25fSPoul-Henning Kamp    XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
4315bb6a25fSPoul-Henning Kamp 
4325bb6a25fSPoul-Henning Kamp    Note that unlike other handlers the first argument is the parser,
4335bb6a25fSPoul-Henning Kamp    not userData.
4345bb6a25fSPoul-Henning Kamp */
4356b2c1e49SXin LI typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser,
4365bb6a25fSPoul-Henning Kamp                                                    const XML_Char *context,
4375bb6a25fSPoul-Henning Kamp                                                    const XML_Char *base,
4385bb6a25fSPoul-Henning Kamp                                                    const XML_Char *systemId,
4395bb6a25fSPoul-Henning Kamp                                                    const XML_Char *publicId);
4405bb6a25fSPoul-Henning Kamp 
4415bb6a25fSPoul-Henning Kamp /* This is called in two situations:
4425bb6a25fSPoul-Henning Kamp    1) An entity reference is encountered for which no declaration
4435bb6a25fSPoul-Henning Kamp       has been read *and* this is not an error.
4445bb6a25fSPoul-Henning Kamp    2) An internal entity reference is read, but not expanded, because
4455bb6a25fSPoul-Henning Kamp       XML_SetDefaultHandler has been called.
4465bb6a25fSPoul-Henning Kamp    Note: skipped parameter entities in declarations and skipped general
4475bb6a25fSPoul-Henning Kamp          entities in attribute values cannot be reported, because
4485bb6a25fSPoul-Henning Kamp          the event would be out of sync with the reporting of the
4495bb6a25fSPoul-Henning Kamp          declarations or attribute values
4505bb6a25fSPoul-Henning Kamp */
4516b2c1e49SXin LI typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData,
4525bb6a25fSPoul-Henning Kamp                                                 const XML_Char *entityName,
4535bb6a25fSPoul-Henning Kamp                                                 int is_parameter_entity);
4545bb6a25fSPoul-Henning Kamp 
4555bb6a25fSPoul-Henning Kamp /* This structure is filled in by the XML_UnknownEncodingHandler to
4565bb6a25fSPoul-Henning Kamp    provide information to the parser about encodings that are unknown
4575bb6a25fSPoul-Henning Kamp    to the parser.
4585bb6a25fSPoul-Henning Kamp 
4595bb6a25fSPoul-Henning Kamp    The map[b] member gives information about byte sequences whose
4605bb6a25fSPoul-Henning Kamp    first byte is b.
4615bb6a25fSPoul-Henning Kamp 
4625bb6a25fSPoul-Henning Kamp    If map[b] is c where c is >= 0, then b by itself encodes the
4635bb6a25fSPoul-Henning Kamp    Unicode scalar value c.
4645bb6a25fSPoul-Henning Kamp 
4655bb6a25fSPoul-Henning Kamp    If map[b] is -1, then the byte sequence is malformed.
4665bb6a25fSPoul-Henning Kamp 
4675bb6a25fSPoul-Henning Kamp    If map[b] is -n, where n >= 2, then b is the first byte of an
4685bb6a25fSPoul-Henning Kamp    n-byte sequence that encodes a single Unicode scalar value.
4695bb6a25fSPoul-Henning Kamp 
4705bb6a25fSPoul-Henning Kamp    The data member will be passed as the first argument to the convert
4715bb6a25fSPoul-Henning Kamp    function.
4725bb6a25fSPoul-Henning Kamp 
4735bb6a25fSPoul-Henning Kamp    The convert function is used to convert multibyte sequences; s will
4745bb6a25fSPoul-Henning Kamp    point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
4755bb6a25fSPoul-Henning Kamp    convert function must return the Unicode scalar value represented
4765bb6a25fSPoul-Henning Kamp    by this byte sequence or -1 if the byte sequence is malformed.
4775bb6a25fSPoul-Henning Kamp 
4785bb6a25fSPoul-Henning Kamp    The convert function may be NULL if the encoding is a single-byte
4795bb6a25fSPoul-Henning Kamp    encoding, that is if map[b] >= -1 for all bytes b.
4805bb6a25fSPoul-Henning Kamp 
4815bb6a25fSPoul-Henning Kamp    When the parser is finished with the encoding, then if release is
4825bb6a25fSPoul-Henning Kamp    not NULL, it will call release passing it the data member; once
4835bb6a25fSPoul-Henning Kamp    release has been called, the convert function will not be called
4845bb6a25fSPoul-Henning Kamp    again.
4855bb6a25fSPoul-Henning Kamp 
4865bb6a25fSPoul-Henning Kamp    Expat places certain restrictions on the encodings that are supported
4875bb6a25fSPoul-Henning Kamp    using this mechanism.
4885bb6a25fSPoul-Henning Kamp 
4895bb6a25fSPoul-Henning Kamp    1. Every ASCII character that can appear in a well-formed XML document,
4905bb6a25fSPoul-Henning Kamp       other than the characters
4915bb6a25fSPoul-Henning Kamp 
4925bb6a25fSPoul-Henning Kamp       $@\^`{}~
4935bb6a25fSPoul-Henning Kamp 
4945bb6a25fSPoul-Henning Kamp       must be represented by a single byte, and that byte must be the
4955bb6a25fSPoul-Henning Kamp       same byte that represents that character in ASCII.
4965bb6a25fSPoul-Henning Kamp 
4975bb6a25fSPoul-Henning Kamp    2. No character may require more than 4 bytes to encode.
4985bb6a25fSPoul-Henning Kamp 
4995bb6a25fSPoul-Henning Kamp    3. All characters encoded must have Unicode scalar values <=
5005bb6a25fSPoul-Henning Kamp       0xFFFF, (i.e., characters that would be encoded by surrogates in
5015bb6a25fSPoul-Henning Kamp       UTF-16 are  not allowed).  Note that this restriction doesn't
5025bb6a25fSPoul-Henning Kamp       apply to the built-in support for UTF-8 and UTF-16.
5035bb6a25fSPoul-Henning Kamp 
5045bb6a25fSPoul-Henning Kamp    4. No Unicode character may be encoded by more than one distinct
5055bb6a25fSPoul-Henning Kamp       sequence of bytes.
5065bb6a25fSPoul-Henning Kamp */
5075bb6a25fSPoul-Henning Kamp typedef struct {
5085bb6a25fSPoul-Henning Kamp   int map[256];
5095bb6a25fSPoul-Henning Kamp   void *data;
510220ed979SColeman Kane   int(XMLCALL *convert)(void *data, const char *s);
511220ed979SColeman Kane   void(XMLCALL *release)(void *data);
5125bb6a25fSPoul-Henning Kamp } XML_Encoding;
5135bb6a25fSPoul-Henning Kamp 
5145bb6a25fSPoul-Henning Kamp /* This is called for an encoding that is unknown to the parser.
5155bb6a25fSPoul-Henning Kamp 
5165bb6a25fSPoul-Henning Kamp    The encodingHandlerData argument is that which was passed as the
5175bb6a25fSPoul-Henning Kamp    second argument to XML_SetUnknownEncodingHandler.
5185bb6a25fSPoul-Henning Kamp 
5195bb6a25fSPoul-Henning Kamp    The name argument gives the name of the encoding as specified in
5205bb6a25fSPoul-Henning Kamp    the encoding declaration.
5215bb6a25fSPoul-Henning Kamp 
5225bb6a25fSPoul-Henning Kamp    If the callback can provide information about the encoding, it must
523220ed979SColeman Kane    fill in the XML_Encoding structure, and return XML_STATUS_OK.
524220ed979SColeman Kane    Otherwise it must return XML_STATUS_ERROR.
5255bb6a25fSPoul-Henning Kamp 
5265bb6a25fSPoul-Henning Kamp    If info does not describe a suitable encoding, then the parser will
527*cc68614dSXin LI    return an XML_ERROR_UNKNOWN_ENCODING error.
5285bb6a25fSPoul-Henning Kamp */
5296b2c1e49SXin LI typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
5305bb6a25fSPoul-Henning Kamp                                                  const XML_Char *name,
5315bb6a25fSPoul-Henning Kamp                                                  XML_Encoding *info);
5325bb6a25fSPoul-Henning Kamp 
5335bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5346b2c1e49SXin LI XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start,
5355bb6a25fSPoul-Henning Kamp                       XML_EndElementHandler end);
5365bb6a25fSPoul-Henning Kamp 
5375bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5386b2c1e49SXin LI XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler);
5395bb6a25fSPoul-Henning Kamp 
5405bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5416b2c1e49SXin LI XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler);
5425bb6a25fSPoul-Henning Kamp 
5435bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5445bb6a25fSPoul-Henning Kamp XML_SetCharacterDataHandler(XML_Parser parser,
5455bb6a25fSPoul-Henning Kamp                             XML_CharacterDataHandler handler);
5465bb6a25fSPoul-Henning Kamp 
5475bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5485bb6a25fSPoul-Henning Kamp XML_SetProcessingInstructionHandler(XML_Parser parser,
5495bb6a25fSPoul-Henning Kamp                                     XML_ProcessingInstructionHandler handler);
5505bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5516b2c1e49SXin LI XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler);
5525bb6a25fSPoul-Henning Kamp 
5535bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5545bb6a25fSPoul-Henning Kamp XML_SetCdataSectionHandler(XML_Parser parser,
5555bb6a25fSPoul-Henning Kamp                            XML_StartCdataSectionHandler start,
5565bb6a25fSPoul-Henning Kamp                            XML_EndCdataSectionHandler end);
5575bb6a25fSPoul-Henning Kamp 
5585bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5595bb6a25fSPoul-Henning Kamp XML_SetStartCdataSectionHandler(XML_Parser parser,
5605bb6a25fSPoul-Henning Kamp                                 XML_StartCdataSectionHandler start);
5615bb6a25fSPoul-Henning Kamp 
5625bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5635bb6a25fSPoul-Henning Kamp XML_SetEndCdataSectionHandler(XML_Parser parser,
5645bb6a25fSPoul-Henning Kamp                               XML_EndCdataSectionHandler end);
5655bb6a25fSPoul-Henning Kamp 
5665bb6a25fSPoul-Henning Kamp /* This sets the default handler and also inhibits expansion of
5675bb6a25fSPoul-Henning Kamp    internal entities. These entity references will be passed to the
5685bb6a25fSPoul-Henning Kamp    default handler, or to the skipped entity handler, if one is set.
5695bb6a25fSPoul-Henning Kamp */
5705bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5716b2c1e49SXin LI XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler);
5725bb6a25fSPoul-Henning Kamp 
5735bb6a25fSPoul-Henning Kamp /* This sets the default handler but does not inhibit expansion of
5745bb6a25fSPoul-Henning Kamp    internal entities.  The entity reference will not be passed to the
5755bb6a25fSPoul-Henning Kamp    default handler.
5765bb6a25fSPoul-Henning Kamp */
5775bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5786b2c1e49SXin LI XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler);
5795bb6a25fSPoul-Henning Kamp 
5805bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5816b2c1e49SXin LI XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start,
5825bb6a25fSPoul-Henning Kamp                           XML_EndDoctypeDeclHandler end);
5835bb6a25fSPoul-Henning Kamp 
5845bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5855bb6a25fSPoul-Henning Kamp XML_SetStartDoctypeDeclHandler(XML_Parser parser,
5865bb6a25fSPoul-Henning Kamp                                XML_StartDoctypeDeclHandler start);
5875bb6a25fSPoul-Henning Kamp 
5885bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5896b2c1e49SXin LI XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end);
5905bb6a25fSPoul-Henning Kamp 
5915bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5925bb6a25fSPoul-Henning Kamp XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
5935bb6a25fSPoul-Henning Kamp                                  XML_UnparsedEntityDeclHandler handler);
5945bb6a25fSPoul-Henning Kamp 
5955bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5966b2c1e49SXin LI XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler);
5975bb6a25fSPoul-Henning Kamp 
5985bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5995bb6a25fSPoul-Henning Kamp XML_SetNamespaceDeclHandler(XML_Parser parser,
6005bb6a25fSPoul-Henning Kamp                             XML_StartNamespaceDeclHandler start,
6015bb6a25fSPoul-Henning Kamp                             XML_EndNamespaceDeclHandler end);
6025bb6a25fSPoul-Henning Kamp 
6035bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6045bb6a25fSPoul-Henning Kamp XML_SetStartNamespaceDeclHandler(XML_Parser parser,
6055bb6a25fSPoul-Henning Kamp                                  XML_StartNamespaceDeclHandler start);
6065bb6a25fSPoul-Henning Kamp 
6075bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6085bb6a25fSPoul-Henning Kamp XML_SetEndNamespaceDeclHandler(XML_Parser parser,
6095bb6a25fSPoul-Henning Kamp                                XML_EndNamespaceDeclHandler end);
6105bb6a25fSPoul-Henning Kamp 
6115bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6125bb6a25fSPoul-Henning Kamp XML_SetNotStandaloneHandler(XML_Parser parser,
6135bb6a25fSPoul-Henning Kamp                             XML_NotStandaloneHandler handler);
6145bb6a25fSPoul-Henning Kamp 
6155bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6165bb6a25fSPoul-Henning Kamp XML_SetExternalEntityRefHandler(XML_Parser parser,
6175bb6a25fSPoul-Henning Kamp                                 XML_ExternalEntityRefHandler handler);
6185bb6a25fSPoul-Henning Kamp 
6195bb6a25fSPoul-Henning Kamp /* If a non-NULL value for arg is specified here, then it will be
6205bb6a25fSPoul-Henning Kamp    passed as the first argument to the external entity ref handler
6215bb6a25fSPoul-Henning Kamp    instead of the parser object.
6225bb6a25fSPoul-Henning Kamp */
6235bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6246b2c1e49SXin LI XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg);
6255bb6a25fSPoul-Henning Kamp 
6265bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6275bb6a25fSPoul-Henning Kamp XML_SetSkippedEntityHandler(XML_Parser parser,
6285bb6a25fSPoul-Henning Kamp                             XML_SkippedEntityHandler handler);
6295bb6a25fSPoul-Henning Kamp 
6305bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6315bb6a25fSPoul-Henning Kamp XML_SetUnknownEncodingHandler(XML_Parser parser,
6325bb6a25fSPoul-Henning Kamp                               XML_UnknownEncodingHandler handler,
6335bb6a25fSPoul-Henning Kamp                               void *encodingHandlerData);
6345bb6a25fSPoul-Henning Kamp 
6355bb6a25fSPoul-Henning Kamp /* This can be called within a handler for a start element, end
6365bb6a25fSPoul-Henning Kamp    element, processing instruction or character data.  It causes the
6375bb6a25fSPoul-Henning Kamp    corresponding markup to be passed to the default handler.
6385bb6a25fSPoul-Henning Kamp */
6395bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6405bb6a25fSPoul-Henning Kamp XML_DefaultCurrent(XML_Parser parser);
6415bb6a25fSPoul-Henning Kamp 
6425bb6a25fSPoul-Henning Kamp /* If do_nst is non-zero, and namespace processing is in effect, and
6435bb6a25fSPoul-Henning Kamp    a name has a prefix (i.e. an explicit namespace qualifier) then
6445bb6a25fSPoul-Henning Kamp    that name is returned as a triplet in a single string separated by
6455bb6a25fSPoul-Henning Kamp    the separator character specified when the parser was created: URI
6465bb6a25fSPoul-Henning Kamp    + sep + local_name + sep + prefix.
6475bb6a25fSPoul-Henning Kamp 
6485bb6a25fSPoul-Henning Kamp    If do_nst is zero, then namespace information is returned in the
6495bb6a25fSPoul-Henning Kamp    default manner (URI + sep + local_name) whether or not the name
6505bb6a25fSPoul-Henning Kamp    has a prefix.
6515bb6a25fSPoul-Henning Kamp 
6525bb6a25fSPoul-Henning Kamp    Note: Calling XML_SetReturnNSTriplet after XML_Parse or
6535bb6a25fSPoul-Henning Kamp      XML_ParseBuffer has no effect.
6545bb6a25fSPoul-Henning Kamp */
6555bb6a25fSPoul-Henning Kamp 
6565bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6575bb6a25fSPoul-Henning Kamp XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
6585bb6a25fSPoul-Henning Kamp 
6595bb6a25fSPoul-Henning Kamp /* This value is passed as the userData argument to callbacks. */
6605bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6615bb6a25fSPoul-Henning Kamp XML_SetUserData(XML_Parser parser, void *userData);
6625bb6a25fSPoul-Henning Kamp 
6635bb6a25fSPoul-Henning Kamp /* Returns the last value set by XML_SetUserData or NULL. */
6645bb6a25fSPoul-Henning Kamp #define XML_GetUserData(parser) (*(void **)(parser))
6655bb6a25fSPoul-Henning Kamp 
6665bb6a25fSPoul-Henning Kamp /* This is equivalent to supplying an encoding argument to
6675bb6a25fSPoul-Henning Kamp    XML_ParserCreate. On success XML_SetEncoding returns non-zero,
6685bb6a25fSPoul-Henning Kamp    zero otherwise.
6695bb6a25fSPoul-Henning Kamp    Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
670220ed979SColeman Kane      has no effect and returns XML_STATUS_ERROR.
6715bb6a25fSPoul-Henning Kamp */
672220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
6735bb6a25fSPoul-Henning Kamp XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
6745bb6a25fSPoul-Henning Kamp 
6755bb6a25fSPoul-Henning Kamp /* If this function is called, then the parser will be passed as the
6765bb6a25fSPoul-Henning Kamp    first argument to callbacks instead of userData.  The userData will
6775bb6a25fSPoul-Henning Kamp    still be accessible using XML_GetUserData.
6785bb6a25fSPoul-Henning Kamp */
6795bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6805bb6a25fSPoul-Henning Kamp XML_UseParserAsHandlerArg(XML_Parser parser);
6815bb6a25fSPoul-Henning Kamp 
6825bb6a25fSPoul-Henning Kamp /* If useDTD == XML_TRUE is passed to this function, then the parser
6835bb6a25fSPoul-Henning Kamp    will assume that there is an external subset, even if none is
6845bb6a25fSPoul-Henning Kamp    specified in the document. In such a case the parser will call the
6855bb6a25fSPoul-Henning Kamp    externalEntityRefHandler with a value of NULL for the systemId
6865bb6a25fSPoul-Henning Kamp    argument (the publicId and context arguments will be NULL as well).
687220ed979SColeman Kane    Note: For the purpose of checking WFC: Entity Declared, passing
688220ed979SColeman Kane      useDTD == XML_TRUE will make the parser behave as if the document
689220ed979SColeman Kane      had a DTD with an external subset.
6905bb6a25fSPoul-Henning Kamp    Note: If this function is called, then this must be done before
6915bb6a25fSPoul-Henning Kamp      the first call to XML_Parse or XML_ParseBuffer, since it will
6925bb6a25fSPoul-Henning Kamp      have no effect after that.  Returns
6935bb6a25fSPoul-Henning Kamp      XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
6945bb6a25fSPoul-Henning Kamp    Note: If the document does not have a DOCTYPE declaration at all,
6955bb6a25fSPoul-Henning Kamp      then startDoctypeDeclHandler and endDoctypeDeclHandler will not
6965bb6a25fSPoul-Henning Kamp      be called, despite an external subset being parsed.
6975bb6a25fSPoul-Henning Kamp    Note: If XML_DTD is not defined when Expat is compiled, returns
6985bb6a25fSPoul-Henning Kamp      XML_ERROR_FEATURE_REQUIRES_XML_DTD.
6990a48773fSEric van Gyzen    Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT.
7005bb6a25fSPoul-Henning Kamp */
7015bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Error)
7025bb6a25fSPoul-Henning Kamp XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
7035bb6a25fSPoul-Henning Kamp 
7045bb6a25fSPoul-Henning Kamp /* Sets the base to be used for resolving relative URIs in system
7055bb6a25fSPoul-Henning Kamp    identifiers in declarations.  Resolving relative identifiers is
7065bb6a25fSPoul-Henning Kamp    left to the application: this value will be passed through as the
7075bb6a25fSPoul-Henning Kamp    base argument to the XML_ExternalEntityRefHandler,
7085bb6a25fSPoul-Henning Kamp    XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
709220ed979SColeman Kane    argument will be copied.  Returns XML_STATUS_ERROR if out of memory,
710220ed979SColeman Kane    XML_STATUS_OK otherwise.
7115bb6a25fSPoul-Henning Kamp */
712220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
7135bb6a25fSPoul-Henning Kamp XML_SetBase(XML_Parser parser, const XML_Char *base);
7145bb6a25fSPoul-Henning Kamp 
7155bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_Char *)
7165bb6a25fSPoul-Henning Kamp XML_GetBase(XML_Parser parser);
7175bb6a25fSPoul-Henning Kamp 
7185bb6a25fSPoul-Henning Kamp /* Returns the number of the attribute/value pairs passed in last call
7195bb6a25fSPoul-Henning Kamp    to the XML_StartElementHandler that were specified in the start-tag
7205bb6a25fSPoul-Henning Kamp    rather than defaulted. Each attribute/value pair counts as 2; thus
721*cc68614dSXin LI    this corresponds to an index into the atts array passed to the
7220a48773fSEric van Gyzen    XML_StartElementHandler.  Returns -1 if parser == NULL.
7235bb6a25fSPoul-Henning Kamp */
7245bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
7255bb6a25fSPoul-Henning Kamp XML_GetSpecifiedAttributeCount(XML_Parser parser);
7265bb6a25fSPoul-Henning Kamp 
7275bb6a25fSPoul-Henning Kamp /* Returns the index of the ID attribute passed in the last call to
7280a48773fSEric van Gyzen    XML_StartElementHandler, or -1 if there is no ID attribute or
7290a48773fSEric van Gyzen    parser == NULL.  Each attribute/value pair counts as 2; thus this
730*cc68614dSXin LI    corresponds to an index into the atts array passed to the
7310a48773fSEric van Gyzen    XML_StartElementHandler.
7325bb6a25fSPoul-Henning Kamp */
7335bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
7345bb6a25fSPoul-Henning Kamp XML_GetIdAttributeIndex(XML_Parser parser);
7355bb6a25fSPoul-Henning Kamp 
736e3466a89SXin LI #ifdef XML_ATTR_INFO
737e3466a89SXin LI /* Source file byte offsets for the start and end of attribute names and values.
738e3466a89SXin LI    The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
739e3466a89SXin LI    file an attribute value of "blah" will yield:
740e3466a89SXin LI    info->valueEnd - info->valueStart = 4 bytes.
741e3466a89SXin LI */
742e3466a89SXin LI typedef struct {
743e3466a89SXin LI   XML_Index nameStart;  /* Offset to beginning of the attribute name. */
744e3466a89SXin LI   XML_Index nameEnd;    /* Offset after the attribute name's last byte. */
745e3466a89SXin LI   XML_Index valueStart; /* Offset to beginning of the attribute value. */
746e3466a89SXin LI   XML_Index valueEnd;   /* Offset after the attribute value's last byte. */
747e3466a89SXin LI } XML_AttrInfo;
748e3466a89SXin LI 
749e3466a89SXin LI /* Returns an array of XML_AttrInfo structures for the attribute/value pairs
750e3466a89SXin LI    passed in last call to the XML_StartElementHandler that were specified
751e3466a89SXin LI    in the start-tag rather than defaulted. Each attribute/value pair counts
752e3466a89SXin LI    as 1; thus the number of entries in the array is
753e3466a89SXin LI    XML_GetSpecifiedAttributeCount(parser) / 2.
754e3466a89SXin LI */
755e3466a89SXin LI XMLPARSEAPI(const XML_AttrInfo *)
756e3466a89SXin LI XML_GetAttributeInfo(XML_Parser parser);
757e3466a89SXin LI #endif
758e3466a89SXin LI 
7595bb6a25fSPoul-Henning Kamp /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
7605bb6a25fSPoul-Henning Kamp    detected.  The last call to XML_Parse must have isFinal true; len
7615bb6a25fSPoul-Henning Kamp    may be zero for this call (or any other).
7625bb6a25fSPoul-Henning Kamp 
763220ed979SColeman Kane    Though the return values for these functions has always been
764220ed979SColeman Kane    described as a Boolean value, the implementation, at least for the
765220ed979SColeman Kane    1.95.x series, has always returned exactly one of the XML_Status
766220ed979SColeman Kane    values.
7675bb6a25fSPoul-Henning Kamp */
7685bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Status)
7695bb6a25fSPoul-Henning Kamp XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
7705bb6a25fSPoul-Henning Kamp 
7715bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void *)
7725bb6a25fSPoul-Henning Kamp XML_GetBuffer(XML_Parser parser, int len);
7735bb6a25fSPoul-Henning Kamp 
7745bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Status)
7755bb6a25fSPoul-Henning Kamp XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
7765bb6a25fSPoul-Henning Kamp 
777220ed979SColeman Kane /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
778220ed979SColeman Kane    Must be called from within a call-back handler, except when aborting
779220ed979SColeman Kane    (resumable = 0) an already suspended parser. Some call-backs may
780220ed979SColeman Kane    still follow because they would otherwise get lost. Examples:
781220ed979SColeman Kane    - endElementHandler() for empty elements when stopped in
782220ed979SColeman Kane      startElementHandler(),
783220ed979SColeman Kane    - endNameSpaceDeclHandler() when stopped in endElementHandler(),
784220ed979SColeman Kane    and possibly others.
785220ed979SColeman Kane 
786220ed979SColeman Kane    Can be called from most handlers, including DTD related call-backs,
787220ed979SColeman Kane    except when parsing an external parameter entity and resumable != 0.
788220ed979SColeman Kane    Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
789220ed979SColeman Kane    Possible error codes:
790220ed979SColeman Kane    - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
791220ed979SColeman Kane    - XML_ERROR_FINISHED: when the parser has already finished.
792220ed979SColeman Kane    - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
793220ed979SColeman Kane 
794220ed979SColeman Kane    When resumable != 0 (true) then parsing is suspended, that is,
795220ed979SColeman Kane    XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
796220ed979SColeman Kane    Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
797220ed979SColeman Kane    return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
798220ed979SColeman Kane 
799220ed979SColeman Kane    *Note*:
800220ed979SColeman Kane    This will be applied to the current parser instance only, that is, if
801220ed979SColeman Kane    there is a parent parser then it will continue parsing when the
802220ed979SColeman Kane    externalEntityRefHandler() returns. It is up to the implementation of
803220ed979SColeman Kane    the externalEntityRefHandler() to call XML_StopParser() on the parent
804220ed979SColeman Kane    parser (recursively), if one wants to stop parsing altogether.
805220ed979SColeman Kane 
806220ed979SColeman Kane    When suspended, parsing can be resumed by calling XML_ResumeParser().
807220ed979SColeman Kane */
808220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
809220ed979SColeman Kane XML_StopParser(XML_Parser parser, XML_Bool resumable);
810220ed979SColeman Kane 
811220ed979SColeman Kane /* Resumes parsing after it has been suspended with XML_StopParser().
812220ed979SColeman Kane    Must not be called from within a handler call-back. Returns same
813220ed979SColeman Kane    status codes as XML_Parse() or XML_ParseBuffer().
814220ed979SColeman Kane    Additional error code XML_ERROR_NOT_SUSPENDED possible.
815220ed979SColeman Kane 
816220ed979SColeman Kane    *Note*:
817220ed979SColeman Kane    This must be called on the most deeply nested child parser instance
818220ed979SColeman Kane    first, and on its parent parser only after the child parser has finished,
819220ed979SColeman Kane    to be applied recursively until the document entity's parser is restarted.
820220ed979SColeman Kane    That is, the parent parser will not resume by itself and it is up to the
821220ed979SColeman Kane    application to call XML_ResumeParser() on it at the appropriate moment.
822220ed979SColeman Kane */
823220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
824220ed979SColeman Kane XML_ResumeParser(XML_Parser parser);
825220ed979SColeman Kane 
8266b2c1e49SXin LI enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED };
827220ed979SColeman Kane 
828220ed979SColeman Kane typedef struct {
829220ed979SColeman Kane   enum XML_Parsing parsing;
830220ed979SColeman Kane   XML_Bool finalBuffer;
831220ed979SColeman Kane } XML_ParsingStatus;
832220ed979SColeman Kane 
833220ed979SColeman Kane /* Returns status of parser with respect to being initialized, parsing,
834220ed979SColeman Kane    finished, or suspended and processing the final buffer.
835220ed979SColeman Kane    XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
836220ed979SColeman Kane    XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
837220ed979SColeman Kane */
838220ed979SColeman Kane XMLPARSEAPI(void)
839220ed979SColeman Kane XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
840220ed979SColeman Kane 
8415bb6a25fSPoul-Henning Kamp /* Creates an XML_Parser object that can parse an external general
8425bb6a25fSPoul-Henning Kamp    entity; context is a '\0'-terminated string specifying the parse
8435bb6a25fSPoul-Henning Kamp    context; encoding is a '\0'-terminated string giving the name of
8445bb6a25fSPoul-Henning Kamp    the externally specified encoding, or NULL if there is no
8455bb6a25fSPoul-Henning Kamp    externally specified encoding.  The context string consists of a
8465bb6a25fSPoul-Henning Kamp    sequence of tokens separated by formfeeds (\f); a token consisting
8475bb6a25fSPoul-Henning Kamp    of a name specifies that the general entity of the name is open; a
8485bb6a25fSPoul-Henning Kamp    token of the form prefix=uri specifies the namespace for a
8495bb6a25fSPoul-Henning Kamp    particular prefix; a token of the form =uri specifies the default
8505bb6a25fSPoul-Henning Kamp    namespace.  This can be called at any point after the first call to
8515bb6a25fSPoul-Henning Kamp    an ExternalEntityRefHandler so longer as the parser has not yet
8525bb6a25fSPoul-Henning Kamp    been freed.  The new parser is completely independent and may
8535bb6a25fSPoul-Henning Kamp    safely be used in a separate thread.  The handlers and userData are
854220ed979SColeman Kane    initialized from the parser argument.  Returns NULL if out of memory.
8555bb6a25fSPoul-Henning Kamp    Otherwise returns a new XML_Parser object.
8565bb6a25fSPoul-Henning Kamp */
8575bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
8586b2c1e49SXin LI XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context,
8595bb6a25fSPoul-Henning Kamp                                const XML_Char *encoding);
8605bb6a25fSPoul-Henning Kamp 
8615bb6a25fSPoul-Henning Kamp enum XML_ParamEntityParsing {
8625bb6a25fSPoul-Henning Kamp   XML_PARAM_ENTITY_PARSING_NEVER,
8635bb6a25fSPoul-Henning Kamp   XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
8645bb6a25fSPoul-Henning Kamp   XML_PARAM_ENTITY_PARSING_ALWAYS
8655bb6a25fSPoul-Henning Kamp };
8665bb6a25fSPoul-Henning Kamp 
8675bb6a25fSPoul-Henning Kamp /* Controls parsing of parameter entities (including the external DTD
8685bb6a25fSPoul-Henning Kamp    subset). If parsing of parameter entities is enabled, then
8695bb6a25fSPoul-Henning Kamp    references to external parameter entities (including the external
8705bb6a25fSPoul-Henning Kamp    DTD subset) will be passed to the handler set with
8715bb6a25fSPoul-Henning Kamp    XML_SetExternalEntityRefHandler.  The context passed will be 0.
8725bb6a25fSPoul-Henning Kamp 
8735bb6a25fSPoul-Henning Kamp    Unlike external general entities, external parameter entities can
8745bb6a25fSPoul-Henning Kamp    only be parsed synchronously.  If the external parameter entity is
8755bb6a25fSPoul-Henning Kamp    to be parsed, it must be parsed during the call to the external
8765bb6a25fSPoul-Henning Kamp    entity ref handler: the complete sequence of
8775bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
8785bb6a25fSPoul-Henning Kamp    XML_ParserFree calls must be made during this call.  After
8795bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate has been called to create the parser
8805bb6a25fSPoul-Henning Kamp    for the external parameter entity (context must be 0 for this
8815bb6a25fSPoul-Henning Kamp    call), it is illegal to make any calls on the old parser until
8825bb6a25fSPoul-Henning Kamp    XML_ParserFree has been called on the newly created parser.
8835bb6a25fSPoul-Henning Kamp    If the library has been compiled without support for parameter
8845bb6a25fSPoul-Henning Kamp    entity parsing (ie without XML_DTD being defined), then
8855bb6a25fSPoul-Henning Kamp    XML_SetParamEntityParsing will return 0 if parsing of parameter
8865bb6a25fSPoul-Henning Kamp    entities is requested; otherwise it will return non-zero.
8875bb6a25fSPoul-Henning Kamp    Note: If XML_SetParamEntityParsing is called after XML_Parse or
8885bb6a25fSPoul-Henning Kamp       XML_ParseBuffer, then it has no effect and will always return 0.
8890a48773fSEric van Gyzen    Note: If parser == NULL, the function will do nothing and return 0.
8905bb6a25fSPoul-Henning Kamp */
8915bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
8925bb6a25fSPoul-Henning Kamp XML_SetParamEntityParsing(XML_Parser parser,
8935bb6a25fSPoul-Henning Kamp                           enum XML_ParamEntityParsing parsing);
8945bb6a25fSPoul-Henning Kamp 
895e3466a89SXin LI /* Sets the hash salt to use for internal hash calculations.
896e3466a89SXin LI    Helps in preventing DoS attacks based on predicting hash
897e3466a89SXin LI    function behavior. This must be called before parsing is started.
898e3466a89SXin LI    Returns 1 if successful, 0 when called after parsing has started.
8990a48773fSEric van Gyzen    Note: If parser == NULL, the function will do nothing and return 0.
900e3466a89SXin LI */
901e3466a89SXin LI XMLPARSEAPI(int)
9026b2c1e49SXin LI XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt);
903e3466a89SXin LI 
904220ed979SColeman Kane /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
9055bb6a25fSPoul-Henning Kamp    XML_GetErrorCode returns information about the error.
9065bb6a25fSPoul-Henning Kamp */
9075bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Error)
9085bb6a25fSPoul-Henning Kamp XML_GetErrorCode(XML_Parser parser);
9095bb6a25fSPoul-Henning Kamp 
9105bb6a25fSPoul-Henning Kamp /* These functions return information about the current parse
911220ed979SColeman Kane    location.  They may be called from any callback called to report
912220ed979SColeman Kane    some parse event; in this case the location is the location of the
913220ed979SColeman Kane    first of the sequence of characters that generated the event.  When
914220ed979SColeman Kane    called from callbacks generated by declarations in the document
915220ed979SColeman Kane    prologue, the location identified isn't as neatly defined, but will
916220ed979SColeman Kane    be within the relevant markup.  When called outside of the callback
917220ed979SColeman Kane    functions, the position indicated will be just past the last parse
918220ed979SColeman Kane    event (regardless of whether there was an associated callback).
9195bb6a25fSPoul-Henning Kamp 
920220ed979SColeman Kane    They may also be called after returning from a call to XML_Parse
921220ed979SColeman Kane    or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
922220ed979SColeman Kane    the location is the location of the character at which the error
923220ed979SColeman Kane    was detected; otherwise the location is the location of the last
924220ed979SColeman Kane    parse event, as described above.
9250a48773fSEric van Gyzen 
9260a48773fSEric van Gyzen    Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber
9270a48773fSEric van Gyzen    return 0 to indicate an error.
9280a48773fSEric van Gyzen    Note: XML_GetCurrentByteIndex returns -1 to indicate an error.
9295bb6a25fSPoul-Henning Kamp */
930220ed979SColeman Kane XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
931220ed979SColeman Kane XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
932220ed979SColeman Kane XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
9335bb6a25fSPoul-Henning Kamp 
9345bb6a25fSPoul-Henning Kamp /* Return the number of bytes in the current event.
9355bb6a25fSPoul-Henning Kamp    Returns 0 if the event is in an internal entity.
9365bb6a25fSPoul-Henning Kamp */
9375bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
9385bb6a25fSPoul-Henning Kamp XML_GetCurrentByteCount(XML_Parser parser);
9395bb6a25fSPoul-Henning Kamp 
9405bb6a25fSPoul-Henning Kamp /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
9415bb6a25fSPoul-Henning Kamp    the integer pointed to by offset to the offset within this buffer
9425bb6a25fSPoul-Henning Kamp    of the current parse position, and sets the integer pointed to by size
9435bb6a25fSPoul-Henning Kamp    to the size of this buffer (the number of input bytes). Otherwise
9445bb6a25fSPoul-Henning Kamp    returns a NULL pointer. Also returns a NULL pointer if a parse isn't
9455bb6a25fSPoul-Henning Kamp    active.
9465bb6a25fSPoul-Henning Kamp 
9475bb6a25fSPoul-Henning Kamp    NOTE: The character pointer returned should not be used outside
9485bb6a25fSPoul-Henning Kamp    the handler that makes the call.
9495bb6a25fSPoul-Henning Kamp */
9505bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const char *)
9516b2c1e49SXin LI XML_GetInputContext(XML_Parser parser, int *offset, int *size);
9525bb6a25fSPoul-Henning Kamp 
9535bb6a25fSPoul-Henning Kamp /* For backwards compatibility with previous versions. */
9545bb6a25fSPoul-Henning Kamp #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
9555bb6a25fSPoul-Henning Kamp #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
9565bb6a25fSPoul-Henning Kamp #define XML_GetErrorByteIndex XML_GetCurrentByteIndex
9575bb6a25fSPoul-Henning Kamp 
958220ed979SColeman Kane /* Frees the content model passed to the element declaration handler */
959220ed979SColeman Kane XMLPARSEAPI(void)
960220ed979SColeman Kane XML_FreeContentModel(XML_Parser parser, XML_Content *model);
961220ed979SColeman Kane 
962220ed979SColeman Kane /* Exposing the memory handling functions used in Expat */
963220ed979SColeman Kane XMLPARSEAPI(void *)
964be8aff81SXin LI XML_ATTR_MALLOC
965be8aff81SXin LI XML_ATTR_ALLOC_SIZE(2)
966220ed979SColeman Kane XML_MemMalloc(XML_Parser parser, size_t size);
967220ed979SColeman Kane 
968220ed979SColeman Kane XMLPARSEAPI(void *)
969be8aff81SXin LI XML_ATTR_ALLOC_SIZE(3)
970220ed979SColeman Kane XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
971220ed979SColeman Kane 
972220ed979SColeman Kane XMLPARSEAPI(void)
973220ed979SColeman Kane XML_MemFree(XML_Parser parser, void *ptr);
974220ed979SColeman Kane 
9755bb6a25fSPoul-Henning Kamp /* Frees memory used by the parser. */
9765bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
9775bb6a25fSPoul-Henning Kamp XML_ParserFree(XML_Parser parser);
9785bb6a25fSPoul-Henning Kamp 
9795bb6a25fSPoul-Henning Kamp /* Returns a string describing the error. */
9805bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_LChar *)
9815bb6a25fSPoul-Henning Kamp XML_ErrorString(enum XML_Error code);
9825bb6a25fSPoul-Henning Kamp 
9835bb6a25fSPoul-Henning Kamp /* Return a string containing the version number of this expat */
9845bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_LChar *)
9855bb6a25fSPoul-Henning Kamp XML_ExpatVersion(void);
9865bb6a25fSPoul-Henning Kamp 
9875bb6a25fSPoul-Henning Kamp typedef struct {
9885bb6a25fSPoul-Henning Kamp   int major;
9895bb6a25fSPoul-Henning Kamp   int minor;
9905bb6a25fSPoul-Henning Kamp   int micro;
9915bb6a25fSPoul-Henning Kamp } XML_Expat_Version;
9925bb6a25fSPoul-Henning Kamp 
9935bb6a25fSPoul-Henning Kamp /* Return an XML_Expat_Version structure containing numeric version
9945bb6a25fSPoul-Henning Kamp    number information for this version of expat.
9955bb6a25fSPoul-Henning Kamp */
9965bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Expat_Version)
9975bb6a25fSPoul-Henning Kamp XML_ExpatVersionInfo(void);
9985bb6a25fSPoul-Henning Kamp 
9995bb6a25fSPoul-Henning Kamp /* Added in Expat 1.95.5. */
10005bb6a25fSPoul-Henning Kamp enum XML_FeatureEnum {
10015bb6a25fSPoul-Henning Kamp   XML_FEATURE_END = 0,
10025bb6a25fSPoul-Henning Kamp   XML_FEATURE_UNICODE,
10035bb6a25fSPoul-Henning Kamp   XML_FEATURE_UNICODE_WCHAR_T,
10045bb6a25fSPoul-Henning Kamp   XML_FEATURE_DTD,
10055bb6a25fSPoul-Henning Kamp   XML_FEATURE_CONTEXT_BYTES,
10065bb6a25fSPoul-Henning Kamp   XML_FEATURE_MIN_SIZE,
10075bb6a25fSPoul-Henning Kamp   XML_FEATURE_SIZEOF_XML_CHAR,
1008220ed979SColeman Kane   XML_FEATURE_SIZEOF_XML_LCHAR,
1009220ed979SColeman Kane   XML_FEATURE_NS,
1010e3466a89SXin LI   XML_FEATURE_LARGE_SIZE,
1011*cc68614dSXin LI   XML_FEATURE_ATTR_INFO,
1012*cc68614dSXin LI   /* Added in Expat 2.4.0. */
1013*cc68614dSXin LI   XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
1014*cc68614dSXin LI   XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT
10155bb6a25fSPoul-Henning Kamp   /* Additional features must be added to the end of this enum. */
10165bb6a25fSPoul-Henning Kamp };
10175bb6a25fSPoul-Henning Kamp 
10185bb6a25fSPoul-Henning Kamp typedef struct {
10195bb6a25fSPoul-Henning Kamp   enum XML_FeatureEnum feature;
1020220ed979SColeman Kane   const XML_LChar *name;
10215bb6a25fSPoul-Henning Kamp   long int value;
10225bb6a25fSPoul-Henning Kamp } XML_Feature;
10235bb6a25fSPoul-Henning Kamp 
10245bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_Feature *)
10255bb6a25fSPoul-Henning Kamp XML_GetFeatureList(void);
10265bb6a25fSPoul-Henning Kamp 
1027*cc68614dSXin LI #ifdef XML_DTD
1028*cc68614dSXin LI /* Added in Expat 2.4.0. */
1029*cc68614dSXin LI XMLPARSEAPI(XML_Bool)
1030*cc68614dSXin LI XML_SetBillionLaughsAttackProtectionMaximumAmplification(
1031*cc68614dSXin LI     XML_Parser parser, float maximumAmplificationFactor);
1032*cc68614dSXin LI 
1033*cc68614dSXin LI /* Added in Expat 2.4.0. */
1034*cc68614dSXin LI XMLPARSEAPI(XML_Bool)
1035*cc68614dSXin LI XML_SetBillionLaughsAttackProtectionActivationThreshold(
1036*cc68614dSXin LI     XML_Parser parser, unsigned long long activationThresholdBytes);
1037*cc68614dSXin LI #endif
1038*cc68614dSXin LI 
1039be8aff81SXin LI /* Expat follows the semantic versioning convention.
1040be8aff81SXin LI    See http://semver.org.
10415bb6a25fSPoul-Henning Kamp */
1042220ed979SColeman Kane #define XML_MAJOR_VERSION 2
1043*cc68614dSXin LI #define XML_MINOR_VERSION 4
1044*cc68614dSXin LI #define XML_MICRO_VERSION 3
10455bb6a25fSPoul-Henning Kamp 
10465bb6a25fSPoul-Henning Kamp #ifdef __cplusplus
10475bb6a25fSPoul-Henning Kamp }
10485bb6a25fSPoul-Henning Kamp #endif
10495bb6a25fSPoul-Henning Kamp 
1050220ed979SColeman Kane #endif /* not Expat_INCLUDED */
1051