[gaim-migrate @ 3063]
[pidgin-git.git] / src / protocols / jabber / xmltok.h
blob06544d15cb2c57b5bd6e5add44b0074243caa40c
1 /*
2 The contents of this file are subject to the Mozilla Public License
3 Version 1.1 (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/
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.
12 The Original Code is expat.
14 The Initial Developer of the Original Code is James Clark.
15 Portions created by James Clark are Copyright (C) 1998, 1999
16 James Clark. All Rights Reserved.
18 Contributor(s):
20 Alternatively, the contents of this file may be used under the terms
21 of the GNU General Public License (the "GPL"), in which case the
22 provisions of the GPL are applicable instead of those above. If you
23 wish to allow use of your version of this file only under the terms of
24 the GPL and not to allow others to use your version of this file under
25 the MPL, indicate your decision by deleting the provisions above and
26 replace them with the notice and other provisions required by the
27 GPL. If you do not delete the provisions above, a recipient may use
28 your version of this file under either the MPL or the GPL.
31 #ifndef XmlTok_INCLUDED
32 #define XmlTok_INCLUDED 1
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
38 #ifndef XMLTOKAPI
39 #define XMLTOKAPI /* as nothing */
40 #endif
42 /* The following token may be returned by XmlContentTok */
43 #define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of
44 illegal ]]> sequence */
45 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
46 #define XML_TOK_NONE -4 /* The string to be scanned is empty */
47 #define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
48 might be part of CRLF sequence */
49 #define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
50 #define XML_TOK_PARTIAL -1 /* only part of a token */
51 #define XML_TOK_INVALID 0
53 /* The following tokens are returned by XmlContentTok; some are also
54 returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
56 #define XML_TOK_START_TAG_WITH_ATTS 1
57 #define XML_TOK_START_TAG_NO_ATTS 2
58 #define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
59 #define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
60 #define XML_TOK_END_TAG 5
61 #define XML_TOK_DATA_CHARS 6
62 #define XML_TOK_DATA_NEWLINE 7
63 #define XML_TOK_CDATA_SECT_OPEN 8
64 #define XML_TOK_ENTITY_REF 9
65 #define XML_TOK_CHAR_REF 10 /* numeric character reference */
67 /* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
68 #define XML_TOK_PI 11 /* processing instruction */
69 #define XML_TOK_XML_DECL 12 /* XML decl or text decl */
70 #define XML_TOK_COMMENT 13
71 #define XML_TOK_BOM 14 /* Byte order mark */
73 /* The following tokens are returned only by XmlPrologTok */
74 #define XML_TOK_PROLOG_S 15
75 #define XML_TOK_DECL_OPEN 16 /* <!foo */
76 #define XML_TOK_DECL_CLOSE 17 /* > */
77 #define XML_TOK_NAME 18
78 #define XML_TOK_NMTOKEN 19
79 #define XML_TOK_POUND_NAME 20 /* #name */
80 #define XML_TOK_OR 21 /* | */
81 #define XML_TOK_PERCENT 22
82 #define XML_TOK_OPEN_PAREN 23
83 #define XML_TOK_CLOSE_PAREN 24
84 #define XML_TOK_OPEN_BRACKET 25
85 #define XML_TOK_CLOSE_BRACKET 26
86 #define XML_TOK_LITERAL 27
87 #define XML_TOK_PARAM_ENTITY_REF 28
88 #define XML_TOK_INSTANCE_START 29
90 /* The following occur only in element type declarations */
91 #define XML_TOK_NAME_QUESTION 30 /* name? */
92 #define XML_TOK_NAME_ASTERISK 31 /* name* */
93 #define XML_TOK_NAME_PLUS 32 /* name+ */
94 #define XML_TOK_COND_SECT_OPEN 33 /* <![ */
95 #define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
96 #define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
97 #define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
98 #define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
99 #define XML_TOK_COMMA 38
101 /* The following token is returned only by XmlAttributeValueTok */
102 #define XML_TOK_ATTRIBUTE_VALUE_S 39
104 /* The following token is returned only by XmlCdataSectionTok */
105 #define XML_TOK_CDATA_SECT_CLOSE 40
107 /* With namespace processing this is returned by XmlPrologTok
108 for a name with a colon. */
109 #define XML_TOK_PREFIXED_NAME 41
111 #define XML_N_STATES 3
112 #define XML_PROLOG_STATE 0
113 #define XML_CONTENT_STATE 1
114 #define XML_CDATA_SECTION_STATE 2
116 #define XML_N_LITERAL_TYPES 2
117 #define XML_ATTRIBUTE_VALUE_LITERAL 0
118 #define XML_ENTITY_VALUE_LITERAL 1
120 /* The size of the buffer passed to XmlUtf8Encode must be at least this. */
121 #define XML_UTF8_ENCODE_MAX 4
122 /* The size of the buffer passed to XmlUtf16Encode must be at least this. */
123 #define XML_UTF16_ENCODE_MAX 2
125 typedef struct position {
126 /* first line and first column are 0 not 1 */
127 unsigned long lineNumber;
128 unsigned long columnNumber;
129 } POSITION;
131 typedef struct {
132 const char *name;
133 const char *valuePtr;
134 const char *valueEnd;
135 char normalized;
136 } ATTRIBUTE;
138 struct encoding;
139 typedef struct encoding ENCODING;
141 struct encoding {
142 int (*scanners[XML_N_STATES])(const ENCODING *,
143 const char *,
144 const char *,
145 const char **);
146 int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
147 const char *,
148 const char *,
149 const char **);
150 int (*sameName)(const ENCODING *,
151 const char *, const char *);
152 int (*nameMatchesAscii)(const ENCODING *,
153 const char *, const char *);
154 int (*nameLength)(const ENCODING *, const char *);
155 const char *(*skipS)(const ENCODING *, const char *);
156 int (*getAtts)(const ENCODING *enc, const char *ptr,
157 int attsMax, ATTRIBUTE *atts);
158 int (*charRefNumber)(const ENCODING *enc, const char *ptr);
159 int (*predefinedEntityName)(const ENCODING *, const char *, const char *);
160 void (*updatePosition)(const ENCODING *,
161 const char *ptr,
162 const char *end,
163 POSITION *);
164 int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
165 const char **badPtr);
166 void (*utf8Convert)(const ENCODING *enc,
167 const char **fromP,
168 const char *fromLim,
169 char **toP,
170 const char *toLim);
171 void (*utf16Convert)(const ENCODING *enc,
172 const char **fromP,
173 const char *fromLim,
174 unsigned short **toP,
175 const unsigned short *toLim);
176 int minBytesPerChar;
177 char isUtf8;
178 char isUtf16;
182 Scan the string starting at ptr until the end of the next complete token,
183 but do not scan past eptr. Return an integer giving the type of token.
185 Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
187 Return XML_TOK_PARTIAL when the string does not contain a complete token;
188 nextTokPtr will not be set.
190 Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
191 will be set to point to the character which made the token invalid.
193 Otherwise the string starts with a valid token; nextTokPtr will be set to point
194 to the character following the end of that token.
196 Each data character counts as a single token, but adjacent data characters
197 may be returned together. Similarly for characters in the prolog outside
198 literals, comments and processing instructions.
202 #define XmlTok(enc, state, ptr, end, nextTokPtr) \
203 (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
205 #define XmlPrologTok(enc, ptr, end, nextTokPtr) \
206 XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
208 #define XmlContentTok(enc, ptr, end, nextTokPtr) \
209 XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
211 #define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
212 XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
214 /* This is used for performing a 2nd-level tokenization on
215 the content of a literal that has already been returned by XmlTok. */
217 #define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
218 (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
220 #define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
221 XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
223 #define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
224 XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
226 #define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
228 #define XmlNameMatchesAscii(enc, ptr1, ptr2) \
229 (((enc)->nameMatchesAscii)(enc, ptr1, ptr2))
231 #define XmlNameLength(enc, ptr) \
232 (((enc)->nameLength)(enc, ptr))
234 #define XmlSkipS(enc, ptr) \
235 (((enc)->skipS)(enc, ptr))
237 #define XmlGetAttributes(enc, ptr, attsMax, atts) \
238 (((enc)->getAtts)(enc, ptr, attsMax, atts))
240 #define XmlCharRefNumber(enc, ptr) \
241 (((enc)->charRefNumber)(enc, ptr))
243 #define XmlPredefinedEntityName(enc, ptr, end) \
244 (((enc)->predefinedEntityName)(enc, ptr, end))
246 #define XmlUpdatePosition(enc, ptr, end, pos) \
247 (((enc)->updatePosition)(enc, ptr, end, pos))
249 #define XmlIsPublicId(enc, ptr, end, badPtr) \
250 (((enc)->isPublicId)(enc, ptr, end, badPtr))
252 #define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
253 (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
255 #define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
256 (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
258 typedef struct {
259 ENCODING initEnc;
260 const ENCODING **encPtr;
261 } INIT_ENCODING;
263 int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
264 const ENCODING *enc,
265 const char *ptr,
266 const char *end,
267 const char **badPtr,
268 const char **versionPtr,
269 const char **encodingNamePtr,
270 const ENCODING **namedEncodingPtr,
271 int *standalonePtr);
273 int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
274 const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding();
275 const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding();
276 int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
277 int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
279 int XMLTOKAPI XmlSizeOfUnknownEncoding();
280 ENCODING XMLTOKAPI *
281 XmlInitUnknownEncoding(void *mem,
282 int *table,
283 int (*conv)(void *userData, const char *p),
284 void *userData);
286 int XMLTOKAPI XmlParseXmlDeclNS(int isGeneralTextEntity,
287 const ENCODING *enc,
288 const char *ptr,
289 const char *end,
290 const char **badPtr,
291 const char **versionPtr,
292 const char **encodingNamePtr,
293 const ENCODING **namedEncodingPtr,
294 int *standalonePtr);
295 int XMLTOKAPI XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
296 const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncodingNS();
297 const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS();
298 ENCODING XMLTOKAPI *
299 XmlInitUnknownEncodingNS(void *mem,
300 int *table,
301 int (*conv)(void *userData, const char *p),
302 void *userData);
303 #ifdef __cplusplus
305 #endif
307 #endif /* not XmlTok_INCLUDED */