]> git.ipfire.org Git - thirdparty/squid.git/blame - src/RefreshPattern.h
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / RefreshPattern.h
CommitLineData
8d9a8184 1/*
bf95c10a 2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
8d9a8184 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.
8d9a8184
FC
7 */
8
bbc27441
AJ
9#ifndef SQUID_REFRESHPATTERN_H_
10#define SQUID_REFRESHPATTERN_H_
11
95b8eae2 12#include "base/RegexPattern.h"
09a86349 13
0fa036e3
AR
14#include <memory>
15
95b8eae2 16/// a representation of a refresh pattern.
1b2f0924
FC
17class RefreshPattern
18{
95b8eae2
AJ
19 MEMPROXY_CLASS(RefreshPattern);
20
8d9a8184 21public:
95b8eae2
AJ
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
0fa036e3
AR
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):
95b8eae2 36 min(0), pct(0.20), max(REFRESH_DEFAULT_MAX),
aee3523a 37 next(nullptr),
0fa036e3
AR
38 max_stale(0),
39 regex_(std::move(aRegex))
95b8eae2
AJ
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 }
95b8eae2 51
8d9a8184
FC
52 time_t min;
53 double pct;
54 time_t max;
55 RefreshPattern *next;
56
57 struct {
be4d35dc
FC
58 bool refresh_ims;
59 bool store_stale;
8d9a8184 60#if USE_HTTP_VIOLATIONS
be4d35dc
FC
61 bool override_expire;
62 bool override_lastmod;
63 bool reload_into_ims;
64 bool ignore_reload;
65 bool ignore_no_store;
be4d35dc 66 bool ignore_private;
8d9a8184
FC
67#endif
68 } flags;
69 int max_stale;
a5ea7751
AJ
70
71 // statistics about how many matches this pattern has had
72 mutable struct stats_ {
95b8eae2
AJ
73 stats_() : matchTests(0), matchCount(0) {}
74
a5ea7751
AJ
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;
0fa036e3
AR
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
90private:
91 /// configured regex or, for the implicit refresh_pattern rule, nil
92 RegexPointer regex_;
8d9a8184
FC
93};
94
0fa036e3
AR
95inline std::ostream &
96operator <<(std::ostream &os, const RefreshPattern &r)
97{
98 r.printHead(os);
99 return os;
100}
101
8d9a8184 102#endif /* SQUID_REFRESHPATTERN_H_ */
f53969cc 103