]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/Config.cc
Merged from trunk.
[thirdparty/squid.git] / src / adaptation / Config.cc
CommitLineData
64bdef96
AR
1
2/*
3 * $Id: ICAPConfig.cc,v 1.21 2008/02/12 23:12:45 rousskov Exp $
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 */
32
33#include "squid.h"
34#include "structs.h"
35
36#include "ConfigParser.h"
37#include "ACL.h"
38#include "Store.h"
b6b637eb 39#include "Array.h" // really Vector
64bdef96
AR
40#include "adaptation/Config.h"
41#include "adaptation/Service.h"
62c7f90e
AR
42#include "adaptation/AccessRule.h"
43#include "adaptation/ServiceGroups.h"
64bdef96
AR
44
45
8f361c50
AR
46bool Adaptation::Config::Enabled = false;
47
64bdef96
AR
48void
49Adaptation::Config::parseService()
50{
51 ServiceConfig *cfg = new ServiceConfig;
52 cfg->parse();
53 serviceConfigs.push_back(cfg);
54}
55
56void
57Adaptation::Config::freeService()
58{
62c7f90e
AR
59 while (!serviceConfigs.empty()) {
60 delete serviceConfigs.back();
61 serviceConfigs.pop_back();
b6b637eb 62 }
64bdef96
AR
63}
64
65void
66Adaptation::Config::dumpService(StoreEntry *entry, const char *name) const
67{
68 typedef Services::iterator SCI;
69 for (SCI i = AllServices().begin(); i != AllServices().end(); ++i) {
70 const ServiceConfig &cfg = (*i)->cfg();
71 storeAppendPrintf(entry, "%s %s_%s %s %d %s\n", name, cfg.key.buf(),
72 cfg.methodStr(), cfg.vectPointStr(), cfg.bypass, cfg.uri.buf());
73 }
74}
75
76void
77Adaptation::Config::finalize()
78{
79 // create service reps from service configs
80 typedef Vector<ServiceConfig*>::const_iterator VISCI;
81 const Vector<ServiceConfig*> &configs = serviceConfigs;
82 debugs(93,3, "Found " << configs.size() << " service configs.");
62c7f90e 83 for (VISCI i = configs.begin(); i != configs.end(); ++i) {
e7de5ca3
AR
84 const ServiceConfig &cfg = **i;
85 if (FindService(cfg.key) != NULL) {
86 debugs(93,0, "ERROR: Duplicate adaptation service name: " <<
87 cfg.key);
88 continue; // TODO: make fatal
89 }
62c7f90e 90 ServicePointer s = createService(**i);
64bdef96 91 if (s != NULL)
62c7f90e 92 AllServices().push_back(s);
64bdef96
AR
93 }
94
62c7f90e 95 debugs(93,3, "Created " << configs.size() <<
64bdef96
AR
96 " message adaptation services.");
97}
98
62c7f90e
AR
99// poor man for_each
100template <class Collection>
101static void
102FinalizeEach(Collection &collection, const char *label)
64bdef96 103{
62c7f90e
AR
104 typedef typename Collection::iterator CI;
105 for (CI i = collection.begin(); i != collection.end(); ++i)
106 (*i)->finalize();
64bdef96 107
62c7f90e 108 debugs(93,2, "Initialized " << collection.size() << ' ' << label);
64bdef96
AR
109}
110
111void
8f361c50 112Adaptation::Config::Finalize(bool enabled)
64bdef96 113{
8f361c50
AR
114 Enabled = enabled;
115 debugs(93,1, "Adaptation support is " << (Enabled ? "on" : "off."));
116
62c7f90e
AR
117 FinalizeEach(AllServices(), "message adaptation services");
118 FinalizeEach(AllGroups(), "message adaptation service groups");
119 FinalizeEach(AllRules(), "message adaptation access rules");
120}
64bdef96
AR
121
122void
62c7f90e 123Adaptation::Config::ParseServiceSet()
64bdef96 124{
62c7f90e
AR
125 ServiceSet *g = new ServiceSet();
126 g->parse();
127 AllGroups().push_back(g);
64bdef96
AR
128}
129
130void
62c7f90e 131Adaptation::Config::FreeServiceSet()
64bdef96 132{
62c7f90e 133 while (!AllGroups().empty()) {
b6b637eb
AR
134 delete AllGroups().back();
135 AllGroups().pop_back();
136 }
64bdef96
AR
137}
138
139void
62c7f90e 140Adaptation::Config::DumpServiceSet(StoreEntry *entry, const char *name)
64bdef96 141{
62c7f90e
AR
142 typedef Groups::iterator GI;
143 for (GI i = AllGroups().begin(); i != AllGroups().end(); ++i)
144 storeAppendPrintf(entry, "%s %s\n", name, (*i)->id.buf());
145}
64bdef96 146
62c7f90e
AR
147void
148Adaptation::Config::ParseAccess(ConfigParser &parser)
149{
150 AccessRule *r = new AccessRule;
151 r->parse(parser);
152 AllRules().push_back(r);
153}
64bdef96
AR
154
155void
62c7f90e 156Adaptation::Config::FreeAccess()
64bdef96 157{
62c7f90e
AR
158 while (!AllRules().empty()) {
159 delete AllRules().back();
160 AllRules().pop_back();
b6b637eb 161 }
64bdef96
AR
162}
163
164void
62c7f90e 165Adaptation::Config::DumpAccess(StoreEntry *entry, const char *name)
64bdef96
AR
166{
167 LOCAL_ARRAY(char, nom, 64);
168
62c7f90e
AR
169 typedef AccessRules::iterator CI;
170 for (CI i = AllRules().begin(); i != AllRules().end(); ++i) {
171 snprintf(nom, 64, "%s %s", name, (*i)->groupId.buf());
172 dump_acl_access(entry, nom, (*i)->acl);
b6b637eb 173 }
64bdef96
AR
174}
175
176Adaptation::Config::Config()
177{
178 // XXX: should we init members?
179}
180
62c7f90e
AR
181// XXX: this is called for ICAP and eCAP configs, but deals mostly
182// with global arrays shared by those individual configs
64bdef96
AR
183Adaptation::Config::~Config()
184{
62c7f90e
AR
185 FreeAccess();
186 FreeServiceSet();
64bdef96
AR
187
188 // invalidate each service so that it can be deleted when refcount=0
62c7f90e
AR
189 while (!AllServices().empty()) {
190 AllServices().back()->invalidate();
191 AllServices().pop_back();
b6b637eb 192 }
62c7f90e
AR
193
194 freeService();
64bdef96 195}