Config.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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/FilledChecklist.h"
11#include "acl/Gadgets.h"
13#include "adaptation/Config.h"
14#include "adaptation/History.h"
15#include "adaptation/Service.h"
17#include "cache_cf.h"
18#include "ConfigParser.h"
19#include "debug/Messages.h"
20#include "globals.h"
21#include "HttpReply.h"
22#include "HttpRequest.h"
23#include "Store.h"
24
25#include <algorithm>
26
33static const char *protectedFieldNamesRaw[] = {
34 "Allow",
35 "Date",
36 "Encapsulated",
37 "ISTag",
38 "Max-Connections",
39 "Methods",
40 "Opt-body-type",
41 "Options-TTL",
42 "Preview",
43 "Service",
44 "Service-ID",
45 "Transfer-Complete",
46 "Transfer-Ignore",
47 "Transfer-Preview"
48};
52
55{
56 return new ServiceConfig();
57}
58
59void
61{
62 removeRule(service);
63 const Groups& groups = AllGroups();
64 for (unsigned int i = 0; i < groups.size(); ) {
65 const ServiceGroupPointer group = groups[i];
66 const ServiceGroup::Store& services = group->services;
67 typedef ServiceGroup::Store::const_iterator SGSI;
68 for (SGSI it = services.begin(); it != services.end(); ++it) {
69 if (*it == service) {
70 group->removedServices.push_back(service);
71 ServiceGroup::Store::iterator newend;
72 newend = std::remove(group->services.begin(), group->services.end(), service);
73 group->services.resize(newend-group->services.begin());
74 debugs(93, 5, "adaptation service " << service <<
75 " removed from group " << group->id);
76 break;
77 }
78 }
79 if (services.empty()) {
80 removeRule(group->id);
81 Groups::iterator newend;
82 newend = std::remove(AllGroups().begin(), AllGroups().end(), group);
83 AllGroups().resize(newend-AllGroups().begin());
84 } else {
85 ++i;
86 }
87 }
88}
89
92{
93 typedef ServiceConfigs::const_iterator SCI;
94 const ServiceConfigs& configs = serviceConfigs;
95 for (SCI cfg = configs.begin(); cfg != configs.end(); ++cfg) {
96 if ((*cfg)->key == service)
97 return *cfg;
98 }
99 return nullptr;
100}
101
102void
104{
105 typedef AccessRules::const_iterator ARI;
106 const AccessRules& rules = AllRules();
107 for (ARI it = rules.begin(); it != rules.end(); ++it) {
108 AccessRule* rule = *it;
109 if (rule->groupId == id) {
110 debugs(93, 5, "removing access rules for:" << id);
111 AccessRules::iterator newend;
112 newend = std::remove(AllRules().begin(), AllRules().end(), rule);
113 AllRules().resize(newend-AllRules().begin());
114 delete (rule);
115 break;
116 }
117 }
118}
119
120void
122{
123 debugs(93, 3, "rules: " << AllRules().size() << ", groups: " <<
124 AllGroups().size() << ", services: " << serviceConfigs.size());
125 typedef ServiceConfigs::const_iterator SCI;
126 const ServiceConfigs& configs = serviceConfigs;
127 for (SCI cfg = configs.begin(); cfg != configs.end(); ++cfg)
128 removeService((*cfg)->key);
129 serviceConfigs.clear();
130 debugs(93, 3, "rules: " << AllRules().size() << ", groups: " <<
131 AllGroups().size() << ", services: " << serviceConfigs.size());
132}
133
134void
136{
137 ServiceConfigPointer cfg = newServiceConfig();
138 if (!cfg->parse()) {
139 fatalf("%s:%d: malformed adaptation service configuration",
141 }
142 serviceConfigs.push_back(cfg);
143}
144
145void
147{
148 FreeAccess();
149 FreeServiceGroups();
150
152
153 serviceConfigs.clear();
154}
155
156void
157Adaptation::Config::dumpService(StoreEntry *entry, const char *name) const
158{
159 typedef Services::iterator SCI;
160 for (SCI i = AllServices().begin(); i != AllServices().end(); ++i) {
161 const ServiceConfig &cfg = (*i)->cfg();
162 bool isEcap = cfg.protocol.caseCmp("ecap") == 0;
163 bool isIcap = !isEcap;
164 const char *optConnectionEncryption = "";
165 // Print connections_encrypted option if no default value is used
167 optConnectionEncryption = " connection-encryption=off";
168 else if (isEcap && !cfg.connectionEncryption)
169 optConnectionEncryption = " connection-encryption=off";
170 else if (isIcap && !cfg.secure.encryptTransport && cfg.connectionEncryption)
171 optConnectionEncryption = " connection-encryption=on";
172
173 storeAppendPrintf(entry, "%s " SQUIDSTRINGPH " %s_%s %d " SQUIDSTRINGPH "%s\n",
174 name,
176 cfg.methodStr(), cfg.vectPointStr(), cfg.bypass,
178
179 optConnectionEncryption);
180 }
181}
182
183bool
185{
186 if (!onoff) {
187 clear();
188 return false;
189 }
190
191 // create service reps from service configs
192 int created = 0;
193
194 typedef ServiceConfigs::const_iterator VISCI;
195 const ServiceConfigs &configs = serviceConfigs;
196 for (VISCI i = configs.begin(); i != configs.end(); ++i) {
197 const ServiceConfigPointer cfg = *i;
198 if (FindService(cfg->key) != nullptr) {
199 debugs(93, DBG_CRITICAL, "ERROR: Duplicate adaptation service name: " <<
200 cfg->key);
201 continue; // TODO: make fatal
202 }
203 ServicePointer s = createService(cfg);
204 if (s != nullptr) {
205 AllServices().push_back(s);
206 ++created;
207 }
208 }
209
210 debugs(93,3, "Created " << created << " adaptation services");
211
212 // services remember their configs; we do not have to
213 serviceConfigs.clear();
214 return true;
215}
216
217// poor man for_each
218template <class Collection>
219static void
220FinalizeEach(Collection &collection, const char *label)
221{
222 typedef typename Collection::iterator CI;
223 for (CI i = collection.begin(); i != collection.end(); ++i)
224 (*i)->finalize();
225
226 debugs(93,2, "Initialized " << collection.size() << ' ' << label);
227}
228
229void
231{
232 Enabled = enabled;
233 debugs(93, Important(11), "Adaptation support is " << (Enabled ? "on" : "off."));
234
235 FinalizeEach(AllServices(), "message adaptation services");
236 FinalizeEach(AllGroups(), "message adaptation service groups");
237 FinalizeEach(AllRules(), "message adaptation access rules");
238}
239
240void
242{
244}
245
246void
248{
250}
251
252void
254{
255 assert(g != nullptr);
256 g->parse();
257 AllGroups().push_back(g);
258}
259
260void
262{
263 while (!AllGroups().empty()) {
264 // groups are refcounted so we do not explicitly delete them
265 AllGroups().pop_back();
266 }
267}
268
269void
271{
272 typedef Groups::iterator GI;
273 for (GI i = AllGroups().begin(); i != AllGroups().end(); ++i)
274 storeAppendPrintf(entry, "%s " SQUIDSTRINGPH "\n", name, SQUIDSTRINGPRINT((*i)->id));
275}
276
277void
279{
281 AccessRule *r;
282 if (!(r=FindRuleByGroupId(groupId))) {
283 r = new AccessRule(groupId);
284 AllRules().push_back(r);
285 }
286 r->parse(parser);
287}
288
289void
291{
292 while (!AllRules().empty()) {
293 delete AllRules().back();
294 AllRules().pop_back();
295 }
296}
297
298void
300{
301 LOCAL_ARRAY(char, nom, 64);
302
303 typedef AccessRules::iterator CI;
304 for (CI i = AllRules().begin(); i != AllRules().end(); ++i) {
305 snprintf(nom, 64, "%s " SQUIDSTRINGPH, name, SQUIDSTRINGPRINT((*i)->groupId));
306 dump_acl_access(entry, nom, (*i)->acl);
307 }
308}
309
311 onoff(0), service_failure_limit(0), oldest_service_failure(0),
312 service_revival_delay(0)
313{}
314
315// XXX: this is called for ICAP and eCAP configs, but deals mostly
316// with global arrays shared by those individual configs
318{
319 freeService();
320}
321
int size
Definition: ModDevPoll.cc:75
#define SQUIDSTRINGPH
Definition: SquidString.h:21
#define SQUIDSTRINGPRINT(s)
Definition: SquidString.h:22
static void FinalizeEach(Collection &collection, const char *label)
Definition: Config.cc:220
static const Notes::Keys protectedFieldNames(std::begin(protectedFieldNamesRaw), std::end(protectedFieldNamesRaw))
static const char * protectedFieldNamesRaw[]
Definition: Config.cc:33
#define assert(EX)
Definition: assert.h:19
const char * cfg_filename
Definition: cache_cf.cc:271
int config_lineno
Definition: cache_cf.cc:272
void parse(ConfigParser &parser)
Definition: AccessRule.cc:30
static void DumpServiceGroups(StoreEntry *, const char *)
Definition: Config.cc:270
void parseService(void)
Definition: Config.cc:135
static int send_client_ip
Definition: Config.h:47
void removeService(const String &service)
Removes the given service from all service groups.
Definition: Config.cc:60
virtual bool finalize()
Definition: Config.cc:184
virtual void clear()
Removes any reference to the services from configuration.
Definition: Config.cc:121
ServiceConfigPointer findServiceConfig(const String &)
Definition: Config.cc:91
static void ParseServiceSet(void)
Definition: Config.cc:241
static void Finalize(bool enable)
Definition: Config.cc:230
static void FreeServiceGroups(void)
Definition: Config.cc:261
static int use_indirect_client
Definition: Config.h:49
static void ParseAccess(ConfigParser &parser)
Definition: Config.cc:278
static void ParseServiceGroup(ServiceGroupPointer group)
Definition: Config.cc:253
void removeRule(const String &id)
Removes access rules of the given service or group.
Definition: Config.cc:103
static bool needHistory
HttpRequest adaptation history should recorded.
Definition: Config.h:60
static void FreeAccess(void)
Definition: Config.cc:290
static int send_username
Definition: Config.h:48
void dumpService(StoreEntry *, const char *) const
Definition: Config.cc:157
std::vector< ServiceConfigPointer > ServiceConfigs
Definition: Config.h:62
static char * masterx_shared_name
Definition: Config.h:45
static bool Enabled
Definition: Config.h:42
static int service_iteration_limit
Definition: Config.h:46
virtual ~Config()
Definition: Config.cc:317
void freeService(void)
Definition: Config.cc:146
virtual ServiceConfig * newServiceConfig() const
creates service configuration object that will parse and keep cfg info
Definition: Config.cc:54
static Notes metaHeaders
The list of configured meta headers.
Definition: Config.h:58
static void ParseServiceChain(void)
Definition: Config.cc:247
static void DumpAccess(StoreEntry *, const char *)
Definition: Config.cc:299
a group of services that must be used one after another
Security::PeerOptions secure
Definition: ServiceConfig.h:53
const char * vectPointStr() const
YesNoNone connectionEncryption
whether this service uses only secure connections
Definition: ServiceConfig.h:54
const char * methodStr() const
std::vector< String > Store
Definition: ServiceGroups.h:29
Store removedServices
the disabled services in the case ecap or icap is disabled
Definition: ServiceGroups.h:68
static char * NextToken()
Definition: Notes.h:109
std::vector< SBuf > Keys
unordered annotation names
Definition: Notes.h:112
bool encryptTransport
whether transport encryption (TLS/SSL) is to be used on connections to the peer
Definition: PeerOptions.h:145
int caseCmp(char const *) const
Definition: String.cc:285
#define Important(id)
Definition: Messages.h:91
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
void fatalf(const char *fmt,...)
Definition: fatal.cc:68
void dump_acl_access(StoreEntry *entry, const char *name, acl_access *head)
Definition: cache_cf.cc:1515
std::vector< ServiceGroupPointer > Groups
Services & AllServices()
Definition: Service.cc:61
AccessRules & AllRules()
Definition: AccessRule.cc:61
void DetachServices()
detach all adaptation services from current configuration
Definition: Service.cc:78
Groups & AllGroups()
std::vector< Adaptation::AccessRule * > AccessRules
Definition: AccessRule.h:47
ServicePointer FindService(const Service::Id &key)
Definition: Service.cc:68
AccessRule * FindRuleByGroupId(const String &groupId)
Definition: AccessRule.cc:81
#define LOCAL_ARRAY(type, name, size)
Definition: squid.h:68
void storeAppendPrintf(StoreEntry *e, const char *fmt,...)
Definition: store.cc:828

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors