From: Alex Rousskov Date: Fri, 1 Oct 2010 00:41:19 +0000 (-0600) Subject: Cleanup ETag comparison functions in preparation for If-Match support. X-Git-Tag: take1~218 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bd76482d6532f586c4689f8b35f3fc5620004933;p=thirdparty%2Fsquid.git 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. --- diff --git a/src/ETag.cc b/src/ETag.cc index b90f8ca12a..c845c52068 100644 --- a/src/ETag.cc +++ b/src/ETag.cc @@ -40,6 +40,13 @@ * 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); } diff --git a/src/client_side.cc b/src/client_side.cc index 360b139453..3fecaf7643 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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? */ diff --git a/src/protos.h b/src/protos.h index d212b54fc2..b5bea9e330 100644 --- a/src/protos.h +++ b/src/protos.h @@ -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);