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