1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _omiar_xml_h
26 #define _omiar_xml_h
27
28 #include <stddef.h>
|
29 krisbash 1.3 #include "config.h"
30 #include <common.h>
31
32 #ifdef _MSC_VER
33 #pragma prefast (disable: 28252)
34 #pragma prefast (disable: 28253)
35 #endif
36
37 #if defined(CONFIG_ENABLE_WCHAR)
38 # include <wchar.h>
39 #endif
|
40 mike 1.1
41 /* The maximum number of nested XML elements */
42 #define XML_MAX_NESTED 64
43
44 /* The maximum number of XML namespaces */
45 #define XML_MAX_NAMESPACES 32
46
47 /* The maximum number of registered XML namespaces */
48 #define XML_MAX_REGISTERED_NAMESPACES 32
49
50 /* The maximum number of attributes in a start tag */
51 #define XML_MAX_ATTRIBUTES 32
52
53 /* Represents case where tag has no namespace */
54 #define XML_NAMESPACE_NONE 0
55
|
56 krisbash 1.3 #if defined(CONFIG_ENABLE_WCHAR)
57 typedef wchar_t XML_Char;
58 typedef wchar_t XML_UChar;
59 #else
60 typedef char XML_Char;
61 typedef unsigned char XML_UChar;
62 #endif
63
64 typedef _Null_terminated_ XML_Char* XMLCharPtr;
65 typedef _Null_terminated_ XML_UChar* XMLUCharPtr;
66
|
67 mike 1.1 #if defined(__cplusplus)
68 extern "C" {
69 #endif
70
71 /* Represents an XML name */
72 typedef struct _XML_Name
73 {
74 /* Pointer to name */
|
75 krisbash 1.3 XML_Char* data;
|
76 mike 1.1 /* Size of name (excluding zero-terminator) */
77 size_t size;
|
78 krisbash 1.3
79 /* Full namespace URI */
80 const XML_Char* namespaceUri;
81 size_t namespaceUriSize;
82
83 /* Nonzero if a registered namespace was used */
84 XML_Char namespaceId;
|
85 mike 1.1 }
86 XML_Name;
87
88 /* Represents an XML namespace as registered by the client */
89 typedef struct _XML_RegisteredNameSpace
90 {
91 /* URI for this namespace */
|
92 krisbash 1.3 const XML_Char* uri;
|
93 mike 1.1
94 /* Hash code for uri */
95 unsigned int uriCode;
96
97 /* Single character namespace name expected by client */
|
98 krisbash 1.3 XML_Char id;
|
99 mike 1.1 }
100 XML_RegisteredNameSpace;
101
102 /* Represents an XML namespace as encountered during parsing */
103 typedef struct _XML_NameSpace
104 {
105 /* Namespace name */
|
106 krisbash 1.3 const XML_Char* name;
|
107 mike 1.1
108 /* Hash code for name */
109 unsigned int nameCode;
110
111 /* URI for this namespace */
|
112 krisbash 1.3 const XML_Char* uri;
113 size_t uriSize;
|
114 mike 1.1
115 /* Single character namespace name expected by client */
|
116 krisbash 1.3 XML_Char id;
|
117 mike 1.1
118 /* Depth at which this definition was encountered */
119 size_t depth;
120 }
121 XML_NameSpace;
122
123 void XML_NameSpace_Dump(
|
124 krisbash 1.3 _In_ XML_NameSpace* self);
|
125 mike 1.1
126 /* Represents an XML attributes */
127 typedef struct _XML_Attr
128 {
|
129 krisbash 1.3 XML_Name name;
130 const XML_Char* value;
131 size_t valueSize;
|
132 mike 1.1 }
133 XML_Attr;
134
135 /* XML element type tag */
136 typedef enum _XML_Type
137 {
138 XML_NONE,
139 XML_START,
140 XML_END,
141 XML_INSTRUCTION,
142 XML_CHARS,
143 XML_COMMENT
144 }
145 XML_Type;
146
147 /* Represents one XML element */
148 typedef struct _XML_Elem
149 {
150 /* Type of this XML object */
151 XML_Type type;
152
|
153 krisbash 1.3 /* Tag or character data */
154 XML_Name data;
|
155 mike 1.1
156 /* Attributes */
157 XML_Attr attrs[XML_MAX_ATTRIBUTES];
158 size_t attrsSize;
159 }
160 XML_Elem;
161
|
162 krisbash 1.3 const XML_Char* XML_Elem_GetAttr(
163 _Inout_ XML_Elem* self,
164 XML_Char nsId,
165 _In_z_ const XML_Char* name);
|
166 mike 1.1
167 void XML_Elem_Dump(
|
168 krisbash 1.3 _In_ const XML_Elem* self);
|
169 mike 1.1
170 typedef struct _XML
171 {
172 /* Points to first text character zero-terminated text */
|
173 krisbash 1.3 XML_Char* text;
|
174 mike 1.1
175 /* Pointer to current character */
|
176 krisbash 1.3 XML_Char* ptr;
|
177 mike 1.1
178 /* Line number */
179 size_t line;
180
181 /* Status: 0=Okay, 1=Done, 2=Failed */
182 int status;
183
184 /* Error message */
|
185 krisbash 1.3 XML_Char message[256];
|
186 mike 1.1
187 /* Stack of open tags (used to match closing tags) */
188 XML_Name stack[XML_MAX_NESTED];
189 size_t stackSize;
190
191 /* Current nesting level */
192 size_t nesting;
193
194 /* Stack of dummy elements generated for empty tags and PutBack calls */
195 XML_Elem elemStack[XML_MAX_NESTED];
196 size_t elemStackSize;
197
198 /* Array of namespaces */
199 XML_NameSpace nameSpaces[XML_MAX_NAMESPACES];
200 size_t nameSpacesSize;
201
202 /* Index of last namespace lookup from nameSpaces[] array */
203 size_t nameSpacesCacheIndex;
204
205 /* Predefined namespaces */
206 XML_RegisteredNameSpace registeredNameSpaces[XML_MAX_NAMESPACES];
207 mike 1.1 size_t registeredNameSpacesSize;
208
209 /* Internal parser state */
210 int state;
211
212 /* Whether XML root element has been encountered */
213 int foundRoot;
214 }
215 XML;
216
217 void XML_Init(
|
218 krisbash 1.3 _Out_ XML* self);
|
219 mike 1.1
220 void XML_SetText(
|
221 krisbash 1.3 _Inout_ XML* self,
222 _In_z_ XML_Char* text);
|
223 mike 1.1
224 int XML_Next(
|
225 krisbash 1.3 _Inout_ XML* self,
226 _Out_ XML_Elem* elem);
|
227 mike 1.1
228 int XML_Expect(
|
229 krisbash 1.3 _Inout_ XML* self,
230 _Out_ XML_Elem* elem,
|
231 mike 1.1 XML_Type type,
|
232 krisbash 1.3 XML_Char nsId,
233 _In_z_ const XML_Char* name);
|
234 mike 1.1
235 int XML_Skip(
|
236 krisbash 1.3 _Inout_ XML* self);
|
237 mike 1.1
238 int XML_RegisterNameSpace(
|
239 krisbash 1.3 _Inout_ XML* self,
240 XML_Char id,
241 _In_z_ const XML_Char* uri);
|
242 mike 1.1
243 int XML_PutBack(
|
244 krisbash 1.3 _Inout_ XML* self,
245 _In_ const XML_Elem* elem);
246
247 int XML_StripWhitespace(
248 _Inout_ XML_Elem* elem);
|
249 mike 1.1
250 void XML_Dump(
|
251 krisbash 1.3 _In_ XML* self);
252
253 void XML_PutError(_Inout_ XML* self);
254
255 #if defined(_MSC_VER)
256 #include "xml_errors_ids.h"
|
257 mike 1.1
|
258 krisbash 1.3 void XML_Raise(_Inout_ XML* self, unsigned formatStringId, ...);
259 #else
260
261 #define XML_ERROR_BAD_ENTITY_REFERENCE ZT("Failed to parse XML. Bad entity reference. Only these are supported: '<', '>', '&', '"', '''.")
262 #define XML_ERROR_BAD_CHARACTER_REFERENCE ZT("Failed to parse XML. Bad character reference. Only character references in the range of 0 to 255 are supported.")
263 #define XML_ERROR_UNDEFINED_NAMESPACE_PREFIX ZT("Failed to parse XML. Undefined namespace prefix found '%T'.")
264 #define XML_ERROR_EXPECTED_ATTRIBUTE_NAME ZT("Failed to parse XML. An attribute name was expected.")
265 #define XML_ERROR_EXPECTED_ATTRIBUTE_EQUALS ZT("Failed to parse XML. An '=' character was expected while parsing attribute '%T'.")
266 #define XML_ERROR_EXPECTED_ATTRIBUTE_OPENING_QUOTES ZT("Failed to parse XML. An opening quote character was expected while parsing attribute '%T'.")
267 #define XML_ERROR_EXPECTED_ATTRIBUTE_CLOSING_QUOTES ZT("Failed to parse XML. An closing quote character was expected while parsing attribute '%T'.")
268 #define XML_ERROR_TOO_MANY_NAMESPACES ZT("Failed to parse XML. Too many namespaces were detected. A maximum of %u namespaces are allowed.")
269 #define XML_ERROR_TOO_MANY_ATTRIBUTES ZT("Failed to parse XML. Too many attributes were detected on element '%T'. A maximum of %u attributes are allowed per element.")
270 #define XML_ERROR_END_OF_XML_INSTRUCTION ZT("Failed to parse XML. The end of the XML was detected while processing an XML instruction.")
271 #define XML_ERROR_END_OF_INSTRUCTION_MISSING ZT("Failed to parse XML. The end of the XML instruction was not properly terminated with an '?>'.")
272 #define XML_ERROR_ELEMENT_NAME_EXPECTED ZT("Failed to parse XML. An element name was expected while decoding an element start tag.")
273 #define XML_ERROR_ELEMENT_NAME_PREMATURE_END ZT("Failed to parse XML. The end of the XML was detected while processing an XML element name for a element start tag.")
274 #define XML_ERROR_ELEMENT_DEPTH_OVERFLOW ZT("Failed to parse XML. XML element nesting is too deep. A maximum element depth of %u is supported.")
275 #define XML_ERROR_ELEMENT_NAME_NOT_CLOSED ZT("Failed to parse XML. The XML element '%T' was not terminated with a '>' while decoding an element start tag.")
276 #define XML_ERROR_ELEMENT_NAME_EXPECTED_ELEM_END ZT("Failed to parse XML. An element name was expected while decoding an element end tag.")
277 #define XML_ERROR_ELEMENT_NAME_PREMATURE_END_ELEM_END ZT("Failed to parse XML. The end of the XML was detected while processing an XML element name for a element end tag.")
278 #define XML_ERROR_ELEMENT_NAME_NOT_CLOSED_ELEM_END ZT("Failed to parse XML. The XML element '%T' was not terminated with a '>' while decoding an element end tag.")
279 krisbash 1.3 #define XML_ERROR_ELEMENT_TOO_MANY_ENDS ZT("Failed to parse XML. More element end tags were found than element starting tags. The ending tag found is '%T'.")
280 #define XML_ERROR_ELEMENT_END_ELEMENT_TAG_NOT_MATCH_START_TAG ZT("Failed to parse XML. The XML element end tag expected was '%T', but what was found was '%T'.")
281 #define XML_ERROR_COMMENT_END_EXPECTED ZT("Failed to parse XML. Double minus signs in comments are not allowed, unless used to terminate comment. '>' was not found.")
282 #define XML_ERROR_COMMENT_PREMATURE_END ZT("Failed to parse XML. The end of the XML was detected while processing a comment.")
283 #define XML_ERROR_CDATA_PREMATURE_END ZT("Failed to parse XML. The end of the XML was detected while processing a CDATA.")
284 #define XML_ERROR_DOCTYPE_PREMATURE_END ZT("Failed to parse XML. The end of the XML was detected while processing a DOCTYPE.")
285 #define XML_ERROR_CHARDATA_EXPECTED_ELEMENT_END_TAG ZT("Failed to parse XML. While processing the element data no element end tag was discovered.")
286 #define XML_ERROR_OPEN_ANGLE_BRACKET_EXPECTED ZT("Failed to parse XML. An open angle bracket '<' was expected and not found.")
287 #define XML_ERROR_COMMENT_CDATA_DOCTYPE_EXPECTED ZT("Failed to parse XML. A comment, CDATA or DOCTYPE element was expected and not found.")
288 #define XML_ERROR_ELEMENT_EXPECTED ZT("Failed to parse XML. An XML element was expected and not found.")
289 #define XML_ERROR_UNEXPECTED_STATE ZT("Failed to parse XML. The XML parser hit an interal problem that stopped it from progressing.")
290 #define XML_ERROR_SPECIFIC_ELEMENT_EXPECTED ZT("Failed to parse XML. The element name %T was expected but %T was found instead.")
291 #define XML_ERROR_SPECIFIC_END_ELEMENT_EXPECTED ZT("Failed to parse XML. The element name %T end tag was expected but %T was found instead.")
292 #define XML_ERROR_CHARACTER_DATA_EXPECTED ZT("Failed to parse XML. Character data was expected but not found.")
293
294 #define WSMAN_ERROR_NO_CLASS_NAME_IN_SELECTOR ZT("Failed to process WS-Management packet. The class name was not found in the selector.")
295 #define WSMAN_ERROR_NO_RESOURCE_URI ZT("Failed to process WS-Management packet. The resource URI was not found.")
296 #define WSMAN_ERROR_OUTOFMEMORY ZT("Failed to process WS-Management packet. Out of memory.")
297 #define WSMAN_ERROR_BAD_SELECTOR ZT("Failed to process WS-Management packet. Character data or the element EndPointReference was expected in the selector but not found.")
298 #define WSMAN_ERROR_BAD_EPR_IN_SELECTOR ZT("Failed to process WS-Management packet. The element EndPointReference in the selector could not be parsed.")
|
299 mike 1.1
300
|
301 krisbash 1.3 void XML_Raise(XML* self, _In_z_ const XML_Char* format, ...);
302 #endif
303
304 void XML_FormatError(_Inout_ XML* self, _Out_writes_z_(size) XML_Char* buffer, size_t size);
|
305 mike 1.1
306 #if defined(__cplusplus)
307 } /* extern "C" */
308 #endif
309
310 #endif /* _omiar_xml_h */
|