xref: /freebsd/contrib/expat/lib/expat.h (revision 7ed8e142a00d4b711dd2021b37b84a6e7f86516e)
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>
14cc68614dSXin LI    Copyright (c) 2016-2022 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>
18*7ed8e142SXin LI    Copyright (c) 2022      Thijs Schreijer <thijs@thijsschreijer.nl>
190a48773fSEric van Gyzen    Licensed under the MIT license:
200a48773fSEric van Gyzen 
210a48773fSEric van Gyzen    Permission is  hereby granted,  free of charge,  to any  person obtaining
220a48773fSEric van Gyzen    a  copy  of  this  software   and  associated  documentation  files  (the
230a48773fSEric van Gyzen    "Software"),  to  deal in  the  Software  without restriction,  including
240a48773fSEric van Gyzen    without  limitation the  rights  to use,  copy,  modify, merge,  publish,
250a48773fSEric van Gyzen    distribute, sublicense, and/or sell copies of the Software, and to permit
260a48773fSEric van Gyzen    persons  to whom  the Software  is  furnished to  do so,  subject to  the
270a48773fSEric van Gyzen    following conditions:
280a48773fSEric van Gyzen 
290a48773fSEric van Gyzen    The above copyright  notice and this permission notice  shall be included
300a48773fSEric van Gyzen    in all copies or substantial portions of the Software.
310a48773fSEric van Gyzen 
320a48773fSEric van Gyzen    THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
330a48773fSEric van Gyzen    EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
340a48773fSEric van Gyzen    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
350a48773fSEric van Gyzen    NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
360a48773fSEric van Gyzen    DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
370a48773fSEric van Gyzen    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
380a48773fSEric van Gyzen    USE OR OTHER DEALINGS IN THE SOFTWARE.
395bb6a25fSPoul-Henning Kamp */
405bb6a25fSPoul-Henning Kamp 
41220ed979SColeman Kane #ifndef Expat_INCLUDED
42220ed979SColeman Kane #define Expat_INCLUDED 1
435bb6a25fSPoul-Henning Kamp 
445bb6a25fSPoul-Henning Kamp #include <stdlib.h>
45220ed979SColeman Kane #include "expat_external.h"
465bb6a25fSPoul-Henning Kamp 
475bb6a25fSPoul-Henning Kamp #ifdef __cplusplus
485bb6a25fSPoul-Henning Kamp extern "C" {
495bb6a25fSPoul-Henning Kamp #endif
505bb6a25fSPoul-Henning Kamp 
515bb6a25fSPoul-Henning Kamp struct XML_ParserStruct;
525bb6a25fSPoul-Henning Kamp typedef struct XML_ParserStruct *XML_Parser;
535bb6a25fSPoul-Henning Kamp 
545bb6a25fSPoul-Henning Kamp typedef unsigned char XML_Bool;
555bb6a25fSPoul-Henning Kamp #define XML_TRUE ((XML_Bool)1)
565bb6a25fSPoul-Henning Kamp #define XML_FALSE ((XML_Bool)0)
575bb6a25fSPoul-Henning Kamp 
58220ed979SColeman Kane /* The XML_Status enum gives the possible return values for several
59220ed979SColeman Kane    API functions.  The preprocessor #defines are included so this
60220ed979SColeman Kane    stanza can be added to code that still needs to support older
61220ed979SColeman Kane    versions of Expat 1.95.x:
62220ed979SColeman Kane 
63220ed979SColeman Kane    #ifndef XML_STATUS_OK
64220ed979SColeman Kane    #define XML_STATUS_OK    1
65220ed979SColeman Kane    #define XML_STATUS_ERROR 0
66220ed979SColeman Kane    #endif
67220ed979SColeman Kane 
68220ed979SColeman Kane    Otherwise, the #define hackery is quite ugly and would have been
69220ed979SColeman Kane    dropped.
70220ed979SColeman Kane */
71220ed979SColeman Kane enum XML_Status {
72220ed979SColeman Kane   XML_STATUS_ERROR = 0,
73220ed979SColeman Kane #define XML_STATUS_ERROR XML_STATUS_ERROR
74220ed979SColeman Kane   XML_STATUS_OK = 1,
75220ed979SColeman Kane #define XML_STATUS_OK XML_STATUS_OK
76220ed979SColeman Kane   XML_STATUS_SUSPENDED = 2
77220ed979SColeman Kane #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
78220ed979SColeman Kane };
79220ed979SColeman Kane 
805bb6a25fSPoul-Henning Kamp enum XML_Error {
815bb6a25fSPoul-Henning Kamp   XML_ERROR_NONE,
825bb6a25fSPoul-Henning Kamp   XML_ERROR_NO_MEMORY,
835bb6a25fSPoul-Henning Kamp   XML_ERROR_SYNTAX,
845bb6a25fSPoul-Henning Kamp   XML_ERROR_NO_ELEMENTS,
855bb6a25fSPoul-Henning Kamp   XML_ERROR_INVALID_TOKEN,
865bb6a25fSPoul-Henning Kamp   XML_ERROR_UNCLOSED_TOKEN,
875bb6a25fSPoul-Henning Kamp   XML_ERROR_PARTIAL_CHAR,
885bb6a25fSPoul-Henning Kamp   XML_ERROR_TAG_MISMATCH,
895bb6a25fSPoul-Henning Kamp   XML_ERROR_DUPLICATE_ATTRIBUTE,
905bb6a25fSPoul-Henning Kamp   XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
915bb6a25fSPoul-Henning Kamp   XML_ERROR_PARAM_ENTITY_REF,
925bb6a25fSPoul-Henning Kamp   XML_ERROR_UNDEFINED_ENTITY,
935bb6a25fSPoul-Henning Kamp   XML_ERROR_RECURSIVE_ENTITY_REF,
945bb6a25fSPoul-Henning Kamp   XML_ERROR_ASYNC_ENTITY,
955bb6a25fSPoul-Henning Kamp   XML_ERROR_BAD_CHAR_REF,
965bb6a25fSPoul-Henning Kamp   XML_ERROR_BINARY_ENTITY_REF,
975bb6a25fSPoul-Henning Kamp   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
985bb6a25fSPoul-Henning Kamp   XML_ERROR_MISPLACED_XML_PI,
995bb6a25fSPoul-Henning Kamp   XML_ERROR_UNKNOWN_ENCODING,
1005bb6a25fSPoul-Henning Kamp   XML_ERROR_INCORRECT_ENCODING,
1015bb6a25fSPoul-Henning Kamp   XML_ERROR_UNCLOSED_CDATA_SECTION,
1025bb6a25fSPoul-Henning Kamp   XML_ERROR_EXTERNAL_ENTITY_HANDLING,
1035bb6a25fSPoul-Henning Kamp   XML_ERROR_NOT_STANDALONE,
1045bb6a25fSPoul-Henning Kamp   XML_ERROR_UNEXPECTED_STATE,
1055bb6a25fSPoul-Henning Kamp   XML_ERROR_ENTITY_DECLARED_IN_PE,
1065bb6a25fSPoul-Henning Kamp   XML_ERROR_FEATURE_REQUIRES_XML_DTD,
107220ed979SColeman Kane   XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
108220ed979SColeman Kane   /* Added in 1.95.7. */
109220ed979SColeman Kane   XML_ERROR_UNBOUND_PREFIX,
110220ed979SColeman Kane   /* Added in 1.95.8. */
111220ed979SColeman Kane   XML_ERROR_UNDECLARING_PREFIX,
112220ed979SColeman Kane   XML_ERROR_INCOMPLETE_PE,
113220ed979SColeman Kane   XML_ERROR_XML_DECL,
114220ed979SColeman Kane   XML_ERROR_TEXT_DECL,
115220ed979SColeman Kane   XML_ERROR_PUBLICID,
116220ed979SColeman Kane   XML_ERROR_SUSPENDED,
117220ed979SColeman Kane   XML_ERROR_NOT_SUSPENDED,
118220ed979SColeman Kane   XML_ERROR_ABORTED,
119220ed979SColeman Kane   XML_ERROR_FINISHED,
120220ed979SColeman Kane   XML_ERROR_SUSPEND_PE,
121220ed979SColeman Kane   /* Added in 2.0. */
122220ed979SColeman Kane   XML_ERROR_RESERVED_PREFIX_XML,
123220ed979SColeman Kane   XML_ERROR_RESERVED_PREFIX_XMLNS,
1240a48773fSEric van Gyzen   XML_ERROR_RESERVED_NAMESPACE_URI,
1250a48773fSEric van Gyzen   /* Added in 2.2.1. */
126cc68614dSXin LI   XML_ERROR_INVALID_ARGUMENT,
127cc68614dSXin LI   /* Added in 2.3.0. */
128cc68614dSXin LI   XML_ERROR_NO_BUFFER,
129cc68614dSXin LI   /* Added in 2.4.0. */
130cc68614dSXin LI   XML_ERROR_AMPLIFICATION_LIMIT_BREACH
1315bb6a25fSPoul-Henning Kamp };
1325bb6a25fSPoul-Henning Kamp 
1335bb6a25fSPoul-Henning Kamp enum XML_Content_Type {
1345bb6a25fSPoul-Henning Kamp   XML_CTYPE_EMPTY = 1,
1355bb6a25fSPoul-Henning Kamp   XML_CTYPE_ANY,
1365bb6a25fSPoul-Henning Kamp   XML_CTYPE_MIXED,
1375bb6a25fSPoul-Henning Kamp   XML_CTYPE_NAME,
1385bb6a25fSPoul-Henning Kamp   XML_CTYPE_CHOICE,
1395bb6a25fSPoul-Henning Kamp   XML_CTYPE_SEQ
1405bb6a25fSPoul-Henning Kamp };
1415bb6a25fSPoul-Henning Kamp 
1425bb6a25fSPoul-Henning Kamp enum XML_Content_Quant {
1435bb6a25fSPoul-Henning Kamp   XML_CQUANT_NONE,
1445bb6a25fSPoul-Henning Kamp   XML_CQUANT_OPT,
1455bb6a25fSPoul-Henning Kamp   XML_CQUANT_REP,
1465bb6a25fSPoul-Henning Kamp   XML_CQUANT_PLUS
1475bb6a25fSPoul-Henning Kamp };
1485bb6a25fSPoul-Henning Kamp 
1495bb6a25fSPoul-Henning Kamp /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
1505bb6a25fSPoul-Henning Kamp    XML_CQUANT_NONE, and the other fields will be zero or NULL.
1515bb6a25fSPoul-Henning Kamp    If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
1525bb6a25fSPoul-Henning Kamp    numchildren will contain number of elements that may be mixed in
1535bb6a25fSPoul-Henning Kamp    and children point to an array of XML_Content cells that will be
1545bb6a25fSPoul-Henning Kamp    all of XML_CTYPE_NAME type with no quantification.
1555bb6a25fSPoul-Henning Kamp 
1565bb6a25fSPoul-Henning Kamp    If type == XML_CTYPE_NAME, then the name points to the name, and
1575bb6a25fSPoul-Henning Kamp    the numchildren field will be zero and children will be NULL. The
1585bb6a25fSPoul-Henning Kamp    quant fields indicates any quantifiers placed on the name.
1595bb6a25fSPoul-Henning Kamp 
1605bb6a25fSPoul-Henning Kamp    CHOICE and SEQ will have name NULL, the number of children in
1615bb6a25fSPoul-Henning Kamp    numchildren and children will point, recursively, to an array
1625bb6a25fSPoul-Henning Kamp    of XML_Content cells.
1635bb6a25fSPoul-Henning Kamp 
1645bb6a25fSPoul-Henning Kamp    The EMPTY, ANY, and MIXED types will only occur at top level.
1655bb6a25fSPoul-Henning Kamp */
1665bb6a25fSPoul-Henning Kamp 
1675bb6a25fSPoul-Henning Kamp typedef struct XML_cp XML_Content;
1685bb6a25fSPoul-Henning Kamp 
1695bb6a25fSPoul-Henning Kamp struct XML_cp {
1705bb6a25fSPoul-Henning Kamp   enum XML_Content_Type type;
1715bb6a25fSPoul-Henning Kamp   enum XML_Content_Quant quant;
1725bb6a25fSPoul-Henning Kamp   XML_Char *name;
1735bb6a25fSPoul-Henning Kamp   unsigned int numchildren;
1745bb6a25fSPoul-Henning Kamp   XML_Content *children;
1755bb6a25fSPoul-Henning Kamp };
1765bb6a25fSPoul-Henning Kamp 
1775bb6a25fSPoul-Henning Kamp /* This is called for an element declaration. See above for
178*7ed8e142SXin LI    description of the model argument. It's the user code's responsibility
179*7ed8e142SXin LI    to free model when finished with it. See XML_FreeContentModel.
180*7ed8e142SXin LI    There is no need to free the model from the handler, it can be kept
181*7ed8e142SXin LI    around and freed at a later stage.
1825bb6a25fSPoul-Henning Kamp */
183220ed979SColeman Kane typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData,
1845bb6a25fSPoul-Henning Kamp                                               const XML_Char *name,
1855bb6a25fSPoul-Henning Kamp                                               XML_Content *model);
1865bb6a25fSPoul-Henning Kamp 
1875bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
1886b2c1e49SXin LI XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl);
1895bb6a25fSPoul-Henning Kamp 
1905bb6a25fSPoul-Henning Kamp /* The Attlist declaration handler is called for *each* attribute. So
1915bb6a25fSPoul-Henning Kamp    a single Attlist declaration with multiple attributes declared will
1925bb6a25fSPoul-Henning Kamp    generate multiple calls to this handler. The "default" parameter
1935bb6a25fSPoul-Henning Kamp    may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
1945bb6a25fSPoul-Henning Kamp    keyword. The "isrequired" parameter will be true and the default
1955bb6a25fSPoul-Henning Kamp    value will be NULL in the case of "#REQUIRED". If "isrequired" is
1965bb6a25fSPoul-Henning Kamp    true and default is non-NULL, then this is a "#FIXED" default.
1975bb6a25fSPoul-Henning Kamp */
198220ed979SColeman Kane typedef void(XMLCALL *XML_AttlistDeclHandler)(
1996b2c1e49SXin LI     void *userData, const XML_Char *elname, const XML_Char *attname,
2006b2c1e49SXin LI     const XML_Char *att_type, const XML_Char *dflt, int isrequired);
2015bb6a25fSPoul-Henning Kamp 
2025bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
2036b2c1e49SXin LI XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl);
2045bb6a25fSPoul-Henning Kamp 
2055bb6a25fSPoul-Henning Kamp /* The XML declaration handler is called for *both* XML declarations
2065bb6a25fSPoul-Henning Kamp    and text declarations. The way to distinguish is that the version
2075bb6a25fSPoul-Henning Kamp    parameter will be NULL for text declarations. The encoding
2085bb6a25fSPoul-Henning Kamp    parameter may be NULL for XML declarations. The standalone
2095bb6a25fSPoul-Henning Kamp    parameter will be -1, 0, or 1 indicating respectively that there
2105bb6a25fSPoul-Henning Kamp    was no standalone parameter in the declaration, that it was given
2115bb6a25fSPoul-Henning Kamp    as no, or that it was given as yes.
2125bb6a25fSPoul-Henning Kamp */
213220ed979SColeman Kane typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData,
2145bb6a25fSPoul-Henning Kamp                                           const XML_Char *version,
2155bb6a25fSPoul-Henning Kamp                                           const XML_Char *encoding,
2165bb6a25fSPoul-Henning Kamp                                           int standalone);
2175bb6a25fSPoul-Henning Kamp 
2185bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
2196b2c1e49SXin LI XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl);
2205bb6a25fSPoul-Henning Kamp 
2215bb6a25fSPoul-Henning Kamp typedef struct {
2225bb6a25fSPoul-Henning Kamp   void *(*malloc_fcn)(size_t size);
2235bb6a25fSPoul-Henning Kamp   void *(*realloc_fcn)(void *ptr, size_t size);
2245bb6a25fSPoul-Henning Kamp   void (*free_fcn)(void *ptr);
2255bb6a25fSPoul-Henning Kamp } XML_Memory_Handling_Suite;
2265bb6a25fSPoul-Henning Kamp 
2275bb6a25fSPoul-Henning Kamp /* Constructs a new parser; encoding is the encoding specified by the
2285bb6a25fSPoul-Henning Kamp    external protocol or NULL if there is none specified.
2295bb6a25fSPoul-Henning Kamp */
2305bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
2315bb6a25fSPoul-Henning Kamp XML_ParserCreate(const XML_Char *encoding);
2325bb6a25fSPoul-Henning Kamp 
2335bb6a25fSPoul-Henning Kamp /* Constructs a new parser and namespace processor.  Element type
2345bb6a25fSPoul-Henning Kamp    names and attribute names that belong to a namespace will be
2355bb6a25fSPoul-Henning Kamp    expanded; unprefixed attribute names are never expanded; unprefixed
2365bb6a25fSPoul-Henning Kamp    element type names are expanded only if there is a default
2375bb6a25fSPoul-Henning Kamp    namespace. The expanded name is the concatenation of the namespace
2385bb6a25fSPoul-Henning Kamp    URI, the namespace separator character, and the local part of the
2395bb6a25fSPoul-Henning Kamp    name.  If the namespace separator is '\0' then the namespace URI
2405bb6a25fSPoul-Henning Kamp    and the local part will be concatenated without any separator.
241220ed979SColeman Kane    It is a programming error to use the separator '\0' with namespace
242220ed979SColeman Kane    triplets (see XML_SetReturnNSTriplet).
243*7ed8e142SXin LI    If a namespace separator is chosen that can be part of a URI or
244*7ed8e142SXin LI    part of an XML name, splitting an expanded name back into its
245*7ed8e142SXin LI    1, 2 or 3 original parts on application level in the element handler
246*7ed8e142SXin LI    may end up vulnerable, so these are advised against;  sane choices for
247*7ed8e142SXin LI    a namespace separator are e.g. '\n' (line feed) and '|' (pipe).
248*7ed8e142SXin LI 
249*7ed8e142SXin LI    Note that Expat does not validate namespace URIs (beyond encoding)
250*7ed8e142SXin LI    against RFC 3986 today (and is not required to do so with regard to
251*7ed8e142SXin LI    the XML 1.0 namespaces specification) but it may start doing that
252*7ed8e142SXin LI    in future releases.  Before that, an application using Expat must
253*7ed8e142SXin LI    be ready to receive namespace URIs containing non-URI characters.
2545bb6a25fSPoul-Henning Kamp */
2555bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
2565bb6a25fSPoul-Henning Kamp XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
2575bb6a25fSPoul-Henning Kamp 
258220ed979SColeman Kane /* Constructs a new parser using the memory management suite referred to
2595bb6a25fSPoul-Henning Kamp    by memsuite. If memsuite is NULL, then use the standard library memory
2605bb6a25fSPoul-Henning Kamp    suite. If namespaceSeparator is non-NULL it creates a parser with
2615bb6a25fSPoul-Henning Kamp    namespace processing as described above. The character pointed at
2625bb6a25fSPoul-Henning Kamp    will serve as the namespace separator.
2635bb6a25fSPoul-Henning Kamp 
2645bb6a25fSPoul-Henning Kamp    All further memory operations used for the created parser will come from
2655bb6a25fSPoul-Henning Kamp    the given suite.
2665bb6a25fSPoul-Henning Kamp */
2675bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
2685bb6a25fSPoul-Henning Kamp XML_ParserCreate_MM(const XML_Char *encoding,
2695bb6a25fSPoul-Henning Kamp                     const XML_Memory_Handling_Suite *memsuite,
2705bb6a25fSPoul-Henning Kamp                     const XML_Char *namespaceSeparator);
2715bb6a25fSPoul-Henning Kamp 
2725bb6a25fSPoul-Henning Kamp /* Prepare a parser object to be re-used.  This is particularly
2730a48773fSEric van Gyzen    valuable when memory allocation overhead is disproportionately high,
2745bb6a25fSPoul-Henning Kamp    such as when a large number of small documnents need to be parsed.
2755bb6a25fSPoul-Henning Kamp    All handlers are cleared from the parser, except for the
2765bb6a25fSPoul-Henning Kamp    unknownEncodingHandler. The parser's external state is re-initialized
2775bb6a25fSPoul-Henning Kamp    except for the values of ns and ns_triplets.
2785bb6a25fSPoul-Henning Kamp 
2795bb6a25fSPoul-Henning Kamp    Added in Expat 1.95.3.
2805bb6a25fSPoul-Henning Kamp */
2815bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Bool)
2825bb6a25fSPoul-Henning Kamp XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
2835bb6a25fSPoul-Henning Kamp 
2845bb6a25fSPoul-Henning Kamp /* atts is array of name/value pairs, terminated by 0;
2855bb6a25fSPoul-Henning Kamp    names and values are 0 terminated.
2865bb6a25fSPoul-Henning Kamp */
287220ed979SColeman Kane typedef void(XMLCALL *XML_StartElementHandler)(void *userData,
2885bb6a25fSPoul-Henning Kamp                                                const XML_Char *name,
2895bb6a25fSPoul-Henning Kamp                                                const XML_Char **atts);
2905bb6a25fSPoul-Henning Kamp 
291220ed979SColeman Kane typedef void(XMLCALL *XML_EndElementHandler)(void *userData,
2925bb6a25fSPoul-Henning Kamp                                              const XML_Char *name);
2935bb6a25fSPoul-Henning Kamp 
2945bb6a25fSPoul-Henning Kamp /* s is not 0 terminated. */
295220ed979SColeman Kane typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData,
2966b2c1e49SXin LI                                                 const XML_Char *s, int len);
2975bb6a25fSPoul-Henning Kamp 
2985bb6a25fSPoul-Henning Kamp /* target and data are 0 terminated */
2996b2c1e49SXin LI typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,
3005bb6a25fSPoul-Henning Kamp                                                         const XML_Char *target,
3015bb6a25fSPoul-Henning Kamp                                                         const XML_Char *data);
3025bb6a25fSPoul-Henning Kamp 
3035bb6a25fSPoul-Henning Kamp /* data is 0 terminated */
3046b2c1e49SXin LI typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data);
3055bb6a25fSPoul-Henning Kamp 
306220ed979SColeman Kane typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData);
307220ed979SColeman Kane typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData);
3085bb6a25fSPoul-Henning Kamp 
3095bb6a25fSPoul-Henning Kamp /* This is called for any characters in the XML document for which
3105bb6a25fSPoul-Henning Kamp    there is no applicable handler.  This includes both characters that
3115bb6a25fSPoul-Henning Kamp    are part of markup which is of a kind that is not reported
3125bb6a25fSPoul-Henning Kamp    (comments, markup declarations), or characters that are part of a
3135bb6a25fSPoul-Henning Kamp    construct which could be reported but for which no handler has been
3145bb6a25fSPoul-Henning Kamp    supplied. The characters are passed exactly as they were in the XML
3155bb6a25fSPoul-Henning Kamp    document except that they will be encoded in UTF-8 or UTF-16.
3165bb6a25fSPoul-Henning Kamp    Line boundaries are not normalized. Note that a byte order mark
3175bb6a25fSPoul-Henning Kamp    character is not passed to the default handler. There are no
3185bb6a25fSPoul-Henning Kamp    guarantees about how characters are divided between calls to the
3195bb6a25fSPoul-Henning Kamp    default handler: for example, a comment might be split between
3205bb6a25fSPoul-Henning Kamp    multiple calls.
3215bb6a25fSPoul-Henning Kamp */
3226b2c1e49SXin LI typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s,
3235bb6a25fSPoul-Henning Kamp                                           int len);
3245bb6a25fSPoul-Henning Kamp 
3255bb6a25fSPoul-Henning Kamp /* This is called for the start of the DOCTYPE declaration, before
3265bb6a25fSPoul-Henning Kamp    any DTD or internal subset is parsed.
3275bb6a25fSPoul-Henning Kamp */
3286b2c1e49SXin LI typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,
3295bb6a25fSPoul-Henning Kamp                                                    const XML_Char *doctypeName,
3305bb6a25fSPoul-Henning Kamp                                                    const XML_Char *sysid,
3315bb6a25fSPoul-Henning Kamp                                                    const XML_Char *pubid,
3325bb6a25fSPoul-Henning Kamp                                                    int has_internal_subset);
3335bb6a25fSPoul-Henning Kamp 
334*7ed8e142SXin LI /* This is called for the end of the DOCTYPE declaration when the
3355bb6a25fSPoul-Henning Kamp    closing > is encountered, but after processing any external
3365bb6a25fSPoul-Henning Kamp    subset.
3375bb6a25fSPoul-Henning Kamp */
338220ed979SColeman Kane typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
3395bb6a25fSPoul-Henning Kamp 
3405bb6a25fSPoul-Henning Kamp /* This is called for entity declarations. The is_parameter_entity
3415bb6a25fSPoul-Henning Kamp    argument will be non-zero if the entity is a parameter entity, zero
3425bb6a25fSPoul-Henning Kamp    otherwise.
3435bb6a25fSPoul-Henning Kamp 
3445bb6a25fSPoul-Henning Kamp    For internal entities (<!ENTITY foo "bar">), value will
3455bb6a25fSPoul-Henning Kamp    be non-NULL and systemId, publicID, and notationName will be NULL.
346cc68614dSXin LI    The value string is NOT null-terminated; the length is provided in
3475bb6a25fSPoul-Henning Kamp    the value_length argument. Since it is legal to have zero-length
3485bb6a25fSPoul-Henning Kamp    values, do not use this argument to test for internal entities.
3495bb6a25fSPoul-Henning Kamp 
3505bb6a25fSPoul-Henning Kamp    For external entities, value will be NULL and systemId will be
3515bb6a25fSPoul-Henning Kamp    non-NULL. The publicId argument will be NULL unless a public
3525bb6a25fSPoul-Henning Kamp    identifier was provided. The notationName argument will have a
3535bb6a25fSPoul-Henning Kamp    non-NULL value only for unparsed entity declarations.
3545bb6a25fSPoul-Henning Kamp 
3555bb6a25fSPoul-Henning Kamp    Note that is_parameter_entity can't be changed to XML_Bool, since
3565bb6a25fSPoul-Henning Kamp    that would break binary compatibility.
3575bb6a25fSPoul-Henning Kamp */
358220ed979SColeman Kane typedef void(XMLCALL *XML_EntityDeclHandler)(
3596b2c1e49SXin LI     void *userData, const XML_Char *entityName, int is_parameter_entity,
3606b2c1e49SXin LI     const XML_Char *value, int value_length, const XML_Char *base,
3616b2c1e49SXin LI     const XML_Char *systemId, const XML_Char *publicId,
3625bb6a25fSPoul-Henning Kamp     const XML_Char *notationName);
3635bb6a25fSPoul-Henning Kamp 
3645bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
3656b2c1e49SXin LI XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler);
3665bb6a25fSPoul-Henning Kamp 
3675bb6a25fSPoul-Henning Kamp /* OBSOLETE -- OBSOLETE -- OBSOLETE
368be8aff81SXin LI    This handler has been superseded by the EntityDeclHandler above.
3695bb6a25fSPoul-Henning Kamp    It is provided here for backward compatibility.
3705bb6a25fSPoul-Henning Kamp 
3715bb6a25fSPoul-Henning Kamp    This is called for a declaration of an unparsed (NDATA) entity.
3725bb6a25fSPoul-Henning Kamp    The base argument is whatever was set by XML_SetBase. The
3735bb6a25fSPoul-Henning Kamp    entityName, systemId and notationName arguments will never be
3745bb6a25fSPoul-Henning Kamp    NULL. The other arguments may be.
3755bb6a25fSPoul-Henning Kamp */
376220ed979SColeman Kane typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)(
3776b2c1e49SXin LI     void *userData, const XML_Char *entityName, const XML_Char *base,
3786b2c1e49SXin LI     const XML_Char *systemId, const XML_Char *publicId,
3795bb6a25fSPoul-Henning Kamp     const XML_Char *notationName);
3805bb6a25fSPoul-Henning Kamp 
3815bb6a25fSPoul-Henning Kamp /* This is called for a declaration of notation.  The base argument is
3825bb6a25fSPoul-Henning Kamp    whatever was set by XML_SetBase. The notationName will never be
3835bb6a25fSPoul-Henning Kamp    NULL.  The other arguments can be.
3845bb6a25fSPoul-Henning Kamp */
3856b2c1e49SXin LI typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData,
3865bb6a25fSPoul-Henning Kamp                                                const XML_Char *notationName,
3875bb6a25fSPoul-Henning Kamp                                                const XML_Char *base,
3885bb6a25fSPoul-Henning Kamp                                                const XML_Char *systemId,
3895bb6a25fSPoul-Henning Kamp                                                const XML_Char *publicId);
3905bb6a25fSPoul-Henning Kamp 
3915bb6a25fSPoul-Henning Kamp /* When namespace processing is enabled, these are called once for
3925bb6a25fSPoul-Henning Kamp    each namespace declaration. The call to the start and end element
3935bb6a25fSPoul-Henning Kamp    handlers occur between the calls to the start and end namespace
3945bb6a25fSPoul-Henning Kamp    declaration handlers. For an xmlns attribute, prefix will be
3955bb6a25fSPoul-Henning Kamp    NULL.  For an xmlns="" attribute, uri will be NULL.
3965bb6a25fSPoul-Henning Kamp */
3976b2c1e49SXin LI typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,
3985bb6a25fSPoul-Henning Kamp                                                      const XML_Char *prefix,
3995bb6a25fSPoul-Henning Kamp                                                      const XML_Char *uri);
4005bb6a25fSPoul-Henning Kamp 
4016b2c1e49SXin LI typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,
4025bb6a25fSPoul-Henning Kamp                                                    const XML_Char *prefix);
4035bb6a25fSPoul-Henning Kamp 
4045bb6a25fSPoul-Henning Kamp /* This is called if the document is not standalone, that is, it has an
4055bb6a25fSPoul-Henning Kamp    external subset or a reference to a parameter entity, but does not
406220ed979SColeman Kane    have standalone="yes". If this handler returns XML_STATUS_ERROR,
407220ed979SColeman Kane    then processing will not continue, and the parser will return a
4085bb6a25fSPoul-Henning Kamp    XML_ERROR_NOT_STANDALONE error.
4095bb6a25fSPoul-Henning Kamp    If parameter entity parsing is enabled, then in addition to the
4105bb6a25fSPoul-Henning Kamp    conditions above this handler will only be called if the referenced
4115bb6a25fSPoul-Henning Kamp    entity was actually read.
4125bb6a25fSPoul-Henning Kamp */
413220ed979SColeman Kane typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData);
4145bb6a25fSPoul-Henning Kamp 
4155bb6a25fSPoul-Henning Kamp /* This is called for a reference to an external parsed general
4165bb6a25fSPoul-Henning Kamp    entity.  The referenced entity is not automatically parsed.  The
4175bb6a25fSPoul-Henning Kamp    application can parse it immediately or later using
4185bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate.
4195bb6a25fSPoul-Henning Kamp 
4205bb6a25fSPoul-Henning Kamp    The parser argument is the parser parsing the entity containing the
4215bb6a25fSPoul-Henning Kamp    reference; it can be passed as the parser argument to
4225bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate.  The systemId argument is the
4235bb6a25fSPoul-Henning Kamp    system identifier as specified in the entity declaration; it will
4245bb6a25fSPoul-Henning Kamp    not be NULL.
4255bb6a25fSPoul-Henning Kamp 
4265bb6a25fSPoul-Henning Kamp    The base argument is the system identifier that should be used as
4275bb6a25fSPoul-Henning Kamp    the base for resolving systemId if systemId was relative; this is
4285bb6a25fSPoul-Henning Kamp    set by XML_SetBase; it may be NULL.
4295bb6a25fSPoul-Henning Kamp 
4305bb6a25fSPoul-Henning Kamp    The publicId argument is the public identifier as specified in the
4315bb6a25fSPoul-Henning Kamp    entity declaration, or NULL if none was specified; the whitespace
4325bb6a25fSPoul-Henning Kamp    in the public identifier will have been normalized as required by
4335bb6a25fSPoul-Henning Kamp    the XML spec.
4345bb6a25fSPoul-Henning Kamp 
4355bb6a25fSPoul-Henning Kamp    The context argument specifies the parsing context in the format
4365bb6a25fSPoul-Henning Kamp    expected by the context argument to XML_ExternalEntityParserCreate;
4375bb6a25fSPoul-Henning Kamp    context is valid only until the handler returns, so if the
4385bb6a25fSPoul-Henning Kamp    referenced entity is to be parsed later, it must be copied.
439220ed979SColeman Kane    context is NULL only when the entity is a parameter entity.
4405bb6a25fSPoul-Henning Kamp 
441220ed979SColeman Kane    The handler should return XML_STATUS_ERROR if processing should not
442220ed979SColeman Kane    continue because of a fatal error in the handling of the external
443220ed979SColeman Kane    entity.  In this case the calling parser will return an
4445bb6a25fSPoul-Henning Kamp    XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
4455bb6a25fSPoul-Henning Kamp 
4465bb6a25fSPoul-Henning Kamp    Note that unlike other handlers the first argument is the parser,
4475bb6a25fSPoul-Henning Kamp    not userData.
4485bb6a25fSPoul-Henning Kamp */
4496b2c1e49SXin LI typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser,
4505bb6a25fSPoul-Henning Kamp                                                    const XML_Char *context,
4515bb6a25fSPoul-Henning Kamp                                                    const XML_Char *base,
4525bb6a25fSPoul-Henning Kamp                                                    const XML_Char *systemId,
4535bb6a25fSPoul-Henning Kamp                                                    const XML_Char *publicId);
4545bb6a25fSPoul-Henning Kamp 
4555bb6a25fSPoul-Henning Kamp /* This is called in two situations:
4565bb6a25fSPoul-Henning Kamp    1) An entity reference is encountered for which no declaration
4575bb6a25fSPoul-Henning Kamp       has been read *and* this is not an error.
4585bb6a25fSPoul-Henning Kamp    2) An internal entity reference is read, but not expanded, because
4595bb6a25fSPoul-Henning Kamp       XML_SetDefaultHandler has been called.
4605bb6a25fSPoul-Henning Kamp    Note: skipped parameter entities in declarations and skipped general
4615bb6a25fSPoul-Henning Kamp          entities in attribute values cannot be reported, because
4625bb6a25fSPoul-Henning Kamp          the event would be out of sync with the reporting of the
4635bb6a25fSPoul-Henning Kamp          declarations or attribute values
4645bb6a25fSPoul-Henning Kamp */
4656b2c1e49SXin LI typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData,
4665bb6a25fSPoul-Henning Kamp                                                 const XML_Char *entityName,
4675bb6a25fSPoul-Henning Kamp                                                 int is_parameter_entity);
4685bb6a25fSPoul-Henning Kamp 
4695bb6a25fSPoul-Henning Kamp /* This structure is filled in by the XML_UnknownEncodingHandler to
4705bb6a25fSPoul-Henning Kamp    provide information to the parser about encodings that are unknown
4715bb6a25fSPoul-Henning Kamp    to the parser.
4725bb6a25fSPoul-Henning Kamp 
4735bb6a25fSPoul-Henning Kamp    The map[b] member gives information about byte sequences whose
4745bb6a25fSPoul-Henning Kamp    first byte is b.
4755bb6a25fSPoul-Henning Kamp 
4765bb6a25fSPoul-Henning Kamp    If map[b] is c where c is >= 0, then b by itself encodes the
4775bb6a25fSPoul-Henning Kamp    Unicode scalar value c.
4785bb6a25fSPoul-Henning Kamp 
4795bb6a25fSPoul-Henning Kamp    If map[b] is -1, then the byte sequence is malformed.
4805bb6a25fSPoul-Henning Kamp 
4815bb6a25fSPoul-Henning Kamp    If map[b] is -n, where n >= 2, then b is the first byte of an
4825bb6a25fSPoul-Henning Kamp    n-byte sequence that encodes a single Unicode scalar value.
4835bb6a25fSPoul-Henning Kamp 
4845bb6a25fSPoul-Henning Kamp    The data member will be passed as the first argument to the convert
4855bb6a25fSPoul-Henning Kamp    function.
4865bb6a25fSPoul-Henning Kamp 
4875bb6a25fSPoul-Henning Kamp    The convert function is used to convert multibyte sequences; s will
4885bb6a25fSPoul-Henning Kamp    point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
4895bb6a25fSPoul-Henning Kamp    convert function must return the Unicode scalar value represented
4905bb6a25fSPoul-Henning Kamp    by this byte sequence or -1 if the byte sequence is malformed.
4915bb6a25fSPoul-Henning Kamp 
4925bb6a25fSPoul-Henning Kamp    The convert function may be NULL if the encoding is a single-byte
4935bb6a25fSPoul-Henning Kamp    encoding, that is if map[b] >= -1 for all bytes b.
4945bb6a25fSPoul-Henning Kamp 
4955bb6a25fSPoul-Henning Kamp    When the parser is finished with the encoding, then if release is
4965bb6a25fSPoul-Henning Kamp    not NULL, it will call release passing it the data member; once
4975bb6a25fSPoul-Henning Kamp    release has been called, the convert function will not be called
4985bb6a25fSPoul-Henning Kamp    again.
4995bb6a25fSPoul-Henning Kamp 
5005bb6a25fSPoul-Henning Kamp    Expat places certain restrictions on the encodings that are supported
5015bb6a25fSPoul-Henning Kamp    using this mechanism.
5025bb6a25fSPoul-Henning Kamp 
5035bb6a25fSPoul-Henning Kamp    1. Every ASCII character that can appear in a well-formed XML document,
5045bb6a25fSPoul-Henning Kamp       other than the characters
5055bb6a25fSPoul-Henning Kamp 
5065bb6a25fSPoul-Henning Kamp       $@\^`{}~
5075bb6a25fSPoul-Henning Kamp 
5085bb6a25fSPoul-Henning Kamp       must be represented by a single byte, and that byte must be the
5095bb6a25fSPoul-Henning Kamp       same byte that represents that character in ASCII.
5105bb6a25fSPoul-Henning Kamp 
5115bb6a25fSPoul-Henning Kamp    2. No character may require more than 4 bytes to encode.
5125bb6a25fSPoul-Henning Kamp 
5135bb6a25fSPoul-Henning Kamp    3. All characters encoded must have Unicode scalar values <=
5145bb6a25fSPoul-Henning Kamp       0xFFFF, (i.e., characters that would be encoded by surrogates in
5155bb6a25fSPoul-Henning Kamp       UTF-16 are  not allowed).  Note that this restriction doesn't
5165bb6a25fSPoul-Henning Kamp       apply to the built-in support for UTF-8 and UTF-16.
5175bb6a25fSPoul-Henning Kamp 
5185bb6a25fSPoul-Henning Kamp    4. No Unicode character may be encoded by more than one distinct
5195bb6a25fSPoul-Henning Kamp       sequence of bytes.
5205bb6a25fSPoul-Henning Kamp */
5215bb6a25fSPoul-Henning Kamp typedef struct {
5225bb6a25fSPoul-Henning Kamp   int map[256];
5235bb6a25fSPoul-Henning Kamp   void *data;
524220ed979SColeman Kane   int(XMLCALL *convert)(void *data, const char *s);
525220ed979SColeman Kane   void(XMLCALL *release)(void *data);
5265bb6a25fSPoul-Henning Kamp } XML_Encoding;
5275bb6a25fSPoul-Henning Kamp 
5285bb6a25fSPoul-Henning Kamp /* This is called for an encoding that is unknown to the parser.
5295bb6a25fSPoul-Henning Kamp 
5305bb6a25fSPoul-Henning Kamp    The encodingHandlerData argument is that which was passed as the
5315bb6a25fSPoul-Henning Kamp    second argument to XML_SetUnknownEncodingHandler.
5325bb6a25fSPoul-Henning Kamp 
5335bb6a25fSPoul-Henning Kamp    The name argument gives the name of the encoding as specified in
5345bb6a25fSPoul-Henning Kamp    the encoding declaration.
5355bb6a25fSPoul-Henning Kamp 
5365bb6a25fSPoul-Henning Kamp    If the callback can provide information about the encoding, it must
537220ed979SColeman Kane    fill in the XML_Encoding structure, and return XML_STATUS_OK.
538220ed979SColeman Kane    Otherwise it must return XML_STATUS_ERROR.
5395bb6a25fSPoul-Henning Kamp 
5405bb6a25fSPoul-Henning Kamp    If info does not describe a suitable encoding, then the parser will
541cc68614dSXin LI    return an XML_ERROR_UNKNOWN_ENCODING error.
5425bb6a25fSPoul-Henning Kamp */
5436b2c1e49SXin LI typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
5445bb6a25fSPoul-Henning Kamp                                                  const XML_Char *name,
5455bb6a25fSPoul-Henning Kamp                                                  XML_Encoding *info);
5465bb6a25fSPoul-Henning Kamp 
5475bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5486b2c1e49SXin LI XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start,
5495bb6a25fSPoul-Henning Kamp                       XML_EndElementHandler end);
5505bb6a25fSPoul-Henning Kamp 
5515bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5526b2c1e49SXin LI XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler);
5535bb6a25fSPoul-Henning Kamp 
5545bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5556b2c1e49SXin LI XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler);
5565bb6a25fSPoul-Henning Kamp 
5575bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5585bb6a25fSPoul-Henning Kamp XML_SetCharacterDataHandler(XML_Parser parser,
5595bb6a25fSPoul-Henning Kamp                             XML_CharacterDataHandler handler);
5605bb6a25fSPoul-Henning Kamp 
5615bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5625bb6a25fSPoul-Henning Kamp XML_SetProcessingInstructionHandler(XML_Parser parser,
5635bb6a25fSPoul-Henning Kamp                                     XML_ProcessingInstructionHandler handler);
5645bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5656b2c1e49SXin LI XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler);
5665bb6a25fSPoul-Henning Kamp 
5675bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5685bb6a25fSPoul-Henning Kamp XML_SetCdataSectionHandler(XML_Parser parser,
5695bb6a25fSPoul-Henning Kamp                            XML_StartCdataSectionHandler start,
5705bb6a25fSPoul-Henning Kamp                            XML_EndCdataSectionHandler end);
5715bb6a25fSPoul-Henning Kamp 
5725bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5735bb6a25fSPoul-Henning Kamp XML_SetStartCdataSectionHandler(XML_Parser parser,
5745bb6a25fSPoul-Henning Kamp                                 XML_StartCdataSectionHandler start);
5755bb6a25fSPoul-Henning Kamp 
5765bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5775bb6a25fSPoul-Henning Kamp XML_SetEndCdataSectionHandler(XML_Parser parser,
5785bb6a25fSPoul-Henning Kamp                               XML_EndCdataSectionHandler end);
5795bb6a25fSPoul-Henning Kamp 
5805bb6a25fSPoul-Henning Kamp /* This sets the default handler and also inhibits expansion of
5815bb6a25fSPoul-Henning Kamp    internal entities. These entity references will be passed to the
5825bb6a25fSPoul-Henning Kamp    default handler, or to the skipped entity handler, if one is set.
5835bb6a25fSPoul-Henning Kamp */
5845bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5856b2c1e49SXin LI XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler);
5865bb6a25fSPoul-Henning Kamp 
5875bb6a25fSPoul-Henning Kamp /* This sets the default handler but does not inhibit expansion of
5885bb6a25fSPoul-Henning Kamp    internal entities.  The entity reference will not be passed to the
5895bb6a25fSPoul-Henning Kamp    default handler.
5905bb6a25fSPoul-Henning Kamp */
5915bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5926b2c1e49SXin LI XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler);
5935bb6a25fSPoul-Henning Kamp 
5945bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5956b2c1e49SXin LI XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start,
5965bb6a25fSPoul-Henning Kamp                           XML_EndDoctypeDeclHandler end);
5975bb6a25fSPoul-Henning Kamp 
5985bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
5995bb6a25fSPoul-Henning Kamp XML_SetStartDoctypeDeclHandler(XML_Parser parser,
6005bb6a25fSPoul-Henning Kamp                                XML_StartDoctypeDeclHandler start);
6015bb6a25fSPoul-Henning Kamp 
6025bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6036b2c1e49SXin LI XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end);
6045bb6a25fSPoul-Henning Kamp 
6055bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6065bb6a25fSPoul-Henning Kamp XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
6075bb6a25fSPoul-Henning Kamp                                  XML_UnparsedEntityDeclHandler handler);
6085bb6a25fSPoul-Henning Kamp 
6095bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6106b2c1e49SXin LI XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler);
6115bb6a25fSPoul-Henning Kamp 
6125bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6135bb6a25fSPoul-Henning Kamp XML_SetNamespaceDeclHandler(XML_Parser parser,
6145bb6a25fSPoul-Henning Kamp                             XML_StartNamespaceDeclHandler start,
6155bb6a25fSPoul-Henning Kamp                             XML_EndNamespaceDeclHandler end);
6165bb6a25fSPoul-Henning Kamp 
6175bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6185bb6a25fSPoul-Henning Kamp XML_SetStartNamespaceDeclHandler(XML_Parser parser,
6195bb6a25fSPoul-Henning Kamp                                  XML_StartNamespaceDeclHandler start);
6205bb6a25fSPoul-Henning Kamp 
6215bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6225bb6a25fSPoul-Henning Kamp XML_SetEndNamespaceDeclHandler(XML_Parser parser,
6235bb6a25fSPoul-Henning Kamp                                XML_EndNamespaceDeclHandler end);
6245bb6a25fSPoul-Henning Kamp 
6255bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6265bb6a25fSPoul-Henning Kamp XML_SetNotStandaloneHandler(XML_Parser parser,
6275bb6a25fSPoul-Henning Kamp                             XML_NotStandaloneHandler handler);
6285bb6a25fSPoul-Henning Kamp 
6295bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6305bb6a25fSPoul-Henning Kamp XML_SetExternalEntityRefHandler(XML_Parser parser,
6315bb6a25fSPoul-Henning Kamp                                 XML_ExternalEntityRefHandler handler);
6325bb6a25fSPoul-Henning Kamp 
6335bb6a25fSPoul-Henning Kamp /* If a non-NULL value for arg is specified here, then it will be
6345bb6a25fSPoul-Henning Kamp    passed as the first argument to the external entity ref handler
6355bb6a25fSPoul-Henning Kamp    instead of the parser object.
6365bb6a25fSPoul-Henning Kamp */
6375bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6386b2c1e49SXin LI XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg);
6395bb6a25fSPoul-Henning Kamp 
6405bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6415bb6a25fSPoul-Henning Kamp XML_SetSkippedEntityHandler(XML_Parser parser,
6425bb6a25fSPoul-Henning Kamp                             XML_SkippedEntityHandler handler);
6435bb6a25fSPoul-Henning Kamp 
6445bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6455bb6a25fSPoul-Henning Kamp XML_SetUnknownEncodingHandler(XML_Parser parser,
6465bb6a25fSPoul-Henning Kamp                               XML_UnknownEncodingHandler handler,
6475bb6a25fSPoul-Henning Kamp                               void *encodingHandlerData);
6485bb6a25fSPoul-Henning Kamp 
6495bb6a25fSPoul-Henning Kamp /* This can be called within a handler for a start element, end
6505bb6a25fSPoul-Henning Kamp    element, processing instruction or character data.  It causes the
6515bb6a25fSPoul-Henning Kamp    corresponding markup to be passed to the default handler.
6525bb6a25fSPoul-Henning Kamp */
6535bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6545bb6a25fSPoul-Henning Kamp XML_DefaultCurrent(XML_Parser parser);
6555bb6a25fSPoul-Henning Kamp 
6565bb6a25fSPoul-Henning Kamp /* If do_nst is non-zero, and namespace processing is in effect, and
6575bb6a25fSPoul-Henning Kamp    a name has a prefix (i.e. an explicit namespace qualifier) then
6585bb6a25fSPoul-Henning Kamp    that name is returned as a triplet in a single string separated by
6595bb6a25fSPoul-Henning Kamp    the separator character specified when the parser was created: URI
6605bb6a25fSPoul-Henning Kamp    + sep + local_name + sep + prefix.
6615bb6a25fSPoul-Henning Kamp 
6625bb6a25fSPoul-Henning Kamp    If do_nst is zero, then namespace information is returned in the
6635bb6a25fSPoul-Henning Kamp    default manner (URI + sep + local_name) whether or not the name
6645bb6a25fSPoul-Henning Kamp    has a prefix.
6655bb6a25fSPoul-Henning Kamp 
6665bb6a25fSPoul-Henning Kamp    Note: Calling XML_SetReturnNSTriplet after XML_Parse or
6675bb6a25fSPoul-Henning Kamp      XML_ParseBuffer has no effect.
6685bb6a25fSPoul-Henning Kamp */
6695bb6a25fSPoul-Henning Kamp 
6705bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6715bb6a25fSPoul-Henning Kamp XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
6725bb6a25fSPoul-Henning Kamp 
6735bb6a25fSPoul-Henning Kamp /* This value is passed as the userData argument to callbacks. */
6745bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6755bb6a25fSPoul-Henning Kamp XML_SetUserData(XML_Parser parser, void *userData);
6765bb6a25fSPoul-Henning Kamp 
6775bb6a25fSPoul-Henning Kamp /* Returns the last value set by XML_SetUserData or NULL. */
6785bb6a25fSPoul-Henning Kamp #define XML_GetUserData(parser) (*(void **)(parser))
6795bb6a25fSPoul-Henning Kamp 
6805bb6a25fSPoul-Henning Kamp /* This is equivalent to supplying an encoding argument to
6815bb6a25fSPoul-Henning Kamp    XML_ParserCreate. On success XML_SetEncoding returns non-zero,
6825bb6a25fSPoul-Henning Kamp    zero otherwise.
6835bb6a25fSPoul-Henning Kamp    Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
684220ed979SColeman Kane      has no effect and returns XML_STATUS_ERROR.
6855bb6a25fSPoul-Henning Kamp */
686220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
6875bb6a25fSPoul-Henning Kamp XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
6885bb6a25fSPoul-Henning Kamp 
6895bb6a25fSPoul-Henning Kamp /* If this function is called, then the parser will be passed as the
6905bb6a25fSPoul-Henning Kamp    first argument to callbacks instead of userData.  The userData will
6915bb6a25fSPoul-Henning Kamp    still be accessible using XML_GetUserData.
6925bb6a25fSPoul-Henning Kamp */
6935bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
6945bb6a25fSPoul-Henning Kamp XML_UseParserAsHandlerArg(XML_Parser parser);
6955bb6a25fSPoul-Henning Kamp 
6965bb6a25fSPoul-Henning Kamp /* If useDTD == XML_TRUE is passed to this function, then the parser
6975bb6a25fSPoul-Henning Kamp    will assume that there is an external subset, even if none is
6985bb6a25fSPoul-Henning Kamp    specified in the document. In such a case the parser will call the
6995bb6a25fSPoul-Henning Kamp    externalEntityRefHandler with a value of NULL for the systemId
7005bb6a25fSPoul-Henning Kamp    argument (the publicId and context arguments will be NULL as well).
701220ed979SColeman Kane    Note: For the purpose of checking WFC: Entity Declared, passing
702220ed979SColeman Kane      useDTD == XML_TRUE will make the parser behave as if the document
703220ed979SColeman Kane      had a DTD with an external subset.
7045bb6a25fSPoul-Henning Kamp    Note: If this function is called, then this must be done before
7055bb6a25fSPoul-Henning Kamp      the first call to XML_Parse or XML_ParseBuffer, since it will
7065bb6a25fSPoul-Henning Kamp      have no effect after that.  Returns
7075bb6a25fSPoul-Henning Kamp      XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
7085bb6a25fSPoul-Henning Kamp    Note: If the document does not have a DOCTYPE declaration at all,
7095bb6a25fSPoul-Henning Kamp      then startDoctypeDeclHandler and endDoctypeDeclHandler will not
7105bb6a25fSPoul-Henning Kamp      be called, despite an external subset being parsed.
7115bb6a25fSPoul-Henning Kamp    Note: If XML_DTD is not defined when Expat is compiled, returns
7125bb6a25fSPoul-Henning Kamp      XML_ERROR_FEATURE_REQUIRES_XML_DTD.
7130a48773fSEric van Gyzen    Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT.
7145bb6a25fSPoul-Henning Kamp */
7155bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Error)
7165bb6a25fSPoul-Henning Kamp XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
7175bb6a25fSPoul-Henning Kamp 
7185bb6a25fSPoul-Henning Kamp /* Sets the base to be used for resolving relative URIs in system
7195bb6a25fSPoul-Henning Kamp    identifiers in declarations.  Resolving relative identifiers is
7205bb6a25fSPoul-Henning Kamp    left to the application: this value will be passed through as the
7215bb6a25fSPoul-Henning Kamp    base argument to the XML_ExternalEntityRefHandler,
7225bb6a25fSPoul-Henning Kamp    XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
723220ed979SColeman Kane    argument will be copied.  Returns XML_STATUS_ERROR if out of memory,
724220ed979SColeman Kane    XML_STATUS_OK otherwise.
7255bb6a25fSPoul-Henning Kamp */
726220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
7275bb6a25fSPoul-Henning Kamp XML_SetBase(XML_Parser parser, const XML_Char *base);
7285bb6a25fSPoul-Henning Kamp 
7295bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_Char *)
7305bb6a25fSPoul-Henning Kamp XML_GetBase(XML_Parser parser);
7315bb6a25fSPoul-Henning Kamp 
7325bb6a25fSPoul-Henning Kamp /* Returns the number of the attribute/value pairs passed in last call
7335bb6a25fSPoul-Henning Kamp    to the XML_StartElementHandler that were specified in the start-tag
7345bb6a25fSPoul-Henning Kamp    rather than defaulted. Each attribute/value pair counts as 2; thus
735cc68614dSXin LI    this corresponds to an index into the atts array passed to the
7360a48773fSEric van Gyzen    XML_StartElementHandler.  Returns -1 if parser == NULL.
7375bb6a25fSPoul-Henning Kamp */
7385bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
7395bb6a25fSPoul-Henning Kamp XML_GetSpecifiedAttributeCount(XML_Parser parser);
7405bb6a25fSPoul-Henning Kamp 
7415bb6a25fSPoul-Henning Kamp /* Returns the index of the ID attribute passed in the last call to
7420a48773fSEric van Gyzen    XML_StartElementHandler, or -1 if there is no ID attribute or
7430a48773fSEric van Gyzen    parser == NULL.  Each attribute/value pair counts as 2; thus this
744cc68614dSXin LI    corresponds to an index into the atts array passed to the
7450a48773fSEric van Gyzen    XML_StartElementHandler.
7465bb6a25fSPoul-Henning Kamp */
7475bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
7485bb6a25fSPoul-Henning Kamp XML_GetIdAttributeIndex(XML_Parser parser);
7495bb6a25fSPoul-Henning Kamp 
750e3466a89SXin LI #ifdef XML_ATTR_INFO
751e3466a89SXin LI /* Source file byte offsets for the start and end of attribute names and values.
752e3466a89SXin LI    The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
753e3466a89SXin LI    file an attribute value of "blah" will yield:
754e3466a89SXin LI    info->valueEnd - info->valueStart = 4 bytes.
755e3466a89SXin LI */
756e3466a89SXin LI typedef struct {
757e3466a89SXin LI   XML_Index nameStart;  /* Offset to beginning of the attribute name. */
758e3466a89SXin LI   XML_Index nameEnd;    /* Offset after the attribute name's last byte. */
759e3466a89SXin LI   XML_Index valueStart; /* Offset to beginning of the attribute value. */
760e3466a89SXin LI   XML_Index valueEnd;   /* Offset after the attribute value's last byte. */
761e3466a89SXin LI } XML_AttrInfo;
762e3466a89SXin LI 
763e3466a89SXin LI /* Returns an array of XML_AttrInfo structures for the attribute/value pairs
764e3466a89SXin LI    passed in last call to the XML_StartElementHandler that were specified
765e3466a89SXin LI    in the start-tag rather than defaulted. Each attribute/value pair counts
766e3466a89SXin LI    as 1; thus the number of entries in the array is
767e3466a89SXin LI    XML_GetSpecifiedAttributeCount(parser) / 2.
768e3466a89SXin LI */
769e3466a89SXin LI XMLPARSEAPI(const XML_AttrInfo *)
770e3466a89SXin LI XML_GetAttributeInfo(XML_Parser parser);
771e3466a89SXin LI #endif
772e3466a89SXin LI 
7735bb6a25fSPoul-Henning Kamp /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
7745bb6a25fSPoul-Henning Kamp    detected.  The last call to XML_Parse must have isFinal true; len
7755bb6a25fSPoul-Henning Kamp    may be zero for this call (or any other).
7765bb6a25fSPoul-Henning Kamp 
777220ed979SColeman Kane    Though the return values for these functions has always been
778220ed979SColeman Kane    described as a Boolean value, the implementation, at least for the
779220ed979SColeman Kane    1.95.x series, has always returned exactly one of the XML_Status
780220ed979SColeman Kane    values.
7815bb6a25fSPoul-Henning Kamp */
7825bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Status)
7835bb6a25fSPoul-Henning Kamp XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
7845bb6a25fSPoul-Henning Kamp 
7855bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void *)
7865bb6a25fSPoul-Henning Kamp XML_GetBuffer(XML_Parser parser, int len);
7875bb6a25fSPoul-Henning Kamp 
7885bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Status)
7895bb6a25fSPoul-Henning Kamp XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
7905bb6a25fSPoul-Henning Kamp 
791220ed979SColeman Kane /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
792220ed979SColeman Kane    Must be called from within a call-back handler, except when aborting
793220ed979SColeman Kane    (resumable = 0) an already suspended parser. Some call-backs may
794220ed979SColeman Kane    still follow because they would otherwise get lost. Examples:
795220ed979SColeman Kane    - endElementHandler() for empty elements when stopped in
796220ed979SColeman Kane      startElementHandler(),
797220ed979SColeman Kane    - endNameSpaceDeclHandler() when stopped in endElementHandler(),
798220ed979SColeman Kane    and possibly others.
799220ed979SColeman Kane 
800220ed979SColeman Kane    Can be called from most handlers, including DTD related call-backs,
801220ed979SColeman Kane    except when parsing an external parameter entity and resumable != 0.
802220ed979SColeman Kane    Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
803220ed979SColeman Kane    Possible error codes:
804220ed979SColeman Kane    - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
805220ed979SColeman Kane    - XML_ERROR_FINISHED: when the parser has already finished.
806220ed979SColeman Kane    - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
807220ed979SColeman Kane 
808220ed979SColeman Kane    When resumable != 0 (true) then parsing is suspended, that is,
809220ed979SColeman Kane    XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
810220ed979SColeman Kane    Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
811220ed979SColeman Kane    return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
812220ed979SColeman Kane 
813220ed979SColeman Kane    *Note*:
814220ed979SColeman Kane    This will be applied to the current parser instance only, that is, if
815220ed979SColeman Kane    there is a parent parser then it will continue parsing when the
816220ed979SColeman Kane    externalEntityRefHandler() returns. It is up to the implementation of
817220ed979SColeman Kane    the externalEntityRefHandler() to call XML_StopParser() on the parent
818220ed979SColeman Kane    parser (recursively), if one wants to stop parsing altogether.
819220ed979SColeman Kane 
820220ed979SColeman Kane    When suspended, parsing can be resumed by calling XML_ResumeParser().
821220ed979SColeman Kane */
822220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
823220ed979SColeman Kane XML_StopParser(XML_Parser parser, XML_Bool resumable);
824220ed979SColeman Kane 
825220ed979SColeman Kane /* Resumes parsing after it has been suspended with XML_StopParser().
826220ed979SColeman Kane    Must not be called from within a handler call-back. Returns same
827220ed979SColeman Kane    status codes as XML_Parse() or XML_ParseBuffer().
828220ed979SColeman Kane    Additional error code XML_ERROR_NOT_SUSPENDED possible.
829220ed979SColeman Kane 
830220ed979SColeman Kane    *Note*:
831220ed979SColeman Kane    This must be called on the most deeply nested child parser instance
832220ed979SColeman Kane    first, and on its parent parser only after the child parser has finished,
833220ed979SColeman Kane    to be applied recursively until the document entity's parser is restarted.
834220ed979SColeman Kane    That is, the parent parser will not resume by itself and it is up to the
835220ed979SColeman Kane    application to call XML_ResumeParser() on it at the appropriate moment.
836220ed979SColeman Kane */
837220ed979SColeman Kane XMLPARSEAPI(enum XML_Status)
838220ed979SColeman Kane XML_ResumeParser(XML_Parser parser);
839220ed979SColeman Kane 
8406b2c1e49SXin LI enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED };
841220ed979SColeman Kane 
842220ed979SColeman Kane typedef struct {
843220ed979SColeman Kane   enum XML_Parsing parsing;
844220ed979SColeman Kane   XML_Bool finalBuffer;
845220ed979SColeman Kane } XML_ParsingStatus;
846220ed979SColeman Kane 
847220ed979SColeman Kane /* Returns status of parser with respect to being initialized, parsing,
848220ed979SColeman Kane    finished, or suspended and processing the final buffer.
849220ed979SColeman Kane    XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
850220ed979SColeman Kane    XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
851220ed979SColeman Kane */
852220ed979SColeman Kane XMLPARSEAPI(void)
853220ed979SColeman Kane XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
854220ed979SColeman Kane 
8555bb6a25fSPoul-Henning Kamp /* Creates an XML_Parser object that can parse an external general
8565bb6a25fSPoul-Henning Kamp    entity; context is a '\0'-terminated string specifying the parse
8575bb6a25fSPoul-Henning Kamp    context; encoding is a '\0'-terminated string giving the name of
8585bb6a25fSPoul-Henning Kamp    the externally specified encoding, or NULL if there is no
8595bb6a25fSPoul-Henning Kamp    externally specified encoding.  The context string consists of a
8605bb6a25fSPoul-Henning Kamp    sequence of tokens separated by formfeeds (\f); a token consisting
8615bb6a25fSPoul-Henning Kamp    of a name specifies that the general entity of the name is open; a
8625bb6a25fSPoul-Henning Kamp    token of the form prefix=uri specifies the namespace for a
8635bb6a25fSPoul-Henning Kamp    particular prefix; a token of the form =uri specifies the default
8645bb6a25fSPoul-Henning Kamp    namespace.  This can be called at any point after the first call to
8655bb6a25fSPoul-Henning Kamp    an ExternalEntityRefHandler so longer as the parser has not yet
8665bb6a25fSPoul-Henning Kamp    been freed.  The new parser is completely independent and may
8675bb6a25fSPoul-Henning Kamp    safely be used in a separate thread.  The handlers and userData are
868220ed979SColeman Kane    initialized from the parser argument.  Returns NULL if out of memory.
8695bb6a25fSPoul-Henning Kamp    Otherwise returns a new XML_Parser object.
8705bb6a25fSPoul-Henning Kamp */
8715bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Parser)
8726b2c1e49SXin LI XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context,
8735bb6a25fSPoul-Henning Kamp                                const XML_Char *encoding);
8745bb6a25fSPoul-Henning Kamp 
8755bb6a25fSPoul-Henning Kamp enum XML_ParamEntityParsing {
8765bb6a25fSPoul-Henning Kamp   XML_PARAM_ENTITY_PARSING_NEVER,
8775bb6a25fSPoul-Henning Kamp   XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
8785bb6a25fSPoul-Henning Kamp   XML_PARAM_ENTITY_PARSING_ALWAYS
8795bb6a25fSPoul-Henning Kamp };
8805bb6a25fSPoul-Henning Kamp 
8815bb6a25fSPoul-Henning Kamp /* Controls parsing of parameter entities (including the external DTD
8825bb6a25fSPoul-Henning Kamp    subset). If parsing of parameter entities is enabled, then
8835bb6a25fSPoul-Henning Kamp    references to external parameter entities (including the external
8845bb6a25fSPoul-Henning Kamp    DTD subset) will be passed to the handler set with
8855bb6a25fSPoul-Henning Kamp    XML_SetExternalEntityRefHandler.  The context passed will be 0.
8865bb6a25fSPoul-Henning Kamp 
8875bb6a25fSPoul-Henning Kamp    Unlike external general entities, external parameter entities can
8885bb6a25fSPoul-Henning Kamp    only be parsed synchronously.  If the external parameter entity is
8895bb6a25fSPoul-Henning Kamp    to be parsed, it must be parsed during the call to the external
8905bb6a25fSPoul-Henning Kamp    entity ref handler: the complete sequence of
8915bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
8925bb6a25fSPoul-Henning Kamp    XML_ParserFree calls must be made during this call.  After
8935bb6a25fSPoul-Henning Kamp    XML_ExternalEntityParserCreate has been called to create the parser
8945bb6a25fSPoul-Henning Kamp    for the external parameter entity (context must be 0 for this
8955bb6a25fSPoul-Henning Kamp    call), it is illegal to make any calls on the old parser until
8965bb6a25fSPoul-Henning Kamp    XML_ParserFree has been called on the newly created parser.
8975bb6a25fSPoul-Henning Kamp    If the library has been compiled without support for parameter
8985bb6a25fSPoul-Henning Kamp    entity parsing (ie without XML_DTD being defined), then
8995bb6a25fSPoul-Henning Kamp    XML_SetParamEntityParsing will return 0 if parsing of parameter
9005bb6a25fSPoul-Henning Kamp    entities is requested; otherwise it will return non-zero.
9015bb6a25fSPoul-Henning Kamp    Note: If XML_SetParamEntityParsing is called after XML_Parse or
9025bb6a25fSPoul-Henning Kamp       XML_ParseBuffer, then it has no effect and will always return 0.
9030a48773fSEric van Gyzen    Note: If parser == NULL, the function will do nothing and return 0.
9045bb6a25fSPoul-Henning Kamp */
9055bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
9065bb6a25fSPoul-Henning Kamp XML_SetParamEntityParsing(XML_Parser parser,
9075bb6a25fSPoul-Henning Kamp                           enum XML_ParamEntityParsing parsing);
9085bb6a25fSPoul-Henning Kamp 
909e3466a89SXin LI /* Sets the hash salt to use for internal hash calculations.
910e3466a89SXin LI    Helps in preventing DoS attacks based on predicting hash
911e3466a89SXin LI    function behavior. This must be called before parsing is started.
912e3466a89SXin LI    Returns 1 if successful, 0 when called after parsing has started.
9130a48773fSEric van Gyzen    Note: If parser == NULL, the function will do nothing and return 0.
914e3466a89SXin LI */
915e3466a89SXin LI XMLPARSEAPI(int)
9166b2c1e49SXin LI XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt);
917e3466a89SXin LI 
918220ed979SColeman Kane /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
9195bb6a25fSPoul-Henning Kamp    XML_GetErrorCode returns information about the error.
9205bb6a25fSPoul-Henning Kamp */
9215bb6a25fSPoul-Henning Kamp XMLPARSEAPI(enum XML_Error)
9225bb6a25fSPoul-Henning Kamp XML_GetErrorCode(XML_Parser parser);
9235bb6a25fSPoul-Henning Kamp 
9245bb6a25fSPoul-Henning Kamp /* These functions return information about the current parse
925220ed979SColeman Kane    location.  They may be called from any callback called to report
926220ed979SColeman Kane    some parse event; in this case the location is the location of the
927220ed979SColeman Kane    first of the sequence of characters that generated the event.  When
928220ed979SColeman Kane    called from callbacks generated by declarations in the document
929220ed979SColeman Kane    prologue, the location identified isn't as neatly defined, but will
930220ed979SColeman Kane    be within the relevant markup.  When called outside of the callback
931220ed979SColeman Kane    functions, the position indicated will be just past the last parse
932220ed979SColeman Kane    event (regardless of whether there was an associated callback).
9335bb6a25fSPoul-Henning Kamp 
934220ed979SColeman Kane    They may also be called after returning from a call to XML_Parse
935220ed979SColeman Kane    or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
936220ed979SColeman Kane    the location is the location of the character at which the error
937220ed979SColeman Kane    was detected; otherwise the location is the location of the last
938220ed979SColeman Kane    parse event, as described above.
9390a48773fSEric van Gyzen 
9400a48773fSEric van Gyzen    Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber
9410a48773fSEric van Gyzen    return 0 to indicate an error.
9420a48773fSEric van Gyzen    Note: XML_GetCurrentByteIndex returns -1 to indicate an error.
9435bb6a25fSPoul-Henning Kamp */
944220ed979SColeman Kane XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
945220ed979SColeman Kane XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
946220ed979SColeman Kane XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
9475bb6a25fSPoul-Henning Kamp 
9485bb6a25fSPoul-Henning Kamp /* Return the number of bytes in the current event.
9495bb6a25fSPoul-Henning Kamp    Returns 0 if the event is in an internal entity.
9505bb6a25fSPoul-Henning Kamp */
9515bb6a25fSPoul-Henning Kamp XMLPARSEAPI(int)
9525bb6a25fSPoul-Henning Kamp XML_GetCurrentByteCount(XML_Parser parser);
9535bb6a25fSPoul-Henning Kamp 
9545bb6a25fSPoul-Henning Kamp /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
9555bb6a25fSPoul-Henning Kamp    the integer pointed to by offset to the offset within this buffer
9565bb6a25fSPoul-Henning Kamp    of the current parse position, and sets the integer pointed to by size
9575bb6a25fSPoul-Henning Kamp    to the size of this buffer (the number of input bytes). Otherwise
9585bb6a25fSPoul-Henning Kamp    returns a NULL pointer. Also returns a NULL pointer if a parse isn't
9595bb6a25fSPoul-Henning Kamp    active.
9605bb6a25fSPoul-Henning Kamp 
9615bb6a25fSPoul-Henning Kamp    NOTE: The character pointer returned should not be used outside
9625bb6a25fSPoul-Henning Kamp    the handler that makes the call.
9635bb6a25fSPoul-Henning Kamp */
9645bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const char *)
9656b2c1e49SXin LI XML_GetInputContext(XML_Parser parser, int *offset, int *size);
9665bb6a25fSPoul-Henning Kamp 
9675bb6a25fSPoul-Henning Kamp /* For backwards compatibility with previous versions. */
9685bb6a25fSPoul-Henning Kamp #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
9695bb6a25fSPoul-Henning Kamp #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
9705bb6a25fSPoul-Henning Kamp #define XML_GetErrorByteIndex XML_GetCurrentByteIndex
9715bb6a25fSPoul-Henning Kamp 
972220ed979SColeman Kane /* Frees the content model passed to the element declaration handler */
973220ed979SColeman Kane XMLPARSEAPI(void)
974220ed979SColeman Kane XML_FreeContentModel(XML_Parser parser, XML_Content *model);
975220ed979SColeman Kane 
976220ed979SColeman Kane /* Exposing the memory handling functions used in Expat */
977220ed979SColeman Kane XMLPARSEAPI(void *)
978be8aff81SXin LI XML_ATTR_MALLOC
979be8aff81SXin LI XML_ATTR_ALLOC_SIZE(2)
980220ed979SColeman Kane XML_MemMalloc(XML_Parser parser, size_t size);
981220ed979SColeman Kane 
982220ed979SColeman Kane XMLPARSEAPI(void *)
983be8aff81SXin LI XML_ATTR_ALLOC_SIZE(3)
984220ed979SColeman Kane XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
985220ed979SColeman Kane 
986220ed979SColeman Kane XMLPARSEAPI(void)
987220ed979SColeman Kane XML_MemFree(XML_Parser parser, void *ptr);
988220ed979SColeman Kane 
9895bb6a25fSPoul-Henning Kamp /* Frees memory used by the parser. */
9905bb6a25fSPoul-Henning Kamp XMLPARSEAPI(void)
9915bb6a25fSPoul-Henning Kamp XML_ParserFree(XML_Parser parser);
9925bb6a25fSPoul-Henning Kamp 
9935bb6a25fSPoul-Henning Kamp /* Returns a string describing the error. */
9945bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_LChar *)
9955bb6a25fSPoul-Henning Kamp XML_ErrorString(enum XML_Error code);
9965bb6a25fSPoul-Henning Kamp 
9975bb6a25fSPoul-Henning Kamp /* Return a string containing the version number of this expat */
9985bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_LChar *)
9995bb6a25fSPoul-Henning Kamp XML_ExpatVersion(void);
10005bb6a25fSPoul-Henning Kamp 
10015bb6a25fSPoul-Henning Kamp typedef struct {
10025bb6a25fSPoul-Henning Kamp   int major;
10035bb6a25fSPoul-Henning Kamp   int minor;
10045bb6a25fSPoul-Henning Kamp   int micro;
10055bb6a25fSPoul-Henning Kamp } XML_Expat_Version;
10065bb6a25fSPoul-Henning Kamp 
10075bb6a25fSPoul-Henning Kamp /* Return an XML_Expat_Version structure containing numeric version
10085bb6a25fSPoul-Henning Kamp    number information for this version of expat.
10095bb6a25fSPoul-Henning Kamp */
10105bb6a25fSPoul-Henning Kamp XMLPARSEAPI(XML_Expat_Version)
10115bb6a25fSPoul-Henning Kamp XML_ExpatVersionInfo(void);
10125bb6a25fSPoul-Henning Kamp 
10135bb6a25fSPoul-Henning Kamp /* Added in Expat 1.95.5. */
10145bb6a25fSPoul-Henning Kamp enum XML_FeatureEnum {
10155bb6a25fSPoul-Henning Kamp   XML_FEATURE_END = 0,
10165bb6a25fSPoul-Henning Kamp   XML_FEATURE_UNICODE,
10175bb6a25fSPoul-Henning Kamp   XML_FEATURE_UNICODE_WCHAR_T,
10185bb6a25fSPoul-Henning Kamp   XML_FEATURE_DTD,
10195bb6a25fSPoul-Henning Kamp   XML_FEATURE_CONTEXT_BYTES,
10205bb6a25fSPoul-Henning Kamp   XML_FEATURE_MIN_SIZE,
10215bb6a25fSPoul-Henning Kamp   XML_FEATURE_SIZEOF_XML_CHAR,
1022220ed979SColeman Kane   XML_FEATURE_SIZEOF_XML_LCHAR,
1023220ed979SColeman Kane   XML_FEATURE_NS,
1024e3466a89SXin LI   XML_FEATURE_LARGE_SIZE,
1025cc68614dSXin LI   XML_FEATURE_ATTR_INFO,
1026cc68614dSXin LI   /* Added in Expat 2.4.0. */
1027cc68614dSXin LI   XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
1028cc68614dSXin LI   XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT
10295bb6a25fSPoul-Henning Kamp   /* Additional features must be added to the end of this enum. */
10305bb6a25fSPoul-Henning Kamp };
10315bb6a25fSPoul-Henning Kamp 
10325bb6a25fSPoul-Henning Kamp typedef struct {
10335bb6a25fSPoul-Henning Kamp   enum XML_FeatureEnum feature;
1034220ed979SColeman Kane   const XML_LChar *name;
10355bb6a25fSPoul-Henning Kamp   long int value;
10365bb6a25fSPoul-Henning Kamp } XML_Feature;
10375bb6a25fSPoul-Henning Kamp 
10385bb6a25fSPoul-Henning Kamp XMLPARSEAPI(const XML_Feature *)
10395bb6a25fSPoul-Henning Kamp XML_GetFeatureList(void);
10405bb6a25fSPoul-Henning Kamp 
1041cc68614dSXin LI #ifdef XML_DTD
1042cc68614dSXin LI /* Added in Expat 2.4.0. */
1043cc68614dSXin LI XMLPARSEAPI(XML_Bool)
1044cc68614dSXin LI XML_SetBillionLaughsAttackProtectionMaximumAmplification(
1045cc68614dSXin LI     XML_Parser parser, float maximumAmplificationFactor);
1046cc68614dSXin LI 
1047cc68614dSXin LI /* Added in Expat 2.4.0. */
1048cc68614dSXin LI XMLPARSEAPI(XML_Bool)
1049cc68614dSXin LI XML_SetBillionLaughsAttackProtectionActivationThreshold(
1050cc68614dSXin LI     XML_Parser parser, unsigned long long activationThresholdBytes);
1051cc68614dSXin LI #endif
1052cc68614dSXin LI 
1053be8aff81SXin LI /* Expat follows the semantic versioning convention.
1054be8aff81SXin LI    See http://semver.org.
10555bb6a25fSPoul-Henning Kamp */
1056220ed979SColeman Kane #define XML_MAJOR_VERSION 2
1057cc68614dSXin LI #define XML_MINOR_VERSION 4
1058*7ed8e142SXin LI #define XML_MICRO_VERSION 7
10595bb6a25fSPoul-Henning Kamp 
10605bb6a25fSPoul-Henning Kamp #ifdef __cplusplus
10615bb6a25fSPoul-Henning Kamp }
10625bb6a25fSPoul-Henning Kamp #endif
10635bb6a25fSPoul-Henning Kamp 
1064220ed979SColeman Kane #endif /* not Expat_INCLUDED */
1065