--------------------- PatchSet 119 Date: 2002/11/02 10:27:23 Author: rbcollins Branch: esi Tag: (none) Log: more method creation Members: src/ESI.cc:1.1.2.27->1.1.2.28 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.27 retrieving revision 1.1.2.28 diff -u -r1.1.2.27 -r1.1.2.28 --- squid3/src/ESI.cc 2 Nov 2002 10:02:56 -0000 1.1.2.27 +++ squid3/src/ESI.cc 2 Nov 2002 10:27:23 -0000 1.1.2.28 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.27 2002/11/02 10:02:56 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.28 2002/11/02 10:27:23 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -125,7 +125,12 @@ ESI_VAR_OTHER } esiVar_t; struct esiVarState { - void doIt (); + esiSegment *extractList(); + char *extractChar(); + void *operator new (size_t byteCount); + void operator delete (void *address); + void deleteSelf(); + esiVarState::esiVarState (HttpHeader const *hdr, char const *uri); esiSegment *output; HttpHeader hdr; @@ -144,6 +149,7 @@ esiBrowser_t browser; char *browserversion; private: + void doIt (); void eval (esiVar_t type, char const *, char const *); }; CBDATA_TYPE (esiVarState); @@ -151,8 +157,6 @@ static esiVarState *esiVarStateNew(HttpHeader const *, const char *uri); static void esiVarStateFeedData (esiVarState *, const char *buf, size_t len); -static esiSegment *esiVarStateExtractList(esiVarState *); -static char * esiVarStateExtractChar (esiVarState *); static void esiVarBuildVary (esiVarState *, HttpReply *); static char *esiGetProductVersion (char const *s); @@ -1826,7 +1830,7 @@ } /* free the pre-processed content */ esiSegmentFreeList (&buffer); - buffer = esiVarStateExtractList (varState); + buffer = varState->extractList (); } flags.donevars = 1; return ESI_PROCESS_COMPLETE; @@ -2022,7 +2026,7 @@ esiVarStateFeedData(vars, url, strlen (url)); safe_free (url); /* url is eaten by the request */ - url = esiVarStateExtractChar (vars); + url = vars->extractChar (); debug (86,5)("esiIncludeStart: Starting subrequest with url '%s'\n", url); if (clientBeginRequest(METHOD_GET, url, esiBufferRecipient, esiBufferDetach, stream, &tempheaders, stream->localbuffer.buf, HTTP_REQBUF_SZ)) { debug (86,0) ("starting new ESI subrequest failed\n"); @@ -2514,6 +2518,27 @@ safe_free (thisNode->browserversion); } +void * +esiVarState::operator new(size_t byteCount) +{ + assert (byteCount == sizeof (esiVarState)); + void *rv; + CBDATA_INIT_TYPE_FREECB(esiVarState, esiVarStateFree); + rv = (void *)cbdataAlloc (esiVarState); + return rv; +} + +void +esiVarState::operator delete (void *address) +{ + cbdataFree ((esiVarState *)address); +} + +void +esiVarState::deleteSelf() +{ + delete this; +} char * esiGetProductVersion (char const *s) @@ -2530,29 +2555,31 @@ esiVarState * esiVarStateNew (HttpHeader const *hdr, char const *uri) { - esiVarState *rv; + return new esiVarState (hdr, uri); +} + +esiVarState::esiVarState (HttpHeader const *aHeader, char const *uri) +{ char const *query_pos; char const *query_start; - CBDATA_INIT_TYPE_FREECB(esiVarState, esiVarStateFree); - rv = cbdataAlloc (esiVarState); /* Fill out variable values */ /* TODO: only grab the needed headers */ - httpHeaderInit (&rv->hdr, hoReply); - httpHeaderAppend (&rv->hdr, hdr); + httpHeaderInit (&hdr, hoReply); + httpHeaderAppend (&hdr, aHeader); /* Count off the query elements */ query_start = strchr (uri, '?'); if (query_start && query_start[1] != '\0' ) { unsigned int n; - rv->query_string = xstrdup (query_start + 1); - rv->query_elements = 1; + query_string = xstrdup (query_start + 1); + query_elements = 1; query_pos = query_start + 1; while ((query_pos = strchr (query_pos, '&'))) { - ++rv->query_elements; + ++query_elements; ++query_pos; } - rv->query = (_query_elem *)memReallocBuf(rv->query, rv->query_elements * sizeof (struct _query_elem), - &rv->query_sz); + query = (_query_elem *)memReallocBuf(query, query_elements * sizeof (struct _query_elem), + &query_sz); query_pos = query_start + 1; n = 0; while (query_pos) { @@ -2560,30 +2587,30 @@ char *div = strchr (query_pos, '='); if (next) ++next; - assert (n < rv->query_elements); + assert (n < query_elements); if (!div) div = next; if (!(div - query_pos + 1)) /* zero length between & and = or & and & */ continue; - rv->query[n].var = xstrndup (query_pos, div - query_pos + 1) ; + query[n].var = xstrndup (query_pos, div - query_pos + 1) ; if (div == next) { - rv->query[n].val = xstrdup (""); + query[n].val = xstrdup (""); } else { - rv->query[n].val = xstrndup (div + 1, next - div - 1); + query[n].val = xstrndup (div + 1, next - div - 1); } query_pos = next; ++n; } } else { - rv->query_string = xstrdup (""); + query_string = xstrdup (""); } - if (rv->query) { + if (query) { unsigned int n = 0; debug (86,6)("esiVarStateNew: Parsed Query string: '%s'\n",uri); - while (n < rv->query_elements) { - debug (86,6)("esiVarStateNew: Parsed Query element %d '%s'='%s'\n",n + 1, rv->query[n].var, rv->query[n].val); + while (n < query_elements) { + debug (86,6)("esiVarStateNew: Parsed Query element %d '%s'='%s'\n",n + 1, query[n].var, query[n].val); ++n; } } @@ -2611,44 +2638,42 @@ * if MOZILLA doesn't appear, the browser is set to OTHER. * In future, thisNode may be better implemented as a regexp. */ - if (httpHeaderHas(&rv->hdr, HDR_USER_AGENT)) { - char const *s = httpHeaderGetStr (&rv->hdr, HDR_USER_AGENT); + if (httpHeaderHas(&hdr, HDR_USER_AGENT)) { + char const *s = httpHeaderGetStr (&hdr, HDR_USER_AGENT); char const *t, *t1; if (strstr (s, "Windows")) - rv->UserOs = ESI_OS_WIN; + UserOs = ESI_OS_WIN; else if (strstr (s, "Mac")) - rv->UserOs = ESI_OS_MAC; + UserOs = ESI_OS_MAC; else if (strstr (s, "nix") || strstr (s, "BSD")) - rv->UserOs = ESI_OS_UNIX; + UserOs = ESI_OS_UNIX; else - rv->UserOs = ESI_OS_OTHER; + UserOs = ESI_OS_OTHER; /* Now the browser and version */ if ((t = strstr (s, "MSIE"))) { - rv->browser = ESI_BROWSER_MSIE; + browser = ESI_BROWSER_MSIE; t = index (t, ' '); if (!t) - rv->browserversion = xstrdup (""); + browserversion = xstrdup (""); else { t1 = index (t, ';'); if (!t1) - rv->browserversion = xstrdup (t + 1); + browserversion = xstrdup (t + 1); else - rv->browserversion = xstrndup (t + 1, t1-t); + browserversion = xstrndup (t + 1, t1-t); } } else if (strstr (s, "Mozilla")) { - rv->browser = ESI_BROWSER_MOZILLA; - rv->browserversion = esiGetProductVersion(s); + browser = ESI_BROWSER_MOZILLA; + browserversion = esiGetProductVersion(s); } else { - rv->browser = ESI_BROWSER_OTHER; - rv->browserversion = esiGetProductVersion(s); + browser = ESI_BROWSER_OTHER; + browserversion = esiGetProductVersion(s); } } else { - rv->UserOs = ESI_OS_OTHER; - rv->browser = ESI_BROWSER_OTHER; - rv->browserversion = xstrdup (""); + UserOs = ESI_OS_OTHER; + browser = ESI_BROWSER_OTHER; + browserversion = xstrdup (""); } - - return rv; } void @@ -2660,25 +2685,23 @@ } esiSegment * -esiVarStateExtractList(esiVarState *thisNode) +esiVarState::extractList() { - esiSegment *rv; - thisNode->doIt(); - rv = thisNode->output; - thisNode->output = NULL; + doIt(); + esiSegment *rv = output; + output = NULL; debug (86,6)("esiVarStateExtractList: Extracted list\n"); return rv; } char * -esiVarStateExtractChar (esiVarState *thisNode) +esiVarState::extractChar () { - char *rv; - if (!thisNode->output) + if (!output) fatal ("Attempt to extract variable state with no data fed in \n"); - thisNode->doIt(); - rv = esiSegmentListToChar(thisNode->output); - esiSegmentFreeList (&thisNode->output); + doIt(); + char *rv = esiSegmentListToChar(output); + esiSegmentFreeList (&output); debug (86,6)("esiVarStateExtractList: Extracted char\n"); return rv; } @@ -3200,7 +3223,7 @@ esiVarStateFeedData(varState, expression, strlen (expression)); /* expression is not our buffer */ - expression = esiVarStateExtractChar (varState); + expression = varState->extractChar (); rv->setTestResult(esiExpressionEval (expression)); safe_free (expression); return (esiElement *)rv;