From: wessels <> Date: Wed, 14 Dec 2005 01:38:05 +0000 (+0000) Subject: Report ICAP server clock skew based on the Date header in OPTIONS response. X-Git-Tag: SQUID_3_0_PRE4~455 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8eeb99bf5c9285791271a172032f54b77b8b8d8a;p=thirdparty%2Fsquid.git Report ICAP server clock skew based on the Date header in OPTIONS response. To make this work I added timestamp() and ttl() methods to ICAPOptions and renamed the private members. --- diff --git a/src/ICAP/ICAPOptions.cc b/src/ICAP/ICAPOptions.cc index 57172d2c46..16deaf302c 100644 --- a/src/ICAP/ICAPOptions.cc +++ b/src/ICAP/ICAPOptions.cc @@ -5,7 +5,7 @@ ICAPOptions::ICAPOptions(): error("unconfigured"), method(ICAP::methodNone), max_connections(-1), allow204(false), - preview(-1), ttl(-1), transfer_ext(NULL) + preview(-1), theTTL(-1), transfer_ext(NULL) { transfers.preview = transfers.ignore = transfers.complete = NULL; transfers.other = TRANSFER_NONE; @@ -104,7 +104,7 @@ bool ICAPOptions::fresh() const time_t ICAPOptions::expire() const { Must(valid()); - return ttl >= 0 ? timestamp + ttl : -1; + return theTTL >= 0 ? theTimestamp + theTTL : -1; } void ICAPOptions::configure(const HttpReply *reply) @@ -134,12 +134,12 @@ void ICAPOptions::configure(const HttpReply *reply) cfgIntHeader(h, "Max-Connections", max_connections); - cfgIntHeader(h, "Options-TTL", ttl); + cfgIntHeader(h, "Options-TTL", theTTL); - timestamp = httpHeaderGetTime(h, HDR_DATE); + theTimestamp = httpHeaderGetTime(h, HDR_DATE); - if (timestamp < 0) - timestamp = squid_curtime; + if (theTimestamp < 0) + theTimestamp = squid_curtime; if (httpHeaderGetByNameListMember(h, "Allow", "204", ',').size()) allow204 = true; diff --git a/src/ICAP/ICAPOptions.h b/src/ICAP/ICAPOptions.h index cf22aed25e..e95246307b 100644 --- a/src/ICAP/ICAPOptions.h +++ b/src/ICAP/ICAPOptions.h @@ -1,6 +1,6 @@ /* - * $Id: ICAPOptions.h,v 1.2 2005/11/21 23:46:27 wessels Exp $ + * $Id: ICAPOptions.h,v 1.3 2005/12/13 18:38:05 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -57,6 +57,9 @@ public: bool valid() const; bool fresh() const; time_t expire() const; + time_t timestamp() const { return theTimestamp; }; + + int ttl() const { return theTTL; }; typedef enum { TRANSFER_NONE, TRANSFER_PREVIEW, TRANSFER_IGNORE, TRANSFER_COMPLETE } transfer_type; transfer_type getTransferExt(const char *); @@ -88,8 +91,8 @@ public: transfers; protected: - int ttl; - time_t timestamp; + int theTTL; + time_t theTimestamp; // The list of pairs "file extension <-> transfer type" diff --git a/src/ICAP/ICAPServiceRep.cc b/src/ICAP/ICAPServiceRep.cc index dfda856ca0..2df5da6b6c 100644 --- a/src/ICAP/ICAPServiceRep.cc +++ b/src/ICAP/ICAPServiceRep.cc @@ -288,6 +288,16 @@ void ICAPServiceRep::changeOptions(ICAPOptions *newOptions) debugs(93,1, "WARNING: Squid is configured to use ICAP method " << ICAP::methodStr(method) << "for service " << uri.buf() << "but OPTIONS response declares the method is " << ICAP::methodStr(theOptions->method)); + + + /* + * Check the ICAP server's date header for clock skew + */ + int skew = abs((int)(theOptions->timestamp() - squid_curtime)); + + if (skew > theOptions->ttl()) + debugs(93, 1, host.buf() << "'s clock is skewed by " << skew << " seconds!"); + } static