]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup ETag comparison functions in preparation for If-Match support.
authorAlex Rousskov <rousskov@measurement-factory.com>
Fri, 1 Oct 2010 00:41:19 +0000 (18:41 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Fri, 1 Oct 2010 00:41:19 +0000 (18:41 -0600)
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 360b1394531f444f39bc3e589f0b1ba73aba847a..3fecaf764338e9b0fd2abc165c06a16567790699 100644 (file)
@@ -1173,7 +1173,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 d212b54fc2efef09e16792632e27809afd03edc5..b5bea9e330daeff5f36f9bac9d010b5b870d8f12 100644 (file)
@@ -222,7 +222,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);