source: protocols/jabber/xmltok.h @ df70eafa

Last change on this file since df70eafa was b7d3cc34, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-06T18:23:18Z

Initial repository (0.99 release tree)

  • Property mode set to 100644
File size: 10.5 KB
Line 
1/*
2The contents of this file are subject to the Mozilla Public License
3Version 1.1 (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, 1999
16James Clark. All Rights Reserved.
17
18Contributor(s):
19
20Alternatively, the contents of this file may be used under the terms
21of the GNU General Public License (the "GPL"), in which case the
22provisions of the GPL are applicable instead of those above.  If you
23wish to allow use of your version of this file only under the terms of
24the GPL and not to allow others to use your version of this file under
25the MPL, indicate your decision by deleting the provisions above and
26replace them with the notice and other provisions required by the
27GPL. If you do not delete the provisions above, a recipient may use
28your version of this file under either the MPL or the GPL.
29*/
30
31#ifndef XmlTok_INCLUDED
32#define XmlTok_INCLUDED 1
33
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#ifndef XMLTOKAPI
39#define XMLTOKAPI /* as nothing */
40#endif
41
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
52
53/* The following tokens are returned by XmlContentTok; some are also
54  returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
55
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 */
66
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 */
72
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
89
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
100
101/* The following token is returned only by XmlAttributeValueTok */
102#define XML_TOK_ATTRIBUTE_VALUE_S 39
103
104/* The following token is returned only by XmlCdataSectionTok */
105#define XML_TOK_CDATA_SECT_CLOSE 40
106
107/* With namespace processing this is returned by XmlPrologTok
108   for a name with a colon. */
109#define XML_TOK_PREFIXED_NAME 41
110
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
115
116#define XML_N_LITERAL_TYPES 2
117#define XML_ATTRIBUTE_VALUE_LITERAL 0
118#define XML_ENTITY_VALUE_LITERAL 1
119
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
124
125typedef struct position {
126  /* first line and first column are 0 not 1 */
127  unsigned long lineNumber;
128  unsigned long columnNumber;
129} POSITION;
130
131typedef struct {
132  const char *name;
133  const char *valuePtr;
134  const char *valueEnd;
135  char normalized;
136} ATTRIBUTE;
137
138struct encoding;
139typedef struct encoding ENCODING;
140
141struct 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;
179};
180
181/*
182Scan the string starting at ptr until the end of the next complete token,
183but do not scan past eptr.  Return an integer giving the type of token.
184
185Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
186
187Return XML_TOK_PARTIAL when the string does not contain a complete token;
188nextTokPtr will not be set.
189
190Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
191will be set to point to the character which made the token invalid.
192
193Otherwise the string starts with a valid token; nextTokPtr will be set to point
194to the character following the end of that token.
195
196Each data character counts as a single token, but adjacent data characters
197may be returned together.  Similarly for characters in the prolog outside
198literals, comments and processing instructions.
199*/
200
201
202#define XmlTok(enc, state, ptr, end, nextTokPtr) \
203  (((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
204
205#define XmlPrologTok(enc, ptr, end, nextTokPtr) \
206   XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
207
208#define XmlContentTok(enc, ptr, end, nextTokPtr) \
209   XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
210
211#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
212   XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
213
214/* This is used for performing a 2nd-level tokenization on
215the content of a literal that has already been returned by XmlTok. */ 
216
217#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
218  (((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
219
220#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
221   XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
222
223#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
224   XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
225
226#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
227
228#define XmlNameMatchesAscii(enc, ptr1, ptr2) \
229  (((enc)->nameMatchesAscii)(enc, ptr1, ptr2))
230
231#define XmlNameLength(enc, ptr) \
232  (((enc)->nameLength)(enc, ptr))
233
234#define XmlSkipS(enc, ptr) \
235  (((enc)->skipS)(enc, ptr))
236
237#define XmlGetAttributes(enc, ptr, attsMax, atts) \
238  (((enc)->getAtts)(enc, ptr, attsMax, atts))
239
240#define XmlCharRefNumber(enc, ptr) \
241  (((enc)->charRefNumber)(enc, ptr))
242
243#define XmlPredefinedEntityName(enc, ptr, end) \
244  (((enc)->predefinedEntityName)(enc, ptr, end))
245
246#define XmlUpdatePosition(enc, ptr, end, pos) \
247  (((enc)->updatePosition)(enc, ptr, end, pos))
248
249#define XmlIsPublicId(enc, ptr, end, badPtr) \
250  (((enc)->isPublicId)(enc, ptr, end, badPtr))
251
252#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
253  (((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
254
255#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
256  (((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
257
258typedef struct {
259  ENCODING initEnc;
260  const ENCODING **encPtr;
261} INIT_ENCODING;
262
263int 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);
272
273int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
274const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding();
275const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding();
276int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
277int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
278
279int XMLTOKAPI XmlSizeOfUnknownEncoding();
280ENCODING XMLTOKAPI *
281XmlInitUnknownEncoding(void *mem,
282                       int *table,
283                       int (*conv)(void *userData, const char *p),
284                       void *userData);
285
286int 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);
295int XMLTOKAPI XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
296const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncodingNS();
297const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS();
298ENCODING XMLTOKAPI *
299XmlInitUnknownEncodingNS(void *mem,
300                         int *table,
301                         int (*conv)(void *userData, const char *p),
302                         void *userData);
303#ifdef __cplusplus
304}
305#endif
306
307#endif /* not XmlTok_INCLUDED */
Note: See TracBrowser for help on using the repository browser.