--------------------- PatchSet 448 Date: 2002/12/20 23:58:28 Author: rbcollins Branch: esi Tag: (none) Log: and esiWhen Members: src/ESI.cc:1.1.2.61->1.1.2.62 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.61 retrieving revision 1.1.2.62 diff -u -r1.1.2.61 -r1.1.2.62 --- squid3/src/ESI.cc 20 Dec 2002 23:22:33 -0000 1.1.2.61 +++ squid3/src/ESI.cc 20 Dec 2002 23:58:28 -0000 1.1.2.62 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.61 2002/12/20 23:22:33 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.62 2002/12/20 23:58:28 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -252,6 +252,8 @@ struct { int dovars:1; /* for esiVar */ } flags; +protected: + esiSequence(esiSequence const &); private: static MemPool *Pool; esiTreeParentPtr parent; @@ -260,7 +262,6 @@ bool failed; esiProcessResult_t processOne(int, int); bool const provideIncrementalData; - esiSequence(esiSequence const &); }; MemPool *esiSequence::Pool = NULL; @@ -410,13 +411,18 @@ void operator delete (void *address); void deleteSelf() const; esiWhen(esiTreeParentPtr aParent, int attributes, const char **attr, esiVarState *); + ~esiWhen(); Pointer makeCacheable() const; bool testsTrue() const { return testValue;} void setTestResult(bool aBool) {testValue = aBool;} private: static MemPool *Pool; + esiWhen (esiWhen const &); bool testValue; + char const *unevaluatedExpression; + esiVarState *varState; + void evaluate(); }; MemPool *esiWhen::Pool = NULL; @@ -3461,8 +3467,9 @@ delete this; } -esiWhen::esiWhen (esiTreeParentPtr aParent, int attrcount, const char **attr,esiVarState *varState) : esiSequence (aParent) +esiWhen::esiWhen (esiTreeParentPtr aParent, int attrcount, const char **attr,esiVarState *aVar) : esiSequence (aParent) { + varState = NULL; char const *expression = NULL; for (int loopCounter = 0; attr[loopCounter] && loopCounter < attrcount; loopCounter += 2) { if (!strcmp(attr[loopCounter],"test")) { @@ -3481,19 +3488,45 @@ /* No expression ? default is not matching */ if (!expression) return; - - varState->feedData(expression, strlen (expression)); - /* expression is not our buffer */ - expression = varState->extractChar (); + + unevaluatedExpression = xstrdup(expression); + varState = cbdataReference (aVar); + + evaluate(); +} + +esiWhen::~esiWhen() +{ + safe_free (unevaluatedExpression); + if (varState) + cbdataReferenceDone (varState); +} + +void +esiWhen::evaluate() +{ + if (!unevaluatedExpression) + return; + assert (varState); + varState->feedData(unevaluatedExpression, strlen (unevaluatedExpression)); + + char const *expression = varState->extractChar (); setTestResult(esiExpressionEval (expression)); safe_free (expression); } +esiWhen::esiWhen(esiWhen const &old) : esiSequence (old) +{ + unevaluatedExpression = NULL; + if (old.unevaluatedExpression) + unevaluatedExpression = xstrdup(old.unevaluatedExpression); + varState = NULL; +} + ESIElement::Pointer esiWhen::makeCacheable() const { - fatal ("esiWhen not implemented\n"); - return NULL; + return new esiWhen(*this); } /* esiOtherwise */