]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (C) 1996-2023 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 | #ifndef SQUID_HTTPHDRSURROGATECONTROLTARGET_H | |
10 | #define SQUID_HTTPHDRSURROGATECONTROLTARGET_H | |
11 | ||
12 | #include "defines.h" //for bit mask operations | |
13 | #include "http/forward.h" | |
14 | #include "SquidString.h" | |
15 | ||
16 | class Packable; | |
17 | class StatHist; | |
18 | class StoreEntry; | |
19 | ||
20 | /** Representation of HTTP Surogate-Control header field targeted directive | |
21 | * | |
22 | * \see HttpHdrSc | |
23 | */ | |
24 | class HttpHdrScTarget | |
25 | { | |
26 | // parsing is done in HttpHdrSc, need to grant them access. | |
27 | friend class HttpHdrSc; | |
28 | public: | |
29 | static const int MAX_AGE_UNSET=-1; //max-age is unset | |
30 | static const int MAX_STALE_UNSET=0; //max-stale is unset | |
31 | ||
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 | |
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) { | |
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 | } | |
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) { | |
68 | setMask(SC_CONTENT,true); | |
69 | content_=v; | |
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); | |
78 | void packInto(Packable *p) const; | |
79 | void updateStats(StatHist *) const; | |
80 | ||
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 | ||
92 | int mask = 0; | |
93 | int max_age = MAX_AGE_UNSET; | |
94 | int max_stale = MAX_STALE_UNSET; | |
95 | String content_; | |
96 | String target; | |
97 | }; | |
98 | ||
99 | void httpHdrScTargetStatDumper(StoreEntry * sentry, int idx, double val, double size, int count); | |
100 | ||
101 | #endif /* SQUID_HTTPHDRSURROGATECONTROLTARGET_H */ | |
102 |