--------------------- PatchSet 124 Date: 2002/11/02 23:14:09 Author: rbcollins Branch: esi Tag: (none) Log: start putting one class per file Members: src/ESI.cc:1.1.2.32->1.1.2.33 src/ESIElement.h:1.1->1.1.2.1 src/ESISegment.cc:1.1->1.1.2.1 src/ESISegment.h:1.1->1.1.2.1 src/Makefile.am:1.4.2.1->1.4.2.2 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.32 retrieving revision 1.1.2.33 diff -u -r1.1.2.32 -r1.1.2.33 --- squid3/src/ESI.cc 2 Nov 2002 12:53:57 -0000 1.1.2.32 +++ squid3/src/ESI.cc 2 Nov 2002 23:14:09 -0000 1.1.2.33 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.32 2002/11/02 12:53:57 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.33 2002/11/02 23:14:09 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -38,6 +38,8 @@ #include "clientStream.h" #include "client_side_request.h" #include "expat.h" +#include "ESISegment.h" +#include "ESIElement.h" /* quick reference on behaviour here. * The ESI specification 1.0 requires the ESI processor to be able to @@ -48,17 +50,6 @@ * */ -/* TODO: Factor the store memory segment management into a reusable code block - * or perhaps use membuffers here? - */ - -typedef struct _esiSegment { - char buf[HTTP_REQBUF_SZ]; - size_t len; /* how much data has been pushed into this */ - struct _esiSegment *next; -} esiSegment; -CBDATA_TYPE(esiSegment); - typedef struct _esiStreamContext esiStreamContext; typedef struct _esiContext esiContext; @@ -116,6 +107,7 @@ esiVarState (HttpHeader const *hdr, char const *uri); private: + char *getProductVersion (char const *s); esiSegment *input; esiSegment *output; HttpHeader hdr; @@ -155,8 +147,6 @@ }; CBDATA_TYPE (esiVarState); FREE esiVarStateFree; -static esiVarState *esiVarStateNew(HttpHeader const *, const char *uri); - char const *esiVarState::esiUserOs[]= { "WIN", "MAC", @@ -164,16 +154,9 @@ "OTHER" }; -static char *esiGetProductVersion (char const *s); extern int esiExpressionEval (char const *); -typedef enum { - ESI_PROCESS_COMPLETE, - ESI_PROCESS_PENDING_WONTFAIL, - ESI_PROCESS_PENDING_MAYFAIL, - ESI_PROCESS_FAILED -} esiProcessResult_t; typedef enum { ESI_KICK_FAILED, @@ -181,30 +164,9 @@ ESI_KICK_SENT } esiKick_t; -struct esiElement { - virtual bool addElement(esiElement *) { - /* Don't accept children */ - debug (86,5)("esiElement::addElement: Failed for %p\n",this); - return false; - } - virtual void render (esiSegment *) = 0; - /* process this element */ - virtual esiProcessResult_t process (int dovars) { - debug (86,5) ("esiProcessComplete: Processed %p\n",this); - return ESI_PROCESS_COMPLETE; - } - virtual void deleteSelf() = 0; -}; /* some core operators */ -/* the methods for each type */ -esiProcessResult_t processThunk(void *data, int dovars) -{ - return ((esiElement *)data)->process(dovars); -} - - /* the types we have */ typedef enum { ESI_ELEMENT_NONE, @@ -218,10 +180,10 @@ ESI_ELEMENT_CHOOSE, ESI_ELEMENT_WHEN, ESI_ELEMENT_OTHERWISE -} esiElementType_t; +} ESIElementType_t; /* esiComment */ -struct esiComment : public esiElement { +struct esiComment : public ESIElement { void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf(); @@ -232,10 +194,10 @@ }; CBDATA_TYPE (esiComment); static FREE esiCommentFree; -static esiElement * esiCommentNew(void); +static ESIElement * esiCommentNew(void); /* esiLiteral */ -struct esiLiteral : public esiElement{ +struct esiLiteral : public ESIElement{ void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf(); @@ -252,10 +214,10 @@ }; CBDATA_TYPE (esiLiteral); static FREE esiLiteralFree; -static esiElement * esiLiteralNew(esiContext *, const XML_Char *s, int len); +static ESIElement * esiLiteralNew(esiContext *, const XML_Char *s, int len); /* esiSequence */ -class esiSequence : public esiElement{ +class esiSequence : public ESIElement{ public: void *operator new (size_t byteCount); void operator delete (void *address); @@ -263,9 +225,9 @@ esiSequence(); void render(esiSegment *); - bool addElement (esiElement *); + bool addElement (ESIElement *); esiProcessResult_t process (int dovars); - esiElement ** elements; /* unprocessed or rendered nodes */ + ESIElement ** elements; /* unprocessed or rendered nodes */ int allocedcount; size_t allocedsize; int elementcount; @@ -276,10 +238,10 @@ }; CBDATA_TYPE (esiSequence); static FREE esiSequenceFree; -static esiElement * esiSequenceNew(void); +static ESIElement * esiSequenceNew(void); /* esiInclude */ -struct esiInclude : public esiElement{ +struct esiInclude : public ESIElement{ void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf(); @@ -302,10 +264,10 @@ }; CBDATA_TYPE (esiInclude); static FREE esiIncludeFree; -static esiElement * esiIncludeNew (int attributes, const char **attr, esiContext *); +static ESIElement * esiIncludeNew (int attributes, const char **attr, esiContext *); /* esiRemove */ -class esiRemove : public esiElement { +class esiRemove : public ESIElement { public: void *operator new (size_t byteCount); void operator delete (void *address); @@ -313,11 +275,11 @@ esiRemove(); void render(esiSegment *); - bool addElement (esiElement *); + bool addElement (ESIElement *); }; CBDATA_TYPE (esiRemove); static FREE esiRemoveFree; -static esiElement * esiRemoveNew(void); +static ESIElement * esiRemoveNew(void); /* esiAttempt */ struct esiAttempt : public esiSequence{ @@ -326,7 +288,7 @@ void deleteSelf(); }; CBDATA_TYPE(esiAttempt); -static esiElement *esiAttemptNew(void); +static ESIElement *esiAttemptNew(void); /* esiExcept */ struct esiExcept : public esiSequence{ @@ -335,20 +297,20 @@ void deleteSelf(); }; CBDATA_TYPE(esiExcept); -static esiElement *esiExceptNew(void); +static ESIElement *esiExceptNew(void); /* esiTry */ -struct esiTry : public esiElement{ +struct esiTry : public ESIElement{ void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf(); esiTry(); void render(esiSegment *); - bool addElement (esiElement *); + bool addElement (ESIElement *); esiProcessResult_t process (int dovars); - esiElement *attempt; - esiElement *except; + ESIElement *attempt; + ESIElement *except; struct { int attemptok:1; /* the attempt branch process correctly */ int exceptok:1; /* likewise */ @@ -358,7 +320,7 @@ }; CBDATA_TYPE (esiTry); static FREE esiTryFree; -static esiElement *esiTryNew(void); +static ESIElement *esiTryNew(void); /* esiVar */ struct esiVar:public esiSequence{ @@ -367,28 +329,28 @@ void deleteSelf(); }; CBDATA_TYPE(esiVar); -static esiElement *esiVarNew(void); +static ESIElement *esiVarNew(void); /* esiChoose */ -struct esiChoose : public esiElement { +struct esiChoose : public ESIElement { void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf(); esiChoose(); void render(esiSegment *); - bool addElement (esiElement *); + bool addElement (ESIElement *); esiProcessResult_t process (int dovars); - esiElement ** elements; /* unprocessed nodes */ + ESIElement ** elements; /* unprocessed nodes */ int allocedcount; size_t allocedsize; int elementcount; int chosenelement; - esiElement *otherwise; + ESIElement *otherwise; }; CBDATA_TYPE (esiChoose); static FREE esiChooseFree; -static esiElement *esiChooseNew(void); +static ESIElement *esiChooseNew(void); /* esiWhen */ struct esiWhen : public esiSequence @@ -403,7 +365,7 @@ bool testValue; }; CBDATA_TYPE (esiWhen); -static esiElement *esiWhenNew(int attributes, const char **attr, esiVarState *); +static ESIElement *esiWhenNew(int attributes, const char **attr, esiVarState *); /* esiOtherwise */ struct esiOtherwise : public esiSequence{ @@ -412,7 +374,7 @@ void deleteSelf(); }; CBDATA_TYPE(esiOtherwise); -static esiElement *esiOtherwiseNew(void); +static ESIElement *esiOtherwiseNew(void); /* esiContext */ struct _esiContext { @@ -451,12 +413,12 @@ off_t readpos; /* the logical position we are reading from */ off_t pos; /* the logical position of outbound_offset in the data stream */ struct { - esiElement *stack[10]; /* a stack of esi elements that are open */ + ESIElement *stack[10]; /* a stack of esi elements that are open */ int stackdepth; /* self explanatory */ XML_Parser p; /* our parser */ } parserState; /* todo factor this off somewhere else; */ esiVarState *varState; - esiElement *tree; + ESIElement *tree; static void Free(void *); esiKick_t kick (); @@ -484,17 +446,12 @@ /* esiStreamContext */ static FREE esiStreamContextFree; static esiStreamContext *esiStreamContextNew (esiInclude *); -/* esiSegment */ -static void esiSegmentFreeList (esiSegment **head); -static void esiSegmentTransferList (esiSegment **from, esiSegment **to); -static char *esiSegmentListToChar (esiSegment *head); -static void esiSegmentListAppend (esiSegment **head, char const *, size_t); /* other */ static CSCB esiBufferRecipient; static CSD esiBufferDetach; /* static void esiStartSub (void); */ -static void esiAddStackElement (esiContext *context, esiElement *element); +static void esiAddStackElement (esiContext *context, ESIElement *element); /* ESI TO CONSIDER: * 1. retry failed upstream requests @@ -539,7 +496,7 @@ assert (tree || flags.error); if (!outbound) - outbound = outboundtail = cbdataAlloc (esiSegment); + outbound = outboundtail = new esiSegment; if (!flags.error) tree->render(outboundtail); /* TODO: fixup thisNode outboundtail dross a little */ @@ -624,8 +581,7 @@ /* secure a buffer */ if (!context->incoming) { /* create a new buffer segment */ - CBDATA_INIT_TYPE(esiSegment); - context->buffered = cbdataAlloc (esiSegment); + context->buffered = new esiSegment; context->incoming = context->buffered; } assert (context->incoming && context->incoming->len != HTTP_REQBUF_SZ); @@ -842,8 +798,7 @@ if (!context->incoming) { /* create a new buffer segment */ debug (86,5) ("esiProcessStream: Setting up incoming buffer\n"); - CBDATA_INIT_TYPE(esiSegment); - context->buffered = cbdataAlloc (esiSegment); + context->buffered = new esiSegment; context->incoming = context->buffered; } if (recievedData.data != &context->incoming->buf[context->incoming->len]) { @@ -856,7 +811,7 @@ context->incoming->len += len; if (context->incoming->len == HTTP_REQBUF_SZ) { /* append another buffer */ - context->incoming->next = cbdataAlloc (esiSegment); + context->incoming->next = new esiSegment; context->incoming = context->incoming->next; } if (len != recievedData.length) { @@ -872,7 +827,7 @@ assert (context->incoming->len <= HTTP_REQBUF_SZ); if (context->incoming->len > HTTP_REQBUF_SZ * 3 / 4) { /* allocate a new buffer - to stop us asking for ridiculously small amounts */ - context->incoming->next = cbdataAlloc (esiSegment); + context->incoming->next = new esiSegment; context->incoming = context->incoming->next; } context->readpos += recievedData.length; @@ -948,13 +903,11 @@ httpHeaderDelById(hdr, HDR_ETAG); httpHeaderDelById(hdr, HDR_CONTENT_LENGTH); httpHeaderDelById(hdr, HDR_CONTENT_MD5); - /* Tree may use thisNode */ - CBDATA_INIT_TYPE(esiSegment); rv->tree = esiSequenceNew(); rv->thisNode = thisNode; rv->http = http; rv->flags.clientwantsdata = 1; - rv->varState = esiVarStateNew (&http->request->header, http->uri); + rv->varState = new esiVarState (&http->request->header, http->uri); debug (86,5)("esiContextNew: Client wants data (always created during reply cycle\n"); } debug (86,5)("esiContextNew: Create context %p\n",rv); @@ -968,10 +921,10 @@ void esiExpatDefault (void *data, const XML_Char *s, int len); void esiExpatComment (void *data, const XML_Char *s); -static esiElementType_t +static ESIElementType_t esiIdentifyElement (const XML_Char *el) ; -esiElementType_t +ESIElementType_t esiIdentifyElement (const XML_Char *el) { int offset = 0; @@ -1009,7 +962,7 @@ } void -esiAddStackElement (esiContext *context, esiElement *element) +esiAddStackElement (esiContext *context, ESIElement *element) { /* Put on the stack to allow skipping of 'invalid' markup */ assert (context->parserState.stackdepth <11); @@ -1031,7 +984,7 @@ char localbuf [HTTP_REQBUF_SZ]; XML_Parser parser = data; esiContext *context = (esiContext *)XML_GetUserData(parser); - esiElement *element; + ESIElement *element; int specifiedattcount = XML_GetSpecifiedAttributeCount (parser) * 2; char *pos; assert (ellen < sizeof (localbuf)); /* prevent unexpected overruns. */ @@ -1230,7 +1183,7 @@ esiAddLiteral (esiContext *context, const XML_Char *s, int len) { /* handle any skipped data */ - esiElement *element; + ESIElement *element; assert (len); debug (86,5)("literal length is %d\n", len); /* give a literal to the current element */ @@ -1364,87 +1317,13 @@ if (!context->flags.finishedtemplate && !context->incoming) { - context->incoming = context->buffered = cbdataAlloc (esiSegment); + context->incoming = context->buffered = new esiSegment; } PROF_stop(esiProcessing); return status; /* because we have no callbacks */ } } -/* esiSegment */ -void -esiSegmentFreeList (esiSegment **head) { - while (*head) { - esiSegment *temp = *head; - *head = temp->next; - cbdataFree (temp); - } -} - -void -esiSegmentTransferList (esiSegment **from, esiSegment **to) -{ - if (!*to) { - *to = *from; - } else { - esiSegment *temp = *to; - while (temp->next) temp = temp->next; - temp->next = *from; - } - *from = NULL; -} - -char * -esiSegmentListToChar (esiSegment *head) -{ - char *rv; - size_t len = 0, pos = 0; - esiSegment *temp; - assert (head); - temp = head; - while (temp) { - len += temp->len; - temp = temp->next; - } - rv = (char *)xmalloc (len + 1); - assert (rv); - rv [ len] = '\0'; - temp = head; - while (temp) { - xmemcpy (&rv[pos], temp->buf, temp->len); - pos += temp->len; - temp = temp->next; - } - return rv; -} - -void -esiSegmentListAppend (esiSegment **head, char const *s, size_t len) -{ - esiSegment *output; - size_t pos=0; - if (!*head) - *head = cbdataAlloc (esiSegment); - output = *head; - while (output->next) - output=output->next; - /* copy the string to output */ - while (pos < len) { - size_t amount; - if (output->len == sizeof (output->buf)) { - assert (output->next == NULL); - output->next = cbdataAlloc (esiSegment); - output = output->next; - } - amount = len - pos; - if (amount > sizeof (output->buf) - output->len) - amount = sizeof (output->buf) - output->len; - xmemcpy (&output->buf[output->len], s + pos, amount); - output->len += amount; - pos += amount; - } -} - void esiContext::freeResources () { if (rep) { @@ -1494,11 +1373,11 @@ { size_t amount; if (!outbound) { - outboundtail = outbound = cbdataAlloc (esiSegment); + outboundtail = outbound = new esiSegment; } else { /* add to tail */ assert (outboundtail->next == NULL); - outboundtail->next = cbdataAlloc (esiSegment); + outboundtail->next = new esiSegment; outboundtail = outboundtail->next; } amount = rep->body.mb.size - errorprogress; @@ -1652,7 +1531,7 @@ } while (esiStream->buffer->next) esiStream->buffer = esiStream->buffer->next; if (esiStream->buffer->len) { - esiStream->buffer->next = cbdataAlloc (esiSegment); + esiStream->buffer->next = new esiSegment; esiStream->buffer = esiStream->buffer->next; } tempBuffer.offset = http->out.offset; @@ -1691,7 +1570,7 @@ } -/* Implementation of esiElements */ +/* Implementation of ESIElements */ /* esiComment */ void @@ -1701,7 +1580,7 @@ debug (86,5)("esiCommentFree %p\n", thisNode); } -esiElement * +ESIElement * esiCommentNew () { return new esiComment; @@ -1736,7 +1615,7 @@ void esiRenderSelf (void *data, esiSegment *output) { - ((esiElement *)data)->render(output); + ((ESIElement *)data)->render(output); } void @@ -1780,7 +1659,7 @@ /* precondition: the buffer chain has at least start + length bytes of data */ -esiElement * +ESIElement * esiLiteralNew (esiContext *context, const XML_Char *s, int length) { return new esiLiteral(context, s, length); @@ -1791,7 +1670,7 @@ esiSegment *local; off_t start; assert (s); - buffer = cbdataAlloc (esiSegment); + buffer = new esiSegment; local = buffer; start = 0; while (length > 0) { @@ -1803,7 +1682,7 @@ length -= len; s += len; if (local->len == sizeof (local->buf) && length){ - local->next = cbdataAlloc (esiSegment); + local->next = new esiSegment; local=local->next; } } @@ -1878,7 +1757,7 @@ } -esiElement * +ESIElement * esiSequenceNew () { return new esiSequence; @@ -1906,7 +1785,7 @@ cbdataFree (elements[i]); } if (processedcount) { - xmemmove (elements, &elements[processedcount], (elementcount - processedcount) * sizeof (esiElement *)); + xmemmove (elements, &elements[processedcount], (elementcount - processedcount) * sizeof (ESIElement *)); } elementcount -= processedcount; processedcount = 0; @@ -1914,7 +1793,7 @@ } bool -esiSequence::addElement (esiElement *element) +esiSequence::addElement (ESIElement *element) { /* add an element to the output list */ /* Some elements require specific parents */ @@ -1933,7 +1812,7 @@ cbdataFree (element); return true; } - elements = (esiElement **)memReallocBuf (elements, ++elementcount * sizeof (esiElement *), + elements = (ESIElement **)memReallocBuf (elements, ++elementcount * sizeof (ESIElement *), &allocedsize); assert (elements); allocedcount = elementcount; @@ -2038,7 +1917,7 @@ httpHeaderClean (&tempheaders); } -esiElement * +ESIElement * esiIncludeNew (int attrcount, char const **attr, esiContext *context) { return new esiInclude (attrcount, attr, context); @@ -2148,7 +2027,7 @@ if (success) { /* copy the lead segment */ debug (86,3)("esiIncludeSubRequestDone: Src OK - include PASSED.\n"); - srccontent = cbdataAlloc (esiSegment); + srccontent = new esiSegment; xmemcpy (srccontent->buf, stream->localbuffer.buf, stream->localbuffer.len); srccontent->len = stream->localbuffer.len; srccontent->next = stream->localbuffer.next; @@ -2172,7 +2051,7 @@ if (success) { debug (86,3)("esiIncludeSubRequestDone: ALT OK.\n"); /* copy the lead segment */ - altcontent = cbdataAlloc (esiSegment); + altcontent = new esiSegment; xmemcpy (altcontent->buf, stream->localbuffer.buf, stream->localbuffer.len); altcontent->len = stream->localbuffer.len; altcontent->next = stream->localbuffer.next; @@ -2232,7 +2111,7 @@ delete this; } -esiElement * +ESIElement * esiRemoveNew () { return new esiRemove; @@ -2251,7 +2130,7 @@ /* Accept non-ESI children */ bool -esiRemove::addElement (esiElement *element) +esiRemove::addElement (ESIElement *element) { if (!dynamic_cast(element)) { debug (86,5)("esiRemoveAdd: Failed for %p\n",this); @@ -2293,7 +2172,7 @@ delete this; } -esiElement * +ESIElement * esiTryNew () { return new esiTry; @@ -2321,7 +2200,7 @@ /* Accept attempt and except only */ bool -esiTry::addElement(esiElement *element) +esiTry::addElement(ESIElement *element) { debug (86,5)("esiTryAdd: Try %p adding element %p\n",this, element); if (dynamic_cast(element)) { @@ -2437,7 +2316,7 @@ delete this; } -esiElement * +ESIElement * esiAttemptNew () { return new esiAttempt; @@ -2466,7 +2345,7 @@ delete this; } -esiElement * +ESIElement * esiExceptNew () { return new esiExcept; @@ -2495,12 +2374,12 @@ delete this; } -esiElement * +ESIElement * esiVarNew () { esiVar *rv = new esiVar; rv->flags.dovars = 1; - return (esiElement *)rv; + return (ESIElement *)rv; } /* esiVarState */ @@ -2551,7 +2430,7 @@ } char * -esiGetProductVersion (char const *s) +esiVarState::getProductVersion (char const *s) { char const *t; int len; @@ -2562,12 +2441,6 @@ return xstrndup (t, len); } -esiVarState * -esiVarStateNew (HttpHeader const *hdr, char const *uri) -{ - return new esiVarState (hdr, uri); -} - esiVarState::esiVarState (HttpHeader const *aHeader, char const *uri) : output (NULL) { @@ -2675,10 +2548,10 @@ } } else if (strstr (s, "Mozilla")) { browser = ESI_BROWSER_MOZILLA; - browserversion = esiGetProductVersion(s); + browserversion = getProductVersion(s); } else { browser = ESI_BROWSER_OTHER; - browserversion = esiGetProductVersion(s); + browserversion = getProductVersion(s); } } else { UserOs = ESI_OS_OTHER; @@ -3099,7 +2972,7 @@ delete this; } -esiElement * +ESIElement * esiChooseNew () { return new esiChoose; @@ -3125,7 +2998,7 @@ } bool -esiChoose::addElement(esiElement *element) +esiChoose::addElement(ESIElement *element) { /* add an element to the output list */ if (dynamic_cast(element)) { @@ -3147,7 +3020,7 @@ } otherwise = element; } else { - elements = (esiElement **)memReallocBuf (elements, ++elementcount * sizeof (esiElement *), + elements = (ESIElement **)memReallocBuf (elements, ++elementcount * sizeof (ESIElement *), &allocedsize); assert (elements); allocedcount = elementcount; @@ -3203,7 +3076,7 @@ delete this; } -esiElement * +ESIElement * esiWhenNew (int attrcount, const char **attr,esiVarState *varState) { esiWhen *rv = new esiWhen; @@ -3225,14 +3098,14 @@ } /* No expression ? default is not matching */ if (!expression) - return (esiElement *)rv; + return (ESIElement *)rv; varState->feedData(expression, strlen (expression)); /* expression is not our buffer */ expression = varState->extractChar (); rv->setTestResult(esiExpressionEval (expression)); safe_free (expression); - return (esiElement *)rv; + return (ESIElement *)rv; } /* esiOtherwise */ @@ -3258,7 +3131,7 @@ delete this; } -esiElement * +ESIElement * esiOtherwiseNew () { return new esiOtherwise; --- /dev/null Wed Feb 14 12:13:05 2007 +++ squid3/src/ESIElement.h Wed Feb 14 12:13:52 2007 @@ -0,0 +1,58 @@ +/* + * $Id: ESIElement.h,v 1.1.2.1 2002/11/02 23:14:10 rbcollins Exp $ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_ESIELEMENT_H +#define SQUID_ESIELEMENT_H + +class esiSegment; +typedef enum { + ESI_PROCESS_COMPLETE, + ESI_PROCESS_PENDING_WONTFAIL, + ESI_PROCESS_PENDING_MAYFAIL, + ESI_PROCESS_FAILED +} esiProcessResult_t; +struct ESIElement { + virtual bool addElement(ESIElement *) { + /* Don't accept children */ + debug (86,5)("ESIElement::addElement: Failed for %p\n",this); + return false; + } + virtual void render (esiSegment *) = 0; + /* process this element */ + virtual esiProcessResult_t process (int dovars) { + debug (86,5) ("esiProcessComplete: Processed %p\n",this); + return ESI_PROCESS_COMPLETE; + } + virtual void deleteSelf() = 0; +}; + +#endif /* SQUID_ESIELEMENT_H */ --- /dev/null Wed Feb 14 12:13:05 2007 +++ squid3/src/ESISegment.cc Wed Feb 14 12:13:52 2007 @@ -0,0 +1,136 @@ + +/* + * $Id: ESISegment.cc,v 1.1.2.1 2002/11/02 23:14:10 rbcollins Exp $ + * + * DEBUG: section 86 ESI processing + * AUTHOR: Robert Collins + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + ; but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "squid.h" +#include "ESISegment.h" + +CBDATA_TYPE(esiSegment); + +/* esiSegment */ +void +esiSegmentFreeList (esiSegment **head) { + while (*head) { + esiSegment *temp = *head; + *head = temp->next; + cbdataFree (temp); + } +} + +void +esiSegmentTransferList (esiSegment **from, esiSegment **to) +{ + if (!*to) { + *to = *from; + } else { + esiSegment *temp = *to; + while (temp->next) temp = temp->next; + temp->next = *from; + } + *from = NULL; +} + +char * +esiSegmentListToChar (esiSegment *head) +{ + char *rv; + size_t len = 0, pos = 0; + esiSegment *temp; + assert (head); + temp = head; + while (temp) { + len += temp->len; + temp = temp->next; + } + rv = (char *)xmalloc (len + 1); + assert (rv); + rv [ len] = '\0'; + temp = head; + while (temp) { + xmemcpy (&rv[pos], temp->buf, temp->len); + pos += temp->len; + temp = temp->next; + } + return rv; +} + +void +esiSegmentListAppend (esiSegment **head, char const *s, size_t len) +{ + esiSegment *output; + size_t pos=0; + if (!*head) + *head = cbdataAlloc (esiSegment); + output = *head; + while (output->next) + output=output->next; + /* copy the string to output */ + while (pos < len) { + size_t amount; + if (output->len == sizeof (output->buf)) { + assert (output->next == NULL); + output->next = cbdataAlloc (esiSegment); + output = output->next; + } + amount = len - pos; + if (amount > sizeof (output->buf) - output->len) + amount = sizeof (output->buf) - output->len; + xmemcpy (&output->buf[output->len], s + pos, amount); + output->len += amount; + pos += amount; + } +} + +void * +esiSegment::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiSegment)); + void *rv; + CBDATA_INIT_TYPE(esiSegment); + rv = (void *)cbdataAlloc (esiSegment); + return rv; +} + +void +esiSegment::operator delete (void *address) +{ + cbdataFree ((esiSegment *)address); +} + +void +esiSegment::deleteSelf() +{ + delete this; +} + --- /dev/null Wed Feb 14 12:13:05 2007 +++ squid3/src/ESISegment.h Wed Feb 14 12:13:52 2007 @@ -0,0 +1,55 @@ +/* + * $Id: ESISegment.h,v 1.1.2.1 2002/11/02 23:14:10 rbcollins Exp $ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sources; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_ESISEGMENT_H +#define SQUID_ESISEGMENT_H + +/* TODO: Factor the store memory segment management into a reusable code block + * or perhaps use membuffers here? + */ + +struct esiSegment { + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); + + char buf[HTTP_REQBUF_SZ]; + size_t len; /* how much data has been pushed into this */ + esiSegment *next; +}; + +extern void esiSegmentFreeList (esiSegment **head); +extern void esiSegmentTransferList (esiSegment **from, esiSegment **to); +extern char *esiSegmentListToChar (esiSegment *head); +extern void esiSegmentListAppend (esiSegment **head, char const *, size_t); + +#endif /* SQUID_ESISEGMENT_H */ Index: squid3/src/Makefile.am =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Makefile.am,v retrieving revision 1.4.2.1 retrieving revision 1.4.2.2 diff -u -r1.4.2.1 -r1.4.2.2 --- squid3/src/Makefile.am 31 Oct 2002 22:57:32 -0000 1.4.2.1 +++ squid3/src/Makefile.am 2 Nov 2002 23:14:10 -0000 1.4.2.2 @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.am,v 1.4.2.1 2002/10/31 22:57:32 rbcollins Exp $ +# $Id: Makefile.am,v 1.4.2.2 2002/11/02 23:14:10 rbcollins Exp $ # # Uncomment and customize the following to suit your needs: # @@ -26,8 +26,10 @@ DELAY_POOL_SOURCE = endif +ESI_ALL_SOURCE = ESI.cc ESI.h ESIElement.h ESIExpression.cc \ + ESISegment.cc ESISegment.h if USE_ESI - ESI_SOURCE = ESI.cc ESI.h ESIExpression.cc + ESI_SOURCE = $(ESI_ALL_SOURCE) else ESI_SOURCE = endif @@ -114,9 +116,7 @@ dnsserver.cc \ dns_internal.cc \ htcp.cc \ - ESI.cc \ - ESI.h \ - ESIExpression.cc \ + $(ESI_ALL_SOURCE) \ leakfinder.cc \ snmp_core.cc \ snmp_agent.cc \