]>
Commit | Line | Data |
---|---|---|
7ede6971 | 1 | /* |
f70aedc4 | 2 | * Copyright (C) 1996-2021 The Squid Software Foundation and contributors |
7ede6971 | 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. | |
7ede6971 | 7 | */ |
bbc27441 | 8 | |
7ede6971 | 9 | #ifndef SQUID_HTTPHDRSURROGATECONTROLTARGET_H |
10 | #define SQUID_HTTPHDRSURROGATECONTROLTARGET_H | |
11 | ||
1da82544 | 12 | #include "defines.h" //for bit mask operations |
24673a9e AJ |
13 | #include "http/forward.h" |
14 | #include "SquidString.h" | |
7ede6971 | 15 | |
17802cf1 | 16 | class Packable; |
582c2af2 | 17 | class StatHist; |
582c2af2 FC |
18 | class StoreEntry; |
19 | ||
45a58345 FC |
20 | /** Representation of HTTP Surogate-Control header field targeted directive |
21 | * | |
22 | * \see HttpHdrSc | |
23 | */ | |
7ede6971 | 24 | class HttpHdrScTarget |
25 | { | |
45a58345 FC |
26 | // parsing is done in HttpHdrSc, need to grant them access. |
27 | friend class HttpHdrSc; | |
7ede6971 | 28 | public: |
633b9845 A |
29 | static const int MAX_AGE_UNSET=-1; //max-age is unset |
30 | static const int MAX_STALE_UNSET=0; //max-stale is unset | |
45a58345 | 31 | |
24673a9e AJ |
32 | explicit HttpHdrScTarget(const char *aTarget): target(aTarget) {} |
33 | explicit HttpHdrScTarget(const String &aTarget): target(aTarget) {} | |
34 | explicit HttpHdrScTarget(const HttpHdrScTarget &) = delete; // avoid accidental string copies | |
35 | HttpHdrScTarget &operator =(const HttpHdrScTarget &) = delete; // avoid accidental string copies | |
45a58345 FC |
36 | |
37 | bool hasNoStore() const {return isSet(SC_NO_STORE); } | |
38 | void noStore(bool v) { setMask(SC_NO_STORE,v); } | |
39 | bool noStore() const { return isSet(SC_NO_STORE); } | |
40 | void clearNoStore() { setMask(SC_NO_STORE, false); } | |
41 | ||
42 | bool hasNoStoreRemote() const {return isSet(SC_NO_STORE_REMOTE); } | |
43 | void noStoreRemote(bool v) { setMask(SC_NO_STORE_REMOTE,v); } | |
44 | bool noStoreRemote() const { return isSet(SC_NO_STORE_REMOTE); } | |
45 | void clearNoStoreRemote() { setMask(SC_NO_STORE_REMOTE, false); } | |
46 | ||
47 | bool hasMaxAge() const { return isSet(SC_MAX_AGE); } | |
48 | void maxAge(int v) { | |
633b9845 A |
49 | if (v >= 0) { //setting |
50 | setMask(SC_MAX_AGE,true); | |
51 | max_age=v; | |
52 | } else { | |
53 | setMask(SC_MAX_AGE,false); | |
54 | max_age=MAX_AGE_UNSET; | |
55 | } | |
45a58345 FC |
56 | } |
57 | int maxAge() const { return max_age; } | |
58 | void clearMaxAge() { setMask(SC_MAX_AGE,false); max_age=MAX_AGE_UNSET; } | |
59 | ||
60 | //max_stale has no associated status-bit | |
61 | bool hasMaxStale() const { return max_stale != MAX_STALE_UNSET; } | |
62 | void maxStale(int v) { max_stale=v; } | |
63 | int maxStale() const { return max_stale; } | |
64 | void clearMaxStale() { max_stale=MAX_STALE_UNSET; } | |
65 | ||
66 | bool hasContent() const { return isSet(SC_CONTENT); } | |
67 | void Content(const String &v) { | |
633b9845 A |
68 | setMask(SC_CONTENT,true); |
69 | content_=v; | |
45a58345 FC |
70 | } |
71 | String content() const { return content_; } | |
72 | void clearContent() { setMask(SC_CONTENT,false); content_.clean(); } | |
73 | ||
74 | bool hasTarget() const { return target.size() != 0; } | |
75 | String Target() const { return target; } | |
76 | ||
77 | void mergeWith(const HttpHdrScTarget * new_sc); | |
17802cf1 | 78 | void packInto(Packable *p) const; |
45a58345 FC |
79 | void updateStats(StatHist *) const; |
80 | ||
45a58345 FC |
81 | private: |
82 | bool isSet(http_hdr_sc_type id) const { | |
83 | assert (id >= SC_NO_STORE && id < SC_ENUM_END); | |
84 | return EBIT_TEST(mask,id); | |
85 | } | |
86 | ||
87 | void setMask(http_hdr_sc_type id, bool newval) { | |
88 | if (newval) EBIT_SET(mask,id); | |
89 | else EBIT_CLR(mask,id); | |
90 | } | |
91 | ||
24673a9e AJ |
92 | int mask = 0; |
93 | int max_age = MAX_AGE_UNSET; | |
94 | int max_stale = MAX_STALE_UNSET; | |
45a58345 | 95 | String content_; |
30abd221 | 96 | String target; |
7ede6971 | 97 | }; |
98 | ||
8a648e8d | 99 | void httpHdrScTargetStatDumper(StoreEntry * sentry, int idx, double val, double size, int count); |
7ede6971 | 100 | |
101 | #endif /* SQUID_HTTPHDRSURROGATECONTROLTARGET_H */ | |
f53969cc | 102 |