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