]> git.ipfire.org Git - thirdparty/squid.git/blob - src/RefreshPattern.h
5de52b9c4861370f32689de2f702899d94640336
[thirdparty/squid.git] / src / RefreshPattern.h
1 /*
2 * Copyright (C) 1996-2022 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_REFRESHPATTERN_H_
10 #define SQUID_REFRESHPATTERN_H_
11
12 #include "base/RegexPattern.h"
13
14 #include <memory>
15
16 /// a representation of a refresh pattern.
17 class RefreshPattern
18 {
19 MEMPROXY_CLASS(RefreshPattern);
20
21 public:
22
23 /*
24 * Defaults:
25 * MIN NONE
26 * PCT 20%
27 * MAX 3 days
28 */
29 #define REFRESH_DEFAULT_MAX static_cast<time_t>(259200)
30
31 using RegexPointer = std::unique_ptr<RegexPattern>;
32
33 // If given a regex, becomes its owner, creating an explicit refresh_pattern
34 // rule. Otherwise, creates an implicit/default refresh_pattern rule.
35 explicit RefreshPattern(RegexPointer aRegex):
36 min(0), pct(0.20), max(REFRESH_DEFAULT_MAX),
37 next(nullptr),
38 max_stale(0),
39 regex_(std::move(aRegex))
40 {
41 memset(&flags, 0, sizeof(flags));
42 }
43
44 ~RefreshPattern() {
45 while (RefreshPattern *t = next) {
46 next = t->next;
47 t->next = nullptr;
48 delete t;
49 }
50 }
51
52 time_t min;
53 double pct;
54 time_t max;
55 RefreshPattern *next;
56
57 struct {
58 bool refresh_ims;
59 bool store_stale;
60 #if USE_HTTP_VIOLATIONS
61 bool override_expire;
62 bool override_lastmod;
63 bool reload_into_ims;
64 bool ignore_reload;
65 bool ignore_no_store;
66 bool ignore_private;
67 #endif
68 } flags;
69 int max_stale;
70
71 // statistics about how many matches this pattern has had
72 mutable struct stats_ {
73 stats_() : matchTests(0), matchCount(0) {}
74
75 uint64_t matchTests;
76 uint64_t matchCount;
77 // TODO: some stats to indicate how useful/less the flags are would be nice.
78 } stats;
79
80 /// reports configuration excluding trailing options
81 void printHead(std::ostream &) const;
82
83 /// reports the configured pattern or a fake pattern of the implicit rule
84 void printPattern(std::ostream &os) const;
85
86 // TODO: Refactor external refresh_pattern rules iterators to make private.
87 /// configured regex; do not use except when iterating configured rules
88 const RegexPattern &regex() const;
89
90 private:
91 /// configured regex or, for the implicit refresh_pattern rule, nil
92 RegexPointer regex_;
93 };
94
95 inline std::ostream &
96 operator <<(std::ostream &os, const RefreshPattern &r)
97 {
98 r.printHead(os);
99 return os;
100 }
101
102 #endif /* SQUID_REFRESHPATTERN_H_ */
103