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