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