expat.h 41 KB

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