]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
b8ae064d | 2 | * Copyright (C) 1996-2023 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
14a7bbc7 | 9 | #include "squid.h" |
582c2af2 FC |
10 | #include "acl/Acl.h" |
11 | #include "acl/Gadgets.h" | |
14a7bbc7 | 12 | #include "ClientDelayConfig.h" |
582c2af2 | 13 | #include "ConfigParser.h" |
14a7bbc7 CT |
14 | #include "Parsing.h" |
15 | #include "Store.h" | |
14a7bbc7 | 16 | |
b27668ec EB |
17 | ClientDelayPool::~ClientDelayPool() |
18 | { | |
19 | if (access) | |
20 | aclDestroyAccessList(&access); | |
21 | } | |
22 | ||
14a7bbc7 CT |
23 | void ClientDelayPool::dump(StoreEntry * entry, unsigned int poolNumberMinusOne) const |
24 | { | |
25 | LOCAL_ARRAY(char, nom, 32); | |
26 | snprintf(nom, 32, "client_delay_access %d", poolNumberMinusOne + 1); | |
27 | dump_acl_access(entry, nom, access); | |
c91ca3ce | 28 | storeAppendPrintf(entry, "client_delay_parameters %d %d %" PRId64 "\n", poolNumberMinusOne + 1, rate,highwatermark); |
14a7bbc7 CT |
29 | storeAppendPrintf(entry, "\n"); |
30 | } | |
31 | ||
b27668ec EB |
32 | ClientDelayPools * |
33 | ClientDelayPools::Instance() | |
34 | { | |
35 | static ClientDelayPools pools; | |
36 | return &pools; | |
37 | } | |
38 | ||
39 | ClientDelayPools::~ClientDelayPools() | |
40 | { | |
41 | pools.clear(); | |
42 | } | |
43 | ||
14a7bbc7 CT |
44 | void |
45 | ClientDelayConfig::finalize() | |
46 | { | |
b27668ec | 47 | for (unsigned int i = 0; i < pools().size(); ++i) { |
14a7bbc7 | 48 | /* pools require explicit 'allow' to assign a client into them */ |
b27668ec EB |
49 | if (!pool(i).access) { |
50 | debugs(77, DBG_IMPORTANT, "WARNING: client_delay_pool #" << (i+1) << | |
f33d34a8 A |
51 | " has no client_delay_access configured. " << |
52 | "No client will ever use it."); | |
53 | } | |
54 | } | |
14a7bbc7 CT |
55 | } |
56 | ||
b27668ec | 57 | void ClientDelayConfig::dumpPoolCount(StoreEntry * entry, const char *name) const |
14a7bbc7 | 58 | { |
b27668ec EB |
59 | const auto &pools_ = ClientDelayPools::Instance()->pools; |
60 | if (pools_.size()) { | |
61 | storeAppendPrintf(entry, "%s %d\n", name, static_cast<int>(pools_.size())); | |
62 | for (unsigned int i = 0; i < pools_.size(); ++i) | |
63 | pools_[i]->dump(entry, i); | |
64 | } | |
14a7bbc7 CT |
65 | } |
66 | ||
b27668ec EB |
67 | void |
68 | ClientDelayConfig::freePools() | |
14a7bbc7 | 69 | { |
b27668ec | 70 | pools().clear(); |
14a7bbc7 CT |
71 | } |
72 | ||
73 | void ClientDelayConfig::parsePoolCount() | |
74 | { | |
b27668ec EB |
75 | if (pools().size()) { |
76 | debugs(3, DBG_CRITICAL, "parse_client_delay_pool_count: multiple client_delay_pools lines, " << | |
77 | "aborting all previous client_delay_pools config"); | |
78 | freePools(); | |
14a7bbc7 | 79 | } |
f45dd259 | 80 | unsigned short pools_; |
14a7bbc7 | 81 | ConfigParser::ParseUShort(&pools_); |
b27668ec EB |
82 | for (int i = 0; i < pools_; ++i) |
83 | pools().push_back(new ClientDelayPool()); | |
14a7bbc7 CT |
84 | } |
85 | ||
86 | void ClientDelayConfig::parsePoolRates() | |
87 | { | |
b27668ec EB |
88 | if (unsigned short poolId = parsePoolId()) { |
89 | --poolId; | |
90 | pool(poolId).rate = GetInteger(); | |
91 | pool(poolId).highwatermark = GetInteger64(); | |
14a7bbc7 | 92 | } |
14a7bbc7 CT |
93 | } |
94 | ||
95 | void ClientDelayConfig::parsePoolAccess(ConfigParser &parser) | |
96 | { | |
b27668ec EB |
97 | if (const unsigned short poolId = parsePoolId()) |
98 | aclParseAccessLine("client_delay_access", parser, &(pool(poolId-1).access)); | |
14a7bbc7 CT |
99 | } |
100 | ||
b27668ec EB |
101 | unsigned short |
102 | ClientDelayConfig::parsePoolId() | |
14a7bbc7 | 103 | { |
b27668ec EB |
104 | unsigned short poolId = 0; |
105 | ConfigParser::ParseUShort(&poolId); | |
106 | if (poolId < 1 || poolId > pools().size()) { | |
107 | debugs(3, DBG_CRITICAL, "parse_client_delay_pool_rates: Ignoring pool " << | |
108 | poolId << " not in 1 .. " << pools().size()); | |
109 | return 0; | |
14a7bbc7 | 110 | } |
b27668ec | 111 | return poolId; |
14a7bbc7 | 112 | } |
f53969cc | 113 |