Merge James Clark's DTD patch. "ifdefed by XML_DTD".

git-svn-id: svn://10.0.0.236/trunk@37938 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
tao%netscape.com
1999-07-02 02:32:56 +00:00
parent 544a1e8cc6
commit fa7df41183
20 changed files with 2508 additions and 958 deletions

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
csompliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include "xmldef.h"

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,24 +12,38 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include <stddef.h>
#ifdef XML_UNICODE
#ifdef XML_UNICODE_WCHAR_T
typedef const wchar_t *KEY;
#else
#else /* not XML_UNICODE_WCHAR_T */
typedef const unsigned short *KEY;
#endif
#else
#endif /* not XML_UNICODE_WCHAR_T */
#else /* not XML_UNICODE */
typedef const char *KEY;
#endif
#endif /* not XML_UNICODE */
typedef struct {
KEY name;

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef XmlParse_INCLUDED
@@ -107,13 +117,6 @@ typedef void (*XML_ProcessingInstructionHandler)(void *userData,
/* data is 0 terminated */
typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data);
/* #define EXTERNAL_ENTITY_SUPPORT */
#ifdef EXTERNAL_ENTITY_SUPPORT
typedef int (*XML_ExternalDTDLoader)(const XML_Char * base,
const XML_Char * systemId,
char ** data);
#endif
typedef void (*XML_StartCdataSectionHandler)(void *userData);
typedef void (*XML_EndCdataSectionHandler)(void *userData);
@@ -169,6 +172,14 @@ typedef void (*XML_StartNamespaceDeclHandler)(void *userData,
typedef void (*XML_EndNamespaceDeclHandler)(void *userData,
const XML_Char *prefix);
/* This is called if the document is not standalone (it has an
external subset or a reference to a parameter entity, but does not
have standalone="yes"). If this handler returns 0, then processing
will not continue, and the parser will return a
XML_ERROR_NOT_STANDALONE error. */
typedef int (*XML_NotStandaloneHandler)(void *userData);
/* This is called for a reference to an external parsed general entity.
The referenced entity is not automatically parsed.
The application can parse it immediately or later using
@@ -278,13 +289,6 @@ void XMLPARSEAPI
XML_SetCommentHandler(XML_Parser parser,
XML_CommentHandler handler);
#ifdef EXTERNAL_ENTITY_SUPPORT
void XMLPARSEAPI
XML_SetExternalDTDLoader(XML_Parser parser,
XML_ExternalDTDLoader loader);
#endif
void XMLPARSEAPI
XML_SetCdataSectionHandler(XML_Parser parser,
XML_StartCdataSectionHandler start,
@@ -317,6 +321,10 @@ XML_SetNamespaceDeclHandler(XML_Parser parser,
XML_StartNamespaceDeclHandler start,
XML_EndNamespaceDeclHandler end);
void XMLPARSEAPI
XML_SetNotStandaloneHandler(XML_Parser parser,
XML_NotStandaloneHandler handler);
void XMLPARSEAPI
XML_SetExternalEntityRefHandler(XML_Parser parser,
XML_ExternalEntityRefHandler handler);
@@ -371,6 +379,12 @@ XML_SetBase(XML_Parser parser, const XML_Char *base);
const XML_Char XMLPARSEAPI *
XML_GetBase(XML_Parser parser);
/* Returns the number of the attributes passed in last call to the
XML_StartElementHandler that were specified in the start-tag rather
than defaulted. */
int XMLPARSEAPI XML_GetSpecifiedAttributeCount(XML_Parser parser);
/* Parses some input. Returns 0 if a fatal error is detected.
The last call to XML_Parse must have isFinal true;
len may be zero for this call (or any other). */
@@ -396,11 +410,45 @@ so longer as the parser has not yet been freed.
The new parser is completely independent and may safely be used in a separate thread.
The handlers and userData are initialized from the parser argument.
Returns 0 if out of memory. Otherwise returns a new XML_Parser object. */
#if 0
#define XML_DTD
#endif /* 0 */
XML_Parser XMLPARSEAPI
XML_ExternalEntityParserCreate(XML_Parser parser,
const XML_Char *context,
const XML_Char *encoding);
enum XML_ParamEntityParsing {
XML_PARAM_ENTITY_PARSING_NEVER,
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
XML_PARAM_ENTITY_PARSING_ALWAYS
};
/* Controls parsing of parameter entities (including the external DTD
subset). If parsing of parameter entities is enabled, then references
to external parameter entities (including the external DTD subset)
will be passed to the handler set with
XML_SetExternalEntityRefHandler. The context passed will be 0.
Unlike external general entities, external parameter entities can only
be parsed synchronously. If the external parameter entity is to be
parsed, it must be parsed during the call to the external entity ref
handler: the complete sequence of XML_ExternalEntityParserCreate,
XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during
this call. After XML_ExternalEntityParserCreate has been called to
create the parser for the external parameter entity (context must be 0
for this call), it is illegal to make any calls on the old parser
until XML_ParserFree has been called on the newly created parser. If
the library has been compiled without support for parameter entity
parsing (ie without XML_DTD being defined), then
XML_SetParamEntityParsing will return 0 if parsing of parameter
entities is requested; otherwise it will return non-zero. */
int XMLPARSEAPI
XML_SetParamEntityParsing(XML_Parser parser,
enum XML_ParamEntityParsing parsing);
enum XML_Error {
XML_ERROR_NONE,
XML_ERROR_NO_MEMORY,
@@ -423,7 +471,8 @@ enum XML_Error {
XML_ERROR_UNKNOWN_ENCODING,
XML_ERROR_INCORRECT_ENCODING,
XML_ERROR_UNCLOSED_CDATA_SECTION,
XML_ERROR_EXTERNAL_ENTITY_HANDLING
XML_ERROR_EXTERNAL_ENTITY_HANDLING,
XML_ERROR_NOT_STANDALONE
};
/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
@@ -443,6 +492,11 @@ int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser);
int XMLPARSEAPI XML_GetCurrentColumnNumber(XML_Parser parser);
long XMLPARSEAPI XML_GetCurrentByteIndex(XML_Parser parser);
/* Return the number of bytes in the current event.
Returns 0 if the event is in an internal entity. */
int XMLPARSEAPI XML_GetCurrentByteCount(XML_Parser parser);
/* For backwards compatibility with previous versions. */
#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include "xmldef.h"
@@ -32,7 +42,16 @@ Contributor(s):
#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
#endif
typedef int PROLOG_HANDLER(struct prolog_state *state,
#ifdef XML_DTD
#define setTopLevel(state) \
((state)->handler = ((state)->documentEntity \
? internalSubset \
: externalSubset1))
#else /* not XML_DTD */
#define setTopLevel(state) ((state)->handler = internalSubset)
#endif /* not XML_DTD */
typedef int PROLOG_HANDLER(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
@@ -49,11 +68,15 @@ static PROLOG_HANDLER
attlist7, attlist8, attlist9,
element0, element1, element2, element3, element4, element5, element6,
element7,
#ifdef XML_DTD
externalSubset0, externalSubset1,
condSect0, condSect1, condSect2,
#endif /* XML_DTD */
declClose,
error;
static
int syntaxError(PROLOG_STATE *);
int common(PROLOG_STATE *state, int tok);
static
int prolog0(PROLOG_STATE *state,
@@ -79,6 +102,7 @@ int prolog0(PROLOG_STATE *state,
case XML_TOK_DECL_OPEN:
if (!XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"DOCTYPE"))
break;
state->handler = doctype0;
@@ -87,7 +111,7 @@ int prolog0(PROLOG_STATE *state,
state->handler = error;
return XML_ROLE_INSTANCE_START;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -107,6 +131,7 @@ int prolog1(PROLOG_STATE *state,
case XML_TOK_DECL_OPEN:
if (!XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"DOCTYPE"))
break;
state->handler = doctype0;
@@ -115,7 +140,7 @@ int prolog1(PROLOG_STATE *state,
state->handler = error;
return XML_ROLE_INSTANCE_START;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -135,7 +160,7 @@ int prolog2(PROLOG_STATE *state,
state->handler = error;
return XML_ROLE_INSTANCE_START;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -153,7 +178,7 @@ int doctype0(PROLOG_STATE *state,
state->handler = doctype1;
return XML_ROLE_DOCTYPE_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -173,17 +198,17 @@ int doctype1(PROLOG_STATE *state,
state->handler = prolog2;
return XML_ROLE_DOCTYPE_CLOSE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = doctype3;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = doctype2;
return XML_ROLE_NONE;
}
break;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -200,7 +225,7 @@ int doctype2(PROLOG_STATE *state,
state->handler = doctype3;
return XML_ROLE_DOCTYPE_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -217,7 +242,7 @@ int doctype3(PROLOG_STATE *state,
state->handler = doctype4;
return XML_ROLE_DOCTYPE_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -237,7 +262,7 @@ int doctype4(PROLOG_STATE *state,
state->handler = prolog2;
return XML_ROLE_DOCTYPE_CLOSE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -254,7 +279,7 @@ int doctype5(PROLOG_STATE *state,
state->handler = prolog2;
return XML_ROLE_DOCTYPE_CLOSE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -270,24 +295,28 @@ int internalSubset(PROLOG_STATE *state,
case XML_TOK_DECL_OPEN:
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"ENTITY")) {
state->handler = entity0;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"ATTLIST")) {
state->handler = attlist0;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"ELEMENT")) {
state->handler = element0;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"NOTATION")) {
state->handler = notation0;
return XML_ROLE_NONE;
@@ -302,9 +331,56 @@ int internalSubset(PROLOG_STATE *state,
state->handler = doctype5;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
#ifdef XML_DTD
static
int externalSubset0(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
state->handler = externalSubset1;
if (tok == XML_TOK_XML_DECL)
return XML_ROLE_TEXT_DECL;
return externalSubset1(state, tok, ptr, end, enc);
}
static
int externalSubset1(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_COND_SECT_OPEN:
state->handler = condSect0;
return XML_ROLE_NONE;
case XML_TOK_COND_SECT_CLOSE:
if (state->includeLevel == 0)
break;
state->includeLevel -= 1;
return XML_ROLE_NONE;
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_CLOSE_BRACKET:
break;
case XML_TOK_NONE:
if (state->includeLevel)
break;
return XML_ROLE_NONE;
default:
return internalSubset(state, tok, ptr, end, enc);
}
return common(state, tok);
}
#endif /* XML_DTD */
static
int entity0(PROLOG_STATE *state,
int tok,
@@ -322,7 +398,7 @@ int entity0(PROLOG_STATE *state,
state->handler = entity2;
return XML_ROLE_GENERAL_ENTITY_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -339,7 +415,7 @@ int entity1(PROLOG_STATE *state,
state->handler = entity7;
return XML_ROLE_PARAM_ENTITY_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -353,11 +429,11 @@ int entity2(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = entity4;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = entity3;
return XML_ROLE_NONE;
}
@@ -366,7 +442,7 @@ int entity2(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -383,7 +459,7 @@ int entity3(PROLOG_STATE *state,
state->handler = entity4;
return XML_ROLE_ENTITY_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
@@ -401,7 +477,7 @@ int entity4(PROLOG_STATE *state,
state->handler = entity5;
return XML_ROLE_ENTITY_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -415,16 +491,16 @@ int entity5(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "NDATA")) {
if (XmlNameMatchesAscii(enc, ptr, end, "NDATA")) {
state->handler = entity6;
return XML_ROLE_NONE;
}
break;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -441,7 +517,7 @@ int entity6(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_NOTATION_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -455,11 +531,11 @@ int entity7(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = entity9;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = entity8;
return XML_ROLE_NONE;
}
@@ -468,7 +544,7 @@ int entity7(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -485,7 +561,7 @@ int entity8(PROLOG_STATE *state,
state->handler = entity9;
return XML_ROLE_ENTITY_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -502,7 +578,7 @@ int entity9(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -519,7 +595,7 @@ int notation0(PROLOG_STATE *state,
state->handler = notation1;
return XML_ROLE_NOTATION_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -533,17 +609,17 @@ int notation1(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = notation3;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = notation2;
return XML_ROLE_NONE;
}
break;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -560,7 +636,7 @@ int notation2(PROLOG_STATE *state,
state->handler = notation4;
return XML_ROLE_NOTATION_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -577,7 +653,7 @@ int notation3(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_NOTATION_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -594,10 +670,10 @@ int notation4(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_NOTATION_SYSTEM_ID;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NOTATION_NO_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -615,7 +691,7 @@ int attlist0(PROLOG_STATE *state,
state->handler = attlist1;
return XML_ROLE_ATTLIST_ELEMENT_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -629,14 +705,14 @@ int attlist1(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
state->handler = attlist2;
return XML_ROLE_ATTRIBUTE_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -663,12 +739,12 @@ int attlist2(PROLOG_STATE *state,
};
int i;
for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
if (XmlNameMatchesAscii(enc, ptr, types[i])) {
if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
state->handler = attlist8;
return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
}
}
if (XmlNameMatchesAscii(enc, ptr, "NOTATION")) {
if (XmlNameMatchesAscii(enc, ptr, end, "NOTATION")) {
state->handler = attlist5;
return XML_ROLE_NONE;
}
@@ -677,7 +753,7 @@ int attlist2(PROLOG_STATE *state,
state->handler = attlist3;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -696,7 +772,7 @@ int attlist3(PROLOG_STATE *state,
state->handler = attlist4;
return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -716,7 +792,7 @@ int attlist4(PROLOG_STATE *state,
state->handler = attlist3;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -733,7 +809,7 @@ int attlist5(PROLOG_STATE *state,
state->handler = attlist6;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
@@ -751,7 +827,7 @@ int attlist6(PROLOG_STATE *state,
state->handler = attlist7;
return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -771,7 +847,7 @@ int attlist7(PROLOG_STATE *state,
state->handler = attlist6;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
/* default value */
@@ -788,18 +864,21 @@ int attlist8(PROLOG_STATE *state,
case XML_TOK_POUND_NAME:
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"IMPLIED")) {
state->handler = attlist1;
return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
}
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"REQUIRED")) {
state->handler = attlist1;
return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
}
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"FIXED")) {
state->handler = attlist9;
return XML_ROLE_NONE;
@@ -809,7 +888,7 @@ int attlist8(PROLOG_STATE *state,
state->handler = attlist1;
return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -826,7 +905,7 @@ int attlist9(PROLOG_STATE *state,
state->handler = attlist1;
return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -844,7 +923,7 @@ int element0(PROLOG_STATE *state,
state->handler = element1;
return XML_ROLE_ELEMENT_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -858,11 +937,11 @@ int element1(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "EMPTY")) {
if (XmlNameMatchesAscii(enc, ptr, end, "EMPTY")) {
state->handler = declClose;
return XML_ROLE_CONTENT_EMPTY;
}
if (XmlNameMatchesAscii(enc, ptr, "ANY")) {
if (XmlNameMatchesAscii(enc, ptr, end, "ANY")) {
state->handler = declClose;
return XML_ROLE_CONTENT_ANY;
}
@@ -872,7 +951,7 @@ int element1(PROLOG_STATE *state,
state->level = 1;
return XML_ROLE_GROUP_OPEN;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -888,6 +967,7 @@ int element2(PROLOG_STATE *state,
case XML_TOK_POUND_NAME:
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"PCDATA")) {
state->handler = element3;
return XML_ROLE_CONTENT_PCDATA;
@@ -911,7 +991,7 @@ int element2(PROLOG_STATE *state,
state->handler = element7;
return XML_ROLE_CONTENT_ELEMENT_PLUS;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -932,7 +1012,7 @@ int element3(PROLOG_STATE *state,
state->handler = element4;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -950,7 +1030,7 @@ int element4(PROLOG_STATE *state,
state->handler = element5;
return XML_ROLE_CONTENT_ELEMENT;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -970,7 +1050,7 @@ int element5(PROLOG_STATE *state,
state->handler = element4;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -1000,7 +1080,7 @@ int element6(PROLOG_STATE *state,
state->handler = element7;
return XML_ROLE_CONTENT_ELEMENT_PLUS;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -1040,9 +1120,72 @@ int element7(PROLOG_STATE *state,
state->handler = element6;
return XML_ROLE_GROUP_CHOICE;
}
return syntaxError(state);
return common(state, tok);
}
#ifdef XML_DTD
static
int condSect0(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, end, "INCLUDE")) {
state->handler = condSect1;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, end, "IGNORE")) {
state->handler = condSect2;
return XML_ROLE_NONE;
}
break;
}
return common(state, tok);
}
static
int condSect1(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_OPEN_BRACKET:
state->handler = externalSubset1;
state->includeLevel += 1;
return XML_ROLE_NONE;
}
return common(state, tok);
}
static
int condSect2(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_OPEN_BRACKET:
state->handler = externalSubset1;
return XML_ROLE_IGNORE_SECT;
}
return common(state, tok);
}
#endif /* XML_DTD */
static
int declClose(PROLOG_STATE *state,
int tok,
@@ -1054,10 +1197,10 @@ int declClose(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
#if 0
@@ -1076,23 +1219,27 @@ int ignore(PROLOG_STATE *state,
default:
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
#endif
static
int error(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
return XML_ROLE_NONE;
}
static
int syntaxError(PROLOG_STATE *state)
int common(PROLOG_STATE *state, int tok)
{
#ifdef XML_DTD
if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
return XML_ROLE_INNER_PARAM_ENTITY_REF;
#endif
state->handler = error;
return XML_ROLE_ERROR;
}
@@ -1100,11 +1247,19 @@ int syntaxError(PROLOG_STATE *state)
void XmlPrologStateInit(PROLOG_STATE *state)
{
state->handler = prolog0;
#ifdef XML_DTD
state->documentEntity = 1;
state->includeLevel = 0;
#endif /* XML_DTD */
}
#ifdef EXTERNAL_ENTITY_SUPPORT
void XmlPrologStateHack(PROLOG_STATE *state)
#ifdef XML_DTD
void XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
{
state->handler = prolog1;
state->handler = externalSubset0;
state->documentEntity = 0;
state->includeLevel = 0;
}
#endif
#endif /* XML_DTD */

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef XmlRole_INCLUDED
@@ -77,6 +87,11 @@ enum {
XML_ROLE_CONTENT_ELEMENT_REP,
XML_ROLE_CONTENT_ELEMENT_OPT,
XML_ROLE_CONTENT_ELEMENT_PLUS,
#ifdef XML_DTD
XML_ROLE_TEXT_DECL,
XML_ROLE_IGNORE_SECT,
XML_ROLE_INNER_PARAM_ENTITY_REF,
#endif /* XML_DTD */
XML_ROLE_PARAM_ENTITY_REF
};
@@ -87,14 +102,16 @@ typedef struct prolog_state {
const char *end,
const ENCODING *enc);
unsigned level;
#ifdef XML_DTD
unsigned includeLevel;
int documentEntity;
#endif /* XML_DTD */
} PROLOG_STATE;
void XMLTOKAPI XmlPrologStateInit(PROLOG_STATE *);
/* #define EXTERNAL_ENTITY_SUPPORT */
#ifdef EXTERNAL_ENTITY_SUPPORT
void XMLTOKAPI XmlPrologStateHack(PROLOG_STATE *);
#endif
#ifdef XML_DTD
void XMLTOKAPI XmlPrologStateInitExternalEntity(PROLOG_STATE *);
#endif /* XML_DTD */
#define XmlTokenRole(state, tok, ptr, end, enc) \
(((state)->handler)(state, tok, ptr, end, enc))

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,18 +12,35 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include "xmldef.h"
#include "xmltok.h"
#include "nametab.h"
#ifdef XML_DTD
#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok)
#else
#define IGNORE_SECTION_TOK_VTABLE /* as nothing */
#endif
#define VTABLE1 \
{ PREFIX(prologTok), PREFIX(contentTok), PREFIX(cdataSectionTok) }, \
{ PREFIX(prologTok), PREFIX(contentTok), \
PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \
{ PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \
PREFIX(sameName), \
PREFIX(nameMatchesAscii), \
@@ -658,7 +675,7 @@ int little2_isNmstrtMin(const ENCODING *enc, const char *p)
static const struct normal_encoding little2_encoding_ns = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 12
#if XML_BYTE_ORDER == 12
1
#else
0
@@ -675,7 +692,7 @@ static const struct normal_encoding little2_encoding_ns = {
static const struct normal_encoding little2_encoding = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 12
#if XML_BYTE_ORDER == 12
1
#else
0
@@ -690,7 +707,7 @@ static const struct normal_encoding little2_encoding = {
STANDARD_VTABLE(little2_)
};
#if BYTE_ORDER != 21
#if XML_BYTE_ORDER != 21
#ifdef XML_NS
@@ -797,7 +814,7 @@ int big2_isNmstrtMin(const ENCODING *enc, const char *p)
static const struct normal_encoding big2_encoding_ns = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 21
#if XML_BYTE_ORDER == 21
1
#else
0
@@ -814,7 +831,7 @@ static const struct normal_encoding big2_encoding_ns = {
static const struct normal_encoding big2_encoding = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 21
#if XML_BYTE_ORDER == 21
1
#else
0
@@ -829,7 +846,7 @@ static const struct normal_encoding big2_encoding = {
STANDARD_VTABLE(big2_)
};
#if BYTE_ORDER != 12
#if XML_BYTE_ORDER != 12
#ifdef XML_NS
@@ -916,6 +933,7 @@ int parsePseudoAttribute(const ENCODING *enc,
const char *ptr,
const char *end,
const char **namePtr,
const char **nameEndPtr,
const char **valPtr,
const char **nextTokPtr)
{
@@ -943,9 +961,12 @@ int parsePseudoAttribute(const ENCODING *enc,
*nextTokPtr = ptr;
return 0;
}
if (c == '=')
if (c == '=') {
*nameEndPtr = ptr;
break;
}
if (isSpace(c)) {
*nameEndPtr = ptr;
do {
ptr += enc->minBytesPerChar;
} while (isSpace(c = toAscii(enc, ptr, end)));
@@ -1008,13 +1029,14 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
{
const char *val = 0;
const char *name = 0;
const char *nameEnd = 0;
ptr += 5 * enc->minBytesPerChar;
end -= 2 * enc->minBytesPerChar;
if (!parsePseudoAttribute(enc, ptr, end, &name, &val, &ptr) || !name) {
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) || !name) {
*badPtr = ptr;
return 0;
}
if (!XmlNameMatchesAscii(enc, name, "version")) {
if (!XmlNameMatchesAscii(enc, name, nameEnd, "version")) {
if (!isGeneralTextEntity) {
*badPtr = name;
return 0;
@@ -1023,7 +1045,7 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
else {
if (versionPtr)
*versionPtr = val;
if (!parsePseudoAttribute(enc, ptr, end, &name, &val, &ptr)) {
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
*badPtr = ptr;
return 0;
}
@@ -1036,7 +1058,7 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
return 1;
}
}
if (XmlNameMatchesAscii(enc, name, "encoding")) {
if (XmlNameMatchesAscii(enc, name, nameEnd, "encoding")) {
int c = toAscii(enc, val, end);
if (!('a' <= c && c <= 'z') && !('A' <= c && c <= 'Z')) {
*badPtr = val;
@@ -1046,22 +1068,22 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
*encodingName = val;
if (encoding)
*encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar);
if (!parsePseudoAttribute(enc, ptr, end, &name, &val, &ptr)) {
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
*badPtr = ptr;
return 0;
}
if (!name)
return 1;
}
if (!XmlNameMatchesAscii(enc, name, "standalone") || isGeneralTextEntity) {
if (!XmlNameMatchesAscii(enc, name, nameEnd, "standalone") || isGeneralTextEntity) {
*badPtr = name;
return 0;
}
if (XmlNameMatchesAscii(enc, val, "yes")) {
if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, "yes")) {
if (standalone)
*standalone = 1;
}
else if (XmlNameMatchesAscii(enc, val, "no")) {
else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, "no")) {
if (standalone)
*standalone = 0;
}
@@ -1158,7 +1180,7 @@ struct unknown_encoding {
char utf8[256][4];
};
int XmlSizeOfUnknownEncoding()
int XmlSizeOfUnknownEncoding(void)
{
return sizeof(struct unknown_encoding);
}
@@ -1361,7 +1383,8 @@ int getEncodingIndex(const char *name)
/* For binary compatibility, we store the index of the encoding specified
at initialization in the isUtf16 member. */
#define INIT_ENC_INDEX(enc) ((enc)->initEnc.isUtf16)
#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16)
#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i)
/* This is what detects the encoding.
encodingTable maps from encoding indices to encodings;
@@ -1386,9 +1409,11 @@ int initScan(const ENCODING **encodingTable,
encPtr = enc->encPtr;
if (ptr + 1 == end) {
/* only a single byte available for auto-detection */
#ifndef XML_DTD /* FIXME */
/* a well-formed document entity must have more than one byte */
if (state != XML_CONTENT_STATE)
return XML_TOK_PARTIAL;
#endif
/* so we're parsing an external text entity... */
/* if UTF-16 was externally specified, then we need at least 2 bytes */
switch (INIT_ENC_INDEX(enc)) {

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef XmlTok_INCLUDED
@@ -98,10 +108,26 @@ extern "C" {
for a name with a colon. */
#define XML_TOK_PREFIXED_NAME 41
#if 0
#define XML_DTD
#endif /* 0 */
#ifdef XML_DTD
#define XML_TOK_IGNORE_SECT 42
#endif /* XML_DTD */
#ifdef XML_DTD
#define XML_N_STATES 4
#else /* not XML_DTD */
#define XML_N_STATES 3
#endif /* not XML_DTD */
#define XML_PROLOG_STATE 0
#define XML_CONTENT_STATE 1
#define XML_CDATA_SECTION_STATE 2
#ifdef XML_DTD
#define XML_IGNORE_SECTION_STATE 3
#endif /* XML_DTD */
#define XML_N_LITERAL_TYPES 2
#define XML_ATTRIBUTE_VALUE_LITERAL 0
@@ -140,7 +166,7 @@ struct encoding {
int (*sameName)(const ENCODING *,
const char *, const char *);
int (*nameMatchesAscii)(const ENCODING *,
const char *, const char *);
const char *, const char *, const char *);
int (*nameLength)(const ENCODING *, const char *);
const char *(*skipS)(const ENCODING *, const char *);
int (*getAtts)(const ENCODING *enc, const char *ptr,
@@ -201,6 +227,13 @@ literals, comments and processing instructions.
#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
#ifdef XML_DTD
#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
#endif /* XML_DTD */
/* This is used for performing a 2nd-level tokenization on
the content of a literal that has already been returned by XmlTok. */
@@ -215,8 +248,8 @@ the content of a literal that has already been returned by XmlTok. */
#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
#define XmlNameMatchesAscii(enc, ptr1, ptr2) \
(((enc)->nameMatchesAscii)(enc, ptr1, ptr2))
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
(((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
#define XmlNameLength(enc, ptr) \
(((enc)->nameLength)(enc, ptr))
@@ -261,16 +294,16 @@ int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
int *standalonePtr);
int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding();
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding();
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding(void);
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding(void);
int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
int XMLTOKAPI XmlSizeOfUnknownEncoding();
int XMLTOKAPI XmlSizeOfUnknownEncoding(void);
ENCODING XMLTOKAPI *
XmlInitUnknownEncoding(void *mem,
int *table,
int (*convert)(void *userData, const char *p),
int (*conv)(void *userData, const char *p),
void *userData);
int XMLTOKAPI XmlParseXmlDeclNS(int isGeneralTextEntity,
@@ -288,7 +321,7 @@ const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS();
ENCODING XMLTOKAPI *
XmlInitUnknownEncodingNS(void *mem,
int *table,
int (*convert)(void *userData, const char *p),
int (*conv)(void *userData, const char *p),
void *userData);
#ifdef __cplusplus
}

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef IS_INVALID_CHAR
@@ -943,7 +953,7 @@ int PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end,
return XML_TOK_INVALID;
}
}
return XML_TOK_PARTIAL;
return -XML_TOK_POUND_NAME;
}
static
@@ -961,7 +971,7 @@ int PREFIX(scanLit)(int open, const ENCODING *enc,
if (t != open)
break;
if (ptr == end)
return XML_TOK_PARTIAL;
return -XML_TOK_LITERAL;
*nextTokPtr = ptr;
switch (BYTE_TYPE(enc, ptr)) {
case BT_S: case BT_CR: case BT_LF:
@@ -1023,7 +1033,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
}
case BT_CR:
if (ptr + MINBPC(enc) == end)
return XML_TOK_TRAILING_CR;
return -XML_TOK_PROLOG_S;
/* fall through */
case BT_S: case BT_LF:
for (;;) {
@@ -1056,7 +1066,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
case BT_RSQB:
ptr += MINBPC(enc);
if (ptr == end)
return XML_TOK_PARTIAL;
return -XML_TOK_CLOSE_BRACKET;
if (CHAR_MATCHES(enc, ptr, ']')) {
if (ptr + MINBPC(enc) == end)
return XML_TOK_PARTIAL;
@@ -1073,7 +1083,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
case BT_RPAR:
ptr += MINBPC(enc);
if (ptr == end)
return XML_TOK_PARTIAL;
return -XML_TOK_CLOSE_PAREN;
switch (BYTE_TYPE(enc, ptr)) {
case BT_AST:
*nextTokPtr = ptr + MINBPC(enc);
@@ -1203,7 +1213,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
return XML_TOK_INVALID;
}
}
return XML_TOK_PARTIAL;
return -tok;
}
static
@@ -1316,6 +1326,61 @@ int PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end
return XML_TOK_DATA_CHARS;
}
#ifdef XML_DTD
static
int PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
const char **nextTokPtr)
{
int level = 0;
if (MINBPC(enc) > 1) {
size_t n = end - ptr;
if (n & (MINBPC(enc) - 1)) {
n &= ~(MINBPC(enc) - 1);
end = ptr + n;
}
}
while (ptr != end) {
switch (BYTE_TYPE(enc, ptr)) {
INVALID_CASES(ptr, nextTokPtr)
case BT_LT:
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, '!')) {
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, '[')) {
++level;
ptr += MINBPC(enc);
}
}
break;
case BT_RSQB:
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, ']')) {
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, '>')) {
ptr += MINBPC(enc);
if (level == 0) {
*nextTokPtr = ptr;
return XML_TOK_IGNORE_SECT;
}
--level;
}
}
break;
default:
ptr += MINBPC(enc);
break;
}
}
return XML_TOK_PARTIAL;
}
#endif /* XML_DTD */
static
int PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
const char **badPtr)
@@ -1381,7 +1446,8 @@ int PREFIX(getAtts)(const ENCODING *enc, const char *ptr,
{
enum { other, inName, inValue } state = inName;
int nAtts = 0;
int open;
int open = 0; /* defined when state == inValue;
initialization just to shut up compilers */
for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) {
switch (BYTE_TYPE(enc, ptr)) {
@@ -1625,29 +1691,16 @@ int PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2)
}
static
int PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, const char *ptr2)
int PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1,
const char *end1, const char *ptr2)
{
for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
if (ptr1 == end1)
return 0;
if (!CHAR_MATCHES(enc, ptr1, *ptr2))
return 0;
}
switch (BYTE_TYPE(enc, ptr1)) {
case BT_LEAD2:
case BT_LEAD3:
case BT_LEAD4:
case BT_NONASCII:
case BT_NMSTRT:
#ifdef XML_NS
case BT_COLON:
#endif
case BT_HEX:
case BT_DIGIT:
case BT_NAME:
case BT_MINUS:
return 0;
default:
return 1;
}
return ptr1 == end1;
}
static

View File

@@ -1,13 +1,13 @@
const ENCODING *NS(XmlGetUtf8InternalEncoding)()
const ENCODING *NS(XmlGetUtf8InternalEncoding)(void)
{
return &ns(internal_utf8_encoding).enc;
}
const ENCODING *NS(XmlGetUtf16InternalEncoding)()
const ENCODING *NS(XmlGetUtf16InternalEncoding)(void)
{
#if BYTE_ORDER == 12
#if XML_BYTE_ORDER == 12
return &ns(internal_little2_encoding).enc;
#elif BYTE_ORDER == 21
#elif XML_BYTE_ORDER == 21
return &ns(internal_big2_encoding).enc;
#else
const short n = 1;
@@ -45,7 +45,7 @@ int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, const char *n
int i = getEncodingIndex(name);
if (i == UNKNOWN_ENC)
return 0;
INIT_ENC_INDEX(p) = (char)i;
SET_INIT_ENC_INDEX(p, i);
p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
p->initEnc.updatePosition = initUpdatePosition;

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
csompliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include "xmldef.h"

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,24 +12,38 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include <stddef.h>
#ifdef XML_UNICODE
#ifdef XML_UNICODE_WCHAR_T
typedef const wchar_t *KEY;
#else
#else /* not XML_UNICODE_WCHAR_T */
typedef const unsigned short *KEY;
#endif
#else
#endif /* not XML_UNICODE_WCHAR_T */
#else /* not XML_UNICODE */
typedef const char *KEY;
#endif
#endif /* not XML_UNICODE */
typedef struct {
KEY name;

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef XmlParse_INCLUDED
@@ -107,13 +117,6 @@ typedef void (*XML_ProcessingInstructionHandler)(void *userData,
/* data is 0 terminated */
typedef void (*XML_CommentHandler)(void *userData, const XML_Char *data);
/* #define EXTERNAL_ENTITY_SUPPORT */
#ifdef EXTERNAL_ENTITY_SUPPORT
typedef int (*XML_ExternalDTDLoader)(const XML_Char * base,
const XML_Char * systemId,
char ** data);
#endif
typedef void (*XML_StartCdataSectionHandler)(void *userData);
typedef void (*XML_EndCdataSectionHandler)(void *userData);
@@ -169,6 +172,14 @@ typedef void (*XML_StartNamespaceDeclHandler)(void *userData,
typedef void (*XML_EndNamespaceDeclHandler)(void *userData,
const XML_Char *prefix);
/* This is called if the document is not standalone (it has an
external subset or a reference to a parameter entity, but does not
have standalone="yes"). If this handler returns 0, then processing
will not continue, and the parser will return a
XML_ERROR_NOT_STANDALONE error. */
typedef int (*XML_NotStandaloneHandler)(void *userData);
/* This is called for a reference to an external parsed general entity.
The referenced entity is not automatically parsed.
The application can parse it immediately or later using
@@ -278,13 +289,6 @@ void XMLPARSEAPI
XML_SetCommentHandler(XML_Parser parser,
XML_CommentHandler handler);
#ifdef EXTERNAL_ENTITY_SUPPORT
void XMLPARSEAPI
XML_SetExternalDTDLoader(XML_Parser parser,
XML_ExternalDTDLoader loader);
#endif
void XMLPARSEAPI
XML_SetCdataSectionHandler(XML_Parser parser,
XML_StartCdataSectionHandler start,
@@ -317,6 +321,10 @@ XML_SetNamespaceDeclHandler(XML_Parser parser,
XML_StartNamespaceDeclHandler start,
XML_EndNamespaceDeclHandler end);
void XMLPARSEAPI
XML_SetNotStandaloneHandler(XML_Parser parser,
XML_NotStandaloneHandler handler);
void XMLPARSEAPI
XML_SetExternalEntityRefHandler(XML_Parser parser,
XML_ExternalEntityRefHandler handler);
@@ -371,6 +379,12 @@ XML_SetBase(XML_Parser parser, const XML_Char *base);
const XML_Char XMLPARSEAPI *
XML_GetBase(XML_Parser parser);
/* Returns the number of the attributes passed in last call to the
XML_StartElementHandler that were specified in the start-tag rather
than defaulted. */
int XMLPARSEAPI XML_GetSpecifiedAttributeCount(XML_Parser parser);
/* Parses some input. Returns 0 if a fatal error is detected.
The last call to XML_Parse must have isFinal true;
len may be zero for this call (or any other). */
@@ -396,11 +410,45 @@ so longer as the parser has not yet been freed.
The new parser is completely independent and may safely be used in a separate thread.
The handlers and userData are initialized from the parser argument.
Returns 0 if out of memory. Otherwise returns a new XML_Parser object. */
#if 0
#define XML_DTD
#endif /* 0 */
XML_Parser XMLPARSEAPI
XML_ExternalEntityParserCreate(XML_Parser parser,
const XML_Char *context,
const XML_Char *encoding);
enum XML_ParamEntityParsing {
XML_PARAM_ENTITY_PARSING_NEVER,
XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE,
XML_PARAM_ENTITY_PARSING_ALWAYS
};
/* Controls parsing of parameter entities (including the external DTD
subset). If parsing of parameter entities is enabled, then references
to external parameter entities (including the external DTD subset)
will be passed to the handler set with
XML_SetExternalEntityRefHandler. The context passed will be 0.
Unlike external general entities, external parameter entities can only
be parsed synchronously. If the external parameter entity is to be
parsed, it must be parsed during the call to the external entity ref
handler: the complete sequence of XML_ExternalEntityParserCreate,
XML_Parse/XML_ParseBuffer and XML_ParserFree calls must be made during
this call. After XML_ExternalEntityParserCreate has been called to
create the parser for the external parameter entity (context must be 0
for this call), it is illegal to make any calls on the old parser
until XML_ParserFree has been called on the newly created parser. If
the library has been compiled without support for parameter entity
parsing (ie without XML_DTD being defined), then
XML_SetParamEntityParsing will return 0 if parsing of parameter
entities is requested; otherwise it will return non-zero. */
int XMLPARSEAPI
XML_SetParamEntityParsing(XML_Parser parser,
enum XML_ParamEntityParsing parsing);
enum XML_Error {
XML_ERROR_NONE,
XML_ERROR_NO_MEMORY,
@@ -423,7 +471,8 @@ enum XML_Error {
XML_ERROR_UNKNOWN_ENCODING,
XML_ERROR_INCORRECT_ENCODING,
XML_ERROR_UNCLOSED_CDATA_SECTION,
XML_ERROR_EXTERNAL_ENTITY_HANDLING
XML_ERROR_EXTERNAL_ENTITY_HANDLING,
XML_ERROR_NOT_STANDALONE
};
/* If XML_Parse or XML_ParseBuffer have returned 0, then XML_GetErrorCode
@@ -443,6 +492,11 @@ int XMLPARSEAPI XML_GetCurrentLineNumber(XML_Parser parser);
int XMLPARSEAPI XML_GetCurrentColumnNumber(XML_Parser parser);
long XMLPARSEAPI XML_GetCurrentByteIndex(XML_Parser parser);
/* Return the number of bytes in the current event.
Returns 0 if the event is in an internal entity. */
int XMLPARSEAPI XML_GetCurrentByteCount(XML_Parser parser);
/* For backwards compatibility with previous versions. */
#define XML_GetErrorLineNumber XML_GetCurrentLineNumber
#define XML_GetErrorColumnNumber XML_GetCurrentColumnNumber

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include "xmldef.h"
@@ -32,7 +42,16 @@ Contributor(s):
#define MIN_BYTES_PER_CHAR(enc) ((enc)->minBytesPerChar)
#endif
typedef int PROLOG_HANDLER(struct prolog_state *state,
#ifdef XML_DTD
#define setTopLevel(state) \
((state)->handler = ((state)->documentEntity \
? internalSubset \
: externalSubset1))
#else /* not XML_DTD */
#define setTopLevel(state) ((state)->handler = internalSubset)
#endif /* not XML_DTD */
typedef int PROLOG_HANDLER(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
@@ -49,11 +68,15 @@ static PROLOG_HANDLER
attlist7, attlist8, attlist9,
element0, element1, element2, element3, element4, element5, element6,
element7,
#ifdef XML_DTD
externalSubset0, externalSubset1,
condSect0, condSect1, condSect2,
#endif /* XML_DTD */
declClose,
error;
static
int syntaxError(PROLOG_STATE *);
int common(PROLOG_STATE *state, int tok);
static
int prolog0(PROLOG_STATE *state,
@@ -79,6 +102,7 @@ int prolog0(PROLOG_STATE *state,
case XML_TOK_DECL_OPEN:
if (!XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"DOCTYPE"))
break;
state->handler = doctype0;
@@ -87,7 +111,7 @@ int prolog0(PROLOG_STATE *state,
state->handler = error;
return XML_ROLE_INSTANCE_START;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -107,6 +131,7 @@ int prolog1(PROLOG_STATE *state,
case XML_TOK_DECL_OPEN:
if (!XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"DOCTYPE"))
break;
state->handler = doctype0;
@@ -115,7 +140,7 @@ int prolog1(PROLOG_STATE *state,
state->handler = error;
return XML_ROLE_INSTANCE_START;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -135,7 +160,7 @@ int prolog2(PROLOG_STATE *state,
state->handler = error;
return XML_ROLE_INSTANCE_START;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -153,7 +178,7 @@ int doctype0(PROLOG_STATE *state,
state->handler = doctype1;
return XML_ROLE_DOCTYPE_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -173,17 +198,17 @@ int doctype1(PROLOG_STATE *state,
state->handler = prolog2;
return XML_ROLE_DOCTYPE_CLOSE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = doctype3;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = doctype2;
return XML_ROLE_NONE;
}
break;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -200,7 +225,7 @@ int doctype2(PROLOG_STATE *state,
state->handler = doctype3;
return XML_ROLE_DOCTYPE_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -217,7 +242,7 @@ int doctype3(PROLOG_STATE *state,
state->handler = doctype4;
return XML_ROLE_DOCTYPE_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -237,7 +262,7 @@ int doctype4(PROLOG_STATE *state,
state->handler = prolog2;
return XML_ROLE_DOCTYPE_CLOSE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -254,7 +279,7 @@ int doctype5(PROLOG_STATE *state,
state->handler = prolog2;
return XML_ROLE_DOCTYPE_CLOSE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -270,24 +295,28 @@ int internalSubset(PROLOG_STATE *state,
case XML_TOK_DECL_OPEN:
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"ENTITY")) {
state->handler = entity0;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"ATTLIST")) {
state->handler = attlist0;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"ELEMENT")) {
state->handler = element0;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc,
ptr + 2 * MIN_BYTES_PER_CHAR(enc),
end,
"NOTATION")) {
state->handler = notation0;
return XML_ROLE_NONE;
@@ -302,9 +331,56 @@ int internalSubset(PROLOG_STATE *state,
state->handler = doctype5;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
#ifdef XML_DTD
static
int externalSubset0(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
state->handler = externalSubset1;
if (tok == XML_TOK_XML_DECL)
return XML_ROLE_TEXT_DECL;
return externalSubset1(state, tok, ptr, end, enc);
}
static
int externalSubset1(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_COND_SECT_OPEN:
state->handler = condSect0;
return XML_ROLE_NONE;
case XML_TOK_COND_SECT_CLOSE:
if (state->includeLevel == 0)
break;
state->includeLevel -= 1;
return XML_ROLE_NONE;
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_CLOSE_BRACKET:
break;
case XML_TOK_NONE:
if (state->includeLevel)
break;
return XML_ROLE_NONE;
default:
return internalSubset(state, tok, ptr, end, enc);
}
return common(state, tok);
}
#endif /* XML_DTD */
static
int entity0(PROLOG_STATE *state,
int tok,
@@ -322,7 +398,7 @@ int entity0(PROLOG_STATE *state,
state->handler = entity2;
return XML_ROLE_GENERAL_ENTITY_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -339,7 +415,7 @@ int entity1(PROLOG_STATE *state,
state->handler = entity7;
return XML_ROLE_PARAM_ENTITY_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -353,11 +429,11 @@ int entity2(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = entity4;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = entity3;
return XML_ROLE_NONE;
}
@@ -366,7 +442,7 @@ int entity2(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -383,7 +459,7 @@ int entity3(PROLOG_STATE *state,
state->handler = entity4;
return XML_ROLE_ENTITY_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
@@ -401,7 +477,7 @@ int entity4(PROLOG_STATE *state,
state->handler = entity5;
return XML_ROLE_ENTITY_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -415,16 +491,16 @@ int entity5(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "NDATA")) {
if (XmlNameMatchesAscii(enc, ptr, end, "NDATA")) {
state->handler = entity6;
return XML_ROLE_NONE;
}
break;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -441,7 +517,7 @@ int entity6(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_NOTATION_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -455,11 +531,11 @@ int entity7(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = entity9;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = entity8;
return XML_ROLE_NONE;
}
@@ -468,7 +544,7 @@ int entity7(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -485,7 +561,7 @@ int entity8(PROLOG_STATE *state,
state->handler = entity9;
return XML_ROLE_ENTITY_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -502,7 +578,7 @@ int entity9(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_ENTITY_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -519,7 +595,7 @@ int notation0(PROLOG_STATE *state,
state->handler = notation1;
return XML_ROLE_NOTATION_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -533,17 +609,17 @@ int notation1(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "SYSTEM")) {
if (XmlNameMatchesAscii(enc, ptr, end, "SYSTEM")) {
state->handler = notation3;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, "PUBLIC")) {
if (XmlNameMatchesAscii(enc, ptr, end, "PUBLIC")) {
state->handler = notation2;
return XML_ROLE_NONE;
}
break;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -560,7 +636,7 @@ int notation2(PROLOG_STATE *state,
state->handler = notation4;
return XML_ROLE_NOTATION_PUBLIC_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -577,7 +653,7 @@ int notation3(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_NOTATION_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -594,10 +670,10 @@ int notation4(PROLOG_STATE *state,
state->handler = declClose;
return XML_ROLE_NOTATION_SYSTEM_ID;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NOTATION_NO_SYSTEM_ID;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -615,7 +691,7 @@ int attlist0(PROLOG_STATE *state,
state->handler = attlist1;
return XML_ROLE_ATTLIST_ELEMENT_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -629,14 +705,14 @@ int attlist1(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NONE;
case XML_TOK_NAME:
case XML_TOK_PREFIXED_NAME:
state->handler = attlist2;
return XML_ROLE_ATTRIBUTE_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -663,12 +739,12 @@ int attlist2(PROLOG_STATE *state,
};
int i;
for (i = 0; i < (int)(sizeof(types)/sizeof(types[0])); i++)
if (XmlNameMatchesAscii(enc, ptr, types[i])) {
if (XmlNameMatchesAscii(enc, ptr, end, types[i])) {
state->handler = attlist8;
return XML_ROLE_ATTRIBUTE_TYPE_CDATA + i;
}
}
if (XmlNameMatchesAscii(enc, ptr, "NOTATION")) {
if (XmlNameMatchesAscii(enc, ptr, end, "NOTATION")) {
state->handler = attlist5;
return XML_ROLE_NONE;
}
@@ -677,7 +753,7 @@ int attlist2(PROLOG_STATE *state,
state->handler = attlist3;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -696,7 +772,7 @@ int attlist3(PROLOG_STATE *state,
state->handler = attlist4;
return XML_ROLE_ATTRIBUTE_ENUM_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -716,7 +792,7 @@ int attlist4(PROLOG_STATE *state,
state->handler = attlist3;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -733,7 +809,7 @@ int attlist5(PROLOG_STATE *state,
state->handler = attlist6;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
@@ -751,7 +827,7 @@ int attlist6(PROLOG_STATE *state,
state->handler = attlist7;
return XML_ROLE_ATTRIBUTE_NOTATION_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -771,7 +847,7 @@ int attlist7(PROLOG_STATE *state,
state->handler = attlist6;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
/* default value */
@@ -788,18 +864,21 @@ int attlist8(PROLOG_STATE *state,
case XML_TOK_POUND_NAME:
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"IMPLIED")) {
state->handler = attlist1;
return XML_ROLE_IMPLIED_ATTRIBUTE_VALUE;
}
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"REQUIRED")) {
state->handler = attlist1;
return XML_ROLE_REQUIRED_ATTRIBUTE_VALUE;
}
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"FIXED")) {
state->handler = attlist9;
return XML_ROLE_NONE;
@@ -809,7 +888,7 @@ int attlist8(PROLOG_STATE *state,
state->handler = attlist1;
return XML_ROLE_DEFAULT_ATTRIBUTE_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -826,7 +905,7 @@ int attlist9(PROLOG_STATE *state,
state->handler = attlist1;
return XML_ROLE_FIXED_ATTRIBUTE_VALUE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -844,7 +923,7 @@ int element0(PROLOG_STATE *state,
state->handler = element1;
return XML_ROLE_ELEMENT_NAME;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -858,11 +937,11 @@ int element1(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, "EMPTY")) {
if (XmlNameMatchesAscii(enc, ptr, end, "EMPTY")) {
state->handler = declClose;
return XML_ROLE_CONTENT_EMPTY;
}
if (XmlNameMatchesAscii(enc, ptr, "ANY")) {
if (XmlNameMatchesAscii(enc, ptr, end, "ANY")) {
state->handler = declClose;
return XML_ROLE_CONTENT_ANY;
}
@@ -872,7 +951,7 @@ int element1(PROLOG_STATE *state,
state->level = 1;
return XML_ROLE_GROUP_OPEN;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -888,6 +967,7 @@ int element2(PROLOG_STATE *state,
case XML_TOK_POUND_NAME:
if (XmlNameMatchesAscii(enc,
ptr + MIN_BYTES_PER_CHAR(enc),
end,
"PCDATA")) {
state->handler = element3;
return XML_ROLE_CONTENT_PCDATA;
@@ -911,7 +991,7 @@ int element2(PROLOG_STATE *state,
state->handler = element7;
return XML_ROLE_CONTENT_ELEMENT_PLUS;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -932,7 +1012,7 @@ int element3(PROLOG_STATE *state,
state->handler = element4;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -950,7 +1030,7 @@ int element4(PROLOG_STATE *state,
state->handler = element5;
return XML_ROLE_CONTENT_ELEMENT;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -970,7 +1050,7 @@ int element5(PROLOG_STATE *state,
state->handler = element4;
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -1000,7 +1080,7 @@ int element6(PROLOG_STATE *state,
state->handler = element7;
return XML_ROLE_CONTENT_ELEMENT_PLUS;
}
return syntaxError(state);
return common(state, tok);
}
static
@@ -1040,9 +1120,72 @@ int element7(PROLOG_STATE *state,
state->handler = element6;
return XML_ROLE_GROUP_CHOICE;
}
return syntaxError(state);
return common(state, tok);
}
#ifdef XML_DTD
static
int condSect0(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_NAME:
if (XmlNameMatchesAscii(enc, ptr, end, "INCLUDE")) {
state->handler = condSect1;
return XML_ROLE_NONE;
}
if (XmlNameMatchesAscii(enc, ptr, end, "IGNORE")) {
state->handler = condSect2;
return XML_ROLE_NONE;
}
break;
}
return common(state, tok);
}
static
int condSect1(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_OPEN_BRACKET:
state->handler = externalSubset1;
state->includeLevel += 1;
return XML_ROLE_NONE;
}
return common(state, tok);
}
static
int condSect2(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
switch (tok) {
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_OPEN_BRACKET:
state->handler = externalSubset1;
return XML_ROLE_IGNORE_SECT;
}
return common(state, tok);
}
#endif /* XML_DTD */
static
int declClose(PROLOG_STATE *state,
int tok,
@@ -1054,10 +1197,10 @@ int declClose(PROLOG_STATE *state,
case XML_TOK_PROLOG_S:
return XML_ROLE_NONE;
case XML_TOK_DECL_CLOSE:
state->handler = internalSubset;
setTopLevel(state);
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
#if 0
@@ -1076,23 +1219,27 @@ int ignore(PROLOG_STATE *state,
default:
return XML_ROLE_NONE;
}
return syntaxError(state);
return common(state, tok);
}
#endif
static
int error(PROLOG_STATE *state,
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
int tok,
const char *ptr,
const char *end,
const ENCODING *enc)
{
return XML_ROLE_NONE;
}
static
int syntaxError(PROLOG_STATE *state)
int common(PROLOG_STATE *state, int tok)
{
#ifdef XML_DTD
if (!state->documentEntity && tok == XML_TOK_PARAM_ENTITY_REF)
return XML_ROLE_INNER_PARAM_ENTITY_REF;
#endif
state->handler = error;
return XML_ROLE_ERROR;
}
@@ -1100,11 +1247,19 @@ int syntaxError(PROLOG_STATE *state)
void XmlPrologStateInit(PROLOG_STATE *state)
{
state->handler = prolog0;
#ifdef XML_DTD
state->documentEntity = 1;
state->includeLevel = 0;
#endif /* XML_DTD */
}
#ifdef EXTERNAL_ENTITY_SUPPORT
void XmlPrologStateHack(PROLOG_STATE *state)
#ifdef XML_DTD
void XmlPrologStateInitExternalEntity(PROLOG_STATE *state)
{
state->handler = prolog1;
state->handler = externalSubset0;
state->documentEntity = 0;
state->includeLevel = 0;
}
#endif
#endif /* XML_DTD */

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef XmlRole_INCLUDED
@@ -77,6 +87,11 @@ enum {
XML_ROLE_CONTENT_ELEMENT_REP,
XML_ROLE_CONTENT_ELEMENT_OPT,
XML_ROLE_CONTENT_ELEMENT_PLUS,
#ifdef XML_DTD
XML_ROLE_TEXT_DECL,
XML_ROLE_IGNORE_SECT,
XML_ROLE_INNER_PARAM_ENTITY_REF,
#endif /* XML_DTD */
XML_ROLE_PARAM_ENTITY_REF
};
@@ -87,14 +102,16 @@ typedef struct prolog_state {
const char *end,
const ENCODING *enc);
unsigned level;
#ifdef XML_DTD
unsigned includeLevel;
int documentEntity;
#endif /* XML_DTD */
} PROLOG_STATE;
void XMLTOKAPI XmlPrologStateInit(PROLOG_STATE *);
/* #define EXTERNAL_ENTITY_SUPPORT */
#ifdef EXTERNAL_ENTITY_SUPPORT
void XMLTOKAPI XmlPrologStateHack(PROLOG_STATE *);
#endif
#ifdef XML_DTD
void XMLTOKAPI XmlPrologStateInitExternalEntity(PROLOG_STATE *);
#endif /* XML_DTD */
#define XmlTokenRole(state, tok, ptr, end, enc) \
(((state)->handler)(state, tok, ptr, end, enc))

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,18 +12,35 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#include "xmldef.h"
#include "xmltok.h"
#include "nametab.h"
#ifdef XML_DTD
#define IGNORE_SECTION_TOK_VTABLE , PREFIX(ignoreSectionTok)
#else
#define IGNORE_SECTION_TOK_VTABLE /* as nothing */
#endif
#define VTABLE1 \
{ PREFIX(prologTok), PREFIX(contentTok), PREFIX(cdataSectionTok) }, \
{ PREFIX(prologTok), PREFIX(contentTok), \
PREFIX(cdataSectionTok) IGNORE_SECTION_TOK_VTABLE }, \
{ PREFIX(attributeValueTok), PREFIX(entityValueTok) }, \
PREFIX(sameName), \
PREFIX(nameMatchesAscii), \
@@ -658,7 +675,7 @@ int little2_isNmstrtMin(const ENCODING *enc, const char *p)
static const struct normal_encoding little2_encoding_ns = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 12
#if XML_BYTE_ORDER == 12
1
#else
0
@@ -675,7 +692,7 @@ static const struct normal_encoding little2_encoding_ns = {
static const struct normal_encoding little2_encoding = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 12
#if XML_BYTE_ORDER == 12
1
#else
0
@@ -690,7 +707,7 @@ static const struct normal_encoding little2_encoding = {
STANDARD_VTABLE(little2_)
};
#if BYTE_ORDER != 21
#if XML_BYTE_ORDER != 21
#ifdef XML_NS
@@ -797,7 +814,7 @@ int big2_isNmstrtMin(const ENCODING *enc, const char *p)
static const struct normal_encoding big2_encoding_ns = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 21
#if XML_BYTE_ORDER == 21
1
#else
0
@@ -814,7 +831,7 @@ static const struct normal_encoding big2_encoding_ns = {
static const struct normal_encoding big2_encoding = {
{ VTABLE, 2, 0,
#if BYTE_ORDER == 21
#if XML_BYTE_ORDER == 21
1
#else
0
@@ -829,7 +846,7 @@ static const struct normal_encoding big2_encoding = {
STANDARD_VTABLE(big2_)
};
#if BYTE_ORDER != 12
#if XML_BYTE_ORDER != 12
#ifdef XML_NS
@@ -916,6 +933,7 @@ int parsePseudoAttribute(const ENCODING *enc,
const char *ptr,
const char *end,
const char **namePtr,
const char **nameEndPtr,
const char **valPtr,
const char **nextTokPtr)
{
@@ -943,9 +961,12 @@ int parsePseudoAttribute(const ENCODING *enc,
*nextTokPtr = ptr;
return 0;
}
if (c == '=')
if (c == '=') {
*nameEndPtr = ptr;
break;
}
if (isSpace(c)) {
*nameEndPtr = ptr;
do {
ptr += enc->minBytesPerChar;
} while (isSpace(c = toAscii(enc, ptr, end)));
@@ -1008,13 +1029,14 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
{
const char *val = 0;
const char *name = 0;
const char *nameEnd = 0;
ptr += 5 * enc->minBytesPerChar;
end -= 2 * enc->minBytesPerChar;
if (!parsePseudoAttribute(enc, ptr, end, &name, &val, &ptr) || !name) {
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr) || !name) {
*badPtr = ptr;
return 0;
}
if (!XmlNameMatchesAscii(enc, name, "version")) {
if (!XmlNameMatchesAscii(enc, name, nameEnd, "version")) {
if (!isGeneralTextEntity) {
*badPtr = name;
return 0;
@@ -1023,7 +1045,7 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
else {
if (versionPtr)
*versionPtr = val;
if (!parsePseudoAttribute(enc, ptr, end, &name, &val, &ptr)) {
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
*badPtr = ptr;
return 0;
}
@@ -1036,7 +1058,7 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
return 1;
}
}
if (XmlNameMatchesAscii(enc, name, "encoding")) {
if (XmlNameMatchesAscii(enc, name, nameEnd, "encoding")) {
int c = toAscii(enc, val, end);
if (!('a' <= c && c <= 'z') && !('A' <= c && c <= 'Z')) {
*badPtr = val;
@@ -1046,22 +1068,22 @@ int doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
*encodingName = val;
if (encoding)
*encoding = encodingFinder(enc, val, ptr - enc->minBytesPerChar);
if (!parsePseudoAttribute(enc, ptr, end, &name, &val, &ptr)) {
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
*badPtr = ptr;
return 0;
}
if (!name)
return 1;
}
if (!XmlNameMatchesAscii(enc, name, "standalone") || isGeneralTextEntity) {
if (!XmlNameMatchesAscii(enc, name, nameEnd, "standalone") || isGeneralTextEntity) {
*badPtr = name;
return 0;
}
if (XmlNameMatchesAscii(enc, val, "yes")) {
if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, "yes")) {
if (standalone)
*standalone = 1;
}
else if (XmlNameMatchesAscii(enc, val, "no")) {
else if (XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, "no")) {
if (standalone)
*standalone = 0;
}
@@ -1158,7 +1180,7 @@ struct unknown_encoding {
char utf8[256][4];
};
int XmlSizeOfUnknownEncoding()
int XmlSizeOfUnknownEncoding(void)
{
return sizeof(struct unknown_encoding);
}
@@ -1361,7 +1383,8 @@ int getEncodingIndex(const char *name)
/* For binary compatibility, we store the index of the encoding specified
at initialization in the isUtf16 member. */
#define INIT_ENC_INDEX(enc) ((enc)->initEnc.isUtf16)
#define INIT_ENC_INDEX(enc) ((int)(enc)->initEnc.isUtf16)
#define SET_INIT_ENC_INDEX(enc, i) ((enc)->initEnc.isUtf16 = (char)i)
/* This is what detects the encoding.
encodingTable maps from encoding indices to encodings;
@@ -1386,9 +1409,11 @@ int initScan(const ENCODING **encodingTable,
encPtr = enc->encPtr;
if (ptr + 1 == end) {
/* only a single byte available for auto-detection */
#ifndef XML_DTD /* FIXME */
/* a well-formed document entity must have more than one byte */
if (state != XML_CONTENT_STATE)
return XML_TOK_PARTIAL;
#endif
/* so we're parsing an external text entity... */
/* if UTF-16 was externally specified, then we need at least 2 bytes */
switch (INIT_ENC_INDEX(enc)) {

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef XmlTok_INCLUDED
@@ -98,10 +108,26 @@ extern "C" {
for a name with a colon. */
#define XML_TOK_PREFIXED_NAME 41
#if 0
#define XML_DTD
#endif /* 0 */
#ifdef XML_DTD
#define XML_TOK_IGNORE_SECT 42
#endif /* XML_DTD */
#ifdef XML_DTD
#define XML_N_STATES 4
#else /* not XML_DTD */
#define XML_N_STATES 3
#endif /* not XML_DTD */
#define XML_PROLOG_STATE 0
#define XML_CONTENT_STATE 1
#define XML_CDATA_SECTION_STATE 2
#ifdef XML_DTD
#define XML_IGNORE_SECTION_STATE 3
#endif /* XML_DTD */
#define XML_N_LITERAL_TYPES 2
#define XML_ATTRIBUTE_VALUE_LITERAL 0
@@ -140,7 +166,7 @@ struct encoding {
int (*sameName)(const ENCODING *,
const char *, const char *);
int (*nameMatchesAscii)(const ENCODING *,
const char *, const char *);
const char *, const char *, const char *);
int (*nameLength)(const ENCODING *, const char *);
const char *(*skipS)(const ENCODING *, const char *);
int (*getAtts)(const ENCODING *enc, const char *ptr,
@@ -201,6 +227,13 @@ literals, comments and processing instructions.
#define XmlCdataSectionTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_CDATA_SECTION_STATE, ptr, end, nextTokPtr)
#ifdef XML_DTD
#define XmlIgnoreSectionTok(enc, ptr, end, nextTokPtr) \
XmlTok(enc, XML_IGNORE_SECTION_STATE, ptr, end, nextTokPtr)
#endif /* XML_DTD */
/* This is used for performing a 2nd-level tokenization on
the content of a literal that has already been returned by XmlTok. */
@@ -215,8 +248,8 @@ the content of a literal that has already been returned by XmlTok. */
#define XmlSameName(enc, ptr1, ptr2) (((enc)->sameName)(enc, ptr1, ptr2))
#define XmlNameMatchesAscii(enc, ptr1, ptr2) \
(((enc)->nameMatchesAscii)(enc, ptr1, ptr2))
#define XmlNameMatchesAscii(enc, ptr1, end1, ptr2) \
(((enc)->nameMatchesAscii)(enc, ptr1, end1, ptr2))
#define XmlNameLength(enc, ptr) \
(((enc)->nameLength)(enc, ptr))
@@ -261,16 +294,16 @@ int XMLTOKAPI XmlParseXmlDecl(int isGeneralTextEntity,
int *standalonePtr);
int XMLTOKAPI XmlInitEncoding(INIT_ENCODING *, const ENCODING **, const char *name);
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding();
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding();
const ENCODING XMLTOKAPI *XmlGetUtf8InternalEncoding(void);
const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncoding(void);
int XMLTOKAPI XmlUtf8Encode(int charNumber, char *buf);
int XMLTOKAPI XmlUtf16Encode(int charNumber, unsigned short *buf);
int XMLTOKAPI XmlSizeOfUnknownEncoding();
int XMLTOKAPI XmlSizeOfUnknownEncoding(void);
ENCODING XMLTOKAPI *
XmlInitUnknownEncoding(void *mem,
int *table,
int (*convert)(void *userData, const char *p),
int (*conv)(void *userData, const char *p),
void *userData);
int XMLTOKAPI XmlParseXmlDeclNS(int isGeneralTextEntity,
@@ -288,7 +321,7 @@ const ENCODING XMLTOKAPI *XmlGetUtf16InternalEncodingNS();
ENCODING XMLTOKAPI *
XmlInitUnknownEncodingNS(void *mem,
int *table,
int (*convert)(void *userData, const char *p),
int (*conv)(void *userData, const char *p),
void *userData);
#ifdef __cplusplus
}

View File

@@ -1,6 +1,6 @@
/*
The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
@@ -12,10 +12,20 @@ under the License.
The Original Code is expat.
The Initial Developer of the Original Code is James Clark.
Portions created by James Clark are Copyright (C) 1998
Portions created by James Clark are Copyright (C) 1998, 1999
James Clark. All Rights Reserved.
Contributor(s):
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.
*/
#ifndef IS_INVALID_CHAR
@@ -943,7 +953,7 @@ int PREFIX(scanPoundName)(const ENCODING *enc, const char *ptr, const char *end,
return XML_TOK_INVALID;
}
}
return XML_TOK_PARTIAL;
return -XML_TOK_POUND_NAME;
}
static
@@ -961,7 +971,7 @@ int PREFIX(scanLit)(int open, const ENCODING *enc,
if (t != open)
break;
if (ptr == end)
return XML_TOK_PARTIAL;
return -XML_TOK_LITERAL;
*nextTokPtr = ptr;
switch (BYTE_TYPE(enc, ptr)) {
case BT_S: case BT_CR: case BT_LF:
@@ -1023,7 +1033,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
}
case BT_CR:
if (ptr + MINBPC(enc) == end)
return XML_TOK_TRAILING_CR;
return -XML_TOK_PROLOG_S;
/* fall through */
case BT_S: case BT_LF:
for (;;) {
@@ -1056,7 +1066,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
case BT_RSQB:
ptr += MINBPC(enc);
if (ptr == end)
return XML_TOK_PARTIAL;
return -XML_TOK_CLOSE_BRACKET;
if (CHAR_MATCHES(enc, ptr, ']')) {
if (ptr + MINBPC(enc) == end)
return XML_TOK_PARTIAL;
@@ -1073,7 +1083,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
case BT_RPAR:
ptr += MINBPC(enc);
if (ptr == end)
return XML_TOK_PARTIAL;
return -XML_TOK_CLOSE_PAREN;
switch (BYTE_TYPE(enc, ptr)) {
case BT_AST:
*nextTokPtr = ptr + MINBPC(enc);
@@ -1203,7 +1213,7 @@ int PREFIX(prologTok)(const ENCODING *enc, const char *ptr, const char *end,
return XML_TOK_INVALID;
}
}
return XML_TOK_PARTIAL;
return -tok;
}
static
@@ -1316,6 +1326,61 @@ int PREFIX(entityValueTok)(const ENCODING *enc, const char *ptr, const char *end
return XML_TOK_DATA_CHARS;
}
#ifdef XML_DTD
static
int PREFIX(ignoreSectionTok)(const ENCODING *enc, const char *ptr, const char *end,
const char **nextTokPtr)
{
int level = 0;
if (MINBPC(enc) > 1) {
size_t n = end - ptr;
if (n & (MINBPC(enc) - 1)) {
n &= ~(MINBPC(enc) - 1);
end = ptr + n;
}
}
while (ptr != end) {
switch (BYTE_TYPE(enc, ptr)) {
INVALID_CASES(ptr, nextTokPtr)
case BT_LT:
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, '!')) {
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, '[')) {
++level;
ptr += MINBPC(enc);
}
}
break;
case BT_RSQB:
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, ']')) {
if ((ptr += MINBPC(enc)) == end)
return XML_TOK_PARTIAL;
if (CHAR_MATCHES(enc, ptr, '>')) {
ptr += MINBPC(enc);
if (level == 0) {
*nextTokPtr = ptr;
return XML_TOK_IGNORE_SECT;
}
--level;
}
}
break;
default:
ptr += MINBPC(enc);
break;
}
}
return XML_TOK_PARTIAL;
}
#endif /* XML_DTD */
static
int PREFIX(isPublicId)(const ENCODING *enc, const char *ptr, const char *end,
const char **badPtr)
@@ -1381,7 +1446,8 @@ int PREFIX(getAtts)(const ENCODING *enc, const char *ptr,
{
enum { other, inName, inValue } state = inName;
int nAtts = 0;
int open;
int open = 0; /* defined when state == inValue;
initialization just to shut up compilers */
for (ptr += MINBPC(enc);; ptr += MINBPC(enc)) {
switch (BYTE_TYPE(enc, ptr)) {
@@ -1625,29 +1691,16 @@ int PREFIX(sameName)(const ENCODING *enc, const char *ptr1, const char *ptr2)
}
static
int PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1, const char *ptr2)
int PREFIX(nameMatchesAscii)(const ENCODING *enc, const char *ptr1,
const char *end1, const char *ptr2)
{
for (; *ptr2; ptr1 += MINBPC(enc), ptr2++) {
if (ptr1 == end1)
return 0;
if (!CHAR_MATCHES(enc, ptr1, *ptr2))
return 0;
}
switch (BYTE_TYPE(enc, ptr1)) {
case BT_LEAD2:
case BT_LEAD3:
case BT_LEAD4:
case BT_NONASCII:
case BT_NMSTRT:
#ifdef XML_NS
case BT_COLON:
#endif
case BT_HEX:
case BT_DIGIT:
case BT_NAME:
case BT_MINUS:
return 0;
default:
return 1;
}
return ptr1 == end1;
}
static

View File

@@ -1,13 +1,13 @@
const ENCODING *NS(XmlGetUtf8InternalEncoding)()
const ENCODING *NS(XmlGetUtf8InternalEncoding)(void)
{
return &ns(internal_utf8_encoding).enc;
}
const ENCODING *NS(XmlGetUtf16InternalEncoding)()
const ENCODING *NS(XmlGetUtf16InternalEncoding)(void)
{
#if BYTE_ORDER == 12
#if XML_BYTE_ORDER == 12
return &ns(internal_little2_encoding).enc;
#elif BYTE_ORDER == 21
#elif XML_BYTE_ORDER == 21
return &ns(internal_big2_encoding).enc;
#else
const short n = 1;
@@ -45,7 +45,7 @@ int NS(XmlInitEncoding)(INIT_ENCODING *p, const ENCODING **encPtr, const char *n
int i = getEncodingIndex(name);
if (i == UNKNOWN_ENC)
return 0;
INIT_ENC_INDEX(p) = (char)i;
SET_INIT_ENC_INDEX(p, i);
p->initEnc.scanners[XML_PROLOG_STATE] = NS(initScanProlog);
p->initEnc.scanners[XML_CONTENT_STATE] = NS(initScanContent);
p->initEnc.updatePosition = initUpdatePosition;