From ad6f7847317b0a46224204d795d055ba775d103f Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Mon, 8 Jan 2007 12:26:55 +0000 Subject: [PATCH] Fix handling of restart markers. csxml_reset() was clearing the state after encountering a restart marker, leaving us in stream level after state, ctx->buffer.data); + printf("%p: Character '%c' (%02X), state %d, buffer `%s', restartCount %d\n", ctx, ch, ch, ctx->state, ctx->buffer.data, ctx->restartCount); #endif #define ERROR(_reason) do { \ @@ -141,8 +143,8 @@ int csxml_feedChar(struct csxml* ctx, char ch) if(ch == xmlRestartMarker[ctx->restartCount]) { if(++ctx->restartCount == 11) { - ctx->state = StateRestartMarker; csxml_reset(ctx); + ctx->state = StateRestartMarker; return 0; } } else { @@ -343,19 +345,34 @@ int csxml_feedChar(struct csxml* ctx, char ch) case StateOpenBang: if(ch == '[') { - // restart markers handled by lower layer - ctx->state = StateOpenCdataMarker; + ctx->state = StateOpenBangMarker; ctx->xmlCount = 3; - if(!ctx->elementDepth) ERROR("CDATA sections not valid at stream level."); } else if(ch == '-') ctx->state = StateOpenComment; else ERROR("Invalid special tag."); break; + case StateOpenBangMarker: + if(ch == xmlCdataMarker[ctx->xmlCount]) { + ctx->state = StateOpenCdataMarker; + if(!ctx->elementDepth) ERROR("CDATA sections not valid at stream level."); + } else if(ch == xmlRestartMarker[ctx->xmlCount]) { + ctx->state = StateOpenRestartMarker; + } else { + ERROR("Invalid marked section."); + } + ++(ctx->xmlCount); + break; + case StateOpenCdataMarker: if(ch != xmlCdataMarker[ctx->xmlCount]) ERROR("Invalid marked section."); if(!xmlCdataMarker[++ctx->xmlCount]) ctx->state = StateCDATA; break; + case StateOpenRestartMarker: + if(ch != xmlRestartMarker[ctx->xmlCount++]) ERROR("Invalid marked section."); + /* Restart markers handled by lower layer -- if(!xmlRestartMarker[++ctx->xmlCount]) { } */ + break; + case StateOpenComment: if(ch != '-') ERROR("Invalid special tag."); ctx->state = StateComment;