valid.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. {$IFDEF POINTER}
  10. xmlValidStatePtr = ^xmlValidState;
  11. xmlValidCtxtPtr = ^xmlValidCtxt;
  12. xmlNotationTablePtr = ^xmlNotationTable;
  13. xmlElementTablePtr = ^xmlElementTable;
  14. xmlAttributeTablePtr = ^xmlAttributeTable;
  15. xmlIDTablePtr = ^xmlIDTable;
  16. xmlRefTablePtr = ^xmlRefTable;
  17. {$ENDIF}
  18. {$IFDEF TYPE}
  19. (*
  20. * Validation state added for non-determinist content model.
  21. *)
  22. xmlValidState = record end;
  23. (**
  24. * xmlValidityErrorFunc:
  25. * @ctx: usually an xmlValidCtxtPtr to a validity error context,
  26. * but comes from ctxt->userData (which normally contains such
  27. * a pointer); ctxt->userData can be changed by the user.
  28. * @msg: the string to format *printf like vararg
  29. * @...: remaining arguments to the format
  30. *
  31. * Callback called when a validity error is found. This is a message
  32. * oriented function similar to an *printf function.
  33. *)
  34. xmlValidityErrorFunc = procedure(ctx: pointer; msg: pchar); cdecl; varargs;
  35. (**
  36. * xmlValidityWarningFunc:
  37. * @ctx: usually an xmlValidCtxtPtr to a validity error context,
  38. * but comes from ctxt->userData (which normally contains such
  39. * a pointer); ctxt->userData can be changed by the user.
  40. * @msg: the string to format *printf like vararg
  41. * @...: remaining arguments to the format
  42. *
  43. * Callback called when a validity warning is found. This is a message
  44. * oriented function similar to an *printf function.
  45. *)
  46. xmlValidityWarningFunc = procedure(ctx: pointer; msg: pchar); cdecl; varargs;
  47. (*
  48. * xmlValidCtxt:
  49. * An xmlValidCtxt is used for error reporting when validating.
  50. *)
  51. xmlValidCtxt = record
  52. userData : pointer; (* user specific data block *)
  53. error : xmlValidityErrorFunc; (* the callback in case of errors *)
  54. warning : xmlValidityWarningFunc; (* the callback in case of warning *)
  55. (* Node analysis stack used when validating within entities *)
  56. node : xmlNodePtr; (* Current parsed Node *)
  57. nodeNr : cint; (* Depth of the parsing stack *)
  58. nodeMax : cint; (* Max depth of the parsing stack *)
  59. nodeTab : xmlNodePtrPtr; (* array of nodes *)
  60. finishDtd : cuint; (* finished validating the Dtd ? *)
  61. doc : xmlDocPtr; (* the document *)
  62. valid : cint; (* temporary validity check result *)
  63. (* state state used for non-determinist content validation *)
  64. vstate : xmlValidStatePtr; (* current state *)
  65. vstateNr : cint; (* Depth of the validation stack *)
  66. vstateMax : cint; (* Max depth of the validation stack *)
  67. vstateTab : xmlValidStatePtr; (* array of validation states *)
  68. {$IFDEF LIBXML_REGEXP_ENABLED}
  69. am : xmlAutomataPtr; (* the automata *)
  70. state : xmlAutomataStatePtr; (* used to build the automata *)
  71. {$ELSE}
  72. am : pointer;
  73. state : pointer;
  74. {$ENDIF}
  75. end;
  76. (*
  77. * ALL notation declarations are stored in a table.
  78. * There is one table per DTD.
  79. *)
  80. xmlNotationTable = type xmlHashTable;
  81. (*
  82. * ALL element declarations are stored in a table.
  83. * There is one table per DTD.
  84. *)
  85. xmlElementTable = type xmlHashTable;
  86. (*
  87. * ALL attribute declarations are stored in a table.
  88. * There is one table per DTD.
  89. *)
  90. xmlAttributeTable = type xmlHashTable;
  91. (*
  92. * ALL IDs attributes are stored in a table.
  93. * There is one table per document.
  94. *)
  95. xmlIDTable = type xmlHashTable;
  96. (*
  97. * ALL Refs attributes are stored in a table.
  98. * There is one table per document.
  99. *)
  100. xmlRefTable = type xmlHashTable;
  101. {$ENDIF}
  102. {$IFDEF FUNCTION}
  103. (* Notation *)
  104. function xmlAddNotationDecl(ctxt: xmlValidCtxtPtr; dtd: xmlDtdPtr; name, PublicID, SystemID: xmlCharPtr): xmlNotationPtr; EXTDECL; external xml2lib;
  105. {$IFDEF LIBXML_TREE_ENABLED}
  106. function xmlCopyNotationTable(table: xmlNotationTablePtr): xmlNotationTablePtr; EXTDECL; external xml2lib;
  107. {$ENDIF} (* LIBXML_TREE_ENABLED *)
  108. procedure xmlFreeNotationTable(table: xmlNotationTablePtr); EXTDECL; external xml2lib;
  109. {$IFDEF LIBXML_OUTPUT_ENABLED}
  110. procedure xmlDumpNotationDecl(buf: xmlBufferPtr; nota: xmlNotationPtr); EXTDECL; external xml2lib;
  111. procedure xmlDumpNotationTable(buf: xmlBufferPtr; table: xmlNotationTablePtr); EXTDECL; external xml2lib;
  112. {$ENDIF} (* LIBXML_OUTPUT_ENABLED *)
  113. (* Element Content *)
  114. function xmlNewDocElementContent(doc: xmlDocPtr; name: xmlCharPtr; _type: xmlElementContentType): xmlElementContentPtr; EXTDECL; external xml2lib;
  115. function xmlCopyDocElementContent(doc: xmlDocPtr; content: xmlElementContentPtr): xmlElementContentPtr; EXTDECL; external xml2lib;
  116. procedure xmlFreeDocElementContent(doc: xmlDocPtr; cur: xmlElementContentPtr); EXTDECL; external xml2lib;
  117. procedure xmlSnprintfElementContent(buf: pchar; size: cint; content: xmlElementContentPtr; englob: cint); EXTDECL; external xml2lib;
  118. (* Element *)
  119. function xmlAddElementDecl(ctxt: xmlValidCtxtPtr; dtd: xmlDtdPtr; name: xmlCharPtr; _type: xmlElementTypeVal; content: xmlElementContentPtr): xmlElementPtr; EXTDECL; external xml2lib;
  120. {$IFDEF LIBXML_TREE_ENABLED}
  121. function xmlCopyElementTable(table: xmlElementTablePtr): xmlElementTablePtr; EXTDECL; external xml2lib;
  122. {$ENDIF} (* LIBXML_TREE_ENABLED *)
  123. procedure xmlFreeElementTable(table: xmlElementTablePtr); EXTDECL; external xml2lib;
  124. {$IFDEF LIBXML_OUTPUT_ENABLED}
  125. procedure xmlDumpElementTable(buf: xmlBufferPtr; table: xmlElementTablePtr); EXTDECL; external xml2lib;
  126. procedure xmlDumpElementDecl(buf: xmlBufferPtr; elem: xmlElementPtr); EXTDECL; external xml2lib;
  127. {$ENDIF} (* LIBXML_OUTPUT_ENABLED *)
  128. (* Enumeration *)
  129. function xmlCreateEnumeration(name: xmlCharPtr): xmlEnumerationPtr; EXTDECL; external xml2lib;
  130. procedure xmlFreeEnumeration(cur: xmlEnumerationPtr); EXTDECL; external xml2lib;
  131. {$IFDEF LIBXML_TREE_ENABLED}
  132. function xmlCopyEnumeration(cur: xmlEnumerationPtr): xmlEnumerationPtr; EXTDECL; external xml2lib;
  133. {$ENDIF} (* LIBXML_TREE_ENABLED *)
  134. (* Attribute *)
  135. function xmlAddAttributeDecl(ctxt: xmlValidCtxtPtr; dtd: xmlDtdPtr; elem, name, ns: xmlCharPtr; _type: xmlAttributeType;
  136. def: xmlAttributeDefault; defaultValue: xmlCharPtr; tree: xmlEnumerationPtr): xmlAttributePtr; EXTDECL; external xml2lib;
  137. {$IFDEF LIBXML_TREE_ENABLED}
  138. function xmlCopyAttributeTable(table: xmlAttributeTablePtr): xmlAttributeTablePtr; EXTDECL; external xml2lib;
  139. {$ENDIF} (* LIBXML_TREE_ENABLED *)
  140. procedure xmlFreeAttributeTable(table: xmlAttributeTablePtr); EXTDECL; external xml2lib;
  141. {$IFDEF LIBXML_OUTPUT_ENABLED}
  142. procedure xmlDumpAttributeTable(buf: xmlBufferPtr; table: xmlAttributeTablePtr); EXTDECL; external xml2lib;
  143. procedure xmlDumpAttributeDecl(buf: xmlBufferPtr; attr: xmlAttributePtr); EXTDECL; external xml2lib;
  144. {$ENDIF} (* LIBXML_OUTPUT_ENABLED *)
  145. (* IDs *)
  146. function xmlAddID(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; value: xmlCharPtr; attr: xmlAttrPtr): xmlIDPtr; EXTDECL; external xml2lib;
  147. procedure xmlFreeIDTable(table: xmlIDTablePtr); EXTDECL; external xml2lib;
  148. function xmlGetID(doc: xmlDocPtr; ID: xmlCharPtr): xmlAttrPtr; EXTDECL; external xml2lib;
  149. function xmlIsID(doc: xmlDocPtr; elem: xmlNodePtr; attr: xmlAttrPtr): cint; EXTDECL; external xml2lib;
  150. function xmlRemoveID(doc: xmlDocPtr; attr: xmlAttrPtr): cint; EXTDECL; external xml2lib;
  151. (* IDREFs *)
  152. function xmlAddRef(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; value: xmlCharPtr; attr: xmlAttrPtr): xmlRefPtr; EXTDECL; external xml2lib;
  153. procedure xmlFreeRefTable(table: xmlRefTablePtr); EXTDECL; external xml2lib;
  154. function xmlIsRef(doc: xmlDocPtr; elem: xmlNodePtr; attr: xmlAttrPtr): cint; EXTDECL; external xml2lib;
  155. function xmlRemoveRef(doc: xmlDocPtr; attr: xmlAttrPtr): cint; EXTDECL; external xml2lib;
  156. function xmlGetRefs(doc: xmlDocPtr; ID: xmlCharPtr): xmlListPtr; EXTDECL; external xml2lib;
  157. (**
  158. * The public function calls related to validity checking.
  159. *)
  160. {$IFDEF LIBXML_VALID_ENABLED}
  161. (* Allocate/Release Validation Contexts *)
  162. function xmlNewValidCtxt: xmlValidCtxtPtr; EXTDECL; external xml2lib;
  163. procedure xmlFreeValidCtxt(table: xmlValidCtxtPtr); EXTDECL; external xml2lib;
  164. function xmlValidateRoot(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr): cint; EXTDECL; external xml2lib;
  165. function xmlValidateElementDecl(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlElementPtr): cint; EXTDECL; external xml2lib;
  166. function xmlValidNormalizeAttributeValue(doc: xmlDocPtr; elem: xmlNodePtr; name, value: xmlCharPtr): xmlCharPtr; EXTDECL; external xml2lib;
  167. function xmlValidCtxtNormalizeAttributeValue(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlNodePtr; name, value: xmlCharPtr): xmlCharPtr; EXTDECL; external xml2lib;
  168. function xmlValidateAttributeDecl(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; attr: xmlAttributePtr): cint; EXTDECL; external xml2lib;
  169. function xmlValidateAttributeValue(_type: xmlAttributeType; value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  170. function xmlValidateNotationDecl(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; nota: xmlNotationPtr): cint; EXTDECL; external xml2lib;
  171. function xmlValidateDtd(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; dtd: xmlDtdPtr): cint; EXTDECL; external xml2lib;
  172. function xmlValidateDtdFinal(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr): cint; EXTDECL; external xml2lib;
  173. function xmlValidateDocument(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr): cint; EXTDECL; external xml2lib;
  174. function xmlValidateElement(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlNodePtr): cint; EXTDECL; external xml2lib;
  175. function xmlValidateOneElement(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlNodePtr): cint; EXTDECL; external xml2lib;
  176. function xmlValidateOneAttribute(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlNodePtr; attr: xmlAttrPtr; value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  177. function xmlValidateOneNamespace(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlNodePtr; prefix: xmlCharPtr; ns: xmlNsPtr; value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  178. function xmlValidateDocumentFinal(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr): cint; EXTDECL; external xml2lib;
  179. {$ENDIF} (* LIBXML_VALID_ENABLED *)
  180. {$IF defined(LIBXML_VALID_ENABLED) or defined(LIBXML_SCHEMAS_ENABLED)}
  181. function xmlValidateNotationUse(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; notationName: xmlCharPtr): cint; EXTDECL; external xml2lib;
  182. {$ENDIF} (* LIBXML_VALID_ENABLED or LIBXML_SCHEMAS_ENABLED *)
  183. function xmlIsMixedElement(doc: xmlDocPtr; name: xmlCharPtr): cint; EXTDECL; external xml2lib;
  184. function xmlGetDtdAttrDesc(dtd: xmlDtdPtr; elem, name: xmlCharPtr): xmlAttributePtr; EXTDECL; external xml2lib;
  185. function xmlGetDtdQAttrDesc(dtd: xmlDtdPtr; elem, name, prefix: xmlCharPtr): xmlAttributePtr; EXTDECL; external xml2lib;
  186. function xmlGetDtdNotationDesc(dtd: xmlDtdPtr; name: xmlCharPtr): xmlNotationPtr; EXTDECL; external xml2lib;
  187. function xmlGetDtdQElementDesc(dtd: xmlDtdPtr; name, prefix: xmlCharPtr): xmlElementPtr; EXTDECL; external xml2lib;
  188. function xmlGetDtdElementDesc(dtd: xmlDtdPtr; name: xmlCharPtr): xmlElementPtr; EXTDECL; external xml2lib;
  189. {$IFDEF LIBXML_VALID_ENABLED}
  190. function xmlGetDtdElementDesc(ctree: xmlElementContentPtr; var names: xmlCharPtr; var len: cint; max: cint): cint; EXTDECL; external xml2lib;
  191. function xmlValidGetValidElements(prev, next: xmlNodePtr; var names: xmlCharPtr; max: cint): cint; EXTDECL; external xml2lib;
  192. function xmlValidateNameValue(value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  193. function xmlValidateNamesValue(value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  194. function xmlValidateNmtokenValue(value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  195. function xmlValidateNmtokensValue(value: xmlCharPtr): cint; EXTDECL; external xml2lib;
  196. {$IFDEF LIBXML_REGEXP_ENABLED}
  197. (*
  198. * Validation based on the regexp support
  199. *)
  200. function xmlValidBuildContentModel(ctxt: xmlValidCtxtPtr; elem: xmlElementPtr): cint; EXTDECL; external xml2lib;
  201. function xmlValidatePushElement(ctxt: xmlValidCtxtPtr; doc: xmlNodePtr; elem: xmlElementPtr; qname: xmlCharPtr): cint; EXTDECL; external xml2lib;
  202. function xmlValidatePushCData(ctxt: xmlValidCtxtPtr; data: xmlCharPtr; len: cint): cint; EXTDECL; external xml2lib;
  203. function xmlValidatePopElement(ctxt: xmlValidCtxtPtr; doc: xmlDocPtr; elem: xmlNodePtr; qname: xmlCharPtr): cint; EXTDECL; external xml2lib;
  204. {$ENDIF} (* LIBXML_REGEXP_ENABLED *)
  205. {$ENDIF} (* LIBXML_VALID_ENABLED *)
  206. {$ENDIF}