TORCS  1.3.9
The Open Racing Car Simulator
xmlparse.h
Go to the documentation of this file.
1 /*
2 The contents of this file are subject to the Mozilla Public License
3 Version 1.0 (the "License"); you may not use this file except in
4 compliance with the License. You may obtain a copy of the License at
5 http://www.mozilla.org/MPL/
6 
7 Software distributed under the License is distributed on an "AS IS"
8 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
9 License for the specific language governing rights and limitations
10 under the License.
11 
12 The Original Code is expat.
13 
14 The Initial Developer of the Original Code is James Clark.
15 Portions created by James Clark are Copyright (C) 1998
16 James Clark. All Rights Reserved.
17 
18 Contributor(s):
19 $Id$
20 */
21 
22 #ifndef XmlParse_INCLUDED
23 #define XmlParse_INCLUDED 1
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 #ifndef XMLPARSEAPI
30 #define XMLPARSEAPI /* as nothing */
31 #endif
32 
33 typedef void *XML_Parser;
34 
35 #ifdef XML_UNICODE_WCHAR_T
36 
37 /* XML_UNICODE_WCHAR_T will work only if sizeof(wchar_t) == 2 and wchar_t
38 uses Unicode. */
39 /* Information is UTF-16 encoded as wchar_ts */
40 
41 #ifndef XML_UNICODE
42 #define XML_UNICODE
43 #endif
44 
45 #include <stddef.h>
46 typedef wchar_t XML_Char;
47 typedef wchar_t XML_LChar;
48 
49 #else /* not XML_UNICODE_WCHAR_T */
50 
51 #ifdef XML_UNICODE
52 
53 /* Information is UTF-16 encoded as unsigned shorts */
54 typedef unsigned short XML_Char;
55 typedef char XML_LChar;
56 
57 #else /* not XML_UNICODE */
58 
59 /* Information is UTF-8 encoded. */
60 typedef char XML_Char;
61 typedef char XML_LChar;
62 
63 #endif /* not XML_UNICODE */
64 
65 #endif /* not XML_UNICODE_WCHAR_T */
66 
67 
68 /* Constructs a new parser; encoding is the encoding specified by the external
69 protocol or null if there is none specified. */
70 
73 
74 
75 /* atts is array of name/value pairs, terminated by 0;
76  names and values are 0 terminated. */
77 
78 typedef void (*XML_StartElementHandler)(void *userData,
79  const XML_Char *name,
80  const XML_Char **atts);
81 
82 typedef void (*XML_EndElementHandler)(void *userData,
83  const XML_Char *name);
84 
85 /* s is not 0 terminated. */
86 typedef void (*XML_CharacterDataHandler)(void *userData,
87  const XML_Char *s,
88  int len);
89 
90 /* target and data are 0 terminated */
91 typedef void (*XML_ProcessingInstructionHandler)(void *userData,
92  const XML_Char *target,
93  const XML_Char *data);
94 
95 /* This is called for any characters in the XML document for
96 which there is no applicable handler. This includes both
97 characters that are part of markup which is of a kind that is
98 not reported (comments, markup declarations), or characters
99 that are part of a construct which could be reported but
100 for which no handler has been supplied. The characters are passed
101 exactly as they were in the XML document except that
102 they will be encoded in UTF-8. Line boundaries are not normalized.
103 Note that a byte order mark character is not passed to the default handler.
104 If a default handler is set, internal entity references
105 are not expanded. There are no guarantees about
106 how characters are divided between calls to the default handler:
107 for example, a comment might be split between multiple calls. */
108 
109 typedef void (*XML_DefaultHandler)(void *userData,
110  const XML_Char *s,
111  int len);
112 
113 /* This is called for a declaration of an unparsed (NDATA)
114 entity. The base argument is whatever was set by XML_SetBase.
115 The entityName, systemId and notationName arguments will never be null.
116 The other arguments may be. */
117 
118 typedef void (*XML_UnparsedEntityDeclHandler)(void *userData,
119  const XML_Char *entityName,
120  const XML_Char *base,
121  const XML_Char *systemId,
122  const XML_Char *publicId,
123  const XML_Char *notationName);
124 
125 /* This is called for a declaration of notation.
126 The base argument is whatever was set by XML_SetBase.
127 The notationName will never be null. The other arguments can be. */
128 
129 typedef void (*XML_NotationDeclHandler)(void *userData,
130  const XML_Char *notationName,
131  const XML_Char *base,
132  const XML_Char *systemId,
133  const XML_Char *publicId);
134 
135 /* This is called for a reference to an external parsed general entity.
136 The referenced entity is not automatically parsed.
137 The application can parse it immediately or later using
138 XML_ExternalEntityParserCreate.
139 The parser argument is the parser parsing the entity containing the reference;
140 it can be passed as the parser argument to XML_ExternalEntityParserCreate.
141 The systemId argument is the system identifier as specified in the entity declaration;
142 it will not be null.
143 The base argument is the system identifier that should be used as the base for
144 resolving systemId if systemId was relative; this is set by XML_SetBase;
145 it may be null.
146 The publicId argument is the public identifier as specified in the entity declaration,
147 or null if none was specified; the whitespace in the public identifier
148 will have been normalized as required by the XML spec.
149 The openEntityNames argument is a space-separated list of the names of the entities
150 that are open for the parse of this entity (including the name of the referenced
151 entity); this can be passed as the openEntityNames argument to
152 XML_ExternalEntityParserCreate; openEntityNames is valid only until the handler
153 returns, so if the referenced entity is to be parsed later, it must be copied.
154 The handler should return 0 if processing should not continue because of
155 a fatal error in the handling of the external entity.
156 In this case the calling parser will return an XML_ERROR_EXTERNAL_ENTITY_HANDLING
157 error.
158 Note that unlike other handlers the first argument is the parser, not userData. */
159 
161  const XML_Char *openEntityNames,
162  const XML_Char *base,
163  const XML_Char *systemId,
164  const XML_Char *publicId);
165 
166 /* This structure is filled in by the XML_UnknownEncodingHandler
167 to provide information to the parser about encodings that are unknown
168 to the parser.
169 The map[b] member gives information about byte sequences
170 whose first byte is b.
171 If map[b] is c where c is >= 0, then b by itself encodes the Unicode scalar value c.
172 If map[b] is -1, then the byte sequence is malformed.
173 If map[b] is -n, where n >= 2, then b is the first byte of an n-byte
174 sequence that encodes a single Unicode scalar value.
175 The data member will be passed as the first argument to the convert function.
176 The convert function is used to convert multibyte sequences;
177 s will point to a n-byte sequence where map[(unsigned char)*s] == -n.
178 The convert function must return the Unicode scalar value
179 represented by this byte sequence or -1 if the byte sequence is malformed.
180 The convert function may be null if the encoding is a single-byte encoding,
181 that is if map[b] >= -1 for all bytes b.
182 When the parser is finished with the encoding, then if release is not null,
183 it will call release passing it the data member;
184 once release has been called, the convert function will not be called again.
185 
186 Expat places certain restrictions on the encodings that are supported
187 using this mechanism.
188 
189 1. Every ASCII character that can appear in a well-formed XML document,
190 other than the characters
191 
192  $@\^`{}~
193 
194 must be represented by a single byte, and that byte must be the
195 same byte that represents that character in ASCII.
196 
197 2. No character may require more than 4 bytes to encode.
198 
199 3. All characters encoded must have Unicode scalar values <= 0xFFFF,
200 (ie characters that would be encoded by surrogates in UTF-16
201 are not allowed). Note that this restriction doesn't apply to
202 the built-in support for UTF-8 and UTF-16.
203 
204 4. No Unicode character may be encoded by more than one distinct sequence
205 of bytes. */
206 
207 typedef struct {
208  int map[256];
209  void *data;
210  int (*convert)(void *data, const char *s);
211  void (*release)(void *data);
212 } XML_Encoding;
213 
214 /* This is called for an encoding that is unknown to the parser.
215 The encodingHandlerData argument is that which was passed as the
216 second argument to XML_SetUnknownEncodingHandler.
217 The name argument gives the name of the encoding as specified in
218 the encoding declaration.
219 If the callback can provide information about the encoding,
220 it must fill in the XML_Encoding structure, and return 1.
221 Otherwise it must return 0.
222 If info does not describe a suitable encoding,
223 then the parser will return an XML_UNKNOWN_ENCODING error. */
224 
225 typedef int (*XML_UnknownEncodingHandler)(void *encodingHandlerData,
226  const XML_Char *name,
227  XML_Encoding *info);
228 
229 void XMLPARSEAPI
233 
234 void XMLPARSEAPI
236  XML_CharacterDataHandler handler);
237 
238 void XMLPARSEAPI
241 
242 void XMLPARSEAPI
244  XML_DefaultHandler handler);
245 
246 void XMLPARSEAPI
249 
250 void XMLPARSEAPI
252  XML_NotationDeclHandler handler);
253 
254 void XMLPARSEAPI
257 
258 void XMLPARSEAPI
261  void *encodingHandlerData);
262 
263 /* This can be called within a handler for a start element, end element,
264 processing instruction or character data. It causes the corresponding
265 markup to be passed to the default handler.
266 Within the expansion of an internal entity, nothing will be passed
267 to the default handler, although this usually will not happen since
268 setting a default handler inhibits expansion of internal entities. */
270 
271 /* This value is passed as the userData argument to callbacks. */
272 void XMLPARSEAPI
273 XML_SetUserData(XML_Parser parser, void *userData);
274 
275 /* Returns the last value set by XML_SetUserData or null. */
276 #define XML_GetUserData(parser) (*(void **)(parser))
277 
278 /* If this function is called, then the parser will be passed
279 as the first argument to callbacks instead of userData.
280 The userData will still be accessible using XML_GetUserData. */
281 
282 void XMLPARSEAPI
284 
285 /* Sets the base to be used for resolving relative URIs in system identifiers in
286 declarations. Resolving relative identifiers is left to the application:
287 this value will be passed through as the base argument to the
288 XML_ExternalEntityRefHandler, XML_NotationDeclHandler
289 and XML_UnparsedEntityDeclHandler. The base argument will be copied.
290 Returns zero if out of memory, non-zero otherwise. */
291 
292 int XMLPARSEAPI
293 XML_SetBase(XML_Parser parser, const XML_Char *base);
294 
295 const XML_Char XMLPARSEAPI *
296 XML_GetBase(XML_Parser parser);
297 
298 /* Parses some input. Returns 0 if a fatal error is detected.
299 The last call to XML_Parse must have isFinal true;
300 len may be zero for this call (or any other). */
301 int XMLPARSEAPI
302 XML_Parse(XML_Parser parser, const char *s, int len, int isFinal);
303 
304 void XMLPARSEAPI *
305 XML_GetBuffer(XML_Parser parser, int len);
306 
307 int XMLPARSEAPI
308 XML_ParseBuffer(XML_Parser parser, int len, int isFinal);
309 
310 /* Creates an XML_Parser object that can parse an external general entity;
311 openEntityNames is a space-separated list of the names of the entities that are open
312 for the parse of this entity (including the name of this one);
313 encoding is the externally specified encoding,
314 or null if there is no externally specified encoding.
315 This can be called at any point after the first call to an ExternalEntityRefHandler
316 so longer as the parser has not yet been freed.
317 The new parser is completely independent and may safely be used in a separate thread.
318 The handlers and userData are initialized from the parser argument.
319 Returns 0 if out of memory. Otherwise returns a new XML_Parser object. */
322  const XML_Char *openEntityNames,
323  const XML_Char *encoding);
324 
325 enum XML_Error {
348 };
349 
350 /* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
351 returns information about the error. */
352 
354 
355 /* These functions return information about the current parse location.
356 They may be called when XML_Parse or XML_ParseBuffer return 0;
357 in this case the location is the location of the character at which
358 the error was detected.
359 They may also be called from any other callback called to report
360 some parse event; in this the location is the location of the first
361 of the sequence of characters that generated the event. */
362 
366 
367 /* For backwards compatibility with previous versions. */
368 #define XML_GetErrorLineNumber XML_GetCurrentLineNumber
369 #define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber
370 #define XML_GetErrorByteIndex XML_GetCurrentByteIndex
371 
372 /* Frees memory used by the parser. */
373 void XMLPARSEAPI
374 XML_ParserFree(XML_Parser parser);
375 
376 /* Returns a string describing the error. */
377 const XML_LChar XMLPARSEAPI *XML_ErrorString(int code);
378 
379 #ifdef __cplusplus
380 }
381 #endif
382 
383 #endif /* not XmlParse_INCLUDED */
void(* XML_UnparsedEntityDeclHandler)(void *userData, const XML_Char *entityName, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId, const XML_Char *notationName)
Definition: xmlparse.h:118
int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser)
void XMLPARSEAPI XML_SetUserData(XML_Parser parser, void *userData)
int(* XML_ExternalEntityRefHandler)(XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
Definition: xmlparse.h:160
void XMLPARSEAPI XML_SetUnparsedEntityDeclHandler(XML_Parser parser, XML_UnparsedEntityDeclHandler handler)
char XML_LChar
Definition: xmlparse.h:61
const XML_Char XMLPARSEAPI * XML_GetBase(XML_Parser parser)
void XMLPARSEAPI XML_SetExternalEntityRefHandler(XML_Parser parser, XML_ExternalEntityRefHandler handler)
void XMLPARSEAPI XML_SetDefaultHandler(XML_Parser parser, XML_DefaultHandler handler)
void XMLPARSEAPI XML_UseParserAsHandlerArg(XML_Parser parser)
char * name
Definition: xml.h:17
int XMLPARSEAPI XML_GetCurrentColumnNumber(XML_Parser parser)
void XMLPARSEAPI XML_ParserFree(XML_Parser parser)
void XMLPARSEAPI XML_SetCharacterDataHandler(XML_Parser parser, XML_CharacterDataHandler handler)
void(* XML_NotationDeclHandler)(void *userData, const XML_Char *notationName, const XML_Char *base, const XML_Char *systemId, const XML_Char *publicId)
Definition: xmlparse.h:129
int XMLPARSEAPI XML_Parse(XML_Parser parser, const char *s, int len, int isFinal)
int(* XML_UnknownEncodingHandler)(void *encodingHandlerData, const XML_Char *name, XML_Encoding *info)
Definition: xmlparse.h:225
enum XML_Error XMLPARSEAPI XML_GetErrorCode(XML_Parser parser)
XML_Parser XMLPARSEAPI XML_ParserCreate(const XML_Char *encoding)
void(* XML_ProcessingInstructionHandler)(void *userData, const XML_Char *target, const XML_Char *data)
Definition: xmlparse.h:91
void(* XML_StartElementHandler)(void *userData, const XML_Char *name, const XML_Char **atts)
Definition: xmlparse.h:78
void(* XML_CharacterDataHandler)(void *userData, const XML_Char *s, int len)
Definition: xmlparse.h:86
void(* XML_DefaultHandler)(void *userData, const XML_Char *s, int len)
Definition: xmlparse.h:109
void XMLPARSEAPI * XML_GetBuffer(XML_Parser parser, int len)
#define XMLPARSEAPI
Definition: xmlparse.h:30
const XML_LChar XMLPARSEAPI * XML_ErrorString(int code)
void XMLPARSEAPI XML_SetNotationDeclHandler(XML_Parser parser, XML_NotationDeclHandler handler)
int XMLPARSEAPI XML_ParseBuffer(XML_Parser parser, int len, int isFinal)
void XMLPARSEAPI XML_SetUnknownEncodingHandler(XML_Parser parser, XML_UnknownEncodingHandler handler, void *encodingHandlerData)
void * data
Definition: xmlparse.h:209
long XMLPARSEAPI XML_GetCurrentByteIndex(XML_Parser parser)
char XML_Char
Definition: xmlparse.h:60
int XMLPARSEAPI XML_SetBase(XML_Parser parser, const XML_Char *base)
void * XML_Parser
Definition: xmlparse.h:33
void XMLPARSEAPI XML_DefaultCurrent(XML_Parser parser)
void XMLPARSEAPI XML_SetProcessingInstructionHandler(XML_Parser parser, XML_ProcessingInstructionHandler handler)
void XMLPARSEAPI XML_SetElementHandler(XML_Parser parser, XML_StartElementHandler start, XML_EndElementHandler end)
XML_Error
Definition: xmlparse.h:325
void(* XML_EndElementHandler)(void *userData, const XML_Char *name)
Definition: xmlparse.h:82
XML_Parser XMLPARSEAPI XML_ExternalEntityParserCreate(XML_Parser parser, const XML_Char *openEntityNames, const XML_Char *encoding)