]> git.ipfire.org Git - thirdparty/squid.git/blob - src/HttpHdrCc.h
Refactored HttpHdrCc, with improved MemPools integration and more efficient parsing.
[thirdparty/squid.git] / src / HttpHdrCc.h
1 /*
2 * HttpHdrCc.h
3 *
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 */
31
32 #ifndef SQUID_HTTPHDRCC_H
33 #define SQUID_HTTPHDRCC_H
34
35 #include "config.h"
36 #include "MemPool.h"
37 #include "SquidString.h"
38
39 /** Http Cache-Control header representation
40 *
41 * Store and parse the Cache-Control HTTP header.
42 */
43 class HttpHdrCc
44 {
45
46 public:
47 static const int32_t MAX_AGE_UNKNOWN=-1; //max-age is unset
48 static const int32_t S_MAXAGE_UNKNOWN=-1; //s-maxage is unset
49 static const int32_t MAX_STALE_UNKNOWN=-1; //max-stale is unset
50 ///used to mark a valueless Cache-Control: max-stale directive, which instructs
51 /// us to treat responses of any age as fresh
52 static const int32_t MAX_STALE_ANY=0x7fffffff;
53 static const int32_t STALE_IF_ERROR_UNKNOWN=-1; //stale_if_error is unset
54 static const int32_t MIN_FRESH_UNKNOWN=-1; //min_fresh is unset
55
56 HttpHdrCc() :
57 mask(0), max_age(MAX_AGE_UNKNOWN), s_maxage(S_MAXAGE_UNKNOWN),
58 max_stale(MAX_STALE_UNKNOWN), stale_if_error(STALE_IF_ERROR_UNKNOWN),
59 min_fresh(MIN_FRESH_UNKNOWN) {}
60
61 /// reset data-members to default state
62 void clear();
63
64 /// parse a header-string and fill in appropriate values.
65 bool parse(const String & s);
66
67 //manipulation for Cache-Control: public header
68 bool hasPublic() const {return isSet(CC_PUBLIC);}
69 bool Public() const {return isSet(CC_PUBLIC);}
70 void Public(bool v) {setMask(CC_PUBLIC,v);}
71 void clearPublic() {setMask(CC_PUBLIC,false);}
72
73 //manipulation for Cache-Control: private header
74 bool hasPrivate() const {return isSet(CC_PRIVATE);}
75 bool Private() const {return isSet(CC_PRIVATE);}
76 void Private(bool v) {setMask(CC_PRIVATE,v);}
77 void clearPrivate() {setMask(CC_PRIVATE,false);}
78
79 //manipulation for Cache-Control: no-cache header
80 bool hasNoCache() const {return isSet(CC_NO_CACHE);}
81 bool noCache() const {return isSet(CC_NO_CACHE);}
82 void noCache(bool v) {setMask(CC_NO_CACHE,v);}
83 void clearNoCache() {setMask(CC_NO_CACHE,false);}
84
85 //manipulation for Cache-Control: no-store header
86 bool hasNoStore() const {return isSet(CC_NO_STORE);}
87 bool noStore() const {return isSet(CC_NO_STORE);}
88 void noStore(bool v) {setMask(CC_NO_STORE,v);}
89 void clearNoStore() {setMask(CC_NO_STORE,false);}
90
91 //manipulation for Cache-Control: no-transform header
92 bool hasNoTransform() const {return isSet(CC_NO_TRANSFORM);}
93 bool noTransform() const {return isSet(CC_NO_TRANSFORM);}
94 void noTransform(bool v) {setMask(CC_NO_TRANSFORM,v);}
95 void clearNoTransform() {setMask(CC_NO_TRANSFORM,false);}
96
97 //manipulation for Cache-Control: must-revalidate header
98 bool hasMustRevalidate() const {return isSet(CC_MUST_REVALIDATE);}
99 bool mustRevalidate() const {return isSet(CC_MUST_REVALIDATE);}
100 void mustRevalidate(bool v) {setMask(CC_MUST_REVALIDATE,v);}
101 void clearMustRevalidate() {setMask(CC_MUST_REVALIDATE,false);}
102
103 //manipulation for Cache-Control: proxy-revalidate header
104 bool hasProxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);}
105 bool proxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);}
106 void proxyRevalidate(bool v) {setMask(CC_PROXY_REVALIDATE,v);}
107 void clearProxyRevalidate() {setMask(CC_PROXY_REVALIDATE,false);}
108
109 //manipulation for Cache-Control: max-age header
110 bool hasMaxAge() const {return isSet(CC_MAX_AGE);}
111 int32_t maxAge() const { return max_age;}
112 void maxAge(int32_t v) {setValue(max_age,v,CC_MAX_AGE); }
113 void clearMaxAge() {setValue(max_age,MAX_AGE_UNKNOWN,CC_MAX_AGE,false);}
114
115 //manipulation for Cache-Control: s-maxage header
116 bool hasSMaxAge() const {return isSet(CC_S_MAXAGE);}
117 int32_t sMaxAge() const { return s_maxage;}
118 void sMaxAge(int32_t v) {setValue(s_maxage,v,CC_S_MAXAGE); }
119 void clearSMaxAge() {setValue(s_maxage,MAX_AGE_UNKNOWN,CC_S_MAXAGE,false);}
120
121 //manipulation for Cache-Control: max-stale header
122 bool hasMaxStale() const {return isSet(CC_MAX_STALE);}
123 int32_t maxStale() const { return max_stale;}
124 // max-stale has a special value (MAX_STALE_ANY) which correspond to having
125 // the directive without a numeric specification, and directs to consider the object
126 // as always-expired.
127 void maxStale(int32_t v) {setValue(max_stale,v,CC_MAX_STALE);}
128 void clearMaxStale() {setValue(max_stale,MAX_STALE_UNKNOWN,CC_MAX_STALE,false);}
129
130 //manipulation for Cache-Control:min-fresh header
131 bool hasMinFresh() const {return isSet(CC_MIN_FRESH);}
132 int32_t minFresh() const { return min_fresh;}
133 void minFresh(int32_t v) {if (v < 0) return; setValue(min_fresh,v,CC_MIN_FRESH); }
134 void clearMinFresh() {setValue(min_fresh,MIN_FRESH_UNKNOWN,CC_MIN_FRESH,false);}
135
136 //manipulation for Cache-Control: only-if-cached header
137 bool hasOnlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);}
138 bool onlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);}
139 void onlyIfCached(bool v) {setMask(CC_ONLY_IF_CACHED,v);}
140 void clearOnlyIfCached() {setMask(CC_ONLY_IF_CACHED,false);}
141
142 //manipulation for Cache-Control: stale-if-error header
143 bool hasStaleIfError() const {return isSet(CC_STALE_IF_ERROR);}
144 int32_t staleIfError() const { return stale_if_error;}
145 void staleIfError(int32_t v) {setValue(stale_if_error,v,CC_STALE_IF_ERROR); }
146 void clearStaleIfError() {setValue(stale_if_error,STALE_IF_ERROR_UNKNOWN,CC_STALE_IF_ERROR,false);}
147
148 /// check whether the attribute value supplied by id is set
149 _SQUID_INLINE_ bool isSet(http_hdr_cc_type id) const;
150
151 void packInto(Packer * p) const;
152
153 MEMPROXY_CLASS(HttpHdrCc);
154
155 /** bit-mask representing what header values are set among those
156 * recognized by squid.
157 *
158 * managed via EBIT_SET/TEST/CLR
159 */
160 private:
161 int32_t mask;
162 int32_t max_age;
163 int32_t s_maxage;
164 int32_t max_stale;
165 int32_t stale_if_error;
166 int32_t min_fresh;
167 /// low-level part of the public set method, performs no checks
168 _SQUID_INLINE_ void setMask(http_hdr_cc_type id, bool newval=true);
169 _SQUID_INLINE_ void setValue(int32_t &value, int32_t new_value, http_hdr_cc_type hdr, bool setting=true);
170
171 public:
172 /**comma-separated representation of the header values which were
173 * received but are not recognized.
174 */
175 String other;
176 };
177
178 MEMPROXY_CLASS_INLINE(HttpHdrCc);
179
180 #if _USE_INLINE_
181 #include "HttpHdrCc.cci"
182 #endif
183
184 #endif /* SQUID_HTTPHDRCC_H */