ETag.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #include "squid.h"
10 #include "ETag.h"
11 
12 #include <cstring>
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 
20 static bool
21 etagStringsMatch(const ETag &tag1, const ETag &tag2)
22 {
23  return !strcmp(tag1.str, tag2.str);
24 }
25 
26 /* parses a string as weak or strong entity-tag; returns true on success */
27 /* note: we do not duplicate "str"! */
28 int
29 etagParseInit(ETag * etag, const char *str)
30 {
31  int len;
32  assert(etag && str);
33  etag->str = NULL;
34  etag->weak = !strncmp(str, "W/", 2);
35 
36  if (etag->weak)
37  str += 2;
38 
39  /* check format (quoted-string) */
40  len = strlen(str);
41 
42  if (len >= 2 && str[0] == '"' && str[len - 1] == '"')
43  etag->str = str;
44 
45  return etag->str != NULL;
46 }
47 
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)
56 {
57  return etagStringsMatch(tag1, tag2);
58 }
59 
#define assert(EX)
Definition: assert.h:17
bool etagIsStrongEqual(const ETag &tag1, const ETag &tag2)
whether etags are strong-equal
Definition: ETag.cc:49
Definition: ETag.h:17
int etagParseInit(ETag *etag, const char *str)
Definition: ETag.cc:29
bool etagIsWeakEqual(const ETag &tag1, const ETag &tag2)
whether etags are weak-equal
Definition: ETag.cc:55
int weak
true if it is a weak validator
Definition: ETag.h:21
int unsigned int const char *desc STUB void int len
Definition: stub_fd.cc:20
const char * str
quoted-string
Definition: ETag.h:20
static bool etagStringsMatch(const ETag &tag1, const ETag &tag2)
whether etag strings match
Definition: ETag.cc:21
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors