valid.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /**
  2. * @file
  3. *
  4. * @brief DTD validator
  5. *
  6. * API to handle XML Document Type Definitions and validate
  7. * documents.
  8. *
  9. * @copyright See Copyright for the status of this software.
  10. *
  11. * @author Daniel Veillard
  12. */
  13. #ifndef __XML_VALID_H__
  14. #define __XML_VALID_H__
  15. #include <libxml/xmlversion.h>
  16. #include <libxml/xmlerror.h>
  17. #define XML_TREE_INTERNALS
  18. #include <libxml/tree.h>
  19. #undef XML_TREE_INTERNALS
  20. #include <libxml/list.h>
  21. #include <libxml/xmlautomata.h>
  22. #include <libxml/xmlregexp.h>
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /*
  27. * Validation state added for non-deterministic content model.
  28. */
  29. typedef struct _xmlValidState xmlValidState;
  30. typedef xmlValidState *xmlValidStatePtr;
  31. /**
  32. * Report a validity error.
  33. *
  34. * @param ctx user data (usually an xmlValidCtxt)
  35. * @param msg printf-like format string
  36. * @param ... arguments to format
  37. */
  38. typedef void (*xmlValidityErrorFunc) (void *ctx,
  39. const char *msg,
  40. ...) LIBXML_ATTR_FORMAT(2,3);
  41. /**
  42. * Report a validity warning.
  43. *
  44. * @param ctx user data (usually an xmlValidCtxt)
  45. * @param msg printf-like format string
  46. * @param ... arguments to format
  47. */
  48. typedef void (*xmlValidityWarningFunc) (void *ctx,
  49. const char *msg,
  50. ...) LIBXML_ATTR_FORMAT(2,3);
  51. typedef struct _xmlValidCtxt xmlValidCtxt;
  52. typedef xmlValidCtxt *xmlValidCtxtPtr;
  53. /**
  54. * An xmlValidCtxt is used for error reporting when validating.
  55. */
  56. struct _xmlValidCtxt {
  57. void *userData; /* user specific data block */
  58. xmlValidityErrorFunc error; /* the callback in case of errors */
  59. xmlValidityWarningFunc warning; /* the callback in case of warning */
  60. /* Node analysis stack used when validating within entities */
  61. xmlNode *node; /* Current parsed Node */
  62. int nodeNr; /* Depth of the parsing stack */
  63. int nodeMax; /* Max depth of the parsing stack */
  64. xmlNode **nodeTab; /* array of nodes */
  65. unsigned int flags; /* internal flags */
  66. xmlDoc *doc; /* the document */
  67. int valid; /* temporary validity check result */
  68. /* state state used for non-determinist content validation */
  69. xmlValidState *vstate; /* current state */
  70. int vstateNr; /* Depth of the validation stack */
  71. int vstateMax; /* Max depth of the validation stack */
  72. xmlValidState *vstateTab; /* array of validation states */
  73. #ifdef LIBXML_REGEXP_ENABLED
  74. xmlAutomata *am; /* the automata */
  75. xmlAutomataState *state; /* used to build the automata */
  76. #else
  77. void *am;
  78. void *state;
  79. #endif
  80. };
  81. typedef struct _xmlHashTable xmlNotationTable;
  82. typedef xmlNotationTable *xmlNotationTablePtr;
  83. typedef struct _xmlHashTable xmlElementTable;
  84. typedef xmlElementTable *xmlElementTablePtr;
  85. typedef struct _xmlHashTable xmlAttributeTable;
  86. typedef xmlAttributeTable *xmlAttributeTablePtr;
  87. typedef struct _xmlHashTable xmlIDTable;
  88. typedef xmlIDTable *xmlIDTablePtr;
  89. typedef struct _xmlHashTable xmlRefTable;
  90. typedef xmlRefTable *xmlRefTablePtr;
  91. /* Notation */
  92. XMLPUBFUN xmlNotation *
  93. xmlAddNotationDecl (xmlValidCtxt *ctxt,
  94. xmlDtd *dtd,
  95. const xmlChar *name,
  96. const xmlChar *publicId,
  97. const xmlChar *systemId);
  98. XML_DEPRECATED
  99. XMLPUBFUN xmlNotationTable *
  100. xmlCopyNotationTable (xmlNotationTable *table);
  101. XML_DEPRECATED
  102. XMLPUBFUN void
  103. xmlFreeNotationTable (xmlNotationTable *table);
  104. #ifdef LIBXML_OUTPUT_ENABLED
  105. XML_DEPRECATED
  106. XMLPUBFUN void
  107. xmlDumpNotationDecl (xmlBuffer *buf,
  108. xmlNotation *nota);
  109. /* XML_DEPRECATED, still used in lxml */
  110. XMLPUBFUN void
  111. xmlDumpNotationTable (xmlBuffer *buf,
  112. xmlNotationTable *table);
  113. #endif /* LIBXML_OUTPUT_ENABLED */
  114. /* Element Content */
  115. XML_DEPRECATED
  116. XMLPUBFUN xmlElementContent *
  117. xmlNewElementContent (const xmlChar *name,
  118. xmlElementContentType type);
  119. XML_DEPRECATED
  120. XMLPUBFUN xmlElementContent *
  121. xmlCopyElementContent (xmlElementContent *content);
  122. XML_DEPRECATED
  123. XMLPUBFUN void
  124. xmlFreeElementContent (xmlElementContent *cur);
  125. XML_DEPRECATED
  126. XMLPUBFUN xmlElementContent *
  127. xmlNewDocElementContent (xmlDoc *doc,
  128. const xmlChar *name,
  129. xmlElementContentType type);
  130. XML_DEPRECATED
  131. XMLPUBFUN xmlElementContent *
  132. xmlCopyDocElementContent(xmlDoc *doc,
  133. xmlElementContent *content);
  134. XML_DEPRECATED
  135. XMLPUBFUN void
  136. xmlFreeDocElementContent(xmlDoc *doc,
  137. xmlElementContent *cur);
  138. XML_DEPRECATED
  139. XMLPUBFUN void
  140. xmlSnprintfElementContent(char *buf,
  141. int size,
  142. xmlElementContent *content,
  143. int englob);
  144. #ifdef LIBXML_OUTPUT_ENABLED
  145. XML_DEPRECATED
  146. XMLPUBFUN void
  147. xmlSprintfElementContent(char *buf,
  148. xmlElementContent *content,
  149. int englob);
  150. #endif /* LIBXML_OUTPUT_ENABLED */
  151. /* Element */
  152. XMLPUBFUN xmlElement *
  153. xmlAddElementDecl (xmlValidCtxt *ctxt,
  154. xmlDtd *dtd,
  155. const xmlChar *name,
  156. xmlElementTypeVal type,
  157. xmlElementContent *content);
  158. XML_DEPRECATED
  159. XMLPUBFUN xmlElementTable *
  160. xmlCopyElementTable (xmlElementTable *table);
  161. XML_DEPRECATED
  162. XMLPUBFUN void
  163. xmlFreeElementTable (xmlElementTable *table);
  164. #ifdef LIBXML_OUTPUT_ENABLED
  165. XML_DEPRECATED
  166. XMLPUBFUN void
  167. xmlDumpElementTable (xmlBuffer *buf,
  168. xmlElementTable *table);
  169. XML_DEPRECATED
  170. XMLPUBFUN void
  171. xmlDumpElementDecl (xmlBuffer *buf,
  172. xmlElement *elem);
  173. #endif /* LIBXML_OUTPUT_ENABLED */
  174. /* Enumeration */
  175. XML_DEPRECATED
  176. XMLPUBFUN xmlEnumeration *
  177. xmlCreateEnumeration (const xmlChar *name);
  178. /* XML_DEPRECATED, needed for custom attributeDecl SAX handler */
  179. XMLPUBFUN void
  180. xmlFreeEnumeration (xmlEnumeration *cur);
  181. XML_DEPRECATED
  182. XMLPUBFUN xmlEnumeration *
  183. xmlCopyEnumeration (xmlEnumeration *cur);
  184. /* Attribute */
  185. XMLPUBFUN xmlAttribute *
  186. xmlAddAttributeDecl (xmlValidCtxt *ctxt,
  187. xmlDtd *dtd,
  188. const xmlChar *elem,
  189. const xmlChar *name,
  190. const xmlChar *ns,
  191. xmlAttributeType type,
  192. xmlAttributeDefault def,
  193. const xmlChar *defaultValue,
  194. xmlEnumeration *tree);
  195. XML_DEPRECATED
  196. XMLPUBFUN xmlAttributeTable *
  197. xmlCopyAttributeTable (xmlAttributeTable *table);
  198. XML_DEPRECATED
  199. XMLPUBFUN void
  200. xmlFreeAttributeTable (xmlAttributeTable *table);
  201. #ifdef LIBXML_OUTPUT_ENABLED
  202. XML_DEPRECATED
  203. XMLPUBFUN void
  204. xmlDumpAttributeTable (xmlBuffer *buf,
  205. xmlAttributeTable *table);
  206. XML_DEPRECATED
  207. XMLPUBFUN void
  208. xmlDumpAttributeDecl (xmlBuffer *buf,
  209. xmlAttribute *attr);
  210. #endif /* LIBXML_OUTPUT_ENABLED */
  211. /* IDs */
  212. XMLPUBFUN int
  213. xmlAddIDSafe (xmlAttr *attr,
  214. const xmlChar *value);
  215. XMLPUBFUN xmlID *
  216. xmlAddID (xmlValidCtxt *ctxt,
  217. xmlDoc *doc,
  218. const xmlChar *value,
  219. xmlAttr *attr);
  220. XMLPUBFUN void
  221. xmlFreeIDTable (xmlIDTable *table);
  222. XMLPUBFUN xmlAttr *
  223. xmlGetID (xmlDoc *doc,
  224. const xmlChar *ID);
  225. XMLPUBFUN int
  226. xmlIsID (xmlDoc *doc,
  227. xmlNode *elem,
  228. xmlAttr *attr);
  229. XMLPUBFUN int
  230. xmlRemoveID (xmlDoc *doc,
  231. xmlAttr *attr);
  232. /* IDREFs */
  233. XML_DEPRECATED
  234. XMLPUBFUN xmlRef *
  235. xmlAddRef (xmlValidCtxt *ctxt,
  236. xmlDoc *doc,
  237. const xmlChar *value,
  238. xmlAttr *attr);
  239. XML_DEPRECATED
  240. XMLPUBFUN void
  241. xmlFreeRefTable (xmlRefTable *table);
  242. XML_DEPRECATED
  243. XMLPUBFUN int
  244. xmlIsRef (xmlDoc *doc,
  245. xmlNode *elem,
  246. xmlAttr *attr);
  247. XML_DEPRECATED
  248. XMLPUBFUN int
  249. xmlRemoveRef (xmlDoc *doc,
  250. xmlAttr *attr);
  251. XML_DEPRECATED
  252. XMLPUBFUN xmlList *
  253. xmlGetRefs (xmlDoc *doc,
  254. const xmlChar *ID);
  255. /**
  256. * The public function calls related to validity checking.
  257. */
  258. #ifdef LIBXML_VALID_ENABLED
  259. /* Allocate/Release Validation Contexts */
  260. XMLPUBFUN xmlValidCtxt *
  261. xmlNewValidCtxt(void);
  262. XMLPUBFUN void
  263. xmlFreeValidCtxt(xmlValidCtxt *);
  264. XML_DEPRECATED
  265. XMLPUBFUN int
  266. xmlValidateRoot (xmlValidCtxt *ctxt,
  267. xmlDoc *doc);
  268. XML_DEPRECATED
  269. XMLPUBFUN int
  270. xmlValidateElementDecl (xmlValidCtxt *ctxt,
  271. xmlDoc *doc,
  272. xmlElement *elem);
  273. XML_DEPRECATED
  274. XMLPUBFUN xmlChar *
  275. xmlValidNormalizeAttributeValue(xmlDoc *doc,
  276. xmlNode *elem,
  277. const xmlChar *name,
  278. const xmlChar *value);
  279. XML_DEPRECATED
  280. XMLPUBFUN xmlChar *
  281. xmlValidCtxtNormalizeAttributeValue(xmlValidCtxt *ctxt,
  282. xmlDoc *doc,
  283. xmlNode *elem,
  284. const xmlChar *name,
  285. const xmlChar *value);
  286. XML_DEPRECATED
  287. XMLPUBFUN int
  288. xmlValidateAttributeDecl(xmlValidCtxt *ctxt,
  289. xmlDoc *doc,
  290. xmlAttribute *attr);
  291. XML_DEPRECATED
  292. XMLPUBFUN int
  293. xmlValidateAttributeValue(xmlAttributeType type,
  294. const xmlChar *value);
  295. XML_DEPRECATED
  296. XMLPUBFUN int
  297. xmlValidateNotationDecl (xmlValidCtxt *ctxt,
  298. xmlDoc *doc,
  299. xmlNotation *nota);
  300. XMLPUBFUN int
  301. xmlValidateDtd (xmlValidCtxt *ctxt,
  302. xmlDoc *doc,
  303. xmlDtd *dtd);
  304. XML_DEPRECATED
  305. XMLPUBFUN int
  306. xmlValidateDtdFinal (xmlValidCtxt *ctxt,
  307. xmlDoc *doc);
  308. XMLPUBFUN int
  309. xmlValidateDocument (xmlValidCtxt *ctxt,
  310. xmlDoc *doc);
  311. XMLPUBFUN int
  312. xmlValidateElement (xmlValidCtxt *ctxt,
  313. xmlDoc *doc,
  314. xmlNode *elem);
  315. XML_DEPRECATED
  316. XMLPUBFUN int
  317. xmlValidateOneElement (xmlValidCtxt *ctxt,
  318. xmlDoc *doc,
  319. xmlNode *elem);
  320. XML_DEPRECATED
  321. XMLPUBFUN int
  322. xmlValidateOneAttribute (xmlValidCtxt *ctxt,
  323. xmlDoc *doc,
  324. xmlNode *elem,
  325. xmlAttr *attr,
  326. const xmlChar *value);
  327. XML_DEPRECATED
  328. XMLPUBFUN int
  329. xmlValidateOneNamespace (xmlValidCtxt *ctxt,
  330. xmlDoc *doc,
  331. xmlNode *elem,
  332. const xmlChar *prefix,
  333. xmlNs *ns,
  334. const xmlChar *value);
  335. XML_DEPRECATED
  336. XMLPUBFUN int
  337. xmlValidateDocumentFinal(xmlValidCtxt *ctxt,
  338. xmlDoc *doc);
  339. XML_DEPRECATED
  340. XMLPUBFUN int
  341. xmlValidateNotationUse (xmlValidCtxt *ctxt,
  342. xmlDoc *doc,
  343. const xmlChar *notationName);
  344. #endif /* LIBXML_VALID_ENABLED */
  345. XML_DEPRECATED
  346. XMLPUBFUN int
  347. xmlIsMixedElement (xmlDoc *doc,
  348. const xmlChar *name);
  349. XMLPUBFUN xmlAttribute *
  350. xmlGetDtdAttrDesc (xmlDtd *dtd,
  351. const xmlChar *elem,
  352. const xmlChar *name);
  353. XMLPUBFUN xmlAttribute *
  354. xmlGetDtdQAttrDesc (xmlDtd *dtd,
  355. const xmlChar *elem,
  356. const xmlChar *name,
  357. const xmlChar *prefix);
  358. XMLPUBFUN xmlNotation *
  359. xmlGetDtdNotationDesc (xmlDtd *dtd,
  360. const xmlChar *name);
  361. XMLPUBFUN xmlElement *
  362. xmlGetDtdQElementDesc (xmlDtd *dtd,
  363. const xmlChar *name,
  364. const xmlChar *prefix);
  365. XMLPUBFUN xmlElement *
  366. xmlGetDtdElementDesc (xmlDtd *dtd,
  367. const xmlChar *name);
  368. #ifdef LIBXML_VALID_ENABLED
  369. XMLPUBFUN int
  370. xmlValidGetPotentialChildren(xmlElementContent *ctree,
  371. const xmlChar **names,
  372. int *len,
  373. int max);
  374. /* only needed for `xmllint --insert` */
  375. XMLPUBFUN int
  376. xmlValidGetValidElements(xmlNode *prev,
  377. xmlNode *next,
  378. const xmlChar **names,
  379. int max);
  380. XMLPUBFUN int
  381. xmlValidateNameValue (const xmlChar *value);
  382. XMLPUBFUN int
  383. xmlValidateNamesValue (const xmlChar *value);
  384. XMLPUBFUN int
  385. xmlValidateNmtokenValue (const xmlChar *value);
  386. XMLPUBFUN int
  387. xmlValidateNmtokensValue(const xmlChar *value);
  388. #ifdef LIBXML_REGEXP_ENABLED
  389. /*
  390. * Validation based on the regexp support
  391. */
  392. XML_DEPRECATED
  393. XMLPUBFUN int
  394. xmlValidBuildContentModel(xmlValidCtxt *ctxt,
  395. xmlElement *elem);
  396. XML_DEPRECATED
  397. XMLPUBFUN int
  398. xmlValidatePushElement (xmlValidCtxt *ctxt,
  399. xmlDoc *doc,
  400. xmlNode *elem,
  401. const xmlChar *qname);
  402. XML_DEPRECATED
  403. XMLPUBFUN int
  404. xmlValidatePushCData (xmlValidCtxt *ctxt,
  405. const xmlChar *data,
  406. int len);
  407. XML_DEPRECATED
  408. XMLPUBFUN int
  409. xmlValidatePopElement (xmlValidCtxt *ctxt,
  410. xmlDoc *doc,
  411. xmlNode *elem,
  412. const xmlChar *qname);
  413. #endif /* LIBXML_REGEXP_ENABLED */
  414. #endif /* LIBXML_VALID_ENABLED */
  415. #ifdef __cplusplus
  416. }
  417. #endif
  418. #endif /* __XML_VALID_H__ */