--------------------- PatchSet 4707 Date: 2002/08/18 11:29:12 Author: rbcollins Branch: esi Tag: (none) Log: esi:remove support Members: src/ESI.c:1.1.2.11->1.1.2.12 Index: squid/src/ESI.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/ESI.c,v retrieving revision 1.1.2.11 retrieving revision 1.1.2.12 diff -u -r1.1.2.11 -r1.1.2.12 --- squid/src/ESI.c 18 Aug 2002 11:09:22 -0000 1.1.2.11 +++ squid/src/ESI.c 18 Aug 2002 11:29:12 -0000 1.1.2.12 @@ -1,6 +1,6 @@ /* - * $Id: ESI.c,v 1.1.2.11 2002/08/18 11:09:22 rbcollins Exp $ + * $Id: ESI.c,v 1.1.2.12 2002/08/18 11:29:12 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -142,17 +142,22 @@ static esiProcessSelf esiIncludeProcess; static void esiIncludeSubRequestDone (esiInclude *, esiStreamContext *, int); +static esiRender esiRemoveRender; +static esiAddElement esiRemoveAdd; + /* the types we have */ typedef enum { ESI_ELEMENT_NONE, ESI_ELEMENT_INCLUDE, - ESI_ELEMENT_COMMENT + ESI_ELEMENT_COMMENT, + ESI_ELEMENT_REMOVE } esiElementType_t; static esiElementType _esiComment = {esiCommentRender,esiAddFail,esiProcessComplete}; static esiElementType _esiLiteral = {esiLiteralRender,esiAddFail,esiProcessComplete}; static esiElementType _esiSequence = {esiSequenceRender,esiSequenceAdd,esiSequenceProcess}; -static esiElementType _esiInclude = {esiIncludeRender, esiAddFail, esiIncludeProcess}; +static esiElementType _esiInclude = {esiIncludeRender, esiAddFail, esiIncludeProcess}; +static esiElementType _esiRemove = {esiRemoveRender, esiRemoveAdd, esiProcessComplete}; /* esiComment */ typedef struct { @@ -204,6 +209,14 @@ static FREE esiIncludeFree; static esiElement * esiIncludeNew (int attributes, const char **attr, esiContext *); +/* esiRemove */ +typedef struct { + esiElementType *vptr; +} esiRemove; +CBDATA_TYPE (esiRemove); +static FREE esiRemoveFree; +static esiElement * esiRemoveNew(void); + struct _esiContext { clientStreamNode *this; /* our stream node */ clientHttpRequest *http; /* the request we are processing. HMM: cbdataReferencing this will result @@ -237,12 +250,6 @@ off_t readpos; /* the logical position we are reading from */ off_t pos; /* the logical position of outbound_offset in the data stream */ struct { - off_t unprocessed_start; /* the offset into the buffered chain of the - oldest data not processed - */ - off_t buffered_tokenstart; /* the offset into the buffered chain of the - parsers current symbol candidate - */ esiElement *stack[10]; /* a stack of esi elements that are open */ int stackdepth; /* self explanatory */ XML_Parser p; /* our parser */ @@ -730,6 +737,8 @@ return ESI_ELEMENT_COMMENT; if (!strncmp (el + 4, "include",7)) return ESI_ELEMENT_INCLUDE; + if (!strncmp (el + 4, "remove",6)) + return ESI_ELEMENT_REMOVE; return ESI_ELEMENT_NONE; } @@ -747,6 +756,10 @@ debug (86, 5)("esiExpatState: element '%s' with %d tags\n", el, specifiedattcount); + if (context->flags.error) + /* waiting for expat to finish the buffer we gave it */ + return; + switch (esiIdentifyElement (el)) { case ESI_ELEMENT_NONE: /* Spit out elements we aren't interested in */ @@ -780,6 +793,7 @@ debug (86,1)("esiProcess: failed to add esi node, probable error in ESI template\n"); context->flags.error = 1; cbdataFree (element); + break; } else { /* added ok, push onto the stack */ @@ -800,6 +814,20 @@ context->parserState.stack[context->parserState.stackdepth++] = element; } break; + case ESI_ELEMENT_REMOVE: + /* Put on the stack to allow skipping of 'invalid' markup */ + assert (context->parserState.stackdepth <11); + element = esiRemoveNew (); + if (ADDELEMENT (context->parserState.stack[context->parserState.stackdepth-1], element)) { + debug (86,1)("esiProcess: failed to add esi node, probable error in ESI template\n"); + context->flags.error = 1; + cbdataFree (element); + break; + } else { + /* added ok, push onto the stack */ + context->parserState.stack[context->parserState.stackdepth++] = element; + } + break; } @@ -815,6 +843,10 @@ char *pos; esiContext *context = data; + if (context->flags.error) + /* waiting for expat to finish the buffer we gave it */ + return; + switch (esiIdentifyElement (el)) { case ESI_ELEMENT_NONE: assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */ @@ -828,10 +860,8 @@ context->flags.error = 1; break; case ESI_ELEMENT_COMMENT: - /* pop of the stack */ - --context->parserState.stackdepth; - break; case ESI_ELEMENT_INCLUDE: + case ESI_ELEMENT_REMOVE: /* pop of the stack */ --context->parserState.stackdepth; break; @@ -1573,3 +1603,40 @@ esiKick (this->context); } } + +/* esiRemove */ +void +esiRemoveFree (void *data) +{ + esiRemove *this = data; + debug (86,5)("esiRemoveFree %p\n", this); +} + +esiElement * +esiRemoveNew () +{ + esiRemove *rv; + CBDATA_INIT_TYPE_FREECB(esiRemove, esiRemoveFree); + rv = cbdataAlloc (esiRemove); + rv->vptr = &_esiRemove; + return (esiElement *) rv; +} + +void +esiRemoveRender (void *data, esiSegment *output) +{ + /* Removes do nothing dude */ + debug (86, 5)("esiRemoveRender: Rendering remove %p\n", data); +} + +/* Accept non-ESI children */ +int +esiRemoveAdd (void *data, esiElement *element) { + if (element->vptr != & _esiLiteral) { + debug (86,5)("esiRemoveAdd: Failed for %p\n",data); + return -1; + } + return 0; +} + +