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