--------------------- PatchSet 4790 Date: 2002/08/27 13:42:11 Author: rbcollins Branch: esi Tag: (none) Log: factor common code Members: src/HttpHdrSc.c:1.1.2.1->1.1.2.2 src/HttpHdrScTarget.c:1.1.2.2->1.1.2.3 src/http.c:1.21.2.3->1.21.2.4 src/protos.h:1.59.2.11->1.59.2.12 Index: squid/src/HttpHdrSc.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/HttpHdrSc.c,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/HttpHdrSc.c 26 Aug 2002 13:20:36 -0000 1.1.2.1 +++ squid/src/HttpHdrSc.c 27 Aug 2002 13:42:11 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: HttpHdrSc.c,v 1.1.2.1 2002/08/26 13:20:36 rbcollins Exp $ + * $Id: HttpHdrSc.c,v 1.1.2.2 2002/08/27 13:42:11 rbcollins Exp $ * * DEBUG: section 89 HTTP Cache Control Header * AUTHOR: Alex Rousskov @@ -319,3 +319,19 @@ return NULL; } +HttpHdrScTarget * +httpHdrScGetMergedTarget (HttpHdrSc *sc, const char *ourtarget) +{ + HttpHdrScTarget *sctus = httpHdrScFindTarget (sc, ourtarget); + HttpHdrScTarget *sctgeneric = httpHdrScFindTarget (sc, NULL); + HttpHdrScTarget *sctusable = httpHdrScTargetCreate (NULL); + if (sctgeneric || sctus) { + if (sctgeneric) + httpHdrScTargetMergeWith (sctusable, sctgeneric); + if (sctus) + httpHdrScTargetMergeWith (sctusable, sctus); + return sctusable; + } + httpHdrScTargetDestroy (sctusable); + return NULL; +} Index: squid/src/HttpHdrScTarget.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/HttpHdrScTarget.c,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/HttpHdrScTarget.c 26 Aug 2002 15:24:59 -0000 1.1.2.2 +++ squid/src/HttpHdrScTarget.c 27 Aug 2002 13:42:11 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: HttpHdrScTarget.c,v 1.1.2.2 2002/08/26 15:24:59 rbcollins Exp $ + * $Id: HttpHdrScTarget.c,v 1.1.2.3 2002/08/27 13:42:11 rbcollins Exp $ * * DEBUG: section 89 HTTP Cache Control Header * AUTHOR: Alex Rousskov @@ -74,19 +74,45 @@ return dup; } +/* union of two targets */ void httpHdrScTargetJoinWith(HttpHdrScTarget * sc, const HttpHdrScTarget * new_sc) { assert(sc && new_sc); - /* Don't touch the target - this is used to get the operations for a - * single surrogate - */ + /* TODO: check both targets are the same */ if (sc->max_age < 0) sc->max_age = new_sc->max_age; + if (sc->max_stale < new_sc->max_stale) + sc->max_stale = new_sc->max_stale; /* RC TODO: copy unique missing content stringlist entries */ sc->mask |= new_sc->mask; } +/* copies non-extant fields from new_sc to this sc */ +void +httpHdrScTargetMergeWith(HttpHdrScTarget * sc, const HttpHdrScTarget * new_sc) +{ + http_hdr_sc_type c; + assert(sc && new_sc); + /* Don't touch the target - this is used to get the operations for a + * single surrogate + */ + for (c = 0; c < SC_ENUM_END; c++) + if (!EBIT_TEST(sc->mask, c) && EBIT_TEST(new_sc->mask,c)) { + EBIT_SET(sc->mask, c); + switch (c) { + case SC_MAX_AGE: + sc->max_age = new_sc->max_age; + sc->max_stale = new_sc->max_stale; + case SC_CONTENT: + assert (strLen (sc->content) == 0); + sc->content = stringDup (&new_sc->content); + default: + break; + } + } +} + /* negative max_age will clean old max_Age setting */ void httpHdrScTargetSetMaxAge(HttpHdrScTarget * sc, int max_age) Index: squid/src/http.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/http.c,v retrieving revision 1.21.2.3 retrieving revision 1.21.2.4 diff -u -r1.21.2.3 -r1.21.2.4 --- squid/src/http.c 26 Aug 2002 15:24:59 -0000 1.21.2.3 +++ squid/src/http.c 27 Aug 2002 13:42:11 -0000 1.21.2.4 @@ -1,6 +1,6 @@ /* - * $Id: http.c,v 1.21.2.3 2002/08/26 15:24:59 rbcollins Exp $ + * $Id: http.c,v 1.21.2.4 2002/08/27 13:42:11 rbcollins Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -460,15 +460,8 @@ } #if ESI if (httpState->request->flags.accelerated && reply->surrogate_control) { - HttpHdrScTarget *sctus = httpHdrScFindTarget (reply->surrogate_control, - Config.Accel.surrogate_id); - HttpHdrScTarget *sctgeneric = httpHdrScFindTarget (reply->surrogate_control, NULL); - HttpHdrScTarget *sctusable = httpHdrScTargetCreate (NULL); - if (sctgeneric || sctus) { - if (sctgeneric) - httpHdrScTargetJoinWith (sctusable, sctgeneric); - if (sctus) - httpHdrScTargetJoinWith (sctusable, sctus); + HttpHdrScTarget *sctusable = httpHdrScGetMergedTarget (reply->surrogate_control, Config.Accel.surrogate_id); + if (sctusable) { if (EBIT_TEST(sctusable->mask, SC_NO_STORE) || (Config.onoff.surrogate_is_remote && EBIT_TEST(sctusable->mask, SC_NO_STORE_REMOTE))) httpMakePrivate (entry); Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.59.2.11 retrieving revision 1.59.2.12 diff -u -r1.59.2.11 -r1.59.2.12 --- squid/src/protos.h 26 Aug 2002 13:20:37 -0000 1.59.2.11 +++ squid/src/protos.h 27 Aug 2002 13:42:11 -0000 1.59.2.12 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.59.2.11 2002/08/26 13:20:37 rbcollins Exp $ + * $Id: protos.h,v 1.59.2.12 2002/08/27 13:42:11 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -416,6 +416,7 @@ extern void httpHdrScSetMaxAge(HttpHdrSc *, char const *, int); extern void httpHdrScUpdateStats(const HttpHdrSc *, StatHist *); extern HttpHdrScTarget * httpHdrScFindTarget (HttpHdrSc *sc, const char *target); +extern HttpHdrScTarget * httpHdrScGetMergedTarget (HttpHdrSc *sc, const char *ourtarget); /* Http Surrogate control header field 'targets' */ extern HttpHdrScTarget * httpHdrScTargetCreate (const char *); @@ -425,6 +426,7 @@ extern void httpHdrScTargetSetMaxAge(HttpHdrScTarget *, int); extern void httpHdrScTargetUpdateStats(const HttpHdrScTarget *, StatHist *); extern void httpHdrScTargetJoinWith(HttpHdrScTarget *, const HttpHdrScTarget *); +extern void httpHdrScTargetMergeWith(HttpHdrScTarget *, const HttpHdrScTarget *); extern void httpHdrScTargetStatDumper(StoreEntry * sentry, int idx, double val, double size, int count);