expat.h 41 KB

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