valid.h 13 KB

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