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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors