--------------------- PatchSet 118 Date: 2002/11/02 10:02:56 Author: rbcollins Branch: esi Tag: (none) Log: more method creation Members: src/ESI.cc:1.1.2.26->1.1.2.27 Index: squid3/src/ESI.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/ESI.cc,v retrieving revision 1.1.2.26 retrieving revision 1.1.2.27 diff -u -r1.1.2.26 -r1.1.2.27 --- squid3/src/ESI.cc 1 Nov 2002 21:53:42 -0000 1.1.2.26 +++ squid3/src/ESI.cc 2 Nov 2002 10:02:56 -0000 1.1.2.27 @@ -1,6 +1,6 @@ /* - * $Id: ESI.cc,v 1.1.2.26 2002/11/01 21:53:42 rbcollins Exp $ + * $Id: ESI.cc,v 1.1.2.27 2002/11/02 10:02:56 rbcollins Exp $ * * DEBUG: section 86 ESI processing * AUTHOR: Robert Collins @@ -115,7 +115,18 @@ /* Recursive uses are not supported by design */ struct _query_elem{char *var, *val;}; -typedef struct { +typedef enum { + ESI_VAR_LANGUAGE, + ESI_VAR_COOKIE, + ESI_VAR_HOST, + ESI_VAR_REFERER, + ESI_VAR_USERAGENT, + ESI_QUERY_STRING, + ESI_VAR_OTHER +} esiVar_t; +struct esiVarState { + void doIt (); + esiSegment *output; HttpHeader hdr; struct _query_elem *query; @@ -132,11 +143,13 @@ esiUserOs_t UserOs; esiBrowser_t browser; char *browserversion; -} esiVarState; +private: + void eval (esiVar_t type, char const *, char const *); +}; CBDATA_TYPE (esiVarState); FREE esiVarStateFree; static esiVarState *esiVarStateNew(HttpHeader const *, const char *uri); -static void esiVarStateDoIt (esiVarState *); + static void esiVarStateFeedData (esiVarState *, const char *buf, size_t len); static esiSegment *esiVarStateExtractList(esiVarState *); static char * esiVarStateExtractChar (esiVarState *); @@ -2501,15 +2514,6 @@ safe_free (thisNode->browserversion); } -typedef enum { - ESI_VAR_LANGUAGE, - ESI_VAR_COOKIE, - ESI_VAR_HOST, - ESI_VAR_REFERER, - ESI_VAR_USERAGENT, - ESI_QUERY_STRING, - ESI_VAR_OTHER -} esiVar_t; char * esiGetProductVersion (char const *s) @@ -2659,7 +2663,7 @@ esiVarStateExtractList(esiVarState *thisNode) { esiSegment *rv; - esiVarStateDoIt (thisNode); + thisNode->doIt(); rv = thisNode->output; thisNode->output = NULL; debug (86,6)("esiVarStateExtractList: Extracted list\n"); @@ -2672,7 +2676,7 @@ char *rv; if (!thisNode->output) fatal ("Attempt to extract variable state with no data fed in \n"); - esiVarStateDoIt (thisNode); + thisNode->doIt(); rv = esiSegmentListToChar(thisNode->output); esiSegmentFreeList (&thisNode->output); debug (86,6)("esiVarStateExtractList: Extracted char\n"); @@ -2685,9 +2689,6 @@ static esiVar_t esiGetVar(char *s, int len); -static void -esiVarEval (esiVarState *thisNode, esiVar_t type, char const *, char const *); - int httpHeaderHasListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator); @@ -2718,102 +2719,102 @@ } -static void -esiVarEval (esiVarState *thisNode, esiVar_t type, char const *subref, char const *found_default ) { +void +esiVarState::eval (esiVar_t type, char const *subref, char const *found_default ) { const char *s = NULL; if (!found_default) found_default = ""; switch (type) { case ESI_VAR_HOST: - thisNode->flags.host = 1; - if (!subref && httpHeaderHas(&thisNode->hdr,HDR_HOST)) { - s = httpHeaderGetStr (&thisNode->hdr, HDR_HOST); + flags.host = 1; + if (!subref && httpHeaderHas(&hdr,HDR_HOST)) { + s = httpHeaderGetStr (&hdr, HDR_HOST); } else s = found_default; - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); break; case ESI_VAR_COOKIE: - thisNode->flags.cookie = 1; - if (httpHeaderHas(&thisNode->hdr, HDR_COOKIE)) { + flags.cookie = 1; + if (httpHeaderHas(&hdr, HDR_COOKIE)) { if (!subref) - s = httpHeaderGetStr (&thisNode->hdr, HDR_COOKIE); + s = httpHeaderGetStr (&hdr, HDR_COOKIE); else { - String S = httpHeaderGetListMember (&thisNode->hdr, HDR_COOKIE, subref, ';'); + String S = httpHeaderGetListMember (&hdr, HDR_COOKIE, subref, ';'); if (strLen(S)) - esiSegmentListAppend (&thisNode->output, strBuf(S), strLen (S)); + esiSegmentListAppend (&output, strBuf(S), strLen (S)); else if (found_default) - esiSegmentListAppend (&thisNode->output, found_default, strlen (found_default)); + esiSegmentListAppend (&output, found_default, strlen (found_default)); stringClean (&S); } } else s = found_default; if (s) - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); break; case ESI_VAR_REFERER: - thisNode->flags.referer = 1; - if (!subref && httpHeaderHas(&thisNode->hdr, HDR_REFERER)) - s = httpHeaderGetStr (&thisNode->hdr, HDR_REFERER); + flags.referer = 1; + if (!subref && httpHeaderHas(&hdr, HDR_REFERER)) + s = httpHeaderGetStr (&hdr, HDR_REFERER); else s = found_default; - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); break; case ESI_QUERY_STRING: if (!subref) - s = thisNode->query_string; + s = query_string; else { unsigned int i = 0; - while (i < thisNode->query_elements && !s) { - if (!strcmp (subref, thisNode->query[i].var)) - s = thisNode->query[i].val; + while (i < query_elements && !s) { + if (!strcmp (subref, query[i].var)) + s = query[i].val; ++i; } if (!s) s = found_default; } - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); break; case ESI_VAR_USERAGENT: - thisNode->flags.useragent = 1; - if (httpHeaderHas(&thisNode->hdr, HDR_USER_AGENT)) { + flags.useragent = 1; + if (httpHeaderHas(&hdr, HDR_USER_AGENT)) { if (!subref) - s = httpHeaderGetStr (&thisNode->hdr, HDR_USER_AGENT); + s = httpHeaderGetStr (&hdr, HDR_USER_AGENT); else { if (!strcmp (subref, "os")) { - s = esiUserOs[thisNode->UserOs]; + s = esiUserOs[UserOs]; } else if (!strcmp (subref, "browser")) { - s = esiBrowsers[thisNode->browser]; + s = esiBrowsers[browser]; } else if (!strcmp (subref, "version")) { - s = thisNode->browserversion; + s = browserversion; } else s = ""; } } else s = found_default; - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); break; case ESI_VAR_LANGUAGE: - thisNode->flags.language = 1; - if (httpHeaderHas(&thisNode->hdr, HDR_ACCEPT_LANGUAGE)) { + flags.language = 1; + if (httpHeaderHas(&hdr, HDR_ACCEPT_LANGUAGE)) { if (!subref) { - String S = httpHeaderGetList (&thisNode->hdr, HDR_ACCEPT_LANGUAGE); - esiSegmentListAppend (&thisNode->output, strBuf(S), strLen (S)); + String S = httpHeaderGetList (&hdr, HDR_ACCEPT_LANGUAGE); + esiSegmentListAppend (&output, strBuf(S), strLen (S)); stringClean (&S); } else { - if (httpHeaderHasListMember (&thisNode->hdr, HDR_ACCEPT_LANGUAGE, subref, ',')) { + if (httpHeaderHasListMember (&hdr, HDR_ACCEPT_LANGUAGE, subref, ',')) { s = "true"; } else { s = "false"; } - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); } } else { s = found_default; - esiSegmentListAppend (&thisNode->output, s, strlen (s)); + esiSegmentListAppend (&output, s, strlen (s)); } break; case ESI_VAR_OTHER: /* No-op. We swallow it */ if (found_default) { - esiSegmentListAppend (&thisNode->output, found_default, strlen (found_default)); + esiSegmentListAppend (&output, found_default, strlen (found_default)); } break; } @@ -2876,10 +2877,10 @@ * of output data preparation */ void -esiVarStateDoIt (esiVarState *thisNode) +esiVarState::doIt () { int state = 0; - char *string = esiSegmentListToChar(thisNode->output); + char *string = esiSegmentListToChar(output); size_t len = strlen (string); size_t pos = 0; size_t var_pos = 0; @@ -2887,7 +2888,7 @@ char * found_subref = NULL; char *found_default = NULL; esiVar_t vartype = ESI_VAR_OTHER; - esiSegmentFreeList (&thisNode->output); + esiSegmentFreeList (&output); while (pos < len) { switch (state) { case 0: /* skipping pre-variables */ @@ -2896,7 +2897,7 @@ } else { if (pos - done_pos) /* extract known good text */ - esiSegmentListAppend (&thisNode->output, string + done_pos, pos - done_pos); + esiSegmentListAppend (&output, string + done_pos, pos - done_pos); done_pos = pos; state = 1; ++pos; @@ -2923,7 +2924,7 @@ case 3: /* looking for variable subref, end bracket or default indicator */ if (string[pos] == ')') { /* end of string */ - esiVarEval (thisNode, vartype, found_subref, found_default); + eval(vartype, found_subref, found_default); done_pos = ++pos; safe_free(found_subref); safe_free(found_default); @@ -2990,7 +2991,7 @@ /* end of default - end of variable*/ found_default = xstrndup (&string[var_pos], pos - var_pos + 1); debug (86,6)("esiVarStateDoIt: found end of variable (w/ unquoted default) '%s'\n",found_default); - esiVarEval (thisNode, vartype,found_subref, found_default); + eval(vartype,found_subref, found_default); done_pos = ++pos; safe_free(found_default); safe_free(found_subref); @@ -3003,7 +3004,7 @@ } /* pos-done_pos chars are ready to copy */ if (pos-done_pos) - esiSegmentListAppend (&thisNode->output, string+done_pos, pos - done_pos); + esiSegmentListAppend (&output, string+done_pos, pos - done_pos); safe_free (found_default); safe_free (found_subref); }