]>
Commit | Line | Data |
---|---|---|
0abdd70d | 1 | /* |
ce394734 | 2 | * HttpHdrCc.h |
0abdd70d | 3 | * |
0abdd70d FC |
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 | ||
576840e8 FC |
32 | #ifndef SQUID_HTTPHDRCC_H |
33 | #define SQUID_HTTPHDRCC_H | |
0abdd70d | 34 | |
582c2af2 | 35 | #include "enums.h" |
0abdd70d FC |
36 | #include "MemPool.h" |
37 | #include "SquidString.h" | |
38 | ||
43ca19e0 FC |
39 | class Packer; |
40 | ||
7ebe76de | 41 | /** Http Cache-Control header representation |
ce394734 | 42 | * |
7ebe76de | 43 | * Store and parse the Cache-Control HTTP header. |
ce394734 | 44 | */ |
0abdd70d FC |
45 | class HttpHdrCc |
46 | { | |
47 | ||
48 | public: | |
77da1817 A |
49 | static const int32_t MAX_AGE_UNKNOWN=-1; //max-age is unset |
50 | static const int32_t S_MAXAGE_UNKNOWN=-1; //s-maxage is unset | |
51 | static const int32_t MAX_STALE_UNKNOWN=-1; //max-stale is unset | |
52 | ///used to mark a valueless Cache-Control: max-stale directive, which instructs | |
53 | /// us to treat responses of any age as fresh | |
54 | static const int32_t MAX_STALE_ANY=0x7fffffff; | |
55 | static const int32_t STALE_IF_ERROR_UNKNOWN=-1; //stale_if_error is unset | |
56 | static const int32_t MIN_FRESH_UNKNOWN=-1; //min_fresh is unset | |
70aff22f | 57 | |
c57b8f05 | 58 | HttpHdrCc() : |
cf7c2e94 FC |
59 | mask(0), max_age(MAX_AGE_UNKNOWN), s_maxage(S_MAXAGE_UNKNOWN), |
60 | max_stale(MAX_STALE_UNKNOWN), stale_if_error(STALE_IF_ERROR_UNKNOWN), | |
61 | min_fresh(MIN_FRESH_UNKNOWN) {} | |
ce394734 | 62 | |
c57b8f05 | 63 | /// reset data-members to default state |
ce394734 | 64 | void clear(); |
c57b8f05 FC |
65 | |
66 | /// parse a header-string and fill in appropriate values. | |
1ba0611a | 67 | bool parse(const String & s); |
70aff22f | 68 | |
cf7c2e94 | 69 | //manipulation for Cache-Control: public header |
d74ad83f FC |
70 | bool hasPublic() const {return isSet(CC_PUBLIC);} |
71 | bool Public() const {return isSet(CC_PUBLIC);} | |
72 | void Public(bool v) {setMask(CC_PUBLIC,v);} | |
73 | void clearPublic() {setMask(CC_PUBLIC,false);} | |
cf7c2e94 FC |
74 | |
75 | //manipulation for Cache-Control: private header | |
d74ad83f | 76 | bool hasPrivate() const {return isSet(CC_PRIVATE);} |
1259f9cf AJ |
77 | const String &Private() const {return private_;} |
78 | void Private(String &v) { | |
79 | setMask(CC_PRIVATE,true); | |
80 | // uses append for multi-line headers | |
b38b26cb | 81 | if (private_.size() > 0) |
1259f9cf AJ |
82 | private_.append(","); |
83 | private_.append(v); | |
84 | } | |
85 | void clearPrivate() {setMask(CC_PRIVATE,false); private_.clean();} | |
cf7c2e94 FC |
86 | |
87 | //manipulation for Cache-Control: no-cache header | |
d74ad83f | 88 | bool hasNoCache() const {return isSet(CC_NO_CACHE);} |
1259f9cf AJ |
89 | const String &noCache() const {return no_cache;} |
90 | void noCache(String &v) { | |
91 | setMask(CC_NO_CACHE,true); | |
92 | // uses append for multi-line headers | |
b38b26cb | 93 | if (no_cache.size() > 0) |
1259f9cf AJ |
94 | no_cache.append(","); |
95 | no_cache.append(v); | |
96 | } | |
97 | void clearNoCache() {setMask(CC_NO_CACHE,false); no_cache.clean();} | |
cf7c2e94 FC |
98 | |
99 | //manipulation for Cache-Control: no-store header | |
d74ad83f FC |
100 | bool hasNoStore() const {return isSet(CC_NO_STORE);} |
101 | bool noStore() const {return isSet(CC_NO_STORE);} | |
102 | void noStore(bool v) {setMask(CC_NO_STORE,v);} | |
103 | void clearNoStore() {setMask(CC_NO_STORE,false);} | |
cf7c2e94 FC |
104 | |
105 | //manipulation for Cache-Control: no-transform header | |
d74ad83f FC |
106 | bool hasNoTransform() const {return isSet(CC_NO_TRANSFORM);} |
107 | bool noTransform() const {return isSet(CC_NO_TRANSFORM);} | |
108 | void noTransform(bool v) {setMask(CC_NO_TRANSFORM,v);} | |
109 | void clearNoTransform() {setMask(CC_NO_TRANSFORM,false);} | |
cf7c2e94 FC |
110 | |
111 | //manipulation for Cache-Control: must-revalidate header | |
d74ad83f FC |
112 | bool hasMustRevalidate() const {return isSet(CC_MUST_REVALIDATE);} |
113 | bool mustRevalidate() const {return isSet(CC_MUST_REVALIDATE);} | |
114 | void mustRevalidate(bool v) {setMask(CC_MUST_REVALIDATE,v);} | |
115 | void clearMustRevalidate() {setMask(CC_MUST_REVALIDATE,false);} | |
cf7c2e94 FC |
116 | |
117 | //manipulation for Cache-Control: proxy-revalidate header | |
d74ad83f FC |
118 | bool hasProxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);} |
119 | bool proxyRevalidate() const {return isSet(CC_PROXY_REVALIDATE);} | |
120 | void proxyRevalidate(bool v) {setMask(CC_PROXY_REVALIDATE,v);} | |
121 | void clearProxyRevalidate() {setMask(CC_PROXY_REVALIDATE,false);} | |
cf7c2e94 FC |
122 | |
123 | //manipulation for Cache-Control: max-age header | |
d74ad83f FC |
124 | bool hasMaxAge() const {return isSet(CC_MAX_AGE);} |
125 | int32_t maxAge() const { return max_age;} | |
126 | void maxAge(int32_t v) {setValue(max_age,v,CC_MAX_AGE); } | |
127 | void clearMaxAge() {setValue(max_age,MAX_AGE_UNKNOWN,CC_MAX_AGE,false);} | |
cf7c2e94 | 128 | |
4ce6e3b5 | 129 | //manipulation for Cache-Control: s-maxage header |
d74ad83f FC |
130 | bool hasSMaxAge() const {return isSet(CC_S_MAXAGE);} |
131 | int32_t sMaxAge() const { return s_maxage;} | |
132 | void sMaxAge(int32_t v) {setValue(s_maxage,v,CC_S_MAXAGE); } | |
133 | void clearSMaxAge() {setValue(s_maxage,MAX_AGE_UNKNOWN,CC_S_MAXAGE,false);} | |
4ce6e3b5 FC |
134 | |
135 | //manipulation for Cache-Control: max-stale header | |
d74ad83f FC |
136 | bool hasMaxStale() const {return isSet(CC_MAX_STALE);} |
137 | int32_t maxStale() const { return max_stale;} | |
138 | // max-stale has a special value (MAX_STALE_ANY) which correspond to having | |
4ce6e3b5 FC |
139 | // the directive without a numeric specification, and directs to consider the object |
140 | // as always-expired. | |
d74ad83f FC |
141 | void maxStale(int32_t v) {setValue(max_stale,v,CC_MAX_STALE);} |
142 | void clearMaxStale() {setValue(max_stale,MAX_STALE_UNKNOWN,CC_MAX_STALE,false);} | |
4ce6e3b5 FC |
143 | |
144 | //manipulation for Cache-Control:min-fresh header | |
d74ad83f FC |
145 | bool hasMinFresh() const {return isSet(CC_MIN_FRESH);} |
146 | int32_t minFresh() const { return min_fresh;} | |
147 | void minFresh(int32_t v) {if (v < 0) return; setValue(min_fresh,v,CC_MIN_FRESH); } | |
148 | void clearMinFresh() {setValue(min_fresh,MIN_FRESH_UNKNOWN,CC_MIN_FRESH,false);} | |
4ce6e3b5 FC |
149 | |
150 | //manipulation for Cache-Control: only-if-cached header | |
d74ad83f FC |
151 | bool hasOnlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);} |
152 | bool onlyIfCached() const {return isSet(CC_ONLY_IF_CACHED);} | |
153 | void onlyIfCached(bool v) {setMask(CC_ONLY_IF_CACHED,v);} | |
154 | void clearOnlyIfCached() {setMask(CC_ONLY_IF_CACHED,false);} | |
4ce6e3b5 FC |
155 | |
156 | //manipulation for Cache-Control: stale-if-error header | |
d74ad83f FC |
157 | bool hasStaleIfError() const {return isSet(CC_STALE_IF_ERROR);} |
158 | int32_t staleIfError() const { return stale_if_error;} | |
159 | void staleIfError(int32_t v) {setValue(stale_if_error,v,CC_STALE_IF_ERROR); } | |
160 | void clearStaleIfError() {setValue(stale_if_error,STALE_IF_ERROR_UNKNOWN,CC_STALE_IF_ERROR,false);} | |
cf7c2e94 | 161 | |
cf7c2e94 FC |
162 | /// check whether the attribute value supplied by id is set |
163 | _SQUID_INLINE_ bool isSet(http_hdr_cc_type id) const; | |
164 | ||
4ce6e3b5 FC |
165 | void packInto(Packer * p) const; |
166 | ||
0abdd70d | 167 | MEMPROXY_CLASS(HttpHdrCc); |
83d46051 | 168 | |
c57b8f05 FC |
169 | /** bit-mask representing what header values are set among those |
170 | * recognized by squid. | |
171 | * | |
172 | * managed via EBIT_SET/TEST/CLR | |
173 | */ | |
1ba0611a | 174 | private: |
b17b9d8d | 175 | int32_t mask; |
7ebe76de FC |
176 | int32_t max_age; |
177 | int32_t s_maxage; | |
178 | int32_t max_stale; | |
179 | int32_t stale_if_error; | |
180 | int32_t min_fresh; | |
1259f9cf AJ |
181 | String private_; ///< List of headers sent as value for CC:private="...". May be empty/undefined if the value is missing. |
182 | String no_cache; ///< List of headers sent as value for CC:no-cache="...". May be empty/undefined if the value is missing. | |
183 | ||
cf7c2e94 FC |
184 | /// low-level part of the public set method, performs no checks |
185 | _SQUID_INLINE_ void setMask(http_hdr_cc_type id, bool newval=true); | |
d74ad83f | 186 | _SQUID_INLINE_ void setValue(int32_t &value, int32_t new_value, http_hdr_cc_type hdr, bool setting=true); |
cf7c2e94 | 187 | |
422acb7f | 188 | public: |
c57b8f05 FC |
189 | /**comma-separated representation of the header values which were |
190 | * received but are not recognized. | |
191 | */ | |
7ebe76de | 192 | String other; |
0abdd70d FC |
193 | }; |
194 | ||
195 | MEMPROXY_CLASS_INLINE(HttpHdrCc); | |
196 | ||
9a117495 FC |
197 | class StatHist; |
198 | class StoreEntry; | |
199 | ||
8a648e8d FC |
200 | void httpHdrCcInitModule(void); |
201 | void httpHdrCcCleanModule(void); | |
202 | void httpHdrCcUpdateStats(const HttpHdrCc * cc, StatHist * hist); | |
203 | void httpHdrCcStatDumper(StoreEntry * sentry, int idx, double val, double size, int count); | |
9a117495 | 204 | |
9774b48e FC |
205 | #if _USE_INLINE_ |
206 | #include "HttpHdrCc.cci" | |
207 | #endif | |
208 | ||
576840e8 | 209 | #endif /* SQUID_HTTPHDRCC_H */ |