--------------------- PatchSet 122 Date: 2002/11/02 12:21:47 Author: rbcollins Branch: esi Tag: (none) Log: start refactoring esiVarState Members: src/ESI.cc:1.1.2.30->1.1.2.31 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.30 retrieving revision 1.1.2.31 diff -u -r1.1.2.30 -r1.1.2.31 --- squid3/src/ESI.cc 2 Nov 2002 11:40:56 -0000 1.1.2.30 +++ squid3/src/ESI.cc 2 Nov 2002 12:21:47 -0000 1.1.2.31 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.30 2002/11/02 11:40:56 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.31 2002/11/02 12:21:47 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -28,7 +28,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with thisNode program; if not, write to the Free Software + * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. * */ @@ -54,7 +54,7 @@ typedef struct _esiSegment { char buf[HTTP_REQBUF_SZ]; - size_t len; /* how much data has been pushed into thisNode */ + size_t len; /* how much data has been pushed into this */ struct _esiSegment *next; } esiSegment; CBDATA_TYPE(esiSegment); @@ -107,10 +107,12 @@ esiSegment *extractList(); char *extractChar(); void feedData (const char *buf, size_t len); + void buildVary (HttpReply *rep); void *operator new (size_t byteCount); void operator delete (void *address); void deleteSelf(); + void freeResources(); esiVarState (HttpHeader const *hdr, char const *uri); esiSegment *output; @@ -148,6 +150,7 @@ } UserOs; static char const * esiUserOs[]; static esiVar_t GetVar(char *s, int len); + bool validChar (char c); }; CBDATA_TYPE (esiVarState); FREE esiVarStateFree; @@ -160,7 +163,6 @@ "OTHER" }; -static void esiVarBuildVary (esiVarState *, HttpReply *); static char *esiGetProductVersion (char const *s); extern int esiExpressionEval (char const *); @@ -743,7 +745,7 @@ rep = context->rep; context->rep = NULL; /* freed downstream */ if (rep && context->varState) - esiVarBuildVary (context->varState, rep); + context->varState->buildVary (rep); { StoreIOBuffer tempBuffer = EMPTYIOBUFFER; tempBuffer.length = len; @@ -2507,18 +2509,24 @@ esiVarStateFree (void *data) { esiVarState *thisNode = (esiVarState*)data; - esiSegmentFreeList (&thisNode->output); - httpHeaderClean (&thisNode->hdr); - if (thisNode->query) { + thisNode->freeResources(); +} + +void +esiVarState::freeResources() +{ + esiSegmentFreeList (&output); + httpHeaderClean (&hdr); + if (query) { unsigned int i; - for (i = 0; i < thisNode->query_elements; ++i) { - safe_free(thisNode->query[i].var); - safe_free(thisNode->query[i].val); + for (i = 0; i < query_elements; ++i) { + safe_free(query[i].var); + safe_free(query[i].val); } - memFreeBuf (thisNode->query_sz, thisNode->query); + memFreeBuf (query_sz, query); } - safe_free (thisNode->query_string); - safe_free (thisNode->browserversion); + safe_free (query_string); + safe_free (browserversion); } void * @@ -2683,7 +2691,7 @@ esiVarState::feedData (const char *buf, size_t len) { /* TODO: if needed - tune to skip segment iteration */ - debug (86,6)("esiVarStateFeedData: accepting %d bytes\n", len); + debug (86,6)("esiVarState::feedData: accepting %d bytes\n", len); esiSegmentListAppend (&output, buf, len); } @@ -2709,9 +2717,6 @@ return rv; } -static int -esiVarChar (char c); - int httpHeaderHasListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator); @@ -2843,14 +2848,14 @@ } } -int -esiVarChar (char c) +bool +esiVarState::validChar (char c) { if (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || '_' == c || '-' == c) - return 1; - return 0; + return true; + return false; } esiVarState::esiVar_t @@ -2935,7 +2940,7 @@ } break; case 2: /* looking for variable name */ - if (!esiVarChar(string[pos])) { + if (!validChar(string[pos])) { /* not a variable name char */ if (pos - var_pos) vartype = GetVar (string + var_pos, pos - var_pos); @@ -2977,7 +2982,7 @@ debug (86,6)("esiVarStateDoIt: found end of variable subref '%s'\n", found_subref); state = 3; ++pos; - } else if (!esiVarChar (string[pos])) { + } else if (!validChar (string[pos])) { debug (86,6)("esiVarStateDoIt: found invalid char in variable subref\n"); /* not a valid subref */ safe_free(found_subref); @@ -3033,20 +3038,20 @@ } void -esiVarBuildVary (esiVarState *thisNode, HttpReply *rep) +esiVarState::buildVary (HttpReply *rep) { String strVary; char tempstr[1024]; tempstr[0]='\0'; - if (thisNode->flags.language) + if (flags.language) strcat (tempstr, "Accept-Language "); - if (thisNode->flags.cookie) + if (flags.cookie) strcat (tempstr, "Cookie "); - if (thisNode->flags.host) + if (flags.host) strcat (tempstr, "Host "); - if (thisNode->flags.referer) + if (flags.referer) strcat (tempstr, "Referer "); - if (thisNode->flags.useragent) + if (flags.useragent) strcat (tempstr, "User-Agent "); strVary = httpHeaderGetList (&rep->header, HDR_VARY); if (tempstr[0] && (!strLen (strVary) || strBuf(strVary)[0] != '*')) {