--------------------- PatchSet 422 Date: 2002/12/20 05:36:29 Author: rbcollins Branch: esi Tag: (none) Log: update to HEAD Members: src/ESI.cc:1.1.2.40->1.1.2.41 src/ESIElement.h:1.1.2.4->1.1.2.5 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.40 retrieving revision 1.1.2.41 diff -u -r1.1.2.40 -r1.1.2.41 --- squid3/src/ESI.cc 12 Nov 2002 00:29:43 -0000 1.1.2.40 +++ squid3/src/ESI.cc 20 Dec 2002 05:36:29 -0000 1.1.2.41 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.40 2002/11/12 00:29:43 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.41 2002/12/20 05:36:29 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -74,6 +74,12 @@ * NOT TODO: esi:inline - out of scope. */ +/* make comparisons with refcount pointers easy */ +bool operator == (ESIElement const *lhs, ESIElement::Pointer const &rhs) +{ + return lhs == rhs.getRaw(); +} + /* esi variable replacement logic */ @@ -227,14 +233,14 @@ ~esiSequence(); void render(esiSegment *); - bool addElement (ESIElementPtr); + bool addElement (ESIElement::Pointer); esiProcessResult_t process (int dovars); - void provideData (esiSegment *, ESIElementPtr); + void provideData (esiSegment *, ESIElement*); bool mayFail () const; void wontFail(); - void fail(ESIElementPtr); + void fail(ESIElement *); - ESIElementPtr * elements; /* unprocessed or rendered nodes */ + ESIElement::Pointer * elements; /* unprocessed or rendered nodes */ int allocedcount; size_t allocedsize; int elementcount; @@ -245,7 +251,7 @@ private: static MemPool *Pool; esiTreeParentPtr parent; - int elementIndex (ESIElementPtr anElement) const; + int elementIndex (ESIElement::Pointer anElement) const; bool mayFail_; bool failed; }; @@ -293,7 +299,7 @@ esiRemove(); void render(esiSegment *); - bool addElement (ESIElementPtr); + bool addElement (ESIElement::Pointer); }; CBDATA_TYPE (esiRemove); static FREE esiRemoveFree; @@ -325,13 +331,13 @@ ~esiTry(); void render(esiSegment *); - bool addElement (ESIElementPtr); - void fail(ESIElementPtr); + bool addElement (ESIElement::Pointer); + void fail(ESIElement *); esiProcessResult_t process (int dovars); - void provideData (esiSegment *data, ESIElementPtr source); + void provideData (esiSegment *data, ESIElement * source); - ESIElementPtr attempt; - ESIElementPtr except; + ESIElement::Pointer attempt; + ESIElement::Pointer except; struct { int attemptok:1; /* the attempt branch process correctly */ int exceptok:1; /* likewise */ @@ -366,22 +372,22 @@ ~esiChoose(); void render(esiSegment *); - bool addElement (ESIElementPtr); - void fail(ESIElementPtr); + bool addElement (ESIElement::Pointer); + void fail(ESIElement *); esiProcessResult_t process (int dovars); - void provideData (esiSegment *data, ESIElementPtr source); + void provideData (esiSegment *data, ESIElement *source); - ESIElementPtr * elements; /* unprocessed nodes */ + ESIElement::Pointer * elements; /* unprocessed nodes */ int allocedcount; size_t allocedsize; int elementcount; int chosenelement; - ESIElementPtr otherwise; + ESIElement::Pointer otherwise; private: static MemPool *Pool; esiTreeParentPtr parent; - void checkValidSource (ESIElementPtr source) const; + void checkValidSource (ESIElement::Pointer source) const; }; MemPool *esiChoose::Pool = NULL; @@ -417,14 +423,14 @@ esiContext():reading_(true) {} /* when esi processing completes */ - void provideData(esiSegment *, ESIElementPtr source); - void fail (ESIElementPtr source); + void provideData(esiSegment *, ESIElement *source); + void fail (ESIElement *source); void startRead(); void finishRead(); bool reading() const; void setError(); - void addStackElement (ESIElementPtr element); + void addStackElement (ESIElement::Pointer element); void addLiteral (const XML_Char *s, int len); clientStreamNode *thisNode; /* our stream node */ @@ -462,13 +468,13 @@ off_t readpos; /* the logical position we are reading from */ off_t pos; /* the logical position of outbound_offset in the data stream */ struct _parserState{ - ESIElementPtr stack[10]; /* a stack of esi elements that are open */ + ESIElement::Pointer stack[10]; /* a stack of esi elements that are open */ int stackdepth; /* self explanatory */ XML_Parser p; /* our parser */ - ESIElementPtr top(); + ESIElement::Pointer top(); } parserState; /* todo factor this off somewhere else; */ esiVarState *varState; - ESIElementPtr tree; + ESIElement::Pointer tree; static void Free(void *); esiKick_t kick (); @@ -553,9 +559,9 @@ } void -esiContext::provideData (esiSegment *theData, ESIElementPtr source) +esiContext::provideData (esiSegment *theData, ESIElement * source) { - debug (86,5)("esiContext::provideData: %p %p %p\n",this, theData, source.getRaw()); + debug (86,5)("esiContext::provideData: %p %p %p\n",this, theData, source); if (!tree.getRaw()) return; assert (source == tree); @@ -569,7 +575,7 @@ } void -esiContext::fail (ESIElementPtr source) +esiContext::fail (ESIElement * source) { setError(); fail (); @@ -580,11 +586,10 @@ esiContext::fixupOutboundTail() { /* TODO: fixup thisNode outboundtail dross a little */ - while (outboundtail->next) + while (outboundtail && outboundtail->next) outboundtail = outboundtail->next; } - esiKick_t esiContext::kick () { @@ -1114,14 +1119,14 @@ return ESI_ELEMENT_NONE; } -ESIElementPtr +ESIElement::Pointer esiContext::_parserState::top() { return stack[stackdepth-1]; } void -esiContext::addStackElement (ESIElementPtr element) +esiContext::addStackElement (ESIElement::Pointer element) { /* Put on the stack to allow skipping of 'invalid' markup */ assert (parserState.stackdepth <11); @@ -1142,7 +1147,7 @@ char localbuf [HTTP_REQBUF_SZ]; XML_Parser parser = data; esiContext *context = (esiContext *)XML_GetUserData(parser); - ESIElementPtr element; + ESIElement::Pointer element; int specifiedattcount = XML_GetSpecifiedAttributeCount (parser) * 2; char *pos; assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */ @@ -1332,7 +1337,7 @@ debug (86,5)("literal length is %d\n", len); /* give a literal to the current element */ assert (parserState.stackdepth <11); - ESIElementPtr element (new esiLiteral (this, s, len)); + ESIElement::Pointer element (new esiLiteral (this, s, len)); if (!parserState.top()->addElement(element)) { debug (86,1)("esiContext::addLiteral: failed to add esi node, probable error in ESI template\n"); flags.error = 1; @@ -1911,7 +1916,7 @@ elements[i] = NULL; } if (processedcount) { - xmemmove (elements, &elements[processedcount], (elementcount - processedcount) * sizeof (ESIElementPtr)); + xmemmove (elements, &elements[processedcount], (elementcount - processedcount) * sizeof (ESIElement::Pointer)); } elementcount -= processedcount; processedcount = 0; @@ -1919,9 +1924,9 @@ } void -esiSequence::provideData (esiSegment *data, ESIElementPtr source) +esiSequence::provideData (esiSegment *data, ESIElement *source) { - debug (86,5) ("esiSequence::provideData %p %p %p\n", this, data, source.getRaw()); + debug (86,5) ("esiSequence::provideData %p %p %p\n", this, data, source); /* when data is provided, the element *must* be completed */ /* XXX: when the callback model is complete, * we can introduce 'finished'. And then this rule can be @@ -1942,7 +1947,7 @@ } bool -esiSequence::addElement (ESIElementPtr element) +esiSequence::addElement (ESIElement::Pointer element) { /* add an element to the output list */ /* Some elements require specific parents */ @@ -1960,7 +1965,7 @@ &((esiLiteral *)elements[elementcount - 1].getRaw())->buffer); return true; } - elements = (ESIElementPtr*)memReallocBuf (elements, ++elementcount * sizeof (ESIElementPtr), + elements = (ESIElement::Pointer*)memReallocBuf (elements, ++elementcount * sizeof (ESIElement::Pointer), &allocedsize); assert (elements); allocedcount = elementcount; @@ -1970,7 +1975,7 @@ } int -esiSequence::elementIndex(ESIElementPtr anElement) const +esiSequence::elementIndex(ESIElement::Pointer anElement) const { for (int i = 0; i < elementcount; ++i) if (elements[i] == anElement) @@ -2036,7 +2041,7 @@ } void -esiSequence::fail (ESIElementPtr source) +esiSequence::fail (ESIElement *source) { parent->fail (this); } @@ -2340,7 +2345,7 @@ /* Accept non-ESI children */ bool -esiRemove::addElement (ESIElementPtr element) +esiRemove::addElement (ESIElement::Pointer element) { if (!dynamic_cast(element.getRaw())) { debug (86,5)("esiRemoveAdd: Failed for %p\n",this); @@ -2401,7 +2406,7 @@ /* Accept attempt and except only */ bool -esiTry::addElement(ESIElementPtr element) +esiTry::addElement(ESIElement::Pointer element) { debug (86,5)("esiTryAdd: Try %p adding element %p\n",this, element.getRaw()); if (dynamic_cast(element.getRaw())) { @@ -2508,11 +2513,11 @@ } void -esiTry::fail(ESIElementPtr source) +esiTry::fail(ESIElement *source) { - assert (source.getRaw()); + assert (source); assert (source == attempt || source == except); - debug (86,5) ("esiTry::fail: this=%p, source=%p\n", this, source.getRaw()); + debug (86,5) ("esiTry::fail: this=%p, source=%p\n", this, source); if (source == except) { flags.exceptfailed = 1; } else { @@ -2522,7 +2527,7 @@ } void -esiTry::provideData (esiSegment *data, ESIElementPtr source) +esiTry::provideData (esiSegment *data, ESIElement* source) { if (source == attempt) { flags.attemptok = 1; @@ -2669,20 +2674,14 @@ esiVarState::esiVarState (HttpHeader const *aHeader, char const *uri) : output (NULL) { - char const *query_pos; - char const *query_start; /* Fill out variable values */ - /* TODO: only grab the needed headers */ - httpHeaderInit (&hdr, hoReply); - httpHeaderAppend (&hdr, aHeader); - /* Count off the query elements */ - query_start = strchr (uri, '?'); + char const *query_start = strchr (uri, '?'); if (query_start && query_start[1] != '\0' ) { unsigned int n; query_string = xstrdup (query_start + 1); query_elements = 1; - query_pos = query_start + 1; + char const *query_pos = query_start + 1; while ((query_pos = strchr (query_pos, '&'))) { ++query_elements; ++query_pos; @@ -2747,6 +2746,9 @@ * if MOZILLA doesn't appear, the browser is set to OTHER. * In future, thisNode may be better implemented as a regexp. */ + /* TODO: only grab the needed headers */ + httpHeaderInit (&hdr, hoReply); + httpHeaderAppend (&hdr, aHeader); if (httpHeaderHas(&hdr, HDR_USER_AGENT)) { char const *s = httpHeaderGetStr (&hdr, HDR_USER_AGENT); char const *t, *t1; @@ -2842,7 +2844,6 @@ } stringClean(&header); return result; - } void @@ -3136,6 +3137,7 @@ safe_free (found_subref); } +/* XXX FIXME: this should be comma delimited, no? */ void esiVarState::buildVary (HttpReply *rep) { @@ -3192,10 +3194,8 @@ delete this; } -esiChoose::esiChoose(esiTreeParentPtr aParent) : parent (aParent) +esiChoose::esiChoose(esiTreeParentPtr aParent) : elements (NULL), chosenelement (-1),parent (aParent) { - elements = NULL; - chosenelement = -1; } void @@ -3212,7 +3212,7 @@ } bool -esiChoose::addElement(ESIElementPtr element) +esiChoose::addElement(ESIElement::Pointer element) { /* add an element to the output list */ if (dynamic_cast(element.getRaw())) { @@ -3233,7 +3233,7 @@ } otherwise = element; } else { - elements = (ESIElementPtr *)memReallocBuf (elements, ++elementcount * sizeof (ESIElementPtr), + elements = (ESIElement::Pointer *)memReallocBuf (elements, ++elementcount * sizeof (ESIElement::Pointer), &allocedsize); assert (elements); allocedcount = elementcount; @@ -3256,8 +3256,10 @@ * faliures */ /* We MUST have a when clause */ - if (!elementcount) + if (!elementcount) { + parent->fail(this); return ESI_PROCESS_FAILED; + } else if (chosenelement >= 0) { return elements[chosenelement]->process(dovars); } else if (otherwise.getRaw()) @@ -3267,7 +3269,7 @@ } void -esiChoose::checkValidSource (ESIElementPtr source) const +esiChoose::checkValidSource (ESIElement::Pointer source) const { if (!elementcount) fatal ("invalid callback = no when clause\n"); @@ -3280,14 +3282,14 @@ } void -esiChoose::fail(ESIElementPtr source) +esiChoose::fail(ESIElement * source) { checkValidSource (source); parent->fail(this); } void -esiChoose::provideData (esiSegment *data, ESIElementPtr source) +esiChoose::provideData (esiSegment *data, ESIElement*source) { checkValidSource (source); parent->provideData (data, this); @@ -3318,19 +3320,18 @@ esiWhen::esiWhen (esiTreeParentPtr aParent, int attrcount, const char **attr,esiVarState *varState) : esiSequence (aParent) { char const *expression = NULL; - int i; - - for (i = 0; attr[i] && i < attrcount; i += 2) { - if (!strcmp(attr[i],"test")) { + for (int loopCounter = 0; attr[loopCounter] && loopCounter < attrcount; loopCounter += 2) { + if (!strcmp(attr[loopCounter],"test")) { /* evaluate test */ - debug (86,5)("esiIncludeNew: Evaluating '%s'\n",attr[i+1]); + debug (86,5)("esiIncludeNew: Evaluating '%s'\n",attr[loopCounter+1]); /* TODO: warn the user instead of asserting */ assert (expression == NULL); - expression = attr[i+1]; + expression = attr[loopCounter+1]; } else { /* ignore mistyped attributes. * TODO:? error on these for user feedback - config parameter needed */ + debug (86,1)("Found misttyped attribute on ESI When clause\n"); } } /* No expression ? default is not matching */ Index: squid3/src/ESIElement.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESIElement.h,v retrieving revision 1.1.2.4 retrieving revision 1.1.2.5 diff -u -r1.1.2.4 -r1.1.2.5 --- squid3/src/ESIElement.h 12 Nov 2002 00:29:43 -0000 1.1.2.4 +++ squid3/src/ESIElement.h 20 Dec 2002 05:36:29 -0000 1.1.2.5 @@ -1,5 +1,5 @@ /* - * $Id: ESIElement.h,v 1.1.2.4 2002/11/12 00:29:43 rbcollins Exp $ + * $Id: ESIElement.h,v 1.1.2.5 2002/12/20 05:36:29 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -44,21 +44,21 @@ } esiProcessResult_t; class ESIElement; -typedef RefCount ESIElementPtr; struct esiTreeParent : public RefCountable { - virtual void provideData (esiSegment *data, ESIElementPtr source) + virtual void provideData (esiSegment *data, ESIElement * source) { /* make abstract when all functionality complete */ assert (0); } - virtual void fail(ESIElementPtr source) {} + virtual void fail(ESIElement * source) {} virtual ~esiTreeParent(){} }; typedef RefCount esiTreeParentPtr; struct ESIElement : public esiTreeParent { - virtual bool addElement(ESIElementPtr) { + typedef RefCount Pointer; + virtual bool addElement(ESIElement::Pointer) { /* Don't accept children */ debug (86,5)("ESIElement::addElement: Failed for %p\n",this); return false;