]> git.ipfire.org Git - thirdparty/squid.git/blame - src/HttpHdrScTarget.h
SourceFormat Enforcement
[thirdparty/squid.git] / src / HttpHdrScTarget.h
CommitLineData
7ede6971 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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
b56ab9e7 13#include "HttpHdrSc.h"
7ede6971 14
17802cf1 15class Packable;
582c2af2 16class StatHist;
582c2af2
FC
17class StoreEntry;
18
45a58345
FC
19/** Representation of HTTP Surogate-Control header field targeted directive
20 *
21 * \see HttpHdrSc
22 */
7ede6971 23class HttpHdrScTarget
24{
741c2986
AJ
25 MEMPROXY_CLASS(HttpHdrScTarget);
26
45a58345
FC
27 // parsing is done in HttpHdrSc, need to grant them access.
28 friend class HttpHdrSc;
7ede6971 29public:
633b9845
A
30 static const int MAX_AGE_UNSET=-1; //max-age is unset
31 static const int MAX_STALE_UNSET=0; //max-stale is unset
45a58345
FC
32
33 HttpHdrScTarget(const char *target_):
f53969cc 34 mask(0), max_age(MAX_AGE_UNSET), max_stale(MAX_STALE_UNSET),target(target_) {}
45a58345 35 HttpHdrScTarget(const String &target_):
f53969cc 36 mask(0), max_age(MAX_AGE_UNSET), max_stale(MAX_STALE_UNSET),target(target_) {}
45a58345 37 HttpHdrScTarget(const HttpHdrScTarget &t):
f53969cc
SM
38 mask(t.mask), max_age(t.max_age), max_stale(t.max_stale),
39 content_(t.content_), target(t.target) {}
45a58345
FC
40
41 bool hasNoStore() const {return isSet(SC_NO_STORE); }
42 void noStore(bool v) { setMask(SC_NO_STORE,v); }
43 bool noStore() const { return isSet(SC_NO_STORE); }
44 void clearNoStore() { setMask(SC_NO_STORE, false); }
45
46 bool hasNoStoreRemote() const {return isSet(SC_NO_STORE_REMOTE); }
47 void noStoreRemote(bool v) { setMask(SC_NO_STORE_REMOTE,v); }
48 bool noStoreRemote() const { return isSet(SC_NO_STORE_REMOTE); }
49 void clearNoStoreRemote() { setMask(SC_NO_STORE_REMOTE, false); }
50
51 bool hasMaxAge() const { return isSet(SC_MAX_AGE); }
52 void maxAge(int v) {
633b9845
A
53 if (v >= 0) { //setting
54 setMask(SC_MAX_AGE,true);
55 max_age=v;
56 } else {
57 setMask(SC_MAX_AGE,false);
58 max_age=MAX_AGE_UNSET;
59 }
45a58345
FC
60 }
61 int maxAge() const { return max_age; }
62 void clearMaxAge() { setMask(SC_MAX_AGE,false); max_age=MAX_AGE_UNSET; }
63
64 //max_stale has no associated status-bit
65 bool hasMaxStale() const { return max_stale != MAX_STALE_UNSET; }
66 void maxStale(int v) { max_stale=v; }
67 int maxStale() const { return max_stale; }
68 void clearMaxStale() { max_stale=MAX_STALE_UNSET; }
69
70 bool hasContent() const { return isSet(SC_CONTENT); }
71 void Content(const String &v) {
633b9845
A
72 setMask(SC_CONTENT,true);
73 content_=v;
45a58345
FC
74 }
75 String content() const { return content_; }
76 void clearContent() { setMask(SC_CONTENT,false); content_.clean(); }
77
78 bool hasTarget() const { return target.size() != 0; }
79 String Target() const { return target; }
80
81 void mergeWith(const HttpHdrScTarget * new_sc);
17802cf1 82 void packInto(Packable *p) const;
45a58345
FC
83 void updateStats(StatHist *) const;
84
45a58345
FC
85private:
86 bool isSet(http_hdr_sc_type id) const {
87 assert (id >= SC_NO_STORE && id < SC_ENUM_END);
88 return EBIT_TEST(mask,id);
89 }
90
91 void setMask(http_hdr_sc_type id, bool newval) {
92 if (newval) EBIT_SET(mask,id);
93 else EBIT_CLR(mask,id);
94 }
95
7ede6971 96 int mask;
97 int max_age;
98 int max_stale;
45a58345 99 String content_;
30abd221 100 String target;
45a58345 101 dlink_node node;
7ede6971 102};
103
8a648e8d 104void httpHdrScTargetStatDumper(StoreEntry * sentry, int idx, double val, double size, int count);
7ede6971 105
106#endif /* SQUID_HTTPHDRSURROGATECONTROLTARGET_H */
f53969cc 107