]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Finished support for parsing ICAP OPTIONS Transfer-* headers.
authorwessels <>
Wed, 14 Dec 2005 04:41:57 +0000 (04:41 +0000)
committerwessels <>
Wed, 14 Dec 2005 04:41:57 +0000 (04:41 +0000)
Squid does not yet use the Transfer-* extensions to make ICAP forwarding
decisions.

src/HttpHeader.cc
src/HttpHeader.h
src/ICAP/ICAPClientReqmodPrecache.cc
src/ICAP/ICAPOptions.cc
src/ICAP/ICAPOptions.h
src/ICAP/ICAPServiceRep.cc

index 253ac32476e2a542fe77c84e9d5bb93d36333447..4cd325007eb286f0bffb534b01f62d4e1798736f 100644 (file)
@@ -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()
 {
index 43a9fd00f60f61022e6fa8f375139a6bae676aca..a33807ed4741841f1bbac55d48e635a78477d5ad 100644 (file)
@@ -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);
 
index 97db5ad08eaa0bb6746cf028bb4260b966e769eb..7058a9e2feabb447f5ed8f675357450908419ee5 100644 (file)
@@ -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);
 }
index 16deaf302ca97b323b8194e80d9f4f77aa2c4c63..9b96d33d729ff3b5f2e645c5ee475f6bd96209a0 100644 (file)
@@ -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<TransferPair> **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<String> *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<String> *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)
index e95246307b70643f259b896d8155b8484c748883..6ddbb8d5eba9a2610a3f3c6c588a9b545c335475 100644 (file)
@@ -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<String> *ICAPOptions::parseExtFileList(const char *start, const char *end, transfer_type t_type);
 };
 
 
index 2df5da6b6c2d49f331bb44893b81f30a964a71b0..c2d38dc7bb9b64afa6eb406ebf1d944301ac3359 100644 (file)
@@ -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<String> *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