valid.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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_CTXT_FINISH_DTD_0:
  56. *
  57. * Special value for finishDtd field when embedded in an xmlParserCtxt
  58. */
  59. #define XML_CTXT_FINISH_DTD_0 0xabcd1234
  60. /**
  61. * XML_CTXT_FINISH_DTD_1:
  62. *
  63. * Special value for finishDtd field when embedded in an xmlParserCtxt
  64. */
  65. #define XML_CTXT_FINISH_DTD_1 0xabcd1235
  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 finishDtd; /* finished validating the Dtd ? */
  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. XMLPUBFUN xmlRefPtr XMLCALL
  257. xmlAddRef (xmlValidCtxtPtr ctxt,
  258. xmlDocPtr doc,
  259. const xmlChar *value,
  260. xmlAttrPtr attr);
  261. XMLPUBFUN void XMLCALL
  262. xmlFreeRefTable (xmlRefTablePtr table);
  263. XMLPUBFUN int XMLCALL
  264. xmlIsRef (xmlDocPtr doc,
  265. xmlNodePtr elem,
  266. xmlAttrPtr attr);
  267. XMLPUBFUN int XMLCALL
  268. xmlRemoveRef (xmlDocPtr doc,
  269. xmlAttrPtr attr);
  270. XMLPUBFUN xmlListPtr XMLCALL
  271. xmlGetRefs (xmlDocPtr doc,
  272. const xmlChar *ID);
  273. /**
  274. * The public function calls related to validity checking.
  275. */
  276. #ifdef LIBXML_VALID_ENABLED
  277. /* Allocate/Release Validation Contexts */
  278. XMLPUBFUN xmlValidCtxtPtr XMLCALL
  279. xmlNewValidCtxt(void);
  280. XMLPUBFUN void XMLCALL
  281. xmlFreeValidCtxt(xmlValidCtxtPtr);
  282. XMLPUBFUN int XMLCALL
  283. xmlValidateRoot (xmlValidCtxtPtr ctxt,
  284. xmlDocPtr doc);
  285. XMLPUBFUN int XMLCALL
  286. xmlValidateElementDecl (xmlValidCtxtPtr ctxt,
  287. xmlDocPtr doc,
  288. xmlElementPtr elem);
  289. XMLPUBFUN xmlChar * XMLCALL
  290. xmlValidNormalizeAttributeValue(xmlDocPtr doc,
  291. xmlNodePtr elem,
  292. const xmlChar *name,
  293. const xmlChar *value);
  294. XMLPUBFUN xmlChar * XMLCALL
  295. xmlValidCtxtNormalizeAttributeValue(xmlValidCtxtPtr ctxt,
  296. xmlDocPtr doc,
  297. xmlNodePtr elem,
  298. const xmlChar *name,
  299. const xmlChar *value);
  300. XMLPUBFUN int XMLCALL
  301. xmlValidateAttributeDecl(xmlValidCtxtPtr ctxt,
  302. xmlDocPtr doc,
  303. xmlAttributePtr attr);
  304. XMLPUBFUN int XMLCALL
  305. xmlValidateAttributeValue(xmlAttributeType type,
  306. const xmlChar *value);
  307. XMLPUBFUN int XMLCALL
  308. xmlValidateNotationDecl (xmlValidCtxtPtr ctxt,
  309. xmlDocPtr doc,
  310. xmlNotationPtr nota);
  311. XMLPUBFUN int XMLCALL
  312. xmlValidateDtd (xmlValidCtxtPtr ctxt,
  313. xmlDocPtr doc,
  314. xmlDtdPtr dtd);
  315. XMLPUBFUN int XMLCALL
  316. xmlValidateDtdFinal (xmlValidCtxtPtr ctxt,
  317. xmlDocPtr doc);
  318. XMLPUBFUN int XMLCALL
  319. xmlValidateDocument (xmlValidCtxtPtr ctxt,
  320. xmlDocPtr doc);
  321. XMLPUBFUN int XMLCALL
  322. xmlValidateElement (xmlValidCtxtPtr ctxt,
  323. xmlDocPtr doc,
  324. xmlNodePtr elem);
  325. XMLPUBFUN int XMLCALL
  326. xmlValidateOneElement (xmlValidCtxtPtr ctxt,
  327. xmlDocPtr doc,
  328. xmlNodePtr elem);
  329. XMLPUBFUN int XMLCALL
  330. xmlValidateOneAttribute (xmlValidCtxtPtr ctxt,
  331. xmlDocPtr doc,
  332. xmlNodePtr elem,
  333. xmlAttrPtr attr,
  334. const xmlChar *value);
  335. XMLPUBFUN int XMLCALL
  336. xmlValidateOneNamespace (xmlValidCtxtPtr ctxt,
  337. xmlDocPtr doc,
  338. xmlNodePtr elem,
  339. const xmlChar *prefix,
  340. xmlNsPtr ns,
  341. const xmlChar *value);
  342. XMLPUBFUN int XMLCALL
  343. xmlValidateDocumentFinal(xmlValidCtxtPtr ctxt,
  344. xmlDocPtr doc);
  345. #endif /* LIBXML_VALID_ENABLED */
  346. #if defined(LIBXML_VALID_ENABLED) || defined(LIBXML_SCHEMAS_ENABLED)
  347. XMLPUBFUN int XMLCALL
  348. xmlValidateNotationUse (xmlValidCtxtPtr ctxt,
  349. xmlDocPtr doc,
  350. const xmlChar *notationName);
  351. #endif /* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED */
  352. XMLPUBFUN int XMLCALL
  353. xmlIsMixedElement (xmlDocPtr doc,
  354. const xmlChar *name);
  355. XMLPUBFUN xmlAttributePtr XMLCALL
  356. xmlGetDtdAttrDesc (xmlDtdPtr dtd,
  357. const xmlChar *elem,
  358. const xmlChar *name);
  359. XMLPUBFUN xmlAttributePtr XMLCALL
  360. xmlGetDtdQAttrDesc (xmlDtdPtr dtd,
  361. const xmlChar *elem,
  362. const xmlChar *name,
  363. const xmlChar *prefix);
  364. XMLPUBFUN xmlNotationPtr XMLCALL
  365. xmlGetDtdNotationDesc (xmlDtdPtr dtd,
  366. const xmlChar *name);
  367. XMLPUBFUN xmlElementPtr XMLCALL
  368. xmlGetDtdQElementDesc (xmlDtdPtr dtd,
  369. const xmlChar *name,
  370. const xmlChar *prefix);
  371. XMLPUBFUN xmlElementPtr XMLCALL
  372. xmlGetDtdElementDesc (xmlDtdPtr dtd,
  373. const xmlChar *name);
  374. #ifdef LIBXML_VALID_ENABLED
  375. XMLPUBFUN int XMLCALL
  376. xmlValidGetPotentialChildren(xmlElementContent *ctree,
  377. const xmlChar **names,
  378. int *len,
  379. int max);
  380. XMLPUBFUN int XMLCALL
  381. xmlValidGetValidElements(xmlNode *prev,
  382. xmlNode *next,
  383. const xmlChar **names,
  384. int max);
  385. XMLPUBFUN int XMLCALL
  386. xmlValidateNameValue (const xmlChar *value);
  387. XMLPUBFUN int XMLCALL
  388. xmlValidateNamesValue (const xmlChar *value);
  389. XMLPUBFUN int XMLCALL
  390. xmlValidateNmtokenValue (const xmlChar *value);
  391. XMLPUBFUN int XMLCALL
  392. xmlValidateNmtokensValue(const xmlChar *value);
  393. #ifdef LIBXML_REGEXP_ENABLED
  394. /*
  395. * Validation based on the regexp support
  396. */
  397. XMLPUBFUN int XMLCALL
  398. xmlValidBuildContentModel(xmlValidCtxtPtr ctxt,
  399. xmlElementPtr elem);
  400. XMLPUBFUN int XMLCALL
  401. xmlValidatePushElement (xmlValidCtxtPtr ctxt,
  402. xmlDocPtr doc,
  403. xmlNodePtr elem,
  404. const xmlChar *qname);
  405. XMLPUBFUN int XMLCALL
  406. xmlValidatePushCData (xmlValidCtxtPtr ctxt,
  407. const xmlChar *data,
  408. int len);
  409. XMLPUBFUN int XMLCALL
  410. xmlValidatePopElement (xmlValidCtxtPtr ctxt,
  411. xmlDocPtr doc,
  412. xmlNodePtr elem,
  413. const xmlChar *qname);
  414. #endif /* LIBXML_REGEXP_ENABLED */
  415. #endif /* LIBXML_VALID_ENABLED */
  416. #ifdef __cplusplus
  417. }
  418. #endif
  419. #endif /* __XML_VALID_H__ */