1104349Sphk/* Copyright (c) 1998, 1999, 2000 Thai Open Source Software Center Ltd
2104349Sphk   See the file COPYING for copying permission.
3104349Sphk*/
4104349Sphk
5178848Scokane#ifndef Expat_INCLUDED
6178848Scokane#define Expat_INCLUDED 1
7104349Sphk
8104349Sphk#ifdef __VMS
9104349Sphk/*      0        1         2         3      0        1         2         3
10104349Sphk        1234567890123456789012345678901     1234567890123456789012345678901 */
11178848Scokane#define XML_SetProcessingInstructionHandler XML_SetProcessingInstrHandler
12178848Scokane#define XML_SetUnparsedEntityDeclHandler    XML_SetUnparsedEntDeclHandler
13178848Scokane#define XML_SetStartNamespaceDeclHandler    XML_SetStartNamespcDeclHandler
14178848Scokane#define XML_SetExternalEntityRefHandlerArg  XML_SetExternalEntRefHandlerArg
15104349Sphk#endif
16104349Sphk
17104349Sphk#include <stdlib.h>
18178848Scokane#include "expat_external.h"
19104349Sphk
20104349Sphk#ifdef __cplusplus
21104349Sphkextern "C" {
22104349Sphk#endif
23104349Sphk
24104349Sphkstruct XML_ParserStruct;
25104349Sphktypedef struct XML_ParserStruct *XML_Parser;
26104349Sphk
27104349Sphk/* Should this be defined using stdbool.h when C99 is available? */
28104349Sphktypedef unsigned char XML_Bool;
29104349Sphk#define XML_TRUE   ((XML_Bool) 1)
30104349Sphk#define XML_FALSE  ((XML_Bool) 0)
31104349Sphk
32178848Scokane/* The XML_Status enum gives the possible return values for several
33178848Scokane   API functions.  The preprocessor #defines are included so this
34178848Scokane   stanza can be added to code that still needs to support older
35178848Scokane   versions of Expat 1.95.x:
36178848Scokane
37178848Scokane   #ifndef XML_STATUS_OK
38178848Scokane   #define XML_STATUS_OK    1
39178848Scokane   #define XML_STATUS_ERROR 0
40178848Scokane   #endif
41178848Scokane
42178848Scokane   Otherwise, the #define hackery is quite ugly and would have been
43178848Scokane   dropped.
44178848Scokane*/
45178848Scokaneenum XML_Status {
46178848Scokane  XML_STATUS_ERROR = 0,
47178848Scokane#define XML_STATUS_ERROR XML_STATUS_ERROR
48178848Scokane  XML_STATUS_OK = 1,
49178848Scokane#define XML_STATUS_OK XML_STATUS_OK
50178848Scokane  XML_STATUS_SUSPENDED = 2
51178848Scokane#define XML_STATUS_SUSPENDED XML_STATUS_SUSPENDED
52178848Scokane};
53178848Scokane
54104349Sphkenum XML_Error {
55104349Sphk  XML_ERROR_NONE,
56104349Sphk  XML_ERROR_NO_MEMORY,
57104349Sphk  XML_ERROR_SYNTAX,
58104349Sphk  XML_ERROR_NO_ELEMENTS,
59104349Sphk  XML_ERROR_INVALID_TOKEN,
60104349Sphk  XML_ERROR_UNCLOSED_TOKEN,
61104349Sphk  XML_ERROR_PARTIAL_CHAR,
62104349Sphk  XML_ERROR_TAG_MISMATCH,
63104349Sphk  XML_ERROR_DUPLICATE_ATTRIBUTE,
64104349Sphk  XML_ERROR_JUNK_AFTER_DOC_ELEMENT,
65104349Sphk  XML_ERROR_PARAM_ENTITY_REF,
66104349Sphk  XML_ERROR_UNDEFINED_ENTITY,
67104349Sphk  XML_ERROR_RECURSIVE_ENTITY_REF,
68104349Sphk  XML_ERROR_ASYNC_ENTITY,
69104349Sphk  XML_ERROR_BAD_CHAR_REF,
70104349Sphk  XML_ERROR_BINARY_ENTITY_REF,
71104349Sphk  XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF,
72104349Sphk  XML_ERROR_MISPLACED_XML_PI,
73104349Sphk  XML_ERROR_UNKNOWN_ENCODING,
74104349Sphk  XML_ERROR_INCORRECT_ENCODING,
75104349Sphk  XML_ERROR_UNCLOSED_CDATA_SECTION,
76104349Sphk  XML_ERROR_EXTERNAL_ENTITY_HANDLING,
77104349Sphk  XML_ERROR_NOT_STANDALONE,
78104349Sphk  XML_ERROR_UNEXPECTED_STATE,
79104349Sphk  XML_ERROR_ENTITY_DECLARED_IN_PE,
80104349Sphk  XML_ERROR_FEATURE_REQUIRES_XML_DTD,
81178848Scokane  XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING,
82178848Scokane  /* Added in 1.95.7. */
83178848Scokane  XML_ERROR_UNBOUND_PREFIX,
84178848Scokane  /* Added in 1.95.8. */
85178848Scokane  XML_ERROR_UNDECLARING_PREFIX,
86178848Scokane  XML_ERROR_INCOMPLETE_PE,
87178848Scokane  XML_ERROR_XML_DECL,
88178848Scokane  XML_ERROR_TEXT_DECL,
89178848Scokane  XML_ERROR_PUBLICID,
90178848Scokane  XML_ERROR_SUSPENDED,
91178848Scokane  XML_ERROR_NOT_SUSPENDED,
92178848Scokane  XML_ERROR_ABORTED,
93178848Scokane  XML_ERROR_FINISHED,
94178848Scokane  XML_ERROR_SUSPEND_PE,
95178848Scokane  /* Added in 2.0. */
96178848Scokane  XML_ERROR_RESERVED_PREFIX_XML,
97178848Scokane  XML_ERROR_RESERVED_PREFIX_XMLNS,
98178848Scokane  XML_ERROR_RESERVED_NAMESPACE_URI
99104349Sphk};
100104349Sphk
101104349Sphkenum XML_Content_Type {
102104349Sphk  XML_CTYPE_EMPTY = 1,
103104349Sphk  XML_CTYPE_ANY,
104104349Sphk  XML_CTYPE_MIXED,
105104349Sphk  XML_CTYPE_NAME,
106104349Sphk  XML_CTYPE_CHOICE,
107104349Sphk  XML_CTYPE_SEQ
108104349Sphk};
109104349Sphk
110104349Sphkenum XML_Content_Quant {
111104349Sphk  XML_CQUANT_NONE,
112104349Sphk  XML_CQUANT_OPT,
113104349Sphk  XML_CQUANT_REP,
114104349Sphk  XML_CQUANT_PLUS
115104349Sphk};
116104349Sphk
117104349Sphk/* If type == XML_CTYPE_EMPTY or XML_CTYPE_ANY, then quant will be
118104349Sphk   XML_CQUANT_NONE, and the other fields will be zero or NULL.
119104349Sphk   If type == XML_CTYPE_MIXED, then quant will be NONE or REP and
120104349Sphk   numchildren will contain number of elements that may be mixed in
121104349Sphk   and children point to an array of XML_Content cells that will be
122104349Sphk   all of XML_CTYPE_NAME type with no quantification.
123104349Sphk
124104349Sphk   If type == XML_CTYPE_NAME, then the name points to the name, and
125104349Sphk   the numchildren field will be zero and children will be NULL. The
126104349Sphk   quant fields indicates any quantifiers placed on the name.
127104349Sphk
128104349Sphk   CHOICE and SEQ will have name NULL, the number of children in
129104349Sphk   numchildren and children will point, recursively, to an array
130104349Sphk   of XML_Content cells.
131104349Sphk
132104349Sphk   The EMPTY, ANY, and MIXED types will only occur at top level.
133104349Sphk*/
134104349Sphk
135104349Sphktypedef struct XML_cp XML_Content;
136104349Sphk
137104349Sphkstruct XML_cp {
138104349Sphk  enum XML_Content_Type         type;
139104349Sphk  enum XML_Content_Quant        quant;
140104349Sphk  XML_Char *                    name;
141104349Sphk  unsigned int                  numchildren;
142104349Sphk  XML_Content *                 children;
143104349Sphk};
144104349Sphk
145104349Sphk
146104349Sphk/* This is called for an element declaration. See above for
147104349Sphk   description of the model argument. It's the caller's responsibility
148104349Sphk   to free model when finished with it.
149104349Sphk*/
150178848Scokanetypedef void (XMLCALL *XML_ElementDeclHandler) (void *userData,
151178848Scokane                                                const XML_Char *name,
152178848Scokane                                                XML_Content *model);
153104349Sphk
154104349SphkXMLPARSEAPI(void)
155104349SphkXML_SetElementDeclHandler(XML_Parser parser,
156104349Sphk                          XML_ElementDeclHandler eldecl);
157104349Sphk
158104349Sphk/* The Attlist declaration handler is called for *each* attribute. So
159104349Sphk   a single Attlist declaration with multiple attributes declared will
160104349Sphk   generate multiple calls to this handler. The "default" parameter
161104349Sphk   may be NULL in the case of the "#IMPLIED" or "#REQUIRED"
162104349Sphk   keyword. The "isrequired" parameter will be true and the default
163104349Sphk   value will be NULL in the case of "#REQUIRED". If "isrequired" is
164104349Sphk   true and default is non-NULL, then this is a "#FIXED" default.
165104349Sphk*/
166178848Scokanetypedef void (XMLCALL *XML_AttlistDeclHandler) (
167178848Scokane                                    void            *userData,
168178848Scokane                                    const XML_Char  *elname,
169178848Scokane                                    const XML_Char  *attname,
170178848Scokane                                    const XML_Char  *att_type,
171178848Scokane                                    const XML_Char  *dflt,
172178848Scokane                                    int              isrequired);
173104349Sphk
174104349SphkXMLPARSEAPI(void)
175104349SphkXML_SetAttlistDeclHandler(XML_Parser parser,
176104349Sphk                          XML_AttlistDeclHandler attdecl);
177104349Sphk
178104349Sphk/* The XML declaration handler is called for *both* XML declarations
179104349Sphk   and text declarations. The way to distinguish is that the version
180104349Sphk   parameter will be NULL for text declarations. The encoding
181104349Sphk   parameter may be NULL for XML declarations. The standalone
182104349Sphk   parameter will be -1, 0, or 1 indicating respectively that there
183104349Sphk   was no standalone parameter in the declaration, that it was given
184104349Sphk   as no, or that it was given as yes.
185104349Sphk*/
186178848Scokanetypedef void (XMLCALL *XML_XmlDeclHandler) (void           *userData,
187178848Scokane                                            const XML_Char *version,
188178848Scokane                                            const XML_Char *encoding,
189178848Scokane                                            int             standalone);
190104349Sphk
191104349SphkXMLPARSEAPI(void)
192104349SphkXML_SetXmlDeclHandler(XML_Parser parser,
193104349Sphk                      XML_XmlDeclHandler xmldecl);
194104349Sphk
195104349Sphk
196104349Sphktypedef struct {
197104349Sphk  void *(*malloc_fcn)(size_t size);
198104349Sphk  void *(*realloc_fcn)(void *ptr, size_t size);
199104349Sphk  void (*free_fcn)(void *ptr);
200104349Sphk} XML_Memory_Handling_Suite;
201104349Sphk
202104349Sphk/* Constructs a new parser; encoding is the encoding specified by the
203104349Sphk   external protocol or NULL if there is none specified.
204104349Sphk*/
205104349SphkXMLPARSEAPI(XML_Parser)
206104349SphkXML_ParserCreate(const XML_Char *encoding);
207104349Sphk
208104349Sphk/* Constructs a new parser and namespace processor.  Element type
209104349Sphk   names and attribute names that belong to a namespace will be
210104349Sphk   expanded; unprefixed attribute names are never expanded; unprefixed
211104349Sphk   element type names are expanded only if there is a default
212104349Sphk   namespace. The expanded name is the concatenation of the namespace
213104349Sphk   URI, the namespace separator character, and the local part of the
214104349Sphk   name.  If the namespace separator is '\0' then the namespace URI
215104349Sphk   and the local part will be concatenated without any separator.
216178848Scokane   It is a programming error to use the separator '\0' with namespace
217178848Scokane   triplets (see XML_SetReturnNSTriplet).
218104349Sphk*/
219104349SphkXMLPARSEAPI(XML_Parser)
220104349SphkXML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
221104349Sphk
222104349Sphk
223178848Scokane/* Constructs a new parser using the memory management suite referred to
224104349Sphk   by memsuite. If memsuite is NULL, then use the standard library memory
225104349Sphk   suite. If namespaceSeparator is non-NULL it creates a parser with
226104349Sphk   namespace processing as described above. The character pointed at
227104349Sphk   will serve as the namespace separator.
228104349Sphk
229104349Sphk   All further memory operations used for the created parser will come from
230104349Sphk   the given suite.
231104349Sphk*/
232104349SphkXMLPARSEAPI(XML_Parser)
233104349SphkXML_ParserCreate_MM(const XML_Char *encoding,
234104349Sphk                    const XML_Memory_Handling_Suite *memsuite,
235104349Sphk                    const XML_Char *namespaceSeparator);
236104349Sphk
237104349Sphk/* Prepare a parser object to be re-used.  This is particularly
238104349Sphk   valuable when memory allocation overhead is disproportionatly high,
239104349Sphk   such as when a large number of small documnents need to be parsed.
240178848Scokane   All handlers are cleared from the parser, except for the
241104349Sphk   unknownEncodingHandler. The parser's external state is re-initialized
242104349Sphk   except for the values of ns and ns_triplets.
243104349Sphk
244104349Sphk   Added in Expat 1.95.3.
245104349Sphk*/
246104349SphkXMLPARSEAPI(XML_Bool)
247104349SphkXML_ParserReset(XML_Parser parser, const XML_Char *encoding);
248104349Sphk
249104349Sphk/* atts is array of name/value pairs, terminated by 0;
250104349Sphk   names and values are 0 terminated.
251104349Sphk*/
252178848Scokanetypedef void (XMLCALL *XML_StartElementHandler) (void *userData,
253178848Scokane                                                 const XML_Char *name,
254178848Scokane                                                 const XML_Char **atts);
255104349Sphk
256178848Scokanetypedef void (XMLCALL *XML_EndElementHandler) (void *userData,
257178848Scokane                                               const XML_Char *name);
258104349Sphk
259104349Sphk
260104349Sphk/* s is not 0 terminated. */
261178848Scokanetypedef void (XMLCALL *XML_CharacterDataHandler) (void *userData,
262178848Scokane                                                  const XML_Char *s,
263178848Scokane                                                  int len);
264104349Sphk
265104349Sphk/* target and data are 0 terminated */
266178848Scokanetypedef void (XMLCALL *XML_ProcessingInstructionHandler) (
267178848Scokane                                                void *userData,
268178848Scokane                                                const XML_Char *target,
269178848Scokane                                                const XML_Char *data);
270104349Sphk
271104349Sphk/* data is 0 terminated */
272178848Scokanetypedef void (XMLCALL *XML_CommentHandler) (void *userData,
273178848Scokane                                            const XML_Char *data);
274104349Sphk
275178848Scokanetypedef void (XMLCALL *XML_StartCdataSectionHandler) (void *userData);
276178848Scokanetypedef void (XMLCALL *XML_EndCdataSectionHandler) (void *userData);
277104349Sphk
278104349Sphk/* This is called for any characters in the XML document for which
279104349Sphk   there is no applicable handler.  This includes both characters that
280104349Sphk   are part of markup which is of a kind that is not reported
281104349Sphk   (comments, markup declarations), or characters that are part of a
282104349Sphk   construct which could be reported but for which no handler has been
283104349Sphk   supplied. The characters are passed exactly as they were in the XML
284178848Scokane   document except that they will be encoded in UTF-8 or UTF-16.
285104349Sphk   Line boundaries are not normalized. Note that a byte order mark
286104349Sphk   character is not passed to the default handler. There are no
287104349Sphk   guarantees about how characters are divided between calls to the
288104349Sphk   default handler: for example, a comment might be split between
289104349Sphk   multiple calls.
290104349Sphk*/
291178848Scokanetypedef void (XMLCALL *XML_DefaultHandler) (void *userData,
292178848Scokane                                            const XML_Char *s,
293178848Scokane                                            int len);
294104349Sphk
295104349Sphk/* This is called for the start of the DOCTYPE declaration, before
296104349Sphk   any DTD or internal subset is parsed.
297104349Sphk*/
298178848Scokanetypedef void (XMLCALL *XML_StartDoctypeDeclHandler) (
299178848Scokane                                            void *userData,
300104349Sphk                                            const XML_Char *doctypeName,
301104349Sphk                                            const XML_Char *sysid,
302104349Sphk                                            const XML_Char *pubid,
303104349Sphk                                            int has_internal_subset);
304104349Sphk
305104349Sphk/* This is called for the start of the DOCTYPE declaration when the
306104349Sphk   closing > is encountered, but after processing any external
307104349Sphk   subset.
308104349Sphk*/
309178848Scokanetypedef void (XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
310104349Sphk
311104349Sphk/* This is called for entity declarations. The is_parameter_entity
312104349Sphk   argument will be non-zero if the entity is a parameter entity, zero
313104349Sphk   otherwise.
314104349Sphk
315104349Sphk   For internal entities (<!ENTITY foo "bar">), value will
316104349Sphk   be non-NULL and systemId, publicID, and notationName will be NULL.
317104349Sphk   The value string is NOT nul-terminated; the length is provided in
318104349Sphk   the value_length argument. Since it is legal to have zero-length
319104349Sphk   values, do not use this argument to test for internal entities.
320104349Sphk
321104349Sphk   For external entities, value will be NULL and systemId will be
322104349Sphk   non-NULL. The publicId argument will be NULL unless a public
323104349Sphk   identifier was provided. The notationName argument will have a
324104349Sphk   non-NULL value only for unparsed entity declarations.
325104349Sphk
326104349Sphk   Note that is_parameter_entity can't be changed to XML_Bool, since
327104349Sphk   that would break binary compatibility.
328104349Sphk*/
329178848Scokanetypedef void (XMLCALL *XML_EntityDeclHandler) (
330178848Scokane                              void *userData,
331178848Scokane                              const XML_Char *entityName,
332178848Scokane                              int is_parameter_entity,
333178848Scokane                              const XML_Char *value,
334178848Scokane                              int value_length,
335178848Scokane                              const XML_Char *base,
336178848Scokane                              const XML_Char *systemId,
337178848Scokane                              const XML_Char *publicId,
338178848Scokane                              const XML_Char *notationName);
339178848Scokane
340104349SphkXMLPARSEAPI(void)
341104349SphkXML_SetEntityDeclHandler(XML_Parser parser,
342104349Sphk                         XML_EntityDeclHandler handler);
343104349Sphk
344104349Sphk/* OBSOLETE -- OBSOLETE -- OBSOLETE
345302385Sdelphij   This handler has been superseded by the EntityDeclHandler above.
346104349Sphk   It is provided here for backward compatibility.
347104349Sphk
348104349Sphk   This is called for a declaration of an unparsed (NDATA) entity.
349104349Sphk   The base argument is whatever was set by XML_SetBase. The
350104349Sphk   entityName, systemId and notationName arguments will never be
351104349Sphk   NULL. The other arguments may be.
352104349Sphk*/
353178848Scokanetypedef void (XMLCALL *XML_UnparsedEntityDeclHandler) (
354178848Scokane                                    void *userData,
355178848Scokane                                    const XML_Char *entityName,
356178848Scokane                                    const XML_Char *base,
357178848Scokane                                    const XML_Char *systemId,
358178848Scokane                                    const XML_Char *publicId,
359178848Scokane                                    const XML_Char *notationName);
360104349Sphk
361104349Sphk/* This is called for a declaration of notation.  The base argument is
362104349Sphk   whatever was set by XML_SetBase. The notationName will never be
363104349Sphk   NULL.  The other arguments can be.
364104349Sphk*/
365178848Scokanetypedef void (XMLCALL *XML_NotationDeclHandler) (
366178848Scokane                                    void *userData,
367178848Scokane                                    const XML_Char *notationName,
368178848Scokane                                    const XML_Char *base,
369178848Scokane                                    const XML_Char *systemId,
370178848Scokane                                    const XML_Char *publicId);
371104349Sphk
372104349Sphk/* When namespace processing is enabled, these are called once for
373104349Sphk   each namespace declaration. The call to the start and end element
374104349Sphk   handlers occur between the calls to the start and end namespace
375104349Sphk   declaration handlers. For an xmlns attribute, prefix will be
376104349Sphk   NULL.  For an xmlns="" attribute, uri will be NULL.
377104349Sphk*/
378178848Scokanetypedef void (XMLCALL *XML_StartNamespaceDeclHandler) (
379178848Scokane                                    void *userData,
380178848Scokane                                    const XML_Char *prefix,
381178848Scokane                                    const XML_Char *uri);
382104349Sphk
383178848Scokanetypedef void (XMLCALL *XML_EndNamespaceDeclHandler) (
384178848Scokane                                    void *userData,
385178848Scokane                                    const XML_Char *prefix);
386104349Sphk
387104349Sphk/* This is called if the document is not standalone, that is, it has an
388104349Sphk   external subset or a reference to a parameter entity, but does not
389178848Scokane   have standalone="yes". If this handler returns XML_STATUS_ERROR,
390178848Scokane   then processing will not continue, and the parser will return a
391104349Sphk   XML_ERROR_NOT_STANDALONE error.
392104349Sphk   If parameter entity parsing is enabled, then in addition to the
393104349Sphk   conditions above this handler will only be called if the referenced
394104349Sphk   entity was actually read.
395104349Sphk*/
396178848Scokanetypedef int (XMLCALL *XML_NotStandaloneHandler) (void *userData);
397104349Sphk
398104349Sphk/* This is called for a reference to an external parsed general
399104349Sphk   entity.  The referenced entity is not automatically parsed.  The
400104349Sphk   application can parse it immediately or later using
401104349Sphk   XML_ExternalEntityParserCreate.
402104349Sphk
403104349Sphk   The parser argument is the parser parsing the entity containing the
404104349Sphk   reference; it can be passed as the parser argument to
405104349Sphk   XML_ExternalEntityParserCreate.  The systemId argument is the
406104349Sphk   system identifier as specified in the entity declaration; it will
407104349Sphk   not be NULL.
408104349Sphk
409104349Sphk   The base argument is the system identifier that should be used as
410104349Sphk   the base for resolving systemId if systemId was relative; this is
411104349Sphk   set by XML_SetBase; it may be NULL.
412104349Sphk
413104349Sphk   The publicId argument is the public identifier as specified in the
414104349Sphk   entity declaration, or NULL if none was specified; the whitespace
415104349Sphk   in the public identifier will have been normalized as required by
416104349Sphk   the XML spec.
417104349Sphk
418104349Sphk   The context argument specifies the parsing context in the format
419104349Sphk   expected by the context argument to XML_ExternalEntityParserCreate;
420104349Sphk   context is valid only until the handler returns, so if the
421104349Sphk   referenced entity is to be parsed later, it must be copied.
422178848Scokane   context is NULL only when the entity is a parameter entity.
423104349Sphk
424178848Scokane   The handler should return XML_STATUS_ERROR if processing should not
425178848Scokane   continue because of a fatal error in the handling of the external
426178848Scokane   entity.  In this case the calling parser will return an
427104349Sphk   XML_ERROR_EXTERNAL_ENTITY_HANDLING error.
428104349Sphk
429104349Sphk   Note that unlike other handlers the first argument is the parser,
430104349Sphk   not userData.
431104349Sphk*/
432178848Scokanetypedef int (XMLCALL *XML_ExternalEntityRefHandler) (
433178848Scokane                                    XML_Parser parser,
434178848Scokane                                    const XML_Char *context,
435178848Scokane                                    const XML_Char *base,
436178848Scokane                                    const XML_Char *systemId,
437178848Scokane                                    const XML_Char *publicId);
438104349Sphk
439104349Sphk/* This is called in two situations:
440104349Sphk   1) An entity reference is encountered for which no declaration
441104349Sphk      has been read *and* this is not an error.
442104349Sphk   2) An internal entity reference is read, but not expanded, because
443104349Sphk      XML_SetDefaultHandler has been called.
444104349Sphk   Note: skipped parameter entities in declarations and skipped general
445104349Sphk         entities in attribute values cannot be reported, because
446104349Sphk         the event would be out of sync with the reporting of the
447104349Sphk         declarations or attribute values
448104349Sphk*/
449178848Scokanetypedef void (XMLCALL *XML_SkippedEntityHandler) (
450178848Scokane                                    void *userData,
451178848Scokane                                    const XML_Char *entityName,
452178848Scokane                                    int is_parameter_entity);
453104349Sphk
454104349Sphk/* This structure is filled in by the XML_UnknownEncodingHandler to
455104349Sphk   provide information to the parser about encodings that are unknown
456104349Sphk   to the parser.
457104349Sphk
458104349Sphk   The map[b] member gives information about byte sequences whose
459104349Sphk   first byte is b.
460104349Sphk
461104349Sphk   If map[b] is c where c is >= 0, then b by itself encodes the
462104349Sphk   Unicode scalar value c.
463104349Sphk
464104349Sphk   If map[b] is -1, then the byte sequence is malformed.
465104349Sphk
466104349Sphk   If map[b] is -n, where n >= 2, then b is the first byte of an
467104349Sphk   n-byte sequence that encodes a single Unicode scalar value.
468104349Sphk
469104349Sphk   The data member will be passed as the first argument to the convert
470104349Sphk   function.
471104349Sphk
472104349Sphk   The convert function is used to convert multibyte sequences; s will
473104349Sphk   point to a n-byte sequence where map[(unsigned char)*s] == -n.  The
474104349Sphk   convert function must return the Unicode scalar value represented
475104349Sphk   by this byte sequence or -1 if the byte sequence is malformed.
476104349Sphk
477104349Sphk   The convert function may be NULL if the encoding is a single-byte
478104349Sphk   encoding, that is if map[b] >= -1 for all bytes b.
479104349Sphk
480104349Sphk   When the parser is finished with the encoding, then if release is
481104349Sphk   not NULL, it will call release passing it the data member; once
482104349Sphk   release has been called, the convert function will not be called
483104349Sphk   again.
484104349Sphk
485104349Sphk   Expat places certain restrictions on the encodings that are supported
486104349Sphk   using this mechanism.
487104349Sphk
488104349Sphk   1. Every ASCII character that can appear in a well-formed XML document,
489104349Sphk      other than the characters
490104349Sphk
491104349Sphk      $@\^`{}~
492104349Sphk
493104349Sphk      must be represented by a single byte, and that byte must be the
494104349Sphk      same byte that represents that character in ASCII.
495104349Sphk
496104349Sphk   2. No character may require more than 4 bytes to encode.
497104349Sphk
498104349Sphk   3. All characters encoded must have Unicode scalar values <=
499104349Sphk      0xFFFF, (i.e., characters that would be encoded by surrogates in
500104349Sphk      UTF-16 are  not allowed).  Note that this restriction doesn't
501104349Sphk      apply to the built-in support for UTF-8 and UTF-16.
502104349Sphk
503104349Sphk   4. No Unicode character may be encoded by more than one distinct
504104349Sphk      sequence of bytes.
505104349Sphk*/
506104349Sphktypedef struct {
507104349Sphk  int map[256];
508104349Sphk  void *data;
509178848Scokane  int (XMLCALL *convert)(void *data, const char *s);
510178848Scokane  void (XMLCALL *release)(void *data);
511104349Sphk} XML_Encoding;
512104349Sphk
513104349Sphk/* This is called for an encoding that is unknown to the parser.
514104349Sphk
515104349Sphk   The encodingHandlerData argument is that which was passed as the
516104349Sphk   second argument to XML_SetUnknownEncodingHandler.
517104349Sphk
518104349Sphk   The name argument gives the name of the encoding as specified in
519104349Sphk   the encoding declaration.
520104349Sphk
521104349Sphk   If the callback can provide information about the encoding, it must
522178848Scokane   fill in the XML_Encoding structure, and return XML_STATUS_OK.
523178848Scokane   Otherwise it must return XML_STATUS_ERROR.
524104349Sphk
525104349Sphk   If info does not describe a suitable encoding, then the parser will
526104349Sphk   return an XML_UNKNOWN_ENCODING error.
527104349Sphk*/
528178848Scokanetypedef int (XMLCALL *XML_UnknownEncodingHandler) (
529178848Scokane                                    void *encodingHandlerData,
530178848Scokane                                    const XML_Char *name,
531178848Scokane                                    XML_Encoding *info);
532104349Sphk
533104349SphkXMLPARSEAPI(void)
534104349SphkXML_SetElementHandler(XML_Parser parser,
535104349Sphk                      XML_StartElementHandler start,
536104349Sphk                      XML_EndElementHandler end);
537104349Sphk
538104349SphkXMLPARSEAPI(void)
539178848ScokaneXML_SetStartElementHandler(XML_Parser parser,
540178848Scokane                           XML_StartElementHandler handler);
541104349Sphk
542104349SphkXMLPARSEAPI(void)
543178848ScokaneXML_SetEndElementHandler(XML_Parser parser,
544178848Scokane                         XML_EndElementHandler handler);
545104349Sphk
546104349SphkXMLPARSEAPI(void)
547104349SphkXML_SetCharacterDataHandler(XML_Parser parser,
548104349Sphk                            XML_CharacterDataHandler handler);
549104349Sphk
550104349SphkXMLPARSEAPI(void)
551104349SphkXML_SetProcessingInstructionHandler(XML_Parser parser,
552104349Sphk                                    XML_ProcessingInstructionHandler handler);
553104349SphkXMLPARSEAPI(void)
554104349SphkXML_SetCommentHandler(XML_Parser parser,
555104349Sphk                      XML_CommentHandler handler);
556104349Sphk
557104349SphkXMLPARSEAPI(void)
558104349SphkXML_SetCdataSectionHandler(XML_Parser parser,
559104349Sphk                           XML_StartCdataSectionHandler start,
560104349Sphk                           XML_EndCdataSectionHandler end);
561104349Sphk
562104349SphkXMLPARSEAPI(void)
563104349SphkXML_SetStartCdataSectionHandler(XML_Parser parser,
564104349Sphk                                XML_StartCdataSectionHandler start);
565104349Sphk
566104349SphkXMLPARSEAPI(void)
567104349SphkXML_SetEndCdataSectionHandler(XML_Parser parser,
568104349Sphk                              XML_EndCdataSectionHandler end);
569104349Sphk
570104349Sphk/* This sets the default handler and also inhibits expansion of
571104349Sphk   internal entities. These entity references will be passed to the
572104349Sphk   default handler, or to the skipped entity handler, if one is set.
573104349Sphk*/
574104349SphkXMLPARSEAPI(void)
575104349SphkXML_SetDefaultHandler(XML_Parser parser,
576104349Sphk                      XML_DefaultHandler handler);
577104349Sphk
578104349Sphk/* This sets the default handler but does not inhibit expansion of
579104349Sphk   internal entities.  The entity reference will not be passed to the
580104349Sphk   default handler.
581104349Sphk*/
582104349SphkXMLPARSEAPI(void)
583104349SphkXML_SetDefaultHandlerExpand(XML_Parser parser,
584104349Sphk                            XML_DefaultHandler handler);
585104349Sphk
586104349SphkXMLPARSEAPI(void)
587104349SphkXML_SetDoctypeDeclHandler(XML_Parser parser,
588104349Sphk                          XML_StartDoctypeDeclHandler start,
589104349Sphk                          XML_EndDoctypeDeclHandler end);
590104349Sphk
591104349SphkXMLPARSEAPI(void)
592104349SphkXML_SetStartDoctypeDeclHandler(XML_Parser parser,
593104349Sphk                               XML_StartDoctypeDeclHandler start);
594104349Sphk
595104349SphkXMLPARSEAPI(void)
596104349SphkXML_SetEndDoctypeDeclHandler(XML_Parser parser,
597104349Sphk                             XML_EndDoctypeDeclHandler end);
598104349Sphk
599104349SphkXMLPARSEAPI(void)
600104349SphkXML_SetUnparsedEntityDeclHandler(XML_Parser parser,
601104349Sphk                                 XML_UnparsedEntityDeclHandler handler);
602104349Sphk
603104349SphkXMLPARSEAPI(void)
604104349SphkXML_SetNotationDeclHandler(XML_Parser parser,
605104349Sphk                           XML_NotationDeclHandler handler);
606104349Sphk
607104349SphkXMLPARSEAPI(void)
608104349SphkXML_SetNamespaceDeclHandler(XML_Parser parser,
609104349Sphk                            XML_StartNamespaceDeclHandler start,
610104349Sphk                            XML_EndNamespaceDeclHandler end);
611104349Sphk
612104349SphkXMLPARSEAPI(void)
613104349SphkXML_SetStartNamespaceDeclHandler(XML_Parser parser,
614104349Sphk                                 XML_StartNamespaceDeclHandler start);
615104349Sphk
616104349SphkXMLPARSEAPI(void)
617104349SphkXML_SetEndNamespaceDeclHandler(XML_Parser parser,
618104349Sphk                               XML_EndNamespaceDeclHandler end);
619104349Sphk
620104349SphkXMLPARSEAPI(void)
621104349SphkXML_SetNotStandaloneHandler(XML_Parser parser,
622104349Sphk                            XML_NotStandaloneHandler handler);
623104349Sphk
624104349SphkXMLPARSEAPI(void)
625104349SphkXML_SetExternalEntityRefHandler(XML_Parser parser,
626104349Sphk                                XML_ExternalEntityRefHandler handler);
627104349Sphk
628104349Sphk/* If a non-NULL value for arg is specified here, then it will be
629104349Sphk   passed as the first argument to the external entity ref handler
630104349Sphk   instead of the parser object.
631104349Sphk*/
632104349SphkXMLPARSEAPI(void)
633178848ScokaneXML_SetExternalEntityRefHandlerArg(XML_Parser parser,
634178848Scokane                                   void *arg);
635104349Sphk
636104349SphkXMLPARSEAPI(void)
637104349SphkXML_SetSkippedEntityHandler(XML_Parser parser,
638104349Sphk                            XML_SkippedEntityHandler handler);
639104349Sphk
640104349SphkXMLPARSEAPI(void)
641104349SphkXML_SetUnknownEncodingHandler(XML_Parser parser,
642104349Sphk                              XML_UnknownEncodingHandler handler,
643104349Sphk                              void *encodingHandlerData);
644104349Sphk
645104349Sphk/* This can be called within a handler for a start element, end
646104349Sphk   element, processing instruction or character data.  It causes the
647104349Sphk   corresponding markup to be passed to the default handler.
648104349Sphk*/
649104349SphkXMLPARSEAPI(void)
650104349SphkXML_DefaultCurrent(XML_Parser parser);
651104349Sphk
652104349Sphk/* If do_nst is non-zero, and namespace processing is in effect, and
653104349Sphk   a name has a prefix (i.e. an explicit namespace qualifier) then
654104349Sphk   that name is returned as a triplet in a single string separated by
655104349Sphk   the separator character specified when the parser was created: URI
656104349Sphk   + sep + local_name + sep + prefix.
657104349Sphk
658104349Sphk   If do_nst is zero, then namespace information is returned in the
659104349Sphk   default manner (URI + sep + local_name) whether or not the name
660104349Sphk   has a prefix.
661104349Sphk
662104349Sphk   Note: Calling XML_SetReturnNSTriplet after XML_Parse or
663104349Sphk     XML_ParseBuffer has no effect.
664104349Sphk*/
665104349Sphk
666104349SphkXMLPARSEAPI(void)
667104349SphkXML_SetReturnNSTriplet(XML_Parser parser, int do_nst);
668104349Sphk
669104349Sphk/* This value is passed as the userData argument to callbacks. */
670104349SphkXMLPARSEAPI(void)
671104349SphkXML_SetUserData(XML_Parser parser, void *userData);
672104349Sphk
673104349Sphk/* Returns the last value set by XML_SetUserData or NULL. */
674104349Sphk#define XML_GetUserData(parser) (*(void **)(parser))
675104349Sphk
676104349Sphk/* This is equivalent to supplying an encoding argument to
677104349Sphk   XML_ParserCreate. On success XML_SetEncoding returns non-zero,
678104349Sphk   zero otherwise.
679104349Sphk   Note: Calling XML_SetEncoding after XML_Parse or XML_ParseBuffer
680178848Scokane     has no effect and returns XML_STATUS_ERROR.
681104349Sphk*/
682178848ScokaneXMLPARSEAPI(enum XML_Status)
683104349SphkXML_SetEncoding(XML_Parser parser, const XML_Char *encoding);
684104349Sphk
685104349Sphk/* If this function is called, then the parser will be passed as the
686104349Sphk   first argument to callbacks instead of userData.  The userData will
687104349Sphk   still be accessible using XML_GetUserData.
688104349Sphk*/
689104349SphkXMLPARSEAPI(void)
690104349SphkXML_UseParserAsHandlerArg(XML_Parser parser);
691104349Sphk
692104349Sphk/* If useDTD == XML_TRUE is passed to this function, then the parser
693104349Sphk   will assume that there is an external subset, even if none is
694104349Sphk   specified in the document. In such a case the parser will call the
695104349Sphk   externalEntityRefHandler with a value of NULL for the systemId
696104349Sphk   argument (the publicId and context arguments will be NULL as well).
697178848Scokane   Note: For the purpose of checking WFC: Entity Declared, passing
698178848Scokane     useDTD == XML_TRUE will make the parser behave as if the document
699178848Scokane     had a DTD with an external subset.
700104349Sphk   Note: If this function is called, then this must be done before
701104349Sphk     the first call to XML_Parse or XML_ParseBuffer, since it will
702104349Sphk     have no effect after that.  Returns
703104349Sphk     XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING.
704104349Sphk   Note: If the document does not have a DOCTYPE declaration at all,
705104349Sphk     then startDoctypeDeclHandler and endDoctypeDeclHandler will not
706104349Sphk     be called, despite an external subset being parsed.
707104349Sphk   Note: If XML_DTD is not defined when Expat is compiled, returns
708104349Sphk     XML_ERROR_FEATURE_REQUIRES_XML_DTD.
709104349Sphk*/
710104349SphkXMLPARSEAPI(enum XML_Error)
711104349SphkXML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD);
712104349Sphk
713104349Sphk
714104349Sphk/* Sets the base to be used for resolving relative URIs in system
715104349Sphk   identifiers in declarations.  Resolving relative identifiers is
716104349Sphk   left to the application: this value will be passed through as the
717104349Sphk   base argument to the XML_ExternalEntityRefHandler,
718104349Sphk   XML_NotationDeclHandler and XML_UnparsedEntityDeclHandler. The base
719178848Scokane   argument will be copied.  Returns XML_STATUS_ERROR if out of memory,
720178848Scokane   XML_STATUS_OK otherwise.
721104349Sphk*/
722178848ScokaneXMLPARSEAPI(enum XML_Status)
723104349SphkXML_SetBase(XML_Parser parser, const XML_Char *base);
724104349Sphk
725104349SphkXMLPARSEAPI(const XML_Char *)
726104349SphkXML_GetBase(XML_Parser parser);
727104349Sphk
728104349Sphk/* Returns the number of the attribute/value pairs passed in last call
729104349Sphk   to the XML_StartElementHandler that were specified in the start-tag
730104349Sphk   rather than defaulted. Each attribute/value pair counts as 2; thus
731104349Sphk   this correspondds to an index into the atts array passed to the
732104349Sphk   XML_StartElementHandler.
733104349Sphk*/
734104349SphkXMLPARSEAPI(int)
735104349SphkXML_GetSpecifiedAttributeCount(XML_Parser parser);
736104349Sphk
737104349Sphk/* Returns the index of the ID attribute passed in the last call to
738104349Sphk   XML_StartElementHandler, or -1 if there is no ID attribute.  Each
739104349Sphk   attribute/value pair counts as 2; thus this correspondds to an
740104349Sphk   index into the atts array passed to the XML_StartElementHandler.
741104349Sphk*/
742104349SphkXMLPARSEAPI(int)
743104349SphkXML_GetIdAttributeIndex(XML_Parser parser);
744104349Sphk
745247296Sdelphij#ifdef XML_ATTR_INFO
746247296Sdelphij/* Source file byte offsets for the start and end of attribute names and values.
747247296Sdelphij   The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
748247296Sdelphij   file an attribute value of "blah" will yield:
749247296Sdelphij   info->valueEnd - info->valueStart = 4 bytes.
750247296Sdelphij*/
751247296Sdelphijtypedef struct {
752247296Sdelphij  XML_Index  nameStart;  /* Offset to beginning of the attribute name. */
753247296Sdelphij  XML_Index  nameEnd;    /* Offset after the attribute name's last byte. */
754247296Sdelphij  XML_Index  valueStart; /* Offset to beginning of the attribute value. */
755247296Sdelphij  XML_Index  valueEnd;   /* Offset after the attribute value's last byte. */
756247296Sdelphij} XML_AttrInfo;
757247296Sdelphij
758247296Sdelphij/* Returns an array of XML_AttrInfo structures for the attribute/value pairs
759247296Sdelphij   passed in last call to the XML_StartElementHandler that were specified
760247296Sdelphij   in the start-tag rather than defaulted. Each attribute/value pair counts
761247296Sdelphij   as 1; thus the number of entries in the array is
762247296Sdelphij   XML_GetSpecifiedAttributeCount(parser) / 2.
763247296Sdelphij*/
764247296SdelphijXMLPARSEAPI(const XML_AttrInfo *)
765247296SdelphijXML_GetAttributeInfo(XML_Parser parser);
766247296Sdelphij#endif
767247296Sdelphij
768104349Sphk/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
769104349Sphk   detected.  The last call to XML_Parse must have isFinal true; len
770104349Sphk   may be zero for this call (or any other).
771104349Sphk
772178848Scokane   Though the return values for these functions has always been
773178848Scokane   described as a Boolean value, the implementation, at least for the
774178848Scokane   1.95.x series, has always returned exactly one of the XML_Status
775178848Scokane   values.
776104349Sphk*/
777104349SphkXMLPARSEAPI(enum XML_Status)
778104349SphkXML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
779104349Sphk
780104349SphkXMLPARSEAPI(void *)
781104349SphkXML_GetBuffer(XML_Parser parser, int len);
782104349Sphk
783104349SphkXMLPARSEAPI(enum XML_Status)
784104349SphkXML_ParseBuffer(XML_Parser parser, int len, int isFinal);
785104349Sphk
786178848Scokane/* Stops parsing, causing XML_Parse() or XML_ParseBuffer() to return.
787178848Scokane   Must be called from within a call-back handler, except when aborting
788178848Scokane   (resumable = 0) an already suspended parser. Some call-backs may
789178848Scokane   still follow because they would otherwise get lost. Examples:
790178848Scokane   - endElementHandler() for empty elements when stopped in
791178848Scokane     startElementHandler(),
792178848Scokane   - endNameSpaceDeclHandler() when stopped in endElementHandler(),
793178848Scokane   and possibly others.
794178848Scokane
795178848Scokane   Can be called from most handlers, including DTD related call-backs,
796178848Scokane   except when parsing an external parameter entity and resumable != 0.
797178848Scokane   Returns XML_STATUS_OK when successful, XML_STATUS_ERROR otherwise.
798178848Scokane   Possible error codes:
799178848Scokane   - XML_ERROR_SUSPENDED: when suspending an already suspended parser.
800178848Scokane   - XML_ERROR_FINISHED: when the parser has already finished.
801178848Scokane   - XML_ERROR_SUSPEND_PE: when suspending while parsing an external PE.
802178848Scokane
803178848Scokane   When resumable != 0 (true) then parsing is suspended, that is,
804178848Scokane   XML_Parse() and XML_ParseBuffer() return XML_STATUS_SUSPENDED.
805178848Scokane   Otherwise, parsing is aborted, that is, XML_Parse() and XML_ParseBuffer()
806178848Scokane   return XML_STATUS_ERROR with error code XML_ERROR_ABORTED.
807178848Scokane
808178848Scokane   *Note*:
809178848Scokane   This will be applied to the current parser instance only, that is, if
810178848Scokane   there is a parent parser then it will continue parsing when the
811178848Scokane   externalEntityRefHandler() returns. It is up to the implementation of
812178848Scokane   the externalEntityRefHandler() to call XML_StopParser() on the parent
813178848Scokane   parser (recursively), if one wants to stop parsing altogether.
814178848Scokane
815178848Scokane   When suspended, parsing can be resumed by calling XML_ResumeParser().
816178848Scokane*/
817178848ScokaneXMLPARSEAPI(enum XML_Status)
818178848ScokaneXML_StopParser(XML_Parser parser, XML_Bool resumable);
819178848Scokane
820178848Scokane/* Resumes parsing after it has been suspended with XML_StopParser().
821178848Scokane   Must not be called from within a handler call-back. Returns same
822178848Scokane   status codes as XML_Parse() or XML_ParseBuffer().
823178848Scokane   Additional error code XML_ERROR_NOT_SUSPENDED possible.
824178848Scokane
825178848Scokane   *Note*:
826178848Scokane   This must be called on the most deeply nested child parser instance
827178848Scokane   first, and on its parent parser only after the child parser has finished,
828178848Scokane   to be applied recursively until the document entity's parser is restarted.
829178848Scokane   That is, the parent parser will not resume by itself and it is up to the
830178848Scokane   application to call XML_ResumeParser() on it at the appropriate moment.
831178848Scokane*/
832178848ScokaneXMLPARSEAPI(enum XML_Status)
833178848ScokaneXML_ResumeParser(XML_Parser parser);
834178848Scokane
835178848Scokaneenum XML_Parsing {
836178848Scokane  XML_INITIALIZED,
837178848Scokane  XML_PARSING,
838178848Scokane  XML_FINISHED,
839178848Scokane  XML_SUSPENDED
840178848Scokane};
841178848Scokane
842178848Scokanetypedef struct {
843178848Scokane  enum XML_Parsing parsing;
844178848Scokane  XML_Bool finalBuffer;
845178848Scokane} XML_ParsingStatus;
846178848Scokane
847178848Scokane/* Returns status of parser with respect to being initialized, parsing,
848178848Scokane   finished, or suspended and processing the final buffer.
849178848Scokane   XXX XML_Parse() and XML_ParseBuffer() should return XML_ParsingStatus,
850178848Scokane   XXX with XML_FINISHED_OK or XML_FINISHED_ERROR replacing XML_FINISHED
851178848Scokane*/
852178848ScokaneXMLPARSEAPI(void)
853178848ScokaneXML_GetParsingStatus(XML_Parser parser, XML_ParsingStatus *status);
854178848Scokane
855104349Sphk/* Creates an XML_Parser object that can parse an external general
856104349Sphk   entity; context is a '\0'-terminated string specifying the parse
857104349Sphk   context; encoding is a '\0'-terminated string giving the name of
858104349Sphk   the externally specified encoding, or NULL if there is no
859104349Sphk   externally specified encoding.  The context string consists of a
860104349Sphk   sequence of tokens separated by formfeeds (\f); a token consisting
861104349Sphk   of a name specifies that the general entity of the name is open; a
862104349Sphk   token of the form prefix=uri specifies the namespace for a
863104349Sphk   particular prefix; a token of the form =uri specifies the default
864104349Sphk   namespace.  This can be called at any point after the first call to
865104349Sphk   an ExternalEntityRefHandler so longer as the parser has not yet
866104349Sphk   been freed.  The new parser is completely independent and may
867104349Sphk   safely be used in a separate thread.  The handlers and userData are
868178848Scokane   initialized from the parser argument.  Returns NULL if out of memory.
869104349Sphk   Otherwise returns a new XML_Parser object.
870104349Sphk*/
871104349SphkXMLPARSEAPI(XML_Parser)
872104349SphkXML_ExternalEntityParserCreate(XML_Parser parser,
873104349Sphk                               const XML_Char *context,
874104349Sphk                               const XML_Char *encoding);
875104349Sphk
876104349Sphkenum XML_ParamEntityParsing {
877104349Sphk  XML_PARAM_ENTITY_PARSING_NEVER,
878104349Sphk  XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
879104349Sphk  XML_PARAM_ENTITY_PARSING_ALWAYS
880104349Sphk};
881104349Sphk
882104349Sphk/* Controls parsing of parameter entities (including the external DTD
883104349Sphk   subset). If parsing of parameter entities is enabled, then
884104349Sphk   references to external parameter entities (including the external
885104349Sphk   DTD subset) will be passed to the handler set with
886104349Sphk   XML_SetExternalEntityRefHandler.  The context passed will be 0.
887104349Sphk
888104349Sphk   Unlike external general entities, external parameter entities can
889104349Sphk   only be parsed synchronously.  If the external parameter entity is
890104349Sphk   to be parsed, it must be parsed during the call to the external
891104349Sphk   entity ref handler: the complete sequence of
892104349Sphk   XML_ExternalEntityParserCreate, XML_Parse/XML_ParseBuffer and
893104349Sphk   XML_ParserFree calls must be made during this call.  After
894104349Sphk   XML_ExternalEntityParserCreate has been called to create the parser
895104349Sphk   for the external parameter entity (context must be 0 for this
896104349Sphk   call), it is illegal to make any calls on the old parser until
897104349Sphk   XML_ParserFree has been called on the newly created parser.
898104349Sphk   If the library has been compiled without support for parameter
899104349Sphk   entity parsing (ie without XML_DTD being defined), then
900104349Sphk   XML_SetParamEntityParsing will return 0 if parsing of parameter
901104349Sphk   entities is requested; otherwise it will return non-zero.
902104349Sphk   Note: If XML_SetParamEntityParsing is called after XML_Parse or
903104349Sphk      XML_ParseBuffer, then it has no effect and will always return 0.
904104349Sphk*/
905104349SphkXMLPARSEAPI(int)
906104349SphkXML_SetParamEntityParsing(XML_Parser parser,
907104349Sphk                          enum XML_ParamEntityParsing parsing);
908104349Sphk
909247296Sdelphij/* Sets the hash salt to use for internal hash calculations.
910247296Sdelphij   Helps in preventing DoS attacks based on predicting hash
911247296Sdelphij   function behavior. This must be called before parsing is started.
912247296Sdelphij   Returns 1 if successful, 0 when called after parsing has started.
913247296Sdelphij*/
914247296SdelphijXMLPARSEAPI(int)
915247296SdelphijXML_SetHashSalt(XML_Parser parser,
916247296Sdelphij                unsigned long hash_salt);
917247296Sdelphij
918178848Scokane/* If XML_Parse or XML_ParseBuffer have returned XML_STATUS_ERROR, then
919104349Sphk   XML_GetErrorCode returns information about the error.
920104349Sphk*/
921104349SphkXMLPARSEAPI(enum XML_Error)
922104349SphkXML_GetErrorCode(XML_Parser parser);
923104349Sphk
924104349Sphk/* These functions return information about the current parse
925178848Scokane   location.  They may be called from any callback called to report
926178848Scokane   some parse event; in this case the location is the location of the
927178848Scokane   first of the sequence of characters that generated the event.  When
928178848Scokane   called from callbacks generated by declarations in the document
929178848Scokane   prologue, the location identified isn't as neatly defined, but will
930178848Scokane   be within the relevant markup.  When called outside of the callback
931178848Scokane   functions, the position indicated will be just past the last parse
932178848Scokane   event (regardless of whether there was an associated callback).
933178848Scokane
934178848Scokane   They may also be called after returning from a call to XML_Parse
935178848Scokane   or XML_ParseBuffer.  If the return value is XML_STATUS_ERROR then
936178848Scokane   the location is the location of the character at which the error
937178848Scokane   was detected; otherwise the location is the location of the last
938178848Scokane   parse event, as described above.
939104349Sphk*/
940178848ScokaneXMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
941178848ScokaneXMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
942178848ScokaneXMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
943104349Sphk
944104349Sphk/* Return the number of bytes in the current event.
945104349Sphk   Returns 0 if the event is in an internal entity.
946104349Sphk*/
947104349SphkXMLPARSEAPI(int)
948104349SphkXML_GetCurrentByteCount(XML_Parser parser);
949104349Sphk
950104349Sphk/* If XML_CONTEXT_BYTES is defined, returns the input buffer, sets
951104349Sphk   the integer pointed to by offset to the offset within this buffer
952104349Sphk   of the current parse position, and sets the integer pointed to by size
953104349Sphk   to the size of this buffer (the number of input bytes). Otherwise
954104349Sphk   returns a NULL pointer. Also returns a NULL pointer if a parse isn't
955104349Sphk   active.
956104349Sphk
957104349Sphk   NOTE: The character pointer returned should not be used outside
958104349Sphk   the handler that makes the call.
959104349Sphk*/
960104349SphkXMLPARSEAPI(const char *)
961104349SphkXML_GetInputContext(XML_Parser parser,
962104349Sphk                    int *offset,
963104349Sphk                    int *size);
964104349Sphk
965104349Sphk/* For backwards compatibility with previous versions. */
966104349Sphk#define XML_GetErrorLineNumber   XML_GetCurrentLineNumber
967104349Sphk#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
968104349Sphk#define XML_GetErrorByteIndex    XML_GetCurrentByteIndex
969104349Sphk
970178848Scokane/* Frees the content model passed to the element declaration handler */
971178848ScokaneXMLPARSEAPI(void)
972178848ScokaneXML_FreeContentModel(XML_Parser parser, XML_Content *model);
973178848Scokane
974178848Scokane/* Exposing the memory handling functions used in Expat */
975178848ScokaneXMLPARSEAPI(void *)
976302385SdelphijXML_ATTR_MALLOC
977302385SdelphijXML_ATTR_ALLOC_SIZE(2)
978178848ScokaneXML_MemMalloc(XML_Parser parser, size_t size);
979178848Scokane
980178848ScokaneXMLPARSEAPI(void *)
981302385SdelphijXML_ATTR_ALLOC_SIZE(3)
982178848ScokaneXML_MemRealloc(XML_Parser parser, void *ptr, size_t size);
983178848Scokane
984178848ScokaneXMLPARSEAPI(void)
985178848ScokaneXML_MemFree(XML_Parser parser, void *ptr);
986178848Scokane
987104349Sphk/* Frees memory used by the parser. */
988104349SphkXMLPARSEAPI(void)
989104349SphkXML_ParserFree(XML_Parser parser);
990104349Sphk
991104349Sphk/* Returns a string describing the error. */
992104349SphkXMLPARSEAPI(const XML_LChar *)
993104349SphkXML_ErrorString(enum XML_Error code);
994104349Sphk
995104349Sphk/* Return a string containing the version number of this expat */
996104349SphkXMLPARSEAPI(const XML_LChar *)
997104349SphkXML_ExpatVersion(void);
998104349Sphk
999104349Sphktypedef struct {
1000104349Sphk  int major;
1001104349Sphk  int minor;
1002104349Sphk  int micro;
1003104349Sphk} XML_Expat_Version;
1004104349Sphk
1005104349Sphk/* Return an XML_Expat_Version structure containing numeric version
1006104349Sphk   number information for this version of expat.
1007104349Sphk*/
1008104349SphkXMLPARSEAPI(XML_Expat_Version)
1009104349SphkXML_ExpatVersionInfo(void);
1010104349Sphk
1011104349Sphk/* Added in Expat 1.95.5. */
1012104349Sphkenum XML_FeatureEnum {
1013104349Sphk  XML_FEATURE_END = 0,
1014104349Sphk  XML_FEATURE_UNICODE,
1015104349Sphk  XML_FEATURE_UNICODE_WCHAR_T,
1016104349Sphk  XML_FEATURE_DTD,
1017104349Sphk  XML_FEATURE_CONTEXT_BYTES,
1018104349Sphk  XML_FEATURE_MIN_SIZE,
1019104349Sphk  XML_FEATURE_SIZEOF_XML_CHAR,
1020178848Scokane  XML_FEATURE_SIZEOF_XML_LCHAR,
1021178848Scokane  XML_FEATURE_NS,
1022247296Sdelphij  XML_FEATURE_LARGE_SIZE,
1023247296Sdelphij  XML_FEATURE_ATTR_INFO
1024104349Sphk  /* Additional features must be added to the end of this enum. */
1025104349Sphk};
1026104349Sphk
1027104349Sphktypedef struct {
1028104349Sphk  enum XML_FeatureEnum  feature;
1029178848Scokane  const XML_LChar       *name;
1030104349Sphk  long int              value;
1031104349Sphk} XML_Feature;
1032104349Sphk
1033104349SphkXMLPARSEAPI(const XML_Feature *)
1034104349SphkXML_GetFeatureList(void);
1035104349Sphk
1036104349Sphk
1037302385Sdelphij/* Expat follows the semantic versioning convention.
1038302385Sdelphij   See http://semver.org.
1039104349Sphk*/
1040178848Scokane#define XML_MAJOR_VERSION 2
1041302385Sdelphij#define XML_MINOR_VERSION 2
1042247296Sdelphij#define XML_MICRO_VERSION 0
1043104349Sphk
1044104349Sphk#ifdef __cplusplus
1045104349Sphk}
1046104349Sphk#endif
1047104349Sphk
1048178848Scokane#endif /* not Expat_INCLUDED */
1049