Add XML_SetDefaultHandlerExpand

This commit is contained in:
James Clark 1998-09-24 03:40:44 +00:00
parent 2b1702456d
commit fe3c72da7a
2 changed files with 76 additions and 34 deletions

View file

@ -161,6 +161,13 @@ typedef struct {
PREFIX defaultPrefix;
} DTD;
typedef struct open_internal_entity {
const char *internalEventPtr;
const char *internalEventEndPtr;
struct open_internal_entity *next;
ENTITY *entity;
} OPEN_INTERNAL_ENTITY;
typedef enum XML_Error Processor(XML_Parser parser,
const char *start,
const char *end,
@ -277,6 +284,8 @@ typedef struct {
const char *eventPtr;
const char *eventEndPtr;
const char *positionPtr;
OPEN_INTERNAL_ENTITY *openInternalEntities;
int defaultExpandInternalEntities;
int tagLevel;
ENTITY *declEntity;
const XML_Char *declNotationName;
@ -327,6 +336,8 @@ typedef struct {
#define eventEndPtr (((Parser *)parser)->eventEndPtr)
#define positionPtr (((Parser *)parser)->positionPtr)
#define position (((Parser *)parser)->position)
#define openInternalEntities (((Parser *)parser)->openInternalEntities)
#define defaultExpandInternalEntities (((Parser *)parser)->defaultExpandInternalEntities)
#define tagLevel (((Parser *)parser)->tagLevel)
#define buffer (((Parser *)parser)->buffer)
#define bufferPtr (((Parser *)parser)->bufferPtr)
@ -390,6 +401,7 @@ XML_Parser XML_ParserCreate(const XML_Char *encodingName)
eventPtr = 0;
eventEndPtr = 0;
positionPtr = 0;
openInternalEntities = 0;
tagLevel = 0;
tagStack = 0;
freeTagList = 0;
@ -571,6 +583,14 @@ void XML_SetDefaultHandler(XML_Parser parser,
XML_DefaultHandler handler)
{
defaultHandler = handler;
defaultExpandInternalEntities = 0;
}
void XML_SetDefaultHandlerExpand(XML_Parser parser,
XML_DefaultHandler handler)
{
defaultHandler = handler;
defaultExpandInternalEntities = 1;
}
void XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
@ -738,8 +758,15 @@ int XML_GetCurrentColumnNumber(XML_Parser parser)
void XML_DefaultCurrent(XML_Parser parser)
{
if (defaultHandler)
reportDefault(parser, encoding, eventPtr, eventEndPtr);
if (defaultHandler) {
if (openInternalEntities)
reportDefault(parser,
ns ? XmlGetInternalEncodingNS() : XmlGetInternalEncoding(),
openInternalEntities->internalEventPtr,
openInternalEntities->internalEventEndPtr);
else
reportDefault(parser, encoding, eventPtr, eventEndPtr);
}
}
const XML_LChar *XML_ErrorString(int code)
@ -881,16 +908,17 @@ doContent(XML_Parser parser,
const char **nextPtr)
{
const ENCODING *internalEnc = ns ? XmlGetInternalEncodingNS() : XmlGetInternalEncoding();
const char *dummy;
const char **eventPP;
const char **eventEndPP;
if (enc == encoding) {
eventPP = &eventPtr;
*eventPP = s;
eventEndPP = &eventEndPtr;
}
else
eventPP = eventEndPP = &dummy;
else {
eventPP = &(openInternalEntities->internalEventPtr);
eventEndPP = &(openInternalEntities->internalEventEndPtr);
}
*eventPP = s;
for (;;) {
const char *next;
int tok = XmlContentTok(enc, s, end, &next);
@ -974,14 +1002,17 @@ doContent(XML_Parser parser,
if (entity) {
if (entity->textPtr) {
enum XML_Error result;
if (defaultHandler) {
OPEN_INTERNAL_ENTITY openEntity;
if (defaultHandler && !defaultExpandInternalEntities) {
reportDefault(parser, enc, s, next);
break;
}
/* Protect against the possibility that somebody sets
the defaultHandler from inside another handler. */
*eventEndPP = *eventPP;
entity->open = 1;
openEntity.next = openInternalEntities;
openInternalEntities = &openEntity;
openEntity.entity = entity;
openEntity.internalEventPtr = 0;
openEntity.internalEventEndPtr = 0;
result = doContent(parser,
tagLevel,
internalEnc,
@ -989,6 +1020,7 @@ doContent(XML_Parser parser,
(char *)(entity->textPtr + entity->textLen),
0);
entity->open = 0;
openInternalEntities = openEntity.next;
if (result)
return result;
}
@ -1525,7 +1557,6 @@ enum XML_Error doCdataSection(XML_Parser parser,
const char **nextPtr)
{
const char *s = *startPtr;
const char *dummy;
const char **eventPP;
const char **eventEndPP;
if (enc == encoding) {
@ -1533,8 +1564,11 @@ enum XML_Error doCdataSection(XML_Parser parser,
*eventPP = s;
eventEndPP = &eventEndPtr;
}
else
eventPP = eventEndPP = &dummy;
else {
eventPP = &(openInternalEntities->internalEventPtr);
eventEndPP = &(openInternalEntities->internalEventEndPtr);
}
*eventPP = s;
*startPtr = 0;
for (;;) {
const char *next;
@ -2358,21 +2392,23 @@ static void
reportDefault(XML_Parser parser, const ENCODING *enc, const char *s, const char *end)
{
if (MUST_CONVERT(enc, s)) {
for (;;) {
const char **eventPP;
const char **eventEndPP;
if (enc == encoding) {
eventPP = &eventPtr;
eventEndPP = &eventEndPtr;
}
else {
eventPP = &(openInternalEntities->internalEventPtr);
eventEndPP = &(openInternalEntities->internalEventEndPtr);
}
do {
ICHAR *dataPtr = (ICHAR *)dataBuf;
XmlConvert(enc, &s, end, &dataPtr, (ICHAR *)dataBufEnd);
if (s == end) {
defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
break;
}
if (enc == encoding) {
eventEndPtr = s;
defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
eventPtr = s;
}
else
defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
}
*eventEndPP = s;
defaultHandler(handlerArg, dataBuf, dataPtr - (ICHAR *)dataBuf);
*eventPP = s;
} while (s != end);
}
else
defaultHandler(handlerArg, (XML_Char *)s, (XML_Char *)end - (XML_Char *)s);

View file

@ -113,10 +113,9 @@ for which no handler has been supplied. The characters are passed
exactly as they were in the XML document except that
they will be encoded in UTF-8. Line boundaries are not normalized.
Note that a byte order mark character is not passed to the default handler.
If a default handler is set, internal entity references
are not expanded. There are no guarantees about
how characters are divided between calls to the default handler:
for example, a comment might be split between multiple calls. */
There are no guarantees about how characters are divided between calls
to the default handler: for example, a comment might be split between
multiple calls. */
typedef void (*XML_DefaultHandler)(void *userData,
const XML_Char *s,
@ -250,10 +249,20 @@ void XMLPARSEAPI
XML_SetProcessingInstructionHandler(XML_Parser parser,
XML_ProcessingInstructionHandler handler);
/* This sets the default handler and also inhibits expansion of internal entities.
The entity reference will be passed to the default handler. */
void XMLPARSEAPI
XML_SetDefaultHandler(XML_Parser parser,
XML_DefaultHandler handler);
/* This sets the default handler but does not inhibit expansion of internal entities.
The entity reference will not be passed to the default handler. */
void XMLPARSEAPI
XML_SetDefaultHandlerExpand(XML_Parser parser,
XML_DefaultHandler handler);
void XMLPARSEAPI
XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
XML_UnparsedEntityDeclHandler handler);
@ -273,10 +282,7 @@ XML_SetUnknownEncodingHandler(XML_Parser parser,
/* This can be called within a handler for a start element, end element,
processing instruction or character data. It causes the corresponding
markup to be passed to the default handler.
Within the expansion of an internal entity, nothing will be passed
to the default handler, although this usually will not happen since
setting a default handler inhibits expansion of internal entities. */
markup to be passed to the default handler. */
void XMLPARSEAPI XML_DefaultCurrent(XML_Parser parser);
/* This value is passed as the userData argument to callbacks. */