--------------------- PatchSet 4714 Date: 2002/08/19 00:12:59 Author: rbcollins Branch: esi Tag: (none) Log: 3.4 try attempt except Members: src/ESI.c:1.1.2.14->1.1.2.15 Index: squid/src/ESI.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/ESI.c,v retrieving revision 1.1.2.14 retrieving revision 1.1.2.15 diff -u -r1.1.2.14 -r1.1.2.15 --- squid/src/ESI.c 18 Aug 2002 13:25:15 -0000 1.1.2.14 +++ squid/src/ESI.c 19 Aug 2002 00:12:59 -0000 1.1.2.15 @@ -1,6 +1,6 @@ /* - * $Id: ESI.c,v 1.1.2.14 2002/08/18 13:25:15 rbcollins Exp $ + * $Id: ESI.c,v 1.1.2.15 2002/08/19 00:12:59 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -85,7 +85,6 @@ /* TODO: remove invalid markup (silently swallow markup in invalid locations * TODO: inline variables * TODO: 3.3 choose when otherwise - * TODO: 3.4 try attempt except * TODO: 3.7 vars * * @@ -144,12 +143,19 @@ static esiRender esiRemoveRender; static esiAddElement esiRemoveAdd; +esiAddElement esiTryAdd; +static esiRender esiTryRender; +static esiProcessSelf esiTryProcess; + /* the types we have */ typedef enum { ESI_ELEMENT_NONE, ESI_ELEMENT_INCLUDE, ESI_ELEMENT_COMMENT, - ESI_ELEMENT_REMOVE + ESI_ELEMENT_REMOVE, + ESI_ELEMENT_TRY, + ESI_ELEMENT_ATTEMPT, + ESI_ELEMENT_EXCEPT } esiElementType_t; static esiElementType _esiComment = {esiCommentRender,esiAddFail,esiProcessComplete}; @@ -157,6 +163,10 @@ static esiElementType _esiSequence = {esiSequenceRender,esiSequenceAdd,esiSequenceProcess}; static esiElementType _esiInclude = {esiIncludeRender, esiAddFail, esiIncludeProcess}; static esiElementType _esiRemove = {esiRemoveRender, esiRemoveAdd, esiProcessComplete}; +static esiElementType _esiTry = {esiTryRender, esiTryAdd, esiTryProcess}; +/* esiAttempt and esiExcept are 'Sequences' */ +static esiElementType _esiAttempt = {esiSequenceRender,esiSequenceAdd,esiSequenceProcess}; +static esiElementType _esiExcept = {esiSequenceRender,esiSequenceAdd,esiSequenceProcess}; /* esiComment */ typedef struct { @@ -210,12 +220,37 @@ /* esiRemove */ typedef struct { - esiElementType *vptr; + esiElementType *vptr; } esiRemove; CBDATA_TYPE (esiRemove); static FREE esiRemoveFree; static esiElement * esiRemoveNew(void); +/* esiAttempt */ +typedef esiSequence esiAttempt; +static esiElement *esiAttemptNew(void); + +/* esiExcept */ +typedef esiSequence esiExcept; +static esiElement *esiExceptNew(void); + +/* esiTry */ +typedef struct { + esiElementType *vptr; + esiElement *attempt; + esiElement *except; + struct { + int attemptok:1; /* the attempt branch process correctly */ + int exceptok:1; /* likewise */ + int attemptfailed:1; /* The attempt branch failed */ + int exceptfailed:1; /* the except branch failed */ + } flags; +} esiTry; +CBDATA_TYPE (esiTry); +static FREE esiTryFree; +static esiElement *esiTryNew(void); + +/* esiContext */ struct _esiContext { clientStreamNode *this; /* our stream node */ clientHttpRequest *http; /* the request we are processing. HMM: cbdataReferencing this will result @@ -285,6 +320,7 @@ /* static void esiStartSub (void); */ static void esiFail (clientStreamNode *this, esiContext *context, clientHttpRequest *http); static esiKick_t esiKick (esiContext *context); +static void esiAddStackElement (esiContext *context, esiElement *element); /* ESI TO CONSIDER: * 1. retry failed upstream requests @@ -733,16 +769,38 @@ assert (el); if (strlen (el) < 5 || strncmp (el, "esi:", 4)) return ESI_ELEMENT_NONE; - if (!strncmp (el + 4, "comment",7)) + if (!strncmp (el + 4, "comment", 7)) return ESI_ELEMENT_COMMENT; - if (!strncmp (el + 4, "include",7)) + if (!strncmp (el + 4, "include", 7)) return ESI_ELEMENT_INCLUDE; - if (!strncmp (el + 4, "remove",6)) + if (!strncmp (el + 4, "attempt", 7)) + return ESI_ELEMENT_ATTEMPT; + if (!strncmp (el + 4, "remove", 6)) return ESI_ELEMENT_REMOVE; + if (!strncmp (el + 4, "except", 6)) + return ESI_ELEMENT_EXCEPT; + if (!strncmp (el + 4, "try", 3)) + return ESI_ELEMENT_TRY; + return ESI_ELEMENT_NONE; } void +esiAddStackElement (esiContext *context, esiElement *element) +{ + /* Put on the stack to allow skipping of 'invalid' markup */ + assert (context->parserState.stackdepth <11); + 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); + } else { + /* added ok, push onto the stack */ + context->parserState.stack[context->parserState.stackdepth++] = element; + } +} + +void start(void *data,const XML_Char *el, const char **attr) { int i; @@ -788,49 +846,35 @@ break; case ESI_ELEMENT_COMMENT: /* Put on the stack to allow skipping of 'invalid' markup */ - assert (context->parserState.stackdepth <11); element = esiCommentNew (); - 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; - } + esiAddStackElement (context, element); break; case ESI_ELEMENT_INCLUDE: /* Put on the stack to allow skipping of 'invalid' markup */ - assert (context->parserState.stackdepth <11); element = esiIncludeNew (specifiedattcount, attr, context); - 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; - } + esiAddStackElement (context, 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; - } + esiAddStackElement (context, element); + break; + case ESI_ELEMENT_TRY: + /* Put on the stack to allow skipping of 'invalid' markup */ + element = esiTryNew (); + esiAddStackElement (context, element); + break; + case ESI_ELEMENT_ATTEMPT: + /* Put on the stack to allow skipping of 'invalid' markup */ + element = esiAttemptNew (); + esiAddStackElement (context, element); + break; + case ESI_ELEMENT_EXCEPT: + /* Put on the stack to allow skipping of 'invalid' markup */ + element = esiExceptNew (); + esiAddStackElement (context, element); break; } - debug (86,5)("esi stack depth %d\n",context->parserState.stackdepth); @@ -865,6 +909,9 @@ case ESI_ELEMENT_COMMENT: case ESI_ELEMENT_INCLUDE: case ESI_ELEMENT_REMOVE: + case ESI_ELEMENT_TRY: + case ESI_ELEMENT_ATTEMPT: + case ESI_ELEMENT_EXCEPT: /* pop of the stack */ --context->parserState.stackdepth; break; @@ -888,7 +935,7 @@ esiContext *context = XML_GetUserData(parser); if (!strncmp(s, "esi",3)) { XML_Parser p; - debug (86,1)("esiExpatComment: ESI