1998-04-05 11:11:29 -04:00
|
|
|
/*
|
|
|
|
The contents of this file are subject to the Mozilla Public License
|
1999-05-28 22:19:21 -04:00
|
|
|
Version 1.1 (the "License"); you may not use this file except in
|
1998-04-05 11:11:29 -04:00
|
|
|
compliance with the License. You may obtain a copy of the License at
|
|
|
|
http://www.mozilla.org/MPL/
|
|
|
|
|
|
|
|
Software distributed under the License is distributed on an "AS IS"
|
|
|
|
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
License for the specific language governing rights and limitations
|
|
|
|
under the License.
|
|
|
|
|
|
|
|
The Original Code is expat.
|
|
|
|
|
|
|
|
The Initial Developer of the Original Code is James Clark.
|
1999-05-28 22:19:21 -04:00
|
|
|
Portions created by James Clark are Copyright (C) 1998, 1999
|
1998-04-05 11:11:29 -04:00
|
|
|
James Clark. All Rights Reserved.
|
|
|
|
|
|
|
|
Contributor(s):
|
1999-05-28 22:19:21 -04:00
|
|
|
|
|
|
|
Alternatively, the contents of this file may be used under the terms
|
|
|
|
of the GNU General Public License (the "GPL"), in which case the
|
|
|
|
provisions of the GPL are applicable instead of those above. If you
|
|
|
|
wish to allow use of your version of this file only under the terms of
|
|
|
|
the GPL and not to allow others to use your version of this file under
|
|
|
|
the MPL, indicate your decision by deleting the provisions above and
|
|
|
|
replace them with the notice and other provisions required by the
|
|
|
|
GPL. If you do not delete the provisions above, a recipient may use
|
|
|
|
your version of this file under either the MPL or the GPL.
|
1998-04-05 11:11:29 -04:00
|
|
|
*/
|
|
|
|
|
1997-11-04 00:43:56 -05:00
|
|
|
#ifndef XmlTok_INCLUDED
|
|
|
|
#define XmlTok_INCLUDED 1
|
|
|
|
|
1997-11-10 01:10:50 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
1997-11-04 00:43:56 -05:00
|
|
|
#ifndef XMLTOKAPI
|
|
|
|
#define XMLTOKAPI /* as nothing */
|
|
|
|
#endif
|
|
|
|
|
1998-05-01 23:14:22 -04:00
|
|
|
/* The following token may be returned by XmlContentTok */
|
|
|
|
#define XML_TOK_TRAILING_RSQB -5 /* ] or ]] at the end of the scan; might be start of
|
|
|
|
illegal ]]> sequence */
|
1997-11-04 00:43:56 -05:00
|
|
|
/* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_TOK_NONE -4 /* The string to be scanned is empty */
|
|
|
|
#define XML_TOK_TRAILING_CR -3 /* A CR at the end of the scan;
|
|
|
|
might be part of CRLF sequence */
|
1997-11-10 01:10:50 -05:00
|
|
|
#define XML_TOK_PARTIAL_CHAR -2 /* only part of a multibyte sequence */
|
|
|
|
#define XML_TOK_PARTIAL -1 /* only part of a token */
|
1997-11-04 00:43:56 -05:00
|
|
|
#define XML_TOK_INVALID 0
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
/* The following tokens are returned by XmlContentTok; some are also
|
1998-05-02 01:31:15 -04:00
|
|
|
returned by XmlAttributeValueTok, XmlEntityTok, XmlCdataSectionTok */
|
1997-11-04 00:43:56 -05:00
|
|
|
|
1997-11-11 00:53:20 -05:00
|
|
|
#define XML_TOK_START_TAG_WITH_ATTS 1
|
|
|
|
#define XML_TOK_START_TAG_NO_ATTS 2
|
|
|
|
#define XML_TOK_EMPTY_ELEMENT_WITH_ATTS 3 /* empty element tag <e/> */
|
|
|
|
#define XML_TOK_EMPTY_ELEMENT_NO_ATTS 4
|
|
|
|
#define XML_TOK_END_TAG 5
|
|
|
|
#define XML_TOK_DATA_CHARS 6
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_TOK_DATA_NEWLINE 7
|
1998-05-02 01:31:15 -04:00
|
|
|
#define XML_TOK_CDATA_SECT_OPEN 8
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_TOK_ENTITY_REF 9
|
|
|
|
#define XML_TOK_CHAR_REF 10 /* numeric character reference */
|
1997-11-11 00:53:20 -05:00
|
|
|
|
|
|
|
/* The following tokens may be returned by both XmlPrologTok and XmlContentTok */
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_TOK_PI 11 /* processing instruction */
|
1997-12-11 19:48:27 -05:00
|
|
|
#define XML_TOK_XML_DECL 12 /* XML decl or text decl */
|
|
|
|
#define XML_TOK_COMMENT 13
|
|
|
|
#define XML_TOK_BOM 14 /* Byte order mark */
|
1997-11-11 00:53:20 -05:00
|
|
|
|
|
|
|
/* The following tokens are returned only by XmlPrologTok */
|
|
|
|
#define XML_TOK_PROLOG_S 15
|
1997-11-13 04:05:46 -05:00
|
|
|
#define XML_TOK_DECL_OPEN 16 /* <!foo */
|
|
|
|
#define XML_TOK_DECL_CLOSE 17 /* > */
|
|
|
|
#define XML_TOK_NAME 18
|
|
|
|
#define XML_TOK_NMTOKEN 19
|
|
|
|
#define XML_TOK_POUND_NAME 20 /* #name */
|
1997-11-14 19:51:48 -05:00
|
|
|
#define XML_TOK_OR 21 /* | */
|
|
|
|
#define XML_TOK_PERCENT 22
|
|
|
|
#define XML_TOK_OPEN_PAREN 23
|
|
|
|
#define XML_TOK_CLOSE_PAREN 24
|
|
|
|
#define XML_TOK_OPEN_BRACKET 25
|
|
|
|
#define XML_TOK_CLOSE_BRACKET 26
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_TOK_LITERAL 27
|
|
|
|
#define XML_TOK_PARAM_ENTITY_REF 28
|
1997-12-11 19:48:27 -05:00
|
|
|
#define XML_TOK_INSTANCE_START 29
|
1997-12-10 02:44:19 -05:00
|
|
|
|
1997-11-14 19:51:48 -05:00
|
|
|
/* The following occur only in element type declarations */
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_TOK_NAME_QUESTION 30 /* name? */
|
|
|
|
#define XML_TOK_NAME_ASTERISK 31 /* name* */
|
|
|
|
#define XML_TOK_NAME_PLUS 32 /* name+ */
|
|
|
|
#define XML_TOK_COND_SECT_OPEN 33 /* <![ */
|
|
|
|
#define XML_TOK_COND_SECT_CLOSE 34 /* ]]> */
|
|
|
|
#define XML_TOK_CLOSE_PAREN_QUESTION 35 /* )? */
|
|
|
|
#define XML_TOK_CLOSE_PAREN_ASTERISK 36 /* )* */
|
|
|
|
#define XML_TOK_CLOSE_PAREN_PLUS 37 /* )+ */
|
1997-12-11 19:48:27 -05:00
|
|
|
#define XML_TOK_COMMA 38
|
1997-12-10 02:44:19 -05:00
|
|
|
|
1998-05-02 01:31:15 -04:00
|
|
|
/* The following token is returned only by XmlAttributeValueTok */
|
1998-02-03 04:09:48 -05:00
|
|
|
#define XML_TOK_ATTRIBUTE_VALUE_S 39
|
|
|
|
|
1998-05-02 01:31:15 -04:00
|
|
|
/* The following token is returned only by XmlCdataSectionTok */
|
|
|
|
#define XML_TOK_CDATA_SECT_CLOSE 40
|
|
|
|
|
1998-08-22 18:40:45 -04:00
|
|
|
/* With namespace processing this is returned by XmlPrologTok
|
|
|
|
for a name with a colon. */
|
|
|
|
#define XML_TOK_PREFIXED_NAME 41
|
|
|
|
|
1999-06-25 06:58:20 -04:00
|
|
|
#ifdef XML_DTD
|
|
|
|
#define XML_TOK_IGNORE_SECT 42
|
|
|
|
#endif /* XML_DTD */
|
|
|
|
|
|
|
|
#ifdef XML_DTD
|
|
|
|
#define XML_N_STATES 4
|
|
|
|
#else /* not XML_DTD */
|
1998-05-02 01:31:15 -04:00
|
|
|
#define XML_N_STATES 3
|
1999-06-25 06:58:20 -04:00
|
|
|
#endif /* not XML_DTD */
|
|
|
|
|
1997-11-10 01:10:50 -05:00
|
|
|
#define XML_PROLOG_STATE 0
|
|
|
|
#define XML_CONTENT_STATE 1
|
1998-05-02 01:31:15 -04:00
|
|
|
#define XML_CDATA_SECTION_STATE 2
|
1999-06-25 06:58:20 -04:00
|
|
|
#ifdef XML_DTD
|
|
|
|
#define XML_IGNORE_SECTION_STATE 3
|
|
|
|
#endif /* XML_DTD */
|
1997-11-10 01:10:50 -05:00
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XML_N_LITERAL_TYPES 2
|
|
|
|
#define XML_ATTRIBUTE_VALUE_LITERAL 0
|
|
|
|
#define XML_ENTITY_VALUE_LITERAL 1
|
|
|
|
|
1998-05-31 04:06:01 -04:00
|
|
|
/* The size of the buffer passed to XmlUtf8Encode must be at least this. */
|
|
|
|
#define XML_UTF8_ENCODE_MAX 4
|
|
|
|
/* The size of the buffer passed to XmlUtf16Encode must be at least this. */
|
|
|
|
#define XML_UTF16_ENCODE_MAX 2
|
1997-12-10 02:44:19 -05:00
|
|
|
|
1997-11-12 05:38:58 -05:00
|
|
|
typedef struct position {
|
|
|
|
/* first line and first column are 0 not 1 */
|
|
|
|
unsigned long lineNumber;
|
|
|
|
unsigned long columnNumber;
|
|
|
|
} POSITION;
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
typedef struct {
|
|
|
|
const char *name;
|
|
|
|
const char *valuePtr;
|
|
|
|
const char *valueEnd;
|
1998-02-02 06:15:15 -05:00
|
|
|
char normalized;
|
1997-12-10 02:44:19 -05:00
|
|
|
} ATTRIBUTE;
|
|
|
|
|
|
|
|
struct encoding;
|
|
|
|
typedef struct encoding ENCODING;
|
|
|
|
|
|
|
|
struct encoding {
|
|
|
|
int (*scanners[XML_N_STATES])(const ENCODING *,
|
|
|
|
const char *,
|
|
|
|
const char *,
|
|
|
|
const char **);
|
|
|
|
int (*literalScanners[XML_N_LITERAL_TYPES])(const ENCODING *,
|
|
|
|
const char *,
|
|
|
|
const char *,
|
|
|
|
const char **);
|
|
|
|
int (*sameName)(const ENCODING *,
|
1997-11-11 00:53:20 -05:00
|
|
|
const char *, const char *);
|
1997-12-10 02:44:19 -05:00
|
|
|
int (*nameMatchesAscii)(const ENCODING *,
|
1999-06-25 10:28:06 -04:00
|
|
|
const char *, const char *, const char *);
|
1997-12-10 02:44:19 -05:00
|
|
|
int (*nameLength)(const ENCODING *, const char *);
|
1998-02-02 06:24:03 -05:00
|
|
|
const char *(*skipS)(const ENCODING *, const char *);
|
1997-12-10 02:44:19 -05:00
|
|
|
int (*getAtts)(const ENCODING *enc, const char *ptr,
|
|
|
|
int attsMax, ATTRIBUTE *atts);
|
|
|
|
int (*charRefNumber)(const ENCODING *enc, const char *ptr);
|
1998-06-01 03:28:31 -04:00
|
|
|
int (*predefinedEntityName)(const ENCODING *, const char *, const char *);
|
1997-12-10 02:44:19 -05:00
|
|
|
void (*updatePosition)(const ENCODING *,
|
1997-11-12 05:38:58 -05:00
|
|
|
const char *ptr,
|
|
|
|
const char *end,
|
|
|
|
POSITION *);
|
1997-12-10 02:44:19 -05:00
|
|
|
int (*isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
|
|
|
|
const char **badPtr);
|
1998-05-30 06:13:07 -04:00
|
|
|
void (*utf8Convert)(const ENCODING *enc,
|
|
|
|
const char **fromP,
|
|
|
|
const char *fromLim,
|
|
|
|
char **toP,
|
|
|
|
const char *toLim);
|
|
|
|
void (*utf16Convert)(const ENCODING *enc,
|
|
|
|
const char **fromP,
|
|
|
|
const char *fromLim,
|
1998-05-31 04:06:01 -04:00
|
|
|
unsigned short **toP,
|
|
|
|
const unsigned short *toLim);
|
1997-11-10 01:10:50 -05:00
|
|
|
int minBytesPerChar;
|
1998-06-01 01:55:23 -04:00
|
|
|
char isUtf8;
|
|
|
|
char isUtf16;
|
1997-12-10 02:44:19 -05:00
|
|
|
};
|
1997-11-04 00:43:56 -05:00
|
|
|
|
|
|
|
/*
|
|
|
|
Scan the string starting at ptr until the end of the next complete token,
|
|
|
|
but do not scan past eptr. Return an integer giving the type of token.
|
|
|
|
|
|
|
|
Return XML_TOK_NONE when ptr == eptr; nextTokPtr will not be set.
|
|
|
|
|
|
|
|
Return XML_TOK_PARTIAL when the string does not contain a complete token;
|
|
|
|
nextTokPtr will not be set.
|
|
|
|
|
|
|
|
Return XML_TOK_INVALID when the string does not start a valid token; nextTokPtr
|
|
|
|
will be set to point to the character which made the token invalid.
|
|
|
|
|
|
|
|
Otherwise the string starts with a valid token; nextTokPtr will be set to point
|
|
|
|
to the character following the end of that token.
|
|
|
|
|
|
|
|
Each data character counts as a single token, but adjacent data characters
|
|
|
|
may be returned together. Similarly for characters in the prolog outside
|
|
|
|
literals, comments and processing instructions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
1997-11-10 01:10:50 -05:00
|
|
|
#define XmlTok(enc, state, ptr, end, nextTokPtr) \
|
|
|
|
(((enc)->scanners[state])(enc, ptr, end, nextTokPtr))
|
|
|
|
|
|
|
|
#define XmlPrologTok(enc, ptr, end, nextTokPtr) \
|
|
|
|
XmlTok(enc, XML_PROLOG_STATE, ptr, end, nextTokPtr)
|
|
|
|
|
|
|
|
#define XmlContentTok(enc, ptr, end, nextTokPtr) \
|
|
|
|
XmlTok(enc, XML_CONTENT_STATE, ptr, end, nextTokPtr)
|
|
|
|
|
1998-05-02 01:31:15 -04:00
|
|
|
#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
|
|
|
|
XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
|
|
|
|
|
1999-06-25 06:58:20 -04:00
|
|
|
#ifdef XML_DTD
|
|
|
|
|
|
|
|
#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
|
|
|
|
XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
|
|
|
|
|
|
|
|
#endif /* XML_DTD */
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
/* This is used for performing a 2nd-level tokenization on
|
|
|
|
the content of a literal that has already been returned by XmlTok. */
|
|
|
|
|
|
|
|
#define XmlLiteralTok(enc, literalType, ptr, end, nextTokPtr) \
|
|
|
|
(((enc)->literalScanners[literalType])(enc, ptr, end, nextTokPtr))
|
|
|
|
|
|
|
|
#define XmlAttributeValueTok(enc, ptr, end, nextTokPtr) \
|
|
|
|
XmlLiteralTok(enc, XML_ATTRIBUTE_VALUE_LITERAL, ptr, end, nextTokPtr)
|
|
|
|
|
|
|
|
#define XmlEntityValueTok(enc, ptr, end, nextTokPtr) \
|
|
|
|
XmlLiteralTok(enc, XML_ENTITY_VALUE_LITERAL, ptr, end, nextTokPtr)
|
|
|
|
|
1997-11-11 00:53:20 -05:00
|
|
|
#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
|
1997-12-10 02:44:19 -05:00
|
|
|
|
1999-06-25 10:28:06 -04:00
|
|
|
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
|
|
|
|
(((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
|
1997-12-10 02:44:19 -05:00
|
|
|
|
|
|
|
#define XmlNameLength(enc, ptr) \
|
|
|
|
(((enc)->nameLength)(enc, ptr))
|
1997-11-11 00:53:20 -05:00
|
|
|
|
1998-02-02 06:24:03 -05:00
|
|
|
#define XmlSkipS(enc, ptr) \
|
|
|
|
(((enc)->skipS)(enc, ptr))
|
|
|
|
|
1997-11-11 00:53:20 -05:00
|
|
|
#define XmlGetAttributes(enc, ptr, attsMax, atts) \
|
|
|
|
(((enc)->getAtts)(enc, ptr, attsMax, atts))
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XmlCharRefNumber(enc, ptr) \
|
|
|
|
(((enc)->charRefNumber)(enc, ptr))
|
|
|
|
|
1998-06-01 03:28:31 -04:00
|
|
|
#define XmlPredefinedEntityName(enc, ptr, end) \
|
|
|
|
(((enc)->predefinedEntityName)(enc, ptr, end))
|
|
|
|
|
1997-11-12 05:38:58 -05:00
|
|
|
#define XmlUpdatePosition(enc, ptr, end, pos) \
|
|
|
|
(((enc)->updatePosition)(enc, ptr, end, pos))
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
#define XmlIsPublicId(enc, ptr, end, badPtr) \
|
|
|
|
(((enc)->isPublicId)(enc, ptr, end, badPtr))
|
|
|
|
|
1998-05-30 06:13:07 -04:00
|
|
|
#define XmlUtf8Convert(enc, fromP, fromLim, toP, toLim) \
|
|
|
|
(((enc)->utf8Convert)(enc, fromP, fromLim, toP, toLim))
|
1997-12-10 02:44:19 -05:00
|
|
|
|
1998-05-30 06:13:07 -04:00
|
|
|
#define XmlUtf16Convert(enc, fromP, fromLim, toP, toLim) \
|
|
|
|
(((enc)->utf16Convert)(enc, fromP, fromLim, toP, toLim))
|
1997-12-10 02:44:19 -05:00
|
|
|
|
1997-11-10 01:10:50 -05:00
|
|
|
typedef struct {
|
|
|
|
ENCODING initEnc;
|
|
|
|
const ENCODING **encPtr;
|
|
|
|
} INIT_ENCODING;
|
|
|
|
|
1997-12-10 02:44:19 -05:00
|
|
|
int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
|
|
|
|
const ENCODING *enc,
|
|
|
|
const char *ptr,
|
|
|
|
const char *end,
|
|
|
|
const char **badPtr,
|
|
|
|
const char **versionPtr,
|
|
|
|
const char **encodingNamePtr,
|
|
|
|
const ENCODING **namedEncodingPtr,
|
|
|
|
int *standalonePtr);
|
|
|
|
|
1998-02-06 23:53:44 -05:00
|
|
|
int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
|
1999-06-03 06:21:30 -04:00
|
|
|
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding(void);
|
|
|
|
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding(void);
|
1998-05-30 06:13:07 -04:00
|
|
|
int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
|
1998-05-31 04:06:01 -04:00
|
|
|
int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
|
1997-11-04 00:43:56 -05:00
|
|
|
|
1999-06-02 06:36:45 -04:00
|
|
|
int XMLTOKAPI XmlSizeOfUnknownEncoding(void);
|
1998-06-02 04:57:14 -04:00
|
|
|
ENCODING XMLTOKAPI *
|
|
|
|
XmlInitUnknownEncoding(void *mem,
|
1998-06-03 03:52:49 -04:00
|
|
|
int *table,
|
1999-04-06 08:01:55 -04:00
|
|
|
int (*conv)(void *userData, const char *p),
|
1998-06-02 04:57:14 -04:00
|
|
|
void *userData);
|
1998-06-01 08:12:35 -04:00
|
|
|
|
1998-08-22 18:40:45 -04:00
|
|
|
int XMLTOKAPI XmlParseXmlDeclNS(int isGeneralTextEntity,
|
|
|
|
const ENCODING *enc,
|
|
|
|
const char *ptr,
|
|
|
|
const char *end,
|
|
|
|
const char **badPtr,
|
|
|
|
const char **versionPtr,
|
|
|
|
const char **encodingNamePtr,
|
|
|
|
const ENCODING **namedEncodingPtr,
|
|
|
|
int *standalonePtr);
|
|
|
|
int XMLTOKAPI XmlInitEncodingNS(INIT_ENCODING *, const ENCODING **, const char *name);
|
|
|
|
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncodingNS();
|
|
|
|
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS();
|
|
|
|
ENCODING XMLTOKAPI *
|
|
|
|
XmlInitUnknownEncodingNS(void *mem,
|
|
|
|
int *table,
|
1999-04-06 08:01:55 -04:00
|
|
|
int (*conv)(void *userData, const char *p),
|
1998-08-22 18:40:45 -04:00
|
|
|
void *userData);
|
1997-11-04 00:43:56 -05:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* not XmlTok_INCLUDED */
|