Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

328 lines
8.1 KiB

  1. #ifdef __cplusplus
  2. extern "C" {
  3. #endif
  4. enum XMLDOC_THING_TYPE {
  5. XMLDOC_THING_ERROR,
  6. XMLDOC_THING_END_OF_STREAM,
  7. XMLDOC_THING_XMLDECL,
  8. XMLDOC_THING_ELEMENT,
  9. XMLDOC_THING_END_ELEMENT,
  10. XMLDOC_THING_PROCESSINGINSTRUCTION,
  11. XMLDOC_THING_ATTRIBUTE,
  12. XMLDOC_THING_HYPERSPACE,
  13. XMLDOC_THING_CDATA,
  14. };
  15. typedef enum {
  16. XMLERROR_XMLDECL_NOT_FIRST_THING,
  17. XMLERROR_PI_TARGET_NOT_FOUND,
  18. XMLERROR_PI_EOF_BEFORE_CLOSE,
  19. XMLERROR_PI_CONTENT_ERROR, // There was a problem with the content of the processing instruction
  20. XMLERROR_ELEMENT_NS_PREFIX_MISSING_COLON,
  21. XMLERROR_ELEMENT_NAME_NOT_FOUND, // < binky="bleep"> or <foo: /> - element name not found
  22. XMLERROR_ATTRIBUTE_NAME_NOT_FOUND, // <binky foo:=""> or <binky =""/> - Attribute name part not found
  23. XMLERROR_ATTRIBUTE_NS_PREFIX_MISSING_COLON, // <bingy foo="ham"> - Somehow we got into a state where we thought we had a namespace prefix, but it wasn't followed by a colon
  24. XMLERROR_XMLDECL_INVALID_FORMAT, // Something rotten in the <?xml?>
  25. XMLERROR_ENDELEMENT_NAME_NOT_FOUND, // Missing the name part of a </> tag.
  26. XMLERROR_ENDELEMENT_MALFORMED_NAME, // The name was malformed .. ns missing or something like that
  27. XMLERROR_ENDELEMENT_MALFORMED, // EOF before end of element found, or other problem
  28. XMLERROR_CDATA_MALFORMED, // CDATA not properly formed?
  29. } LOGICAL_XML_ERROR;
  30. typedef struct _XMLDOC_ELEMENT {
  31. //
  32. // Name of this element tag
  33. //
  34. XML_EXTENT Name;
  35. //
  36. // Namespace prefix
  37. //
  38. XML_EXTENT NsPrefix;
  39. //
  40. // How many attributes are there?
  41. //
  42. ULONG ulAttributeCount;
  43. //
  44. // Is this element empty?
  45. //
  46. BOOLEAN fElementEmpty;
  47. }
  48. XMLDOC_ELEMENT, *PXMLDOC_ELEMENT;
  49. typedef struct _XMLDOC_ERROR {
  50. //
  51. // The erroneous extent
  52. //
  53. XML_EXTENT BadExtent;
  54. //
  55. // What was the error?
  56. //
  57. LOGICAL_XML_ERROR Code;
  58. }
  59. XMLDOC_ERROR, *PXMLDOC_ERROR;
  60. typedef struct _XMLDOC_ATTRIBUTE {
  61. //
  62. // Name of this attribute
  63. //
  64. XML_EXTENT Name;
  65. //
  66. // Namespace prefix thereof
  67. //
  68. XML_EXTENT NsPrefix;
  69. //
  70. // The value of this attribute
  71. //
  72. XML_EXTENT Value;
  73. }
  74. XMLDOC_ATTRIBUTE, *PXMLDOC_ATTRIBUTE;
  75. typedef struct _XMLDOC_ENDELEMENT {
  76. //
  77. // End-element namespace prefix
  78. //
  79. XML_EXTENT NsPrefix;
  80. //
  81. // End-element tag name
  82. //
  83. XML_EXTENT Name;
  84. //
  85. // Original element pointer
  86. //
  87. XMLDOC_ELEMENT OpeningElement;
  88. }
  89. XMLDOC_ENDELEMENT, *PXMLDOC_ENDELEMENT;
  90. typedef struct _XMLDOC_XMLDECL {
  91. XML_EXTENT Encoding;
  92. XML_EXTENT Version;
  93. XML_EXTENT Standalone;
  94. }
  95. XMLDOC_XMLDECL, *PXMLDOC_XMLDECL;
  96. typedef struct _XMLDOC_PROCESSING {
  97. XML_EXTENT Target;
  98. XML_EXTENT Instruction;
  99. }
  100. XMLDOC_PROCESSING, *PXMLDOC_PROCESSING;
  101. typedef struct _XMLDOC_THING {
  102. //
  103. // What kind of thing is this?
  104. //
  105. enum XMLDOC_THING_TYPE ulThingType;
  106. //
  107. // How deep down the document is it?
  108. //
  109. ULONG ulDocumentDepth;
  110. //
  111. // Have the namespaces been fixed up yet?
  112. //
  113. BOOLEAN fNamespacesExpanded;
  114. //
  115. // The caller should be passing in a pointer to an attribute
  116. // list that they have initialized to contain XMLDOC_ATTRIBUTE
  117. // objects.
  118. //
  119. PRTL_GROWING_LIST AttributeList;
  120. //
  121. // The total extent of this thing in the document
  122. //
  123. XML_EXTENT TotalExtent;
  124. union {
  125. XMLDOC_ERROR Error;
  126. XMLDOC_ELEMENT Element;
  127. //
  128. // The </close> tag
  129. //
  130. XMLDOC_ENDELEMENT EndElement;
  131. //
  132. // The pcdata that was found in this segment of the document
  133. //
  134. XML_EXTENT CDATA;
  135. //
  136. // The hyperspace found in this section of the document
  137. //
  138. XML_EXTENT Hyperspace;
  139. //
  140. // Information about the <?xml?> section of the document
  141. //
  142. XMLDOC_XMLDECL XmlDecl;
  143. //
  144. // A processing instruction has a target and an actual instruction
  145. //
  146. XMLDOC_PROCESSING ProcessingInstruction;
  147. };
  148. }
  149. XMLDOC_THING, *PXMLDOC_THING;
  150. typedef NTSTATUS (*PFN_CALLBACK_PER_LOGICAL_XML)(
  151. struct _tagXML_LOGICAL_STATE* pLogicalState,
  152. PXMLDOC_THING pLogicalThing,
  153. PRTL_GROWING_LIST pAttributes,
  154. PVOID pvCallbackContext
  155. );
  156. typedef struct _tagXML_LOGICAL_STATE{
  157. //
  158. // The overall state of parsing
  159. //
  160. XML_TOKENIZATION_STATE ParseState;
  161. //
  162. // Have we found the first element yet?
  163. //
  164. BOOLEAN fFirstElementFound;
  165. //
  166. // When sifting through the document, this is the thing that we found
  167. // indicating the encoding. We should process and set the values in
  168. // ParseState before going too far, but for the moment we just hold
  169. // onto it.
  170. //
  171. XML_EXTENT EncodingMarker;
  172. //
  173. // Depth of the 'element stack' that we're building up.
  174. //
  175. ULONG ulElementStackDepth;
  176. //
  177. // Growing list that backs up the stack of elements.
  178. //
  179. RTL_GROWING_LIST ElementStack;
  180. //
  181. // Inline stuff to save some heap allocations.
  182. //
  183. XMLDOC_THING InlineElements[20];
  184. }
  185. XML_LOGICAL_STATE, *PXML_LOGICAL_STATE;
  186. typedef struct _XML_ATTRIBUTE_DEFINITION {
  187. PCXML_SPECIAL_STRING Namespace;
  188. XML_SPECIAL_STRING Name;
  189. } XML_ATTRIBUTE_DEFINITION, *PXML_ATTRIBUTE_DEFINITION;
  190. typedef const XML_ATTRIBUTE_DEFINITION *PCXML_ATTRIBUTE_DEFINITION;
  191. NTSTATUS
  192. RtlXmlInitializeNextLogicalThing(
  193. PXML_LOGICAL_STATE pParseState,
  194. PVOID pvDataPointer,
  195. SIZE_T cbData,
  196. PRTL_ALLOCATOR Allocator
  197. );
  198. //
  199. // This mini-tokenizer allows you to pick up the logical analysis
  200. // from any arbitrary point in another document (handy for when you
  201. // want to go back and re-read something, like in xmldsig...). If you
  202. // are cloning an active logical parse, then it's imperative that
  203. // you pass along the same namespace management object.
  204. //
  205. NTSTATUS
  206. RtlXmlInitializeNextLogicalThingEx(
  207. OUT PXML_LOGICAL_STATE pParseState,
  208. IN PXML_TOKENIZATION_STATE pBaseTokenizationState,
  209. IN PVOID pvDataPointer,
  210. IN SIZE_T cbData,
  211. PRTL_ALLOCATOR Allocator
  212. );
  213. NTSTATUS
  214. RtlXmlNextLogicalThing(
  215. PXML_LOGICAL_STATE pParseState,
  216. PNS_MANAGER pNamespaceManager,
  217. PXMLDOC_THING pDocumentPiece,
  218. PRTL_GROWING_LIST pAttributeList
  219. );
  220. NTSTATUS
  221. RtlXmlDestroyNextLogicalThing(
  222. PXML_LOGICAL_STATE pState
  223. );
  224. NTSTATUS
  225. RtlXmlExtentToString(
  226. PXML_RAWTOKENIZATION_STATE pParseState,
  227. PXML_EXTENT pExtent,
  228. PUNICODE_STRING pString,
  229. PSIZE_T pchString
  230. );
  231. NTSTATUS
  232. RtlXmlMatchLogicalElement(
  233. IN PXML_TOKENIZATION_STATE pState,
  234. IN PXMLDOC_ELEMENT pElement,
  235. IN PCXML_SPECIAL_STRING pNamespace,
  236. IN PCXML_SPECIAL_STRING pElementName,
  237. OUT PBOOLEAN pfMatches
  238. );
  239. NTSTATUS
  240. RtlXmlFindAttributesInElement(
  241. IN PXML_TOKENIZATION_STATE pState,
  242. IN PRTL_GROWING_LIST pAttributeList,
  243. IN ULONG ulAttributeCountInElement,
  244. IN ULONG ulFindCount,
  245. IN PCXML_ATTRIBUTE_DEFINITION pAttributeNames,
  246. OUT PXMLDOC_ATTRIBUTE *ppAttributes,
  247. OUT PULONG pulUnmatchedAttributes
  248. );
  249. NTSTATUS
  250. RtlXmlSkipElement(
  251. PXML_LOGICAL_STATE pState,
  252. PXMLDOC_ELEMENT TheElement
  253. );
  254. NTSTATUS
  255. RtlXmlMatchAttribute(
  256. IN PXML_TOKENIZATION_STATE State,
  257. IN PXMLDOC_ATTRIBUTE Attribute,
  258. IN PCXML_SPECIAL_STRING Namespace,
  259. IN PCXML_SPECIAL_STRING AttributeName,
  260. OUT XML_STRING_COMPARE *CompareResult
  261. );
  262. #ifdef __cplusplus
  263. };
  264. #endif