1 /*
2                             __  __            _
3                          ___\ \/ /_ __   __ _| |_
4                         / _ \\  /| '_ \ / _` | __|
5                        |  __//  \| |_) | (_| | |_
6                         \___/_/\_\ .__/ \__,_|\__|
7                                  |_| XML parser
8 
9    Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10    Copyright (c) 2000      Clark Cooper <coopercc@users.sourceforge.net>
11    Copyright (c) 2000-2005 Fred L. Drake, Jr. <fdrake@users.sourceforge.net>
12    Copyright (c) 2001-2002 Greg Stein <gstein@users.sourceforge.net>
13    Copyright (c) 2002-2016 Karl Waclawek <karl@waclawek.net>
14    Copyright (c) 2016-2021 Sebastian Pipping <sebastian@pipping.org>
15    Copyright (c) 2016      Cristian Rodríguez <crrodriguez@opensuse.org>
16    Copyright (c) 2016      Thomas Beutlich <tc@tbeu.de>
17    Copyright (c) 2017      Rhodri James <rhodri@wildebeest.org.uk>
18    Licensed under the MIT license:
19 
20    Permission is  hereby granted,  free of charge,  to any  person obtaining
21    a  copy  of  this  software   and  associated  documentation  files  (the
22    "Software"),  to  deal in  the  Software  without restriction,  including
23    without  limitation the  rights  to use,  copy,  modify, merge,  publish,
24    distribute, sublicense, and/or sell copies of the Software, and to permit
25    persons  to whom  the Software  is  furnished to  do so,  subject to  the
26    following conditions:
27 
28    The above copyright  notice and this permission notice  shall be included
29    in all copies or substantial portions of the Software.
30 
31    THE  SOFTWARE  IS  PROVIDED  "AS  IS",  WITHOUT  WARRANTY  OF  ANY  KIND,
32    EXPRESS  OR IMPLIED,  INCLUDING  BUT  NOT LIMITED  TO  THE WARRANTIES  OF
33    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
34    NO EVENT SHALL THE AUTHORS OR  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
35    DAMAGES OR  OTHER LIABILITY, WHETHER  IN AN  ACTION OF CONTRACT,  TORT OR
36    OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
37    USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39 
40 #ifndef Expat_INCLUDED
41 #define Expat_INCLUDED 1
42 
43 #include "vtk_expat_mangle.h"
44 
45 #include <stdlib.h>
46 #include "expat_external.h"
47 
48 #ifdef __cplusplus
49 extern "C" {
50 #endif
51 
52 struct XML_ParserStruct;
53 typedef struct XML_ParserStruct *XML_Parser;
54 
55 typedef unsigned char XML_Bool;
56 #define XML_TRUE ((XML_Bool)1)
57 #define XML_FALSE ((XML_Bool)0)
58 
59 /* The XML_Status enum gives the possible return values for several
60    API functions.  The preprocessor #defines are included so this
61    stanza can be added to code that still needs to support older
62    versions of Expat 1.95.x:
63 
64    #ifndef XML_STATUS_OK
65    #define XML_STATUS_OK    1
66    #define XML_STATUS_ERROR 0
67    #endif
68 
69    Otherwise, the #define hackery is quite ugly and would have been
70    dropped.
71 */
72 enum XML_Status {
73   XML_STATUS_ERROR = 0,
74 #define XML_STATUS_ERROR XML_STATUS_ERROR
75   XML_STATUS_OK = 1,
76 #define XML_STATUS_OK XML_STATUS_OK
77   XML_STATUS_SUSPENDED = 2
78 #define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
79 };
80 
81 enum XML_Error {
82   XML_ERROR_NONE,
83   XML_ERROR_NO_MEMORY,
84   XML_ERROR_SYNTAX,
85   XML_ERROR_NO_ELEMENTS,
86   XML_ERROR_INVALID_TOKEN,
87   XML_ERROR_UNCLOSED_TOKEN,
88   XML_ERROR_PARTIAL_CHAR,
89   XML_ERROR_TAG_MISMATCH,
90   XML_ERROR_DUPLICATE_ATTRIBUTE,
91   XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
92   XML_ERROR_PARAM_ENTITY_REF,
93   XML_ERROR_UNDEFINED_ENTITY,
94   XML_ERROR_RECURSIVE_ENTITY_REF,
95   XML_ERROR_ASYNC_ENTITY,
96   XML_ERROR_BAD_CHAR_REF,
97   XML_ERROR_BINARY_ENTITY_REF,
98   XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
99   XML_ERROR_MISPLACED_XML_PI,
100   XML_ERROR_UNKNOWN_ENCODING,
101   XML_ERROR_INCORRECT_ENCODING,
102   XML_ERROR_UNCLOSED_CDATA_SECTION,
103   XML_ERROR_EXTERNAL_ENTITY_HANDLING,
104   XML_ERROR_NOT_STANDALONE,
105   XML_ERROR_UNEXPECTED_STATE,
106   XML_ERROR_ENTITY_DECLARED_IN_PE,
107   XML_ERROR_FEATURE_REQUIRES_XML_DTD,
108   XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
109   /* Added in 1.95.7. */
110   XML_ERROR_UNBOUND_PREFIX,
111   /* Added in 1.95.8. */
112   XML_ERROR_UNDECLARING_PREFIX,
113   XML_ERROR_INCOMPLETE_PE,
114   XML_ERROR_XML_DECL,
115   XML_ERROR_TEXT_DECL,
116   XML_ERROR_PUBLICID,
117   XML_ERROR_SUSPENDED,
118   XML_ERROR_NOT_SUSPENDED,
119   XML_ERROR_ABORTED,
120   XML_ERROR_FINISHED,
121   XML_ERROR_SUSPEND_PE,
122   /* Added in 2.0. */
123   XML_ERROR_RESERVED_PREFIX_XML,
124   XML_ERROR_RESERVED_PREFIX_XMLNS,
125   XML_ERROR_RESERVED_NAMESPACE_URI,
126   /* Added in 2.2.1. */
127   XML_ERROR_INVALID_ARGUMENT,
128   /* Added in 2.3.0. */
129   XML_ERROR_NO_BUFFER,
130   /* Added in 2.4.0. */
131   XML_ERROR_AMPLIFICATION_LIMIT_BREACH
132 };
133 
134 enum XML_Content_Type {
135   XML_CTYPE_EMPTY = 1,
136   XML_CTYPE_ANY,
137   XML_CTYPE_MIXED,
138   XML_CTYPE_NAME,
139   XML_CTYPE_CHOICE,
140   XML_CTYPE_SEQ
141 };
142 
143 enum XML_Content_Quant {
144   XML_CQUANT_NONE,
145   XML_CQUANT_OPT,
146   XML_CQUANT_REP,
147   XML_CQUANT_PLUS
148 };
149 
150 /* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
151    XML_CQUANT_NONE, and the other fields will be zero or NULL.
152    If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
153    numchildren will contain number of elements that may be mixed in
154    and children point to an array of XML_Content cells that will be
155    all of XML_CTYPE_NAME type with no quantification.
156 
157    If type == XML_CTYPE_NAME, then the name points to the name, and
158    the numchildren field will be zero and children will be NULL. The
159    quant fields indicates any quantifiers placed on the name.
160 
161    CHOICE and SEQ will have name NULL, the number of children in
162    numchildren and children will point, recursively, to an array
163    of XML_Content cells.
164 
165    The EMPTY, ANY, and MIXED types will only occur at top level.
166 */
167 
168 typedef struct XML_cp XML_Content;
169 
170 struct XML_cp {
171   enum XML_Content_Type type;
172   enum XML_Content_Quant quant;
173   XML_Char *name;
174   unsigned int numchildren;
175   XML_Content *children;
176 };
177 
178 /* This is called for an element declaration. See above for
179    description of the model argument. It's the caller's responsibility
180    to free model when finished with it.
181 */
182 typedef void(XMLCALL *XML_ElementDeclHandler)(void *userData,
183                                               const XML_Char *name,
184                                               XML_Content *model);
185 
186 XMLPARSEAPI(void)
187 XML_SetElementDeclHandler(XML_Parser parser, XML_ElementDeclHandler eldecl);
188 
189 /* The Attlist declaration handler is called for *each* attribute. So
190    a single Attlist declaration with multiple attributes declared will
191    generate multiple calls to this handler. The "default" parameter
192    may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
193    keyword. The "isrequired" parameter will be true and the default
194    value will be NULL in the case of "#REQUIRED". If "isrequired" is
195    true and default is non-NULL, then this is a "#FIXED" default.
196 */
197 typedef void(XMLCALL *XML_AttlistDeclHandler)(
198     void *userData, const XML_Char *elname, const XML_Char *attname,
199     const XML_Char *att_type, const XML_Char *dflt, int isrequired);
200 
201 XMLPARSEAPI(void)
202 XML_SetAttlistDeclHandler(XML_Parser parser, XML_AttlistDeclHandler attdecl);
203 
204 /* The XML declaration handler is called for *both* XML declarations
205    and text declarations. The way to distinguish is that the version
206    parameter will be NULL for text declarations. The encoding
207    parameter may be NULL for XML declarations. The standalone
208    parameter will be -1, 0, or 1 indicating respectively that there
209    was no standalone parameter in the declaration, that it was given
210    as no, or that it was given as yes.
211 */
212 typedef void(XMLCALL *XML_XmlDeclHandler)(void *userData,
213                                           const XML_Char *version,
214                                           const XML_Char *encoding,
215                                           int standalone);
216 
217 XMLPARSEAPI(void)
218 XML_SetXmlDeclHandler(XML_Parser parser, XML_XmlDeclHandler xmldecl);
219 
220 typedef struct {
221   void *(*malloc_fcn)(size_t size);
222   void *(*realloc_fcn)(void *ptr, size_t size);
223   void (*free_fcn)(void *ptr);
224 } XML_Memory_Handling_Suite;
225 
226 /* Constructs a new parser; encoding is the encoding specified by the
227    external protocol or NULL if there is none specified.
228 */
229 XMLPARSEAPI(XML_Parser)
230 XML_ParserCreate(const XML_Char *encoding);
231 
232 /* Constructs a new parser and namespace processor.  Element type
233    names and attribute names that belong to a namespace will be
234    expanded; unprefixed attribute names are never expanded; unprefixed
235    element type names are expanded only if there is a default
236    namespace. The expanded name is the concatenation of the namespace
237    URI, the namespace separator character, and the local part of the
238    name.  If the namespace separator is '\0' then the namespace URI
239    and the local part will be concatenated without any separator.
240    It is a programming error to use the separator '\0' with namespace
241    triplets (see XML_SetReturnNSTriplet).
242 */
243 XMLPARSEAPI(XML_Parser)
244 XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
245 
246 /* Constructs a new parser using the memory management suite referred to
247    by memsuite. If memsuite is NULL, then use the standard library memory
248    suite. If namespaceSeparator is non-NULL it creates a parser with
249    namespace processing as described above. The character pointed at
250    will serve as the namespace separator.
251 
252    All further memory operations used for the created parser will come from
253    the given suite.
254 */
255 XMLPARSEAPI(XML_Parser)
256 XML_ParserCreate_MM(const XML_Char *encoding,
257                     const XML_Memory_Handling_Suite *memsuite,
258                     const XML_Char *namespaceSeparator);
259 
260 /* Prepare a parser object to be re-used.  This is particularly
261    valuable when memory allocation overhead is disproportionately high,
262    such as when a large number of small documnents need to be parsed.
263    All handlers are cleared from the parser, except for the
264    unknownEncodingHandler. The parser's external state is re-initialized
265    except for the values of ns and ns_triplets.
266 
267    Added in Expat 1.95.3.
268 */
269 XMLPARSEAPI(XML_Bool)
270 XML_ParserReset(XML_Parser parser, const XML_Char *encoding);
271 
272 /* atts is array of name/value pairs, terminated by 0;
273    names and values are 0 terminated.
274 */
275 typedef void(XMLCALL *XML_StartElementHandler)(void *userData,
276                                                const XML_Char *name,
277                                                const XML_Char **atts);
278 
279 typedef void(XMLCALL *XML_EndElementHandler)(void *userData,
280                                              const XML_Char *name);
281 
282 /* s is not 0 terminated. */
283 typedef void(XMLCALL *XML_CharacterDataHandler)(void *userData,
284                                                 const XML_Char *s, int len);
285 
286 /* target and data are 0 terminated */
287 typedef void(XMLCALL *XML_ProcessingInstructionHandler)(void *userData,
288                                                         const XML_Char *target,
289                                                         const XML_Char *data);
290 
291 /* data is 0 terminated */
292 typedef void(XMLCALL *XML_CommentHandler)(void *userData, const XML_Char *data);
293 
294 typedef void(XMLCALL *XML_StartCdataSectionHandler)(void *userData);
295 typedef void(XMLCALL *XML_EndCdataSectionHandler)(void *userData);
296 
297 /* This is called for any characters in the XML document for which
298    there is no applicable handler.  This includes both characters that
299    are part of markup which is of a kind that is not reported
300    (comments, markup declarations), or characters that are part of a
301    construct which could be reported but for which no handler has been
302    supplied. The characters are passed exactly as they were in the XML
303    document except that they will be encoded in UTF-8 or UTF-16.
304    Line boundaries are not normalized. Note that a byte order mark
305    character is not passed to the default handler. There are no
306    guarantees about how characters are divided between calls to the
307    default handler: for example, a comment might be split between
308    multiple calls.
309 */
310 typedef void(XMLCALL *XML_DefaultHandler)(void *userData, const XML_Char *s,
311                                           int len);
312 
313 /* This is called for the start of the DOCTYPE declaration, before
314    any DTD or internal subset is parsed.
315 */
316 typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,
317                                                    const XML_Char *doctypeName,
318                                                    const XML_Char *sysid,
319                                                    const XML_Char *pubid,
320                                                    int has_internal_subset);
321 
322 /* This is called for the start of the DOCTYPE declaration when the
323    closing > is encountered, but after processing any external
324    subset.
325 */
326 typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
327 
328 /* This is called for entity declarations. The is_parameter_entity
329    argument will be non-zero if the entity is a parameter entity, zero
330    otherwise.
331 
332    For internal entities (<!ENTITY foo "bar">), value will
333    be non-NULL and systemId, publicID, and notationName will be NULL.
334    The value string is NOT null-terminated; the length is provided in
335    the value_length argument. Since it is legal to have zero-length
336    values, do not use this argument to test for internal entities.
337 
338    For external entities, value will be NULL and systemId will be
339    non-NULL. The publicId argument will be NULL unless a public
340    identifier was provided. The notationName argument will have a
341    non-NULL value only for unparsed entity declarations.
342 
343    Note that is_parameter_entity can't be changed to XML_Bool, since
344    that would break binary compatibility.
345 */
346 typedef void(XMLCALL *XML_EntityDeclHandler)(
347     void *userData, const XML_Char *entityName, int is_parameter_entity,
348     const XML_Char *value, int value_length, const XML_Char *base,
349     const XML_Char *systemId, const XML_Char *publicId,
350     const XML_Char *notationName);
351 
352 XMLPARSEAPI(void)
353 XML_SetEntityDeclHandler(XML_Parser parser, XML_EntityDeclHandler handler);
354 
355 /* OBSOLETE -- OBSOLETE -- OBSOLETE
356    This handler has been superseded by the EntityDeclHandler above.
357    It is provided here for backward compatibility.
358 
359    This is called for a declaration of an unparsed (NDATA) entity.
360    The base argument is whatever was set by XML_SetBase. The
361    entityName, systemId and notationName arguments will never be
362    NULL. The other arguments may be.
363 */
364 typedef void(XMLCALL *XML_UnparsedEntityDeclHandler)(
365     void *userData, const XML_Char *entityName, const XML_Char *base,
366     const XML_Char *systemId, const XML_Char *publicId,
367     const XML_Char *notationName);
368 
369 /* This is called for a declaration of notation.  The base argument is
370    whatever was set by XML_SetBase. The notationName will never be
371    NULL.  The other arguments can be.
372 */
373 typedef void(XMLCALL *XML_NotationDeclHandler)(void *userData,
374                                                const XML_Char *notationName,
375                                                const XML_Char *base,
376                                                const XML_Char *systemId,
377                                                const XML_Char *publicId);
378 
379 /* When namespace processing is enabled, these are called once for
380    each namespace declaration. The call to the start and end element
381    handlers occur between the calls to the start and end namespace
382    declaration handlers. For an xmlns attribute, prefix will be
383    NULL.  For an xmlns="" attribute, uri will be NULL.
384 */
385 typedef void(XMLCALL *XML_StartNamespaceDeclHandler)(void *userData,
386                                                      const XML_Char *prefix,
387                                                      const XML_Char *uri);
388 
389 typedef void(XMLCALL *XML_EndNamespaceDeclHandler)(void *userData,
390                                                    const XML_Char *prefix);
391 
392 /* This is called if the document is not standalone, that is, it has an
393    external subset or a reference to a parameter entity, but does not
394    have standalone="yes". If this handler returns XML_STATUS_ERROR,
395    then processing will not continue, and the parser will return a
396    XML_ERROR_NOT_STANDALONE error.
397    If parameter entity parsing is enabled, then in addition to the
398    conditions above this handler will only be called if the referenced
399    entity was actually read.
400 */
401 typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData);
402 
403 /* This is called for a reference to an external parsed general
404    entity.  The referenced entity is not automatically parsed.  The
405    application can parse it immediately or later using
406    XML_ExternalEntityParserCreate.
407 
408    The parser argument is the parser parsing the entity containing the
409    reference; it can be passed as the parser argument to
410    XML_ExternalEntityParserCreate.  The systemId argument is the
411    system identifier as specified in the entity declaration; it will
412    not be NULL.
413 
414    The base argument is the system identifier that should be used as
415    the base for resolving systemId if systemId was relative; this is
416    set by XML_SetBase; it may be NULL.
417 
418    The publicId argument is the public identifier as specified in the
419    entity declaration, or NULL if none was specified; the whitespace
420    in the public identifier will have been normalized as required by
421    the XML spec.
422 
423    The context argument specifies the parsing context in the format
424    expected by the context argument to XML_ExternalEntityParserCreate;
425    context is valid only until the handler returns, so if the
426    referenced entity is to be parsed later, it must be copied.
427    context is NULL only when the entity is a parameter entity.
428 
429    The handler should return XML_STATUS_ERROR if processing should not
430    continue because of a fatal error in the handling of the external
431    entity.  In this case the calling parser will return an
432    XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
433 
434    Note that unlike other handlers the first argument is the parser,
435    not userData.
436 */
437 typedef int(XMLCALL *XML_ExternalEntityRefHandler)(XML_Parser parser,
438                                                    const XML_Char *context,
439                                                    const XML_Char *base,
440                                                    const XML_Char *systemId,
441                                                    const XML_Char *publicId);
442 
443 /* This is called in two situations:
444    1) An entity reference is encountered for which no declaration
445       has been read *and* this is not an error.
446    2) An internal entity reference is read, but not expanded, because
447       XML_SetDefaultHandler has been called.
448    Note: skipped parameter entities in declarations and skipped general
449          entities in attribute values cannot be reported, because
450          the event would be out of sync with the reporting of the
451          declarations or attribute values
452 */
453 typedef void(XMLCALL *XML_SkippedEntityHandler)(void *userData,
454                                                 const XML_Char *entityName,
455                                                 int is_parameter_entity);
456 
457 /* This structure is filled in by the XML_UnknownEncodingHandler to
458    provide information to the parser about encodings that are unknown
459    to the parser.
460 
461    The map[b] member gives information about byte sequences whose
462    first byte is b.
463 
464    If map[b] is c where c is >= 0, then b by itself encodes the
465    Unicode scalar value c.
466 
467    If map[b] is -1, then the byte sequence is malformed.
468 
469    If map[b] is -n, where n >= 2, then b is the first byte of an
470    n-byte sequence that encodes a single Unicode scalar value.
471 
472    The data member will be passed as the first argument to the convert
473    function.
474 
475    The convert function is used to convert multibyte sequences; s will
476    point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
477    convert function must return the Unicode scalar value represented
478    by this byte sequence or -1 if the byte sequence is malformed.
479 
480    The convert function may be NULL if the encoding is a single-byte
481    encoding, that is if map[b] >= -1 for all bytes b.
482 
483    When the parser is finished with the encoding, then if release is
484    not NULL, it will call release passing it the data member; once
485    release has been called, the convert function will not be called
486    again.
487 
488    Expat places certain restrictions on the encodings that are supported
489    using this mechanism.
490 
491    1. Every ASCII character that can appear in a well-formed XML document,
492       other than the characters
493 
494       $@\^`{}~
495 
496       must be represented by a single byte, and that byte must be the
497       same byte that represents that character in ASCII.
498 
499    2. No character may require more than 4 bytes to encode.
500 
501    3. All characters encoded must have Unicode scalar values <=
502       0xFFFF, (i.e., characters that would be encoded by surrogates in
503       UTF-16 are  not allowed).  Note that this restriction doesn't
504       apply to the built-in support for UTF-8 and UTF-16.
505 
506    4. No Unicode character may be encoded by more than one distinct
507       sequence of bytes.
508 */
509 typedef struct {
510   int map[256];
511   void *data;
512   int(XMLCALL *convert)(void *data, const char *s);
513   void(XMLCALL *release)(void *data);
514 } XML_Encoding;
515 
516 /* This is called for an encoding that is unknown to the parser.
517 
518    The encodingHandlerData argument is that which was passed as the
519    second argument to XML_SetUnknownEncodingHandler.
520 
521    The name argument gives the name of the encoding as specified in
522    the encoding declaration.
523 
524    If the callback can provide information about the encoding, it must
525    fill in the XML_Encoding structure, and return XML_STATUS_OK.
526    Otherwise it must return XML_STATUS_ERROR.
527 
528    If info does not describe a suitable encoding, then the parser will
529    return an XML_ERROR_UNKNOWN_ENCODING error.
530 */
531 typedef int(XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
532                                                  const XML_Char *name,
533                                                  XML_Encoding *info);
534 
535 XMLPARSEAPI(void)
536 XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start,
537                       XML_EndElementHandler end);
538 
539 XMLPARSEAPI(void)
540 XML_SetStartElementHandler(XML_Parser parser, XML_StartElementHandler handler);
541 
542 XMLPARSEAPI(void)
543 XML_SetEndElementHandler(XML_Parser parser, XML_EndElementHandler handler);
544 
545 XMLPARSEAPI(void)
546 XML_SetCharacterDataHandler(XML_Parser parser,
547                             XML_CharacterDataHandler handler);
548 
549 XMLPARSEAPI(void)
550 XML_SetProcessingInstructionHandler(XML_Parser parser,
551                                     XML_ProcessingInstructionHandler handler);
552 XMLPARSEAPI(void)
553 XML_SetCommentHandler(XML_Parser parser, XML_CommentHandler handler);
554 
555 XMLPARSEAPI(void)
556 XML_SetCdataSectionHandler(XML_Parser parser,
557                            XML_StartCdataSectionHandler start,
558                            XML_EndCdataSectionHandler end);
559 
560 XMLPARSEAPI(void)
561 XML_SetStartCdataSectionHandler(XML_Parser parser,
562                                 XML_StartCdataSectionHandler start);
563 
564 XMLPARSEAPI(void)
565 XML_SetEndCdataSectionHandler(XML_Parser parser,
566                               XML_EndCdataSectionHandler end);
567 
568 /* This sets the default handler and also inhibits expansion of
569    internal entities. These entity references will be passed to the
570    default handler, or to the skipped entity handler, if one is set.
571 */
572 XMLPARSEAPI(void)
573 XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler);
574 
575 /* This sets the default handler but does not inhibit expansion of
576    internal entities.  The entity reference will not be passed to the
577    default handler.
578 */
579 XMLPARSEAPI(void)
580 XML_SetDefaultHandlerExpand(XML_Parser parser, XML_DefaultHandler handler);
581 
582 XMLPARSEAPI(void)
583 XML_SetDoctypeDeclHandler(XML_Parser parser, XML_StartDoctypeDeclHandler start,
584                           XML_EndDoctypeDeclHandler end);
585 
586 XMLPARSEAPI(void)
587 XML_SetStartDoctypeDeclHandler(XML_Parser parser,
588                                XML_StartDoctypeDeclHandler start);
589 
590 XMLPARSEAPI(void)
591 XML_SetEndDoctypeDeclHandler(XML_Parser parser, XML_EndDoctypeDeclHandler end);
592 
593 XMLPARSEAPI(void)
594 XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
595                                  XML_UnparsedEntityDeclHandler handler);
596 
597 XMLPARSEAPI(void)
598 XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler);
599 
600 XMLPARSEAPI(void)
601 XML_SetNamespaceDeclHandler(XML_Parser parser,
602                             XML_StartNamespaceDeclHandler start,
603                             XML_EndNamespaceDeclHandler end);
604 
605 XMLPARSEAPI(void)
606 XML_SetStartNamespaceDeclHandler(XML_Parser parser,
607                                  XML_StartNamespaceDeclHandler start);
608 
609 XMLPARSEAPI(void)
610 XML_SetEndNamespaceDeclHandler(XML_Parser parser,
611                                XML_EndNamespaceDeclHandler end);
612 
613 XMLPARSEAPI(void)
614 XML_SetNotStandaloneHandler(XML_Parser parser,
615                             XML_NotStandaloneHandler handler);
616 
617 XMLPARSEAPI(void)
618 XML_SetExternalEntityRefHandler(XML_Parser parser,
619                                 XML_ExternalEntityRefHandler handler);
620 
621 /* If a non-NULL value for arg is specified here, then it will be
622    passed as the first argument to the external entity ref handler
623    instead of the parser object.
624 */
625 XMLPARSEAPI(void)
626 XML_SetExternalEntityRefHandlerArg(XML_Parser parser, void *arg);
627 
628 XMLPARSEAPI(void)
629 XML_SetSkippedEntityHandler(XML_Parser parser,
630                             XML_SkippedEntityHandler handler);
631 
632 XMLPARSEAPI(void)
633 XML_SetUnknownEncodingHandler(XML_Parser parser,
634                               XML_UnknownEncodingHandler handler,
635                               void *encodingHandlerData);
636 
637 /* This can be called within a handler for a start element, end
638    element, processing instruction or character data.  It causes the
639    corresponding markup to be passed to the default handler.
640 */
641 XMLPARSEAPI(void)
642 XML_DefaultCurrent(XML_Parser parser);
643 
644 /* If do_nst is non-zero, and namespace processing is in effect, and
645    a name has a prefix (i.e. an explicit namespace qualifier) then
646    that name is returned as a triplet in a single string separated by
647    the separator character specified when the parser was created: URI
648    + sep + local_name + sep + prefix.
649 
650    If do_nst is zero, then namespace information is returned in the
651    default manner (URI + sep + local_name) whether or not the name
652    has a prefix.
653 
654    Note: Calling XML_SetReturnNSTriplet after XML_Parse or
655      XML_ParseBuffer has no effect.
656 */
657 
658 XMLPARSEAPI(void)
659 XML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
660 
661 /* This value is passed as the userData argument to callbacks. */
662 XMLPARSEAPI(void)
663 XML_SetUserData(XML_Parser parser, void *userData);
664 
665 /* Returns the last value set by XML_SetUserData or NULL. */
666 #define XML_GetUserData(parser) (*(void **)(parser))
667 
668 /* This is equivalent to supplying an encoding argument to
669    XML_ParserCreate. On success XML_SetEncoding returns non-zero,
670    zero otherwise.
671    Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
672      has no effect and returns XML_STATUS_ERROR.
673 */
674 XMLPARSEAPI(enum XML_Status)
675 XML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
676 
677 /* If this function is called, then the parser will be passed as the
678    first argument to callbacks instead of userData.  The userData will
679    still be accessible using XML_GetUserData.
680 */
681 XMLPARSEAPI(void)
682 XML_UseParserAsHandlerArg(XML_Parser parser);
683 
684 /* If useDTD == XML_TRUE is passed to this function, then the parser
685    will assume that there is an external subset, even if none is
686    specified in the document. In such a case the parser will call the
687    externalEntityRefHandler with a value of NULL for the systemId
688    argument (the publicId and context arguments will be NULL as well).
689    Note: For the purpose of checking WFC: Entity Declared, passing
690      useDTD == XML_TRUE will make the parser behave as if the document
691      had a DTD with an external subset.
692    Note: If this function is called, then this must be done before
693      the first call to XML_Parse or XML_ParseBuffer, since it will
694      have no effect after that.  Returns
695      XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
696    Note: If the document does not have a DOCTYPE declaration at all,
697      then startDoctypeDeclHandler and endDoctypeDeclHandler will not
698      be called, despite an external subset being parsed.
699    Note: If XML_DTD is not defined when Expat is compiled, returns
700      XML_ERROR_FEATURE_REQUIRES_XML_DTD.
701    Note: If parser == NULL, returns XML_ERROR_INVALID_ARGUMENT.
702 */
703 XMLPARSEAPI(enum XML_Error)
704 XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
705 
706 /* Sets the base to be used for resolving relative URIs in system
707    identifiers in declarations.  Resolving relative identifiers is
708    left to the application: this value will be passed through as the
709    base argument to the XML_ExternalEntityRefHandler,
710    XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
711    argument will be copied.  Returns XML_STATUS_ERROR if out of memory,
712    XML_STATUS_OK otherwise.
713 */
714 XMLPARSEAPI(enum XML_Status)
715 XML_SetBase(XML_Parser parser, const XML_Char *base);
716 
717 XMLPARSEAPI(const XML_Char *)
718 XML_GetBase(XML_Parser parser);
719 
720 /* Returns the number of the attribute/value pairs passed in last call
721    to the XML_StartElementHandler that were specified in the start-tag
722    rather than defaulted. Each attribute/value pair counts as 2; thus
723    this corresponds to an index into the atts array passed to the
724    XML_StartElementHandler.  Returns -1 if parser == NULL.
725 */
726 XMLPARSEAPI(int)
727 XML_GetSpecifiedAttributeCount(XML_Parser parser);
728 
729 /* Returns the index of the ID attribute passed in the last call to
730    XML_StartElementHandler, or -1 if there is no ID attribute or
731    parser == NULL.  Each attribute/value pair counts as 2; thus this
732    corresponds to an index into the atts array passed to the
733    XML_StartElementHandler.
734 */
735 XMLPARSEAPI(int)
736 XML_GetIdAttributeIndex(XML_Parser parser);
737 
738 #ifdef XML_ATTR_INFO
739 /* Source file byte offsets for the start and end of attribute names and values.
740    The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
741    file an attribute value of "blah" will yield:
742    info->valueEnd - info->valueStart = 4 bytes.
743 */
744 typedef struct {
745   XML_Index nameStart;  /* Offset to beginning of the attribute name. */
746   XML_Index nameEnd;    /* Offset after the attribute name's last byte. */
747   XML_Index valueStart; /* Offset to beginning of the attribute value. */
748   XML_Index valueEnd;   /* Offset after the attribute value's last byte. */
749 } XML_AttrInfo;
750 
751 /* Returns an array of XML_AttrInfo structures for the attribute/value pairs
752    passed in last call to the XML_StartElementHandler that were specified
753    in the start-tag rather than defaulted. Each attribute/value pair counts
754    as 1; thus the number of entries in the array is
755    XML_GetSpecifiedAttributeCount(parser) / 2.
756 */
757 XMLPARSEAPI(const XML_AttrInfo *)
758 XML_GetAttributeInfo(XML_Parser parser);
759 #endif
760 
761 /* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
762    detected.  The last call to XML_Parse must have isFinal true; len
763    may be zero for this call (or any other).
764 
765    Though the return values for these functions has always been
766    described as a Boolean value, the implementation, at least for the
767    1.95.x series, has always returned exactly one of the XML_Status
768    values.
769 */
770 XMLPARSEAPI(enum XML_Status)
771 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
772 
773 XMLPARSEAPI(void *)
774 XML_GetBuffer(XML_Parser parser, int len);
775 
776 XMLPARSEAPI(enum XML_Status)
777 XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
778 
779 /* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
780    Must be called from within a call-back handler, except when aborting
781    (resumable = 0) an already suspended parser. Some call-backs may
782    still follow because they would otherwise get lost. Examples:
783    - endElementHandler() for empty elements when stopped in
784      startElementHandler(),
785    - endNameSpaceDeclHandler() when stopped in endElementHandler(),
786    and possibly others.
787 
788    Can be called from most handlers, including DTD related call-backs,
789    except when parsing an external parameter entity and resumable != 0.
790    Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
791    Possible error codes:
792    - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
793    - XML_ERROR_FINISHED: when the parser has already finished.
794    - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
795 
796    When resumable != 0 (true) then parsing is suspended, that is,
797    XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
798    Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
799    return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
800 
801    *Note*:
802    This will be applied to the current parser instance only, that is, if
803    there is a parent parser then it will continue parsing when the
804    externalEntityRefHandler() returns. It is up to the implementation of
805    the externalEntityRefHandler() to call XML_StopParser() on the parent
806    parser (recursively), if one wants to stop parsing altogether.
807 
808    When suspended, parsing can be resumed by calling XML_ResumeParser().
809 */
810 XMLPARSEAPI(enum XML_Status)
811 XML_StopParser(XML_Parser parser, XML_Bool resumable);
812 
813 /* Resumes parsing after it has been suspended with XML_StopParser().
814    Must not be called from within a handler call-back. Returns same
815    status codes as XML_Parse() or XML_ParseBuffer().
816    Additional error code XML_ERROR_NOT_SUSPENDED possible.
817 
818    *Note*:
819    This must be called on the most deeply nested child parser instance
820    first, and on its parent parser only after the child parser has finished,
821    to be applied recursively until the document entity's parser is restarted.
822    That is, the parent parser will not resume by itself and it is up to the
823    application to call XML_ResumeParser() on it at the appropriate moment.
824 */
825 XMLPARSEAPI(enum XML_Status)
826 XML_ResumeParser(XML_Parser parser);
827 
828 enum XML_Parsing { XML_INITIALIZED, XML_PARSING, XML_FINISHED, XML_SUSPENDED };
829 
830 typedef struct {
831   enum XML_Parsing parsing;
832   XML_Bool finalBuffer;
833 } XML_ParsingStatus;
834 
835 /* Returns status of parser with respect to being initialized, parsing,
836    finished, or suspended and processing the final buffer.
837    XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
838    XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
839 */
840 XMLPARSEAPI(void)
841 XML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
842 
843 /* Creates an XML_Parser object that can parse an external general
844    entity; context is a '\0'-terminated string specifying the parse
845    context; encoding is a '\0'-terminated string giving the name of
846    the externally specified encoding, or NULL if there is no
847    externally specified encoding.  The context string consists of a
848    sequence of tokens separated by formfeeds (\f); a token consisting
849    of a name specifies that the general entity of the name is open; a
850    token of the form prefix=uri specifies the namespace for a
851    particular prefix; a token of the form =uri specifies the default
852    namespace.  This can be called at any point after the first call to
853    an ExternalEntityRefHandler so longer as the parser has not yet
854    been freed.  The new parser is completely independent and may
855    safely be used in a separate thread.  The handlers and userData are
856    initialized from the parser argument.  Returns NULL if out of memory.
857    Otherwise returns a new XML_Parser object.
858 */
859 XMLPARSEAPI(XML_Parser)
860 XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *context,
861                                const XML_Char *encoding);
862 
863 enum XML_ParamEntityParsing {
864   XML_PARAM_ENTITY_PARSING_NEVER,
865   XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
866   XML_PARAM_ENTITY_PARSING_ALWAYS
867 };
868 
869 /* Controls parsing of parameter entities (including the external DTD
870    subset). If parsing of parameter entities is enabled, then
871    references to external parameter entities (including the external
872    DTD subset) will be passed to the handler set with
873    XML_SetExternalEntityRefHandler.  The context passed will be 0.
874 
875    Unlike external general entities, external parameter entities can
876    only be parsed synchronously.  If the external parameter entity is
877    to be parsed, it must be parsed during the call to the external
878    entity ref handler: the complete sequence of
879    XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
880    XML_ParserFree calls must be made during this call.  After
881    XML_ExternalEntityParserCreate has been called to create the parser
882    for the external parameter entity (context must be 0 for this
883    call), it is illegal to make any calls on the old parser until
884    XML_ParserFree has been called on the newly created parser.
885    If the library has been compiled without support for parameter
886    entity parsing (ie without XML_DTD being defined), then
887    XML_SetParamEntityParsing will return 0 if parsing of parameter
888    entities is requested; otherwise it will return non-zero.
889    Note: If XML_SetParamEntityParsing is called after XML_Parse or
890       XML_ParseBuffer, then it has no effect and will always return 0.
891    Note: If parser == NULL, the function will do nothing and return 0.
892 */
893 XMLPARSEAPI(int)
894 XML_SetParamEntityParsing(XML_Parser parser,
895                           enum XML_ParamEntityParsing parsing);
896 
897 /* Sets the hash salt to use for internal hash calculations.
898    Helps in preventing DoS attacks based on predicting hash
899    function behavior. This must be called before parsing is started.
900    Returns 1 if successful, 0 when called after parsing has started.
901    Note: If parser == NULL, the function will do nothing and return 0.
902 */
903 XMLPARSEAPI(int)
904 XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt);
905 
906 /* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
907    XML_GetErrorCode returns information about the error.
908 */
909 XMLPARSEAPI(enum XML_Error)
910 XML_GetErrorCode(XML_Parser parser);
911 
912 /* These functions return information about the current parse
913    location.  They may be called from any callback called to report
914    some parse event; in this case the location is the location of the
915    first of the sequence of characters that generated the event.  When
916    called from callbacks generated by declarations in the document
917    prologue, the location identified isn't as neatly defined, but will
918    be within the relevant markup.  When called outside of the callback
919    functions, the position indicated will be just past the last parse
920    event (regardless of whether there was an associated callback).
921 
922    They may also be called after returning from a call to XML_Parse
923    or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
924    the location is the location of the character at which the error
925    was detected; otherwise the location is the location of the last
926    parse event, as described above.
927 
928    Note: XML_GetCurrentLineNumber and XML_GetCurrentColumnNumber
929    return 0 to indicate an error.
930    Note: XML_GetCurrentByteIndex returns -1 to indicate an error.
931 */
932 XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
933 XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
934 XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
935 
936 /* Return the number of bytes in the current event.
937    Returns 0 if the event is in an internal entity.
938 */
939 XMLPARSEAPI(int)
940 XML_GetCurrentByteCount(XML_Parser parser);
941 
942 /* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
943    the integer pointed to by offset to the offset within this buffer
944    of the current parse position, and sets the integer pointed to by size
945    to the size of this buffer (the number of input bytes). Otherwise
946    returns a NULL pointer. Also returns a NULL pointer if a parse isn't
947    active.
948 
949    NOTE: The character pointer returned should not be used outside
950    the handler that makes the call.
951 */
952 XMLPARSEAPI(const char *)
953 XML_GetInputContext(XML_Parser parser, int *offset, int *size);
954 
955 /* For backwards compatibility with previous versions. */
956 #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
957 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
958 #define XML_GetErrorByteIndex XML_GetCurrentByteIndex
959 
960 /* Frees the content model passed to the element declaration handler */
961 XMLPARSEAPI(void)
962 XML_FreeContentModel(XML_Parser parser, XML_Content *model);
963 
964 /* Exposing the memory handling functions used in Expat */
965 XMLPARSEAPI(void *)
966 XML_ATTR_MALLOC
967 XML_ATTR_ALLOC_SIZE(2)
968 XML_MemMalloc(XML_Parser parser, size_t size);
969 
970 XMLPARSEAPI(void *)
971 XML_ATTR_ALLOC_SIZE(3)
972 XML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
973 
974 XMLPARSEAPI(void)
975 XML_MemFree(XML_Parser parser, void *ptr);
976 
977 /* Frees memory used by the parser. */
978 XMLPARSEAPI(void)
979 XML_ParserFree(XML_Parser parser);
980 
981 /* Returns a string describing the error. */
982 XMLPARSEAPI(const XML_LChar *)
983 XML_ErrorString(enum XML_Error code);
984 
985 /* Return a string containing the version number of this expat */
986 XMLPARSEAPI(const XML_LChar *)
987 XML_ExpatVersion(void);
988 
989 typedef struct {
990   int major;
991   int minor;
992   int micro;
993 } XML_Expat_Version;
994 
995 /* Return an XML_Expat_Version structure containing numeric version
996    number information for this version of expat.
997 */
998 XMLPARSEAPI(XML_Expat_Version)
999 XML_ExpatVersionInfo(void);
1000 
1001 /* Added in Expat 1.95.5. */
1002 enum XML_FeatureEnum {
1003   XML_FEATURE_END = 0,
1004   XML_FEATURE_UNICODE,
1005   XML_FEATURE_UNICODE_WCHAR_T,
1006   XML_FEATURE_DTD,
1007   XML_FEATURE_CONTEXT_BYTES,
1008   XML_FEATURE_MIN_SIZE,
1009   XML_FEATURE_SIZEOF_XML_CHAR,
1010   XML_FEATURE_SIZEOF_XML_LCHAR,
1011   XML_FEATURE_NS,
1012   XML_FEATURE_LARGE_SIZE,
1013   XML_FEATURE_ATTR_INFO,
1014   /* Added in Expat 2.4.0. */
1015   XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
1016   XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT
1017   /* Additional features must be added to the end of this enum. */
1018 };
1019 
1020 typedef struct {
1021   enum XML_FeatureEnum feature;
1022   const XML_LChar *name;
1023   long int value;
1024 } XML_Feature;
1025 
1026 XMLPARSEAPI(const XML_Feature *)
1027 XML_GetFeatureList(void);
1028 
1029 #ifdef XML_DTD
1030 /* Added in Expat 2.4.0. */
1031 XMLPARSEAPI(XML_Bool)
1032 XML_SetBillionLaughsAttackProtectionMaximumAmplification(
1033     XML_Parser parser, float maximumAmplificationFactor);
1034 
1035 /* Added in Expat 2.4.0. */
1036 XMLPARSEAPI(XML_Bool)
1037 XML_SetBillionLaughsAttackProtectionActivationThreshold(
1038     XML_Parser parser, unsigned long long activationThresholdBytes);
1039 #endif
1040 
1041 /* Expat follows the semantic versioning convention.
1042    See http://semver.org.
1043 */
1044 #define XML_MAJOR_VERSION 2
1045 #define XML_MINOR_VERSION 4
1046 #define XML_MICRO_VERSION 1
1047 
1048 #ifdef __cplusplus
1049 }
1050 #endif
1051 
1052 #endif /* not Expat_INCLUDED */
1053