]> git.ipfire.org Git - thirdparty/squid.git/blob - src/ClientDelayConfig.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / ClientDelayConfig.cc
1 /*
2 * Copyright (C) 1996-2017 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 #include "squid.h"
10 #include "acl/Acl.h"
11 #include "acl/Gadgets.h"
12 #include "ClientDelayConfig.h"
13 #include "ConfigParser.h"
14 #include "Parsing.h"
15 #include "Store.h"
16
17 void ClientDelayPool::dump(StoreEntry * entry, unsigned int poolNumberMinusOne) const
18 {
19 LOCAL_ARRAY(char, nom, 32);
20 snprintf(nom, 32, "client_delay_access %d", poolNumberMinusOne + 1);
21 dump_acl_access(entry, nom, access);
22 storeAppendPrintf(entry, "client_delay_parameters %d %d %" PRId64 "\n", poolNumberMinusOne + 1, rate,highwatermark);
23 storeAppendPrintf(entry, "\n");
24 }
25
26 void
27 ClientDelayConfig::finalize()
28 {
29 for (unsigned int i = 0; i < pools.size(); ++i) {
30 /* pools require explicit 'allow' to assign a client into them */
31 if (!pools[i].access) {
32 debugs(77, DBG_IMPORTANT, "client_delay_pool #" << (i+1) <<
33 " has no client_delay_access configured. " <<
34 "No client will ever use it.");
35 }
36 }
37 }
38
39 void ClientDelayConfig::freePoolCount()
40 {
41 pools.clear();
42 }
43
44 void ClientDelayConfig::dumpPoolCount(StoreEntry * entry, const char *name) const
45 {
46 if (pools.size()) {
47 storeAppendPrintf(entry, "%s %d\n", name, (int)pools.size());
48 for (unsigned int i = 0; i < pools.size(); ++i)
49 pools[i].dump(entry, i);
50 }
51 }
52
53 void ClientDelayConfig::parsePoolCount()
54 {
55 if (pools.size()) {
56 debugs(3, DBG_CRITICAL, "parse_client_delay_pool_count: multiple client_delay_pools lines, aborting all previous client_delay_pools config");
57 clean();
58 }
59 unsigned short pools_;
60 ConfigParser::ParseUShort(&pools_);
61 for (int i = 0; i < pools_; ++i) {
62 pools.push_back(ClientDelayPool());
63 }
64 }
65
66 void ClientDelayConfig::parsePoolRates()
67 {
68 unsigned short pool;
69 ConfigParser::ParseUShort(&pool);
70
71 if (pool < 1 || pool > pools.size()) {
72 debugs(3, DBG_CRITICAL, "parse_client_delay_pool_rates: Ignoring pool " << pool << " not in 1 .. " << pools.size());
73 return;
74 }
75
76 --pool;
77
78 pools[pool].rate = GetInteger();
79 pools[pool].highwatermark = GetInteger64();
80 }
81
82 void ClientDelayConfig::parsePoolAccess(ConfigParser &parser)
83 {
84 unsigned short pool;
85
86 ConfigParser::ParseUShort(&pool);
87
88 if (pool < 1 || pool > pools.size()) {
89 debugs(3, DBG_CRITICAL, "parse_client_delay_pool_rates: Ignoring pool " << pool << " not in 1 .. " << pools.size());
90 return;
91 }
92
93 --pool;
94 aclParseAccessLine("client_delay_access", parser, &pools[pool].access);
95 }
96
97 void ClientDelayConfig::clean()
98 {
99 for (unsigned int i = 0; i < pools.size(); ++i) {
100 aclDestroyAccessList(&pools[i].access);
101 }
102 }
103