ClientDelayConfig.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 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 
18 {
19  if (access)
21 }
22 
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);
28  storeAppendPrintf(entry, "client_delay_parameters %d %d %" PRId64 "\n", poolNumberMinusOne + 1, rate,highwatermark);
29  storeAppendPrintf(entry, "\n");
30 }
31 
34 {
35  static ClientDelayPools pools;
36  return &pools;
37 }
38 
40 {
41  pools.clear();
42 }
43 
44 void
46 {
47  for (unsigned int i = 0; i < pools().size(); ++i) {
48  /* pools require explicit 'allow' to assign a client into them */
49  if (!pool(i).access) {
50  debugs(77, DBG_IMPORTANT, "WARNING: client_delay_pool #" << (i+1) <<
51  " has no client_delay_access configured. " <<
52  "No client will ever use it.");
53  }
54  }
55 }
56 
57 void ClientDelayConfig::dumpPoolCount(StoreEntry * entry, const char *name) const
58 {
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  }
65 }
66 
67 void
69 {
70  pools().clear();
71 }
72 
74 {
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();
79  }
80  unsigned short pools_;
82  for (int i = 0; i < pools_; ++i)
83  pools().push_back(new ClientDelayPool());
84 }
85 
87 {
88  if (unsigned short poolId = parsePoolId()) {
89  --poolId;
90  pool(poolId).rate = GetInteger();
91  pool(poolId).highwatermark = GetInteger64();
92  }
93 }
94 
96 {
97  if (const unsigned short poolId = parsePoolId())
98  aclParseAccessLine("client_delay_access", parser, &(pool(poolId-1).access));
99 }
100 
101 unsigned short
103 {
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;
110  }
111  return poolId;
112 }
113 
#define DBG_CRITICAL
Definition: Stream.h:37
#define LOCAL_ARRAY(type, name, size)
Definition: squid.h:62
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:855
std::vector< ClientDelayPool::Pointer > pools
void finalize()
checks pools configuration
acl_access * access
void parsePoolAccess(ConfigParser &parser)
~ClientDelayPool() override
int size
Definition: ModDevPoll.cc:69
int64_t GetInteger64(void)
Definition: Parsing.cc:132
void dump_acl_access(StoreEntry *entry, const char *name, acl_access *head)
Definition: cache_cf.cc:1511
std::vector< ClientDelayPool::Pointer > & pools()
void dump(StoreEntry *entry, unsigned int poolNumberMinusOne) const
static ClientDelayPools * Instance()
ClientDelayPool & pool(const int i)
void aclDestroyAccessList(acl_access **list)
Definition: Gadgets.cc:223
void dumpPoolCount(StoreEntry *entry, const char *name) const
#define DBG_IMPORTANT
Definition: Stream.h:38
unsigned short parsePoolId()
#define PRId64
Definition: types.h:104
void aclParseAccessLine(const char *directive, ConfigParser &, acl_access **config)
Parses a single line of a "action followed by acls" directive (e.g., http_access).
Definition: Gadgets.cc:132
static void ParseUShort(unsigned short *var)
Definition: cache_cf.cc:3100
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
int GetInteger(void)
Definition: Parsing.cc:148

 

Introduction

Documentation

Support

Miscellaneous