]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorAmos Jeffries <amosjeffries@squid-cache.org>
Sat, 23 Oct 2010 13:34:46 +0000 (07:34 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Sat, 23 Oct 2010 13:34:46 +0000 (07:34 -0600)
Cleanup ETag comparison functions in preparation for If-Match support.

Replace etagIsEqual() with etagIsStrongEqual() function that does proper strong
ETag comparison instead of asserting on weak ETags.

Add etagIsWeakEqual() function for weak ETag comparison. Currently unused.

Both etagIs*Equal() functions call etagStringsMatch() helper to compare the tags.

No runtime behavior changes expected.

src/ETag.cc
src/client_side.cc
src/protos.h

index b90f8ca12a67ff9e902719d75857fb2e18612e22..c845c52068097e4c58d27229776550d1f4560d42 100644 (file)
  * field-value that maybe used in many http fields.
  */
 
+/// whether etag strings match
+static bool
+etagStringsMatch(const ETag &tag1, const ETag &tag2)
+{
+    return !strcmp(tag1.str, tag2.str);
+}
+
 /* parses a string as weak or strong entity-tag; returns true on success */
 /* note: we do not duplicate "str"! */
 int
@@ -62,11 +69,14 @@ etagParseInit(ETag * etag, const char *str)
     return etag->str != NULL;
 }
 
-/* returns true if etags are equal */
-int
-etagIsEqual(const ETag * tag1, const ETag * tag2)
+bool
+etagIsStrongEqual(const ETag &tag1, const ETag &tag2)
+{
+    return !tag1.weak && !tag2.weak && etagStringsMatch(tag1, tag2);
+}
+
+bool
+etagIsWeakEqual(const ETag &tag1, const ETag &tag2)
 {
-    assert(tag1 && tag2);
-    assert(!tag1->weak && !tag2->weak);                /* weak comparison not implemented yet */
-    return !strcmp(tag1->str, tag2->str);
+    return etagStringsMatch(tag1, tag2);
 }
index 9326ee45a3ca560c9301c601459d6d4c15b34bb1..e0864e490a109d9dd06feae935e4fd63a1dbed69 100644 (file)
@@ -1075,7 +1075,7 @@ clientIfRangeMatch(ClientHttpRequest * http, HttpReply * rep)
             return 0;          /* must use strong validator for sub-range requests */
         }
 
-        return etagIsEqual(&rep_tag, &spec.tag);
+        return etagIsStrongEqual(rep_tag, spec.tag);
     }
 
     /* got modification time? */
index acb13ceff1c1ffe2248d085be1fcd18d931928ee..5a2e8ecdc887842c3397adff59a41d2ebe00cb69 100644 (file)
@@ -221,7 +221,10 @@ SQUIDCEXTERN const char *httpMakeVaryMark(HttpRequest * request, HttpReply const
 
 /* ETag */
 SQUIDCEXTERN int etagParseInit(ETag * etag, const char *str);
-SQUIDCEXTERN int etagIsEqual(const ETag * tag1, const ETag * tag2);
+/// whether etags are strong-equal
+SQUIDCEXTERN bool etagIsStrongEqual(const ETag &tag1, const ETag &tag2);
+/// whether etags are weak-equal
+SQUIDCEXTERN bool etagIsWeakEqual(const ETag &tag1, const ETag &tag2);
 
 #include "HttpStatusCode.h"
 SQUIDCEXTERN const char *httpStatusString(http_status status);