]>
Commit | Line | Data |
---|---|---|
a9771e51 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
e25c139f | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
a9771e51 | 7 | */ |
8 | ||
f7f3304a | 9 | #include "squid.h" |
81a94152 AJ |
10 | #include "ETag.h" |
11 | ||
81a94152 | 12 | #include <cstring> |
a9771e51 | 13 | |
14 | /* | |
15 | * Note: ETag is not an http "field" like, for example HttpHdrRange. ETag is a | |
16 | * field-value that maybe used in many http fields. | |
17 | */ | |
18 | ||
bd76482d AR |
19 | /// whether etag strings match |
20 | static bool | |
21 | etagStringsMatch(const ETag &tag1, const ETag &tag2) | |
22 | { | |
23 | return !strcmp(tag1.str, tag2.str); | |
24 | } | |
25 | ||
a9771e51 | 26 | /* parses a string as weak or strong entity-tag; returns true on success */ |
27 | /* note: we do not duplicate "str"! */ | |
28 | int | |
0cdcddb9 | 29 | etagParseInit(ETag * etag, const char *str) |
a9771e51 | 30 | { |
31 | int len; | |
32 | assert(etag && str); | |
aee3523a | 33 | etag->str = nullptr; |
a9771e51 | 34 | etag->weak = !strncmp(str, "W/", 2); |
62e76326 | 35 | |
a9771e51 | 36 | if (etag->weak) |
62e76326 | 37 | str += 2; |
38 | ||
a9771e51 | 39 | /* check format (quoted-string) */ |
40 | len = strlen(str); | |
62e76326 | 41 | |
0cdcddb9 | 42 | if (len >= 2 && str[0] == '"' && str[len - 1] == '"') |
62e76326 | 43 | etag->str = str; |
44 | ||
aee3523a | 45 | return etag->str != nullptr; |
a9771e51 | 46 | } |
47 | ||
bd76482d AR |
48 | bool |
49 | etagIsStrongEqual(const ETag &tag1, const ETag &tag2) | |
50 | { | |
51 | return !tag1.weak && !tag2.weak && etagStringsMatch(tag1, tag2); | |
52 | } | |
53 | ||
54 | bool | |
55 | etagIsWeakEqual(const ETag &tag1, const ETag &tag2) | |
a9771e51 | 56 | { |
bd76482d | 57 | return etagStringsMatch(tag1, tag2); |
a9771e51 | 58 | } |
f53969cc | 59 |