From 45a58345470e2cbc94f334f077c7094fb9729525 Mon Sep 17 00:00:00 2001 From: Francesco Chemolli Date: Sat, 3 Dec 2011 13:40:23 +0100 Subject: [PATCH] Merge: Surrogate-Control c++ refactoring. --- compat/Makefile.am | 2 + src/HttpHdrSc.cc | 217 +++++++++++++++++++---------------------- src/HttpHdrSc.h | 32 +++--- src/HttpHdrScTarget.cc | 104 +++----------------- src/HttpHdrScTarget.h | 93 ++++++++++++++---- src/HttpHeader.cc | 8 +- src/HttpReply.cc | 2 +- src/esi/Esi.cc | 10 +- src/htcp.cc | 1 + src/http.cc | 16 +-- 10 files changed, 232 insertions(+), 253 deletions(-) diff --git a/compat/Makefile.am b/compat/Makefile.am index 7b3f7b8cfc..c9a72487d0 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -39,6 +39,8 @@ libcompat_squid_a_SOURCES = \ strnstr.cc \ strsep.h \ strtoll.h \ + strnrchr.h \ + strnrchr.c \ tempnam.h \ types.h \ unsafe.h \ diff --git a/src/HttpHdrSc.cc b/src/HttpHdrSc.cc index 3ee98faf55..8ad07c49ef 100644 --- a/src/HttpHdrSc.cc +++ b/src/HttpHdrSc.cc @@ -6,6 +6,7 @@ * AUTHOR: Alex Rousskov * Robert Collins (Surrogate-Control is derived from * Cache-Control). + * Francesco Chemolli (c++ refactoring) * * SQUID Web Proxy Cache http://www.squid-cache.org/ * ---------------------------------------------------------- @@ -40,10 +41,22 @@ #include "HttpHeader.h" #include "HttpHdrSc.h" +#if HAVE_MAP +#include +#endif + +/* a row in the table used for parsing surrogate-control header and statistics */ +typedef struct { + const char *name; + http_hdr_sc_type id; + HttpHeaderFieldStat stat; +} HttpHeaderScFields; + /* this table is used for parsing surrogate control header */ +/* order must match that of enum http_hdr_sc_type. The constraint is verified at initialization time */ +//todo: implement constraint static const HttpHeaderFieldAttrs ScAttrs[SC_ENUM_END] = { {"no-store", (http_hdr_type)SC_NO_STORE}, - {"no-store-remote", (http_hdr_type)SC_NO_STORE_REMOTE}, {"max-age", (http_hdr_type)SC_MAX_AGE}, {"content", (http_hdr_type)SC_CONTENT}, @@ -65,9 +78,6 @@ int operator - (http_hdr_sc_type const &anSc, http_hdr_sc_type const &anSc2) } -/* local prototypes */ -static int httpHdrScParseInit(HttpHdrSc * sc, const String * str); - /* module initialization */ void @@ -85,20 +95,14 @@ httpHdrScCleanModule(void) /* implementation */ -HttpHdrSc * -httpHdrScCreate(void) -{ - return new HttpHdrSc(); -} - /* creates an sc object from a 0-terminating string */ HttpHdrSc * -httpHdrScParseCreate(const String * str) +httpHdrScParseCreate(const String & str) { - HttpHdrSc *sc = httpHdrScCreate(); + HttpHdrSc *sc = new HttpHdrSc(); - if (!httpHdrScParseInit(sc, str)) { - httpHdrScDestroy(sc); + if (!sc->parse(&str)) { + delete sc; sc = NULL; } @@ -106,9 +110,10 @@ httpHdrScParseCreate(const String * str) } /* parses a 0-terminating string and inits sc */ -static int -httpHdrScParseInit(HttpHdrSc * sc, const String * str) +bool +HttpHdrSc::parse(const String * str) { + HttpHdrSc * sc=this; const char *item; const char *p; /* '=' parameter */ const char *pos = NULL; @@ -118,7 +123,7 @@ httpHdrScParseInit(HttpHdrSc * sc, const String * str) int ilen, vlen; int initiallen; HttpHdrScTarget *sct; - assert(sc && str); + assert(str); /* iterate through comma separated list */ @@ -138,6 +143,7 @@ httpHdrScParseInit(HttpHdrSc * sc, const String * str) ilen = p++ - item; /* find type */ + /* TODO: use a type-safe map-based lookup */ type = httpHeaderIdByName(item, ilen, ScFieldsInfo, SC_ENUM_END); @@ -147,7 +153,7 @@ httpHdrScParseInit(HttpHdrSc * sc, const String * str) } /* Is this a targeted directive? */ - /* TODO sometime: implement a strnrchr that looks at a substring */ + /* TODO: remove the temporary useage and use memrchr and the information we have instead */ temp = xstrndup (item, initiallen + 1); if (!((target = strrchr (temp, ';')) && !strchr (target, '"') && *(target + 1) != '\0')) @@ -155,16 +161,16 @@ httpHdrScParseInit(HttpHdrSc * sc, const String * str) else ++target; - sct = httpHdrScFindTarget (sc, target); + sct = sc->findTarget(target); if (!sct) { - sct = httpHdrScTargetCreate (target); - dlinkAdd(sct, &sct->node, &sc->targets); + sct = new HttpHdrScTarget(target); + addTarget(sct); } safe_free (temp); - if (EBIT_TEST(sct->mask, type)) { + if (sct->isSet(static_cast(type))) { if (type != SC_OTHER) debugs(90, 2, "hdr sc: ignoring duplicate control-directive: near '" << item << "' in '" << str << "'"); @@ -173,37 +179,51 @@ httpHdrScParseInit(HttpHdrSc * sc, const String * str) continue; } - /* update mask */ - EBIT_SET(sct->mask, type); - - /* post-processing special cases */ + /* process directives */ switch (type) { + case SC_NO_STORE: + sct->noStore(true); + break; - case SC_MAX_AGE: - - if (!p || !httpHeaderParseInt(p, &sct->max_age)) { - debugs(90, 2, "sc: invalid max-age specs near '" << item << "'"); - sct->max_age = -1; - EBIT_CLR(sct->mask, type); - } - - if ((p = strchr (p, '+'))) - if (!httpHeaderParseInt(++p, &sct->max_stale)) { - debugs(90, 2, "sc: invalid max-stale specs near '" << item << "'"); - sct->max_stale = 0; - /* leave the max-age alone */ - } - + case SC_NO_STORE_REMOTE: + sct->noStoreRemote(true); break; + case SC_MAX_AGE: + { + int ma; + if (p && httpHeaderParseInt(p, &ma)) { + sct->maxAge(ma); + } else { + debugs(90, 2, "sc: invalid max-age specs near '" << item << "'"); + sct->clearMaxAge(); + } + + if ((p = strchr (p, '+'))) { + int ms; + ++p; //skip the + char + if (httpHeaderParseInt(p, &ms)) { + sct->maxStale(ms); + } else { + debugs(90, 2, "sc: invalid max-stale specs near '" << item << "'"); + sct->clearMaxStale(); + /* leave the max-age alone */ + } + } + break; + } + case SC_CONTENT: - if (!p || !httpHeaderParseQuotedString(p, vlen, &sct->content)) { + if ( p && httpHeaderParseQuotedString(p, vlen, &sct->content_)) { + sct->setMask(SC_CONTENT,true); // ugly but saves a copy + } else { debugs(90, 2, "sc: invalid content= quoted string near '" << item << "'"); - sct->content.clean(); - EBIT_CLR(sct->mask, type); + sct->clearContent(); } + break; + case SC_OTHER: default: break; } @@ -212,53 +232,41 @@ httpHdrScParseInit(HttpHdrSc * sc, const String * str) return sc->targets.head != NULL; } -void -httpHdrScDestroy(HttpHdrSc * sc) +HttpHdrSc::~HttpHdrSc() { - assert(sc); - - if (sc->targets.head) { - dlink_node *sct = sc->targets.head; + if (targets.head) { + dlink_node *sct = targets.head; while (sct) { - HttpHdrScTarget *t = (HttpHdrScTarget *)sct->data; + HttpHdrScTarget *t = static_cast(sct->data); sct = sct->next; - dlinkDelete (&t->node, &sc->targets); - httpHdrScTargetDestroy (t); + dlinkDelete (&t->node, &targets); + delete t; } } - - delete sc; } -HttpHdrSc * -httpHdrScDup(const HttpHdrSc * sc) + +HttpHdrSc::HttpHdrSc(const HttpHdrSc &sc) { - HttpHdrSc *dup; - dlink_node *node; - assert(sc); - node = sc->targets.head; - dup = httpHdrScCreate(); + dlink_node *node = sc.targets.head; while (node) { - HttpHdrScTarget *dupsct; - dupsct = httpHdrScTargetDup ((HttpHdrScTarget *)node->data); - dlinkAddTail (dupsct, &dupsct->node, &dup->targets); + HttpHdrScTarget *dupsct = new HttpHdrScTarget(*static_cast(node->data)); + addTargetAtTail(dupsct); node = node->next; } - - return dup; } void -httpHdrScTargetPackInto(const HttpHdrScTarget * sc, Packer * p) +HttpHdrScTarget::packInto(Packer * p) const { http_hdr_sc_type flag; int pcount = 0; - assert(sc && p); + assert (p); for (flag = SC_NO_STORE; flag < SC_ENUM_END; ++flag) { - if (EBIT_TEST(sc->mask, flag) && flag != SC_OTHER) { + if (isSet(flag) && flag != SC_OTHER) { /* print option name */ packerPrintf(p, (pcount ? ", " SQUIDSTRINGPH : SQUIDSTRINGPH), @@ -267,73 +275,53 @@ httpHdrScTargetPackInto(const HttpHdrScTarget * sc, Packer * p) /* handle options with values */ if (flag == SC_MAX_AGE) - packerPrintf(p, "=%d", (int) sc->max_age); + packerPrintf(p, "=%d", (int) max_age); if (flag == SC_CONTENT) - packerPrintf(p, "=\"" SQUIDSTRINGPH "\"", SQUIDSTRINGPRINT(sc->content)); + packerPrintf(p, "=\"" SQUIDSTRINGPH "\"", SQUIDSTRINGPRINT(content_)); pcount++; } } - if (sc->target.size()) - packerPrintf (p, ";" SQUIDSTRINGPH, SQUIDSTRINGPRINT(sc->target)); + if (hasTarget()) + packerPrintf (p, ";" SQUIDSTRINGPH, SQUIDSTRINGPRINT(target)); } void -httpHdrScPackInto(const HttpHdrSc * sc, Packer * p) +HttpHdrSc::packInto(Packer * p) const { dlink_node *node; - assert(sc && p); - node = sc->targets.head; + assert(p); + node = targets.head; while (node) { - httpHdrScTargetPackInto((HttpHdrScTarget *)node->data, p); + static_cast(node->data)->packInto(p); node = node->next; } } -void -httpHdrScJoinWith(HttpHdrSc * sc, const HttpHdrSc * new_sc) -{ - assert(sc && new_sc); -#if 0 - /* RC TODO: check that both have the same target */ - - if (sc->max_age < 0) - sc->max_age = new_sc->max_age; - - /* RC TODO: copy unique missing stringlist entries */ - cc->mask |= new_cc->mask; - -#endif -} - /* negative max_age will clean old max_Age setting */ void -httpHdrScSetMaxAge(HttpHdrSc * sc, char const *target, int max_age) +HttpHdrSc::setMaxAge(char const *target, int max_age) { - HttpHdrScTarget *sct; - assert(sc); - sct = httpHdrScFindTarget (sc, target); + HttpHdrScTarget *sct = findTarget(target); if (!sct) { - sct = httpHdrScTargetCreate (target); - dlinkAddTail (sct, &sct->node, &sc->targets); + sct = new HttpHdrScTarget(target); + dlinkAddTail (sct, &sct->node, &targets); } - httpHdrScTargetSetMaxAge(sct, max_age); + sct->maxAge(max_age); } void -httpHdrScUpdateStats(const HttpHdrSc * sc, StatHist * hist) +HttpHdrSc::updateStats(StatHist * hist) const { - dlink_node *sct; - assert(sc); - sct = sc->targets.head; + dlink_node *sct = targets.head; while (sct) { - httpHdrScTargetUpdateStats((HttpHdrScTarget *)sct->data, hist); + static_cast(sct->data)->updateStats(hist); sct = sct->next; } } @@ -365,11 +353,10 @@ httpHdrScStatDumper(StoreEntry * sentry, int idx, double val, double size, int c } HttpHdrScTarget * -httpHdrScFindTarget (HttpHdrSc *sc, const char *target) +HttpHdrSc::findTarget(const char *target) { dlink_node *node; - assert (sc); - node = sc->targets.head; + node = targets.head; while (node) { HttpHdrScTarget *sct = (HttpHdrScTarget *)node->data; @@ -386,19 +373,19 @@ httpHdrScFindTarget (HttpHdrSc *sc, const char *target) } HttpHdrScTarget * -httpHdrScGetMergedTarget (HttpHdrSc *sc, const char *ourtarget) +HttpHdrSc::getMergedTarget(const char *ourtarget) { - HttpHdrScTarget *sctus = httpHdrScFindTarget (sc, ourtarget); - HttpHdrScTarget *sctgeneric = httpHdrScFindTarget (sc, NULL); + HttpHdrScTarget *sctus = findTarget(ourtarget); + HttpHdrScTarget *sctgeneric = findTarget(NULL); if (sctgeneric || sctus) { - HttpHdrScTarget *sctusable = httpHdrScTargetCreate (NULL); + HttpHdrScTarget *sctusable = new HttpHdrScTarget(NULL); if (sctgeneric) - httpHdrScTargetMergeWith (sctusable, sctgeneric); + sctusable->mergeWith(sctgeneric); if (sctus) - httpHdrScTargetMergeWith (sctusable, sctus); + sctusable->mergeWith(sctus); return sctusable; } diff --git a/src/HttpHdrSc.h b/src/HttpHdrSc.h index 9fa65cc859..d26bd9c175 100644 --- a/src/HttpHdrSc.h +++ b/src/HttpHdrSc.h @@ -43,8 +43,27 @@ class HttpHdrSc { public: + HttpHdrSc(const HttpHdrSc &); + HttpHdrSc() {} + ~HttpHdrSc(); + + bool parse(const String *str); + void packInto(Packer * p) const; + void updateStats(StatHist *) const; + HttpHdrScTarget * getMergedTarget (const char *ourtarget); //todo: make const? + void setMaxAge(char const *target, int max_age); + void addTarget(HttpHdrScTarget *t) { + dlinkAdd(t, &t->node, &targets); + } + void addTargetAtTail(HttpHdrScTarget *t) { + dlinkAddTail (t, &t->node, &targets); + } + MEMPROXY_CLASS(HttpHdrSc); dlink_list targets; +private: + HttpHdrScTarget * findTarget (const char *target); + }; MEMPROXY_CLASS_INLINE(HttpHdrSc); @@ -53,18 +72,7 @@ MEMPROXY_CLASS_INLINE(HttpHdrSc); extern void httpHdrScStatDumper(StoreEntry * sentry, int idx, double val, double size, int count); extern void httpHdrScInitModule (void); extern void httpHdrScCleanModule (void); -extern HttpHdrSc *httpHdrScCreate(void); -extern HttpHdrSc *httpHdrScParseCreate(String const *); -extern void httpHdrScDestroy(HttpHdrSc * sc); -extern HttpHdrSc *httpHdrScDup(const HttpHdrSc * sc); -extern void httpHdrScPackInto(const HttpHdrSc * sc, Packer * p); -extern void httpHdrScJoinWith(HttpHdrSc *, const HttpHdrSc *); +extern HttpHdrSc *httpHdrScParseCreate(String const &); 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); - -extern void httpHeaderPutSc(HttpHeader *hdr, const HttpHdrSc *sc); -extern HttpHdrSc *httpHeaderGetSc(const HttpHeader *hdr); #endif /* SQUID_HTTPHDRSURROGATECONTROL_H */ diff --git a/src/HttpHdrScTarget.cc b/src/HttpHdrScTarget.cc index c6382cbddd..8b2f12a0c7 100644 --- a/src/HttpHdrScTarget.cc +++ b/src/HttpHdrScTarget.cc @@ -38,114 +38,38 @@ #include "squid.h" #include "HttpHdrSc.h" -/* local prototypes */ - -/* module initialization */ - -/* implementation */ - -HttpHdrScTarget * -httpHdrScTargetCreate(char const *target) -{ - HttpHdrScTarget *sc = new HttpHdrScTarget(); - sc->max_age = -1; - /* max_stale is specified as 0 if not specified in the header */ - sc->target = target; - return sc; -} - -void -httpHdrScTargetDestroy(HttpHdrScTarget * sc) -{ - assert(sc); - sc->target.clean(); - sc->content.clean(); - delete sc; -} - -HttpHdrScTarget * -httpHdrScTargetDup(const HttpHdrScTarget * sc) -{ - HttpHdrScTarget *dup; - assert(sc); - dup = httpHdrScTargetCreate(sc->target.termedBuf()); - dup->mask = sc->mask; - dup->max_age = sc->max_age; - dup->content = sc->content; - return dup; -} - -/* union of two targets */ -void -httpHdrScTargetJoinWith(HttpHdrScTarget * sc, const HttpHdrScTarget * new_sc) -{ - assert(sc && new_sc); - /* 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; -} - extern http_hdr_sc_type &operator++ (http_hdr_sc_type &aHeader); -extern int operator - (http_hdr_sc_type const &anSc, http_hdr_sc_type const &anSc2); /* copies non-extant fields from new_sc to this sc */ void -httpHdrScTargetMergeWith(HttpHdrScTarget * sc, const HttpHdrScTarget * new_sc) +HttpHdrScTarget::mergeWith(const HttpHdrScTarget * new_sc) { - http_hdr_sc_type c; - assert(sc && new_sc); + assert(new_sc); /* Don't touch the target - this is used to get the operations for a * single surrogate */ - for (c = SC_NO_STORE; 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; - break; + if (new_sc->hasNoStore()) + noStore(true); - case SC_CONTENT: - assert (sc->content.size() == 0); - sc->content = new_sc->content; - break; + if (new_sc->hasNoStoreRemote()) + noStoreRemote(true); - default: - break; - } - } -} + if (new_sc->hasMaxAge() && !hasMaxAge()) { + maxAge(new_sc->maxAge()); + maxStale(new_sc->maxStale()); + } -/* negative max_age will clean old max_Age setting */ -void -httpHdrScTargetSetMaxAge(HttpHdrScTarget * sc, int max_age) -{ - assert(sc); - sc->max_age = max_age; + if (new_sc->hasContent() && !hasContent()) + Content(new_sc->content()); - if (max_age >= 0) - EBIT_SET(sc->mask, SC_MAX_AGE); - else - EBIT_CLR(sc->mask, SC_MAX_AGE); } void -httpHdrScTargetUpdateStats(const HttpHdrScTarget * sc, StatHist * hist) +HttpHdrScTarget::updateStats(StatHist * hist) const { http_hdr_sc_type c; - assert(sc); for (c = SC_NO_STORE; c < SC_ENUM_END; ++c) - if (EBIT_TEST(sc->mask, c)) + if (isSet(c)) statHistCount(hist, c); } diff --git a/src/HttpHdrScTarget.h b/src/HttpHdrScTarget.h index 9348afb104..91ce11cbb3 100644 --- a/src/HttpHdrScTarget.h +++ b/src/HttpHdrScTarget.h @@ -35,42 +35,99 @@ class Packer; class StoreEntry; -/* for MEMPROXY_CLASS() macros */ #include "MemPool.h" -/* for dlink_node */ #include "dlink.h" -/* for String */ #include "SquidString.h" +#include "typedefs.h" -/** HTTP Surogate-Control: header field */ +/** Representation of HTTP Surogate-Control header field targeted directive + * + * \see HttpHdrSc + */ class HttpHdrScTarget { + // parsing is done in HttpHdrSc, need to grant them access. + friend class HttpHdrSc; public: + static const int MAX_AGE_UNSET=-1; //max-age is unset + static const int MAX_STALE_UNSET=0; //max-stale is unset + + HttpHdrScTarget(const char *target_): + mask(0), max_age(MAX_AGE_UNSET), max_stale(MAX_STALE_UNSET),target(target_) {} + HttpHdrScTarget(const String &target_): + mask(0), max_age(MAX_AGE_UNSET), max_stale(MAX_STALE_UNSET),target(target_) {} + HttpHdrScTarget(const HttpHdrScTarget &t): + mask(t.mask), max_age(t.max_age), max_stale(t.max_stale), + content_(t.content_), target(t.target) {} + + bool hasNoStore() const {return isSet(SC_NO_STORE); } + void noStore(bool v) { setMask(SC_NO_STORE,v); } + bool noStore() const { return isSet(SC_NO_STORE); } + void clearNoStore() { setMask(SC_NO_STORE, false); } + + bool hasNoStoreRemote() const {return isSet(SC_NO_STORE_REMOTE); } + void noStoreRemote(bool v) { setMask(SC_NO_STORE_REMOTE,v); } + bool noStoreRemote() const { return isSet(SC_NO_STORE_REMOTE); } + void clearNoStoreRemote() { setMask(SC_NO_STORE_REMOTE, false); } + + bool hasMaxAge() const { return isSet(SC_MAX_AGE); } + void maxAge(int v) { + if (v >= 0) { //setting + setMask(SC_MAX_AGE,true); + max_age=v; + } else { + setMask(SC_MAX_AGE,false); + max_age=MAX_AGE_UNSET; + } + } + int maxAge() const { return max_age; } + void clearMaxAge() { setMask(SC_MAX_AGE,false); max_age=MAX_AGE_UNSET; } + + //max_stale has no associated status-bit + bool hasMaxStale() const { return max_stale != MAX_STALE_UNSET; } + void maxStale(int v) { max_stale=v; } + int maxStale() const { return max_stale; } + void clearMaxStale() { max_stale=MAX_STALE_UNSET; } + + bool hasContent() const { return isSet(SC_CONTENT); } + void Content(const String &v) { + setMask(SC_CONTENT,true); + content_=v; + } + String content() const { return content_; } + void clearContent() { setMask(SC_CONTENT,false); content_.clean(); } + + bool hasTarget() const { return target.size() != 0; } + String Target() const { return target; } + + void mergeWith(const HttpHdrScTarget * new_sc); + void packInto (Packer *p) const; + void updateStats(StatHist *) const; + MEMPROXY_CLASS(HttpHdrScTarget); - dlink_node node; +private: + bool isSet(http_hdr_sc_type id) const { + assert (id >= SC_NO_STORE && id < SC_ENUM_END); + return EBIT_TEST(mask,id); + } + + void setMask(http_hdr_sc_type id, bool newval) { + if (newval) EBIT_SET(mask,id); + else EBIT_CLR(mask,id); + } + int mask; int max_age; int max_stale; - String content; + String content_; String target; + dlink_node node; }; MEMPROXY_CLASS_INLINE(HttpHdrScTarget); -/* Http Surrogate control header field 'targets' */ -extern HttpHdrScTarget * httpHdrScTargetCreate (const char *); -extern void httpHdrScTargetDestroy(HttpHdrScTarget *); -extern HttpHdrScTarget *httpHdrScTargetDup(const HttpHdrScTarget *); -extern void httpHdrScTargetPackInto(const HttpHdrScTarget *, Packer *); -extern void httpHdrScTargetSetMaxAge(HttpHdrScTarget *, int); -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); -/* for StatHist */ -#include "typedefs.h" - -extern void httpHdrScTargetUpdateStats(const HttpHdrScTarget *, StatHist *); #endif /* SQUID_HTTPHDRSURROGATECONTROLTARGET_H */ diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index e293468849..68a844ec98 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1209,7 +1209,7 @@ HttpHeader::putSc(HttpHdrSc *sc) /* pack into mb */ mb.init(); packerToMemInit(&p, &mb); - httpHdrScPackInto(sc, &p); + sc->packInto(&p); /* put */ addEntry(new HttpHeaderEntry(HDR_SURROGATE_CONTROL, NULL, mb.buf)); /* cleanup */ @@ -1366,12 +1366,12 @@ HttpHeader::getSc() const (void) getList(HDR_SURROGATE_CONTROL, &s); - HttpHdrSc *sc = httpHdrScParseCreate(&s); + HttpHdrSc *sc = httpHdrScParseCreate(s); - HttpHeaderStats[owner].ccParsedCount++; + ++HttpHeaderStats[owner].ccParsedCount; if (sc) - httpHdrScUpdateStats(sc, &HttpHeaderStats[owner].scTypeDistr); + sc->updateStats(&HttpHeaderStats[owner].scTypeDistr); httpHeaderNoteParsedEntry(HDR_SURROGATE_CONTROL, s, !sc); diff --git a/src/HttpReply.cc b/src/HttpReply.cc index e41bddfae9..e2506b7842 100644 --- a/src/HttpReply.cc +++ b/src/HttpReply.cc @@ -408,7 +408,7 @@ HttpReply::hdrCacheClean() } if (surrogate_control) { - httpHdrScDestroy(surrogate_control); + delete surrogate_control; surrogate_control = NULL; } diff --git a/src/esi/Esi.cc b/src/esi/Esi.cc index fefca431e6..0bcc5dfbe2 100644 --- a/src/esi/Esi.cc +++ b/src/esi/Esi.cc @@ -2432,19 +2432,19 @@ esiEnableProcessing (HttpReply *rep) int rv = 0; if (rep->surrogate_control) { - HttpHdrScTarget *sctusable = httpHdrScGetMergedTarget (rep->surrogate_control, - Config.Accel.surrogate_id); + HttpHdrScTarget *sctusable = + rep->surrogate_control->getMergedTarget(Config.Accel.surrogate_id); - if (!sctusable || sctusable->content.size() == 0) + if (!sctusable || !sctusable->hasContent()) /* Nothing generic or targeted at us, or no * content processing requested */ return 0; - if (sctusable->content.pos("ESI/1.0") != NULL) + if (sctusable->content().pos("ESI/1.0") != NULL) rv = 1; - httpHdrScTargetDestroy (sctusable); + delete sctusable; } return rv; diff --git a/src/htcp.cc b/src/htcp.cc index 1e2d0a6cd9..20101df6b5 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -49,6 +49,7 @@ #include "SquidTime.h" #include "Store.h" #include "StoreClient.h" +#include "compat/xalloc.h" /// dials htcpIncomingConnectionOpened call class HtcpListeningStartedDialer: public CallDialer, diff --git a/src/http.cc b/src/http.cc index bfebc22bad..232b125cc3 100644 --- a/src/http.cc +++ b/src/http.cc @@ -285,12 +285,12 @@ void HttpStateData::processSurrogateControl(HttpReply *reply) { if (request->flags.accelerated && reply->surrogate_control) { - HttpHdrScTarget *sctusable = httpHdrScGetMergedTarget(reply->surrogate_control, Config.Accel.surrogate_id); + HttpHdrScTarget *sctusable = reply->surrogate_control->getMergedTarget(Config.Accel.surrogate_id); if (sctusable) { - if (EBIT_TEST(sctusable->mask, SC_NO_STORE) || + if (sctusable->noStore() || (Config.onoff.surrogate_is_remote - && EBIT_TEST(sctusable->mask, SC_NO_STORE_REMOTE))) { + && sctusable->noStoreRemote())) { surrogateNoStore = true; entry->makePrivate(); } @@ -299,11 +299,11 @@ HttpStateData::processSurrogateControl(HttpReply *reply) * accelerated request or not... * Still, this is an abstraction breach. - RC */ - if (sctusable->max_age != -1) { - if (sctusable->max_age < sctusable->max_stale) - reply->expires = reply->date + sctusable->max_age; + if (sctusable->hasMaxAge()) { + if (sctusable->maxAge() < sctusable->maxStale()) + reply->expires = reply->date + sctusable->maxAge(); else - reply->expires = reply->date + sctusable->max_stale; + reply->expires = reply->date + sctusable->maxStale(); /* And update the timestamps */ entry->timestampsSet(); @@ -312,7 +312,7 @@ HttpStateData::processSurrogateControl(HttpReply *reply) /* We ignore cache-control directives as per the Surrogate specification */ ignoreCacheControl = true; - httpHdrScTargetDestroy(sctusable); + delete sctusable; } } } -- 2.47.2