valid.h 13 KB

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