From: wessels <> Date: Wed, 14 Dec 2005 04:41:57 +0000 (+0000) Subject: Finished support for parsing ICAP OPTIONS Transfer-* headers. X-Git-Tag: SQUID_3_0_PRE4~454 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9d0cdbb9a001615b7ea0a76f5ed30ba0ec4f16a0;p=thirdparty%2Fsquid.git Finished support for parsing ICAP OPTIONS Transfer-* headers. Squid does not yet use the Transfer-* extensions to make ICAP forwarding decisions. --- diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 253ac32476..4cd325007e 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.cc,v 1.108 2005/09/17 05:50:07 wessels Exp $ + * $Id: HttpHeader.cc,v 1.109 2005/12/13 21:41:57 wessels Exp $ * * DEBUG: section 55 HTTP Header * AUTHOR: Alex Rousskov @@ -1644,6 +1644,31 @@ httpHeaderHasListMember(const HttpHeader * hdr, http_hdr_type id, const char *me return result; } +int +httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator) +{ + int result = 0; + const char *pos = NULL; + const char *item; + int ilen; + int mlen = strlen(member); + + assert(hdr); + assert(name); + + String header (httpHeaderGetByName(hdr, name)); + + while (strListGetItem(&header, separator, &item, &ilen, &pos)) { + if (strncmp(item, member, mlen) == 0 + && (item[mlen] == '=' || item[mlen] == separator || item[mlen] == ';' || item[mlen] == '\0')) { + result = 1; + break; + } + } + + return result; +} + void HttpHeader::removeConnectionHeaderEntries() { diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 43a9fd00f6..a33807ed47 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -1,6 +1,6 @@ /* - * $Id: HttpHeader.h,v 1.7 2003/09/01 03:49:37 robertc Exp $ + * $Id: HttpHeader.h,v 1.8 2005/12/13 21:41:57 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -53,6 +53,7 @@ extern void httpHeaderPutSc(HttpHeader *hdr, const HttpHdrSc *sc); extern HttpHdrSc *httpHeaderGetSc(const HttpHeader *hdr); SQUIDCEXTERN void httpHeaderAddContRange(HttpHeader *, HttpHdrRangeSpec, ssize_t); extern int httpHeaderHasListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator); +SQUIDCEXTERN int httpHeaderHasByNameListMember(const HttpHeader * hdr, const char *name, const char *member, const char separator); SQUIDCEXTERN void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask); int httpMsgIsPersistent(HttpVersion const &http_ver, const HttpHeader * hdr); diff --git a/src/ICAP/ICAPClientReqmodPrecache.cc b/src/ICAP/ICAPClientReqmodPrecache.cc index 97db5ad08e..7058a9e2fe 100644 --- a/src/ICAP/ICAPClientReqmodPrecache.cc +++ b/src/ICAP/ICAPClientReqmodPrecache.cc @@ -110,6 +110,7 @@ void ICAPClientReqmodPrecache::noteSinkAbort(MsgPipe *p) void ICAPClientReqmodPrecache::noteSourceStart(MsgPipe *p) { debug(93,3)("ICAPClientReqmodPrecache::noteSourceStart() called\n"); + assert(adapted->data->header); // What should happen instead? http->takeAdaptedHeaders(adapted->data->header); noteSourceProgress(p); } diff --git a/src/ICAP/ICAPOptions.cc b/src/ICAP/ICAPOptions.cc index 16deaf302c..9b96d33d72 100644 --- a/src/ICAP/ICAPOptions.cc +++ b/src/ICAP/ICAPOptions.cc @@ -37,7 +37,6 @@ ICAPOptions::transfer_type ICAPOptions::getTransferExt(const char *s) return TRANSFER_NONE; } -#if UNUSED_CODE void ICAPOptions::insertTransferExt(const char *t, transfer_type t_type) { List **Tail; @@ -62,9 +61,26 @@ void ICAPOptions::insertTransferExt(const char *t, transfer_type t_type) }; +void ICAPOptions::cfgTransferListHeader(const HttpHeader *h, const char *fname, transfer_type t_type) +{ + const String s = httpHeaderGetByName(h, fname); + + if (!s.size()) + return; + + if (t_type == TRANSFER_PREVIEW) + transfers.preview = parseExtFileList(s.buf(), s.buf() + s.size(), t_type); + else if (t_type == TRANSFER_IGNORE) + transfers.ignore = parseExtFileList(s.buf(), s.buf() + s.size(), t_type); + else if (t_type == TRANSFER_COMPLETE) + transfers.complete = parseExtFileList(s.buf(), s.buf() + s.size(), t_type); + else + fatalf("Unexpected transfer_type at %s:%d", __FILE__,__LINE__); +} + List *ICAPOptions::parseExtFileList(const char *start, const char *end, transfer_type t_type) { - const String s = xstrndup(start, end - start - 1); + const String s = xstrndup(start, end - start + 1); const char *item; const char *pos = NULL; char *fext = NULL; @@ -89,8 +105,6 @@ List *ICAPOptions::parseExtFileList(const char *start, const char *end, return H; } -#endif - bool ICAPOptions::valid() const { return !error; @@ -117,10 +131,10 @@ void ICAPOptions::configure(const HttpReply *reply) error = "unsupported status code of OPTIONS response"; // Methods - if (httpHeaderGetByNameListMember(h, "Methods", "REQMOD", ',').size()) + if (httpHeaderHasByNameListMember(h, "Methods", "REQMOD", ',')) cfgMethod(ICAP::methodReqmod); - if (httpHeaderGetByNameListMember(h, "Methods", "RESPMOD", ',').size()) + if (httpHeaderHasByNameListMember(h, "Methods", "RESPMOD", ',')) cfgMethod(ICAP::methodRespmod); service = httpHeaderGetByName(h, "Service"); @@ -141,23 +155,16 @@ void ICAPOptions::configure(const HttpReply *reply) if (theTimestamp < 0) theTimestamp = squid_curtime; - if (httpHeaderGetByNameListMember(h, "Allow", "204", ',').size()) + if (httpHeaderHasListMember(h, HDR_ALLOW, "204", ',')) allow204 = true; cfgIntHeader(h, "Preview", preview); -#if 0 - - if (!strncasecmp("Transfer-Preview", start, 16)) - headers->transfer_preview = parseExtFileList(value_start, end, TRANSFER_PREVIEW); - - if (!strncasecmp("Transfer-Ignore", start, 15)) - headers->transfer_ignore = parseExtFileList(value_start, end, TRANSFER_IGNORE); + cfgTransferListHeader(h, "Transfer-Preview", TRANSFER_PREVIEW); - if (!strncasecmp("Transfer-Complete", start, 17)) - headers->transfer_complete = parseExtFileList(value_start, end, TRANSFER_COMPLETE); + cfgTransferListHeader(h, "Transfer-Ignore", TRANSFER_IGNORE); -#endif + cfgTransferListHeader(h, "Transfer-Complete", TRANSFER_COMPLETE); } void ICAPOptions::cfgMethod(ICAP::Method m) diff --git a/src/ICAP/ICAPOptions.h b/src/ICAP/ICAPOptions.h index e95246307b..6ddbb8d5eb 100644 --- a/src/ICAP/ICAPOptions.h +++ b/src/ICAP/ICAPOptions.h @@ -1,6 +1,6 @@ /* - * $Id: ICAPOptions.h,v 1.3 2005/12/13 18:38:05 wessels Exp $ + * $Id: ICAPOptions.h,v 1.4 2005/12/13 21:41:58 wessels Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -107,6 +107,9 @@ protected: private: void cfgMethod(ICAP::Method m); void cfgIntHeader(const HttpHeader *h, const char *fname, int &value); + void insertTransferExt(const char *t, transfer_type t_type); + void cfgTransferListHeader(const HttpHeader *h, const char *fname, transfer_type type); + List *ICAPOptions::parseExtFileList(const char *start, const char *end, transfer_type t_type); }; diff --git a/src/ICAP/ICAPServiceRep.cc b/src/ICAP/ICAPServiceRep.cc index 2df5da6b6c..c2d38dc7bb 100644 --- a/src/ICAP/ICAPServiceRep.cc +++ b/src/ICAP/ICAPServiceRep.cc @@ -279,6 +279,9 @@ void ICAPServiceRep::changeOptions(ICAPOptions *newOptions) delete theOptions; theOptions = newOptions; + if (theOptions == NULL) + return; + /* * Maybe it would be better if squid.conf just listed the URI and * then discovered the method via OPTIONS @@ -286,8 +289,8 @@ void ICAPServiceRep::changeOptions(ICAPOptions *newOptions) if (theOptions->method != method) 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)); + " for service " << uri.buf() << + " but OPTIONS response declares the method is " << ICAP::methodStr(theOptions->method)); /* @@ -298,6 +301,20 @@ void ICAPServiceRep::changeOptions(ICAPOptions *newOptions) if (skew > theOptions->ttl()) debugs(93, 1, host.buf() << "'s clock is skewed by " << skew << " seconds!"); +#if 0 + + List *tmp; + + for (tmp = theOptions->transfers.preview; tmp; tmp=tmp->next) + debugs(93,1,"Transfer-Preview: " << tmp->element.buf()); + + for (tmp = theOptions->transfers.ignore; tmp; tmp=tmp->next) + debugs(93,1,"Transfer-Ignore: " << tmp->element.buf()); + + for (tmp = theOptions->transfers.complete; tmp; tmp=tmp->next) + debugs(93,1,"Transfer-Complete: " << tmp->element.buf()); + +#endif } static