]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/Config.cc
Applied --local commits
[thirdparty/squid.git] / src / adaptation / Config.cc
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"
39 #include "Array.h" // really Vector
40 #include "adaptation/Config.h"
41 #include "adaptation/Service.h"
42 #include "adaptation/AccessRule.h"
43 #include "adaptation/ServiceGroups.h"
44
45
46 void
47 Adaptation::Config::parseService()
48 {
49 ServiceConfig *cfg = new ServiceConfig;
50 cfg->parse();
51 serviceConfigs.push_back(cfg);
52 }
53
54 void
55 Adaptation::Config::freeService()
56 {
57 while (!serviceConfigs.empty()) {
58 delete serviceConfigs.back();
59 serviceConfigs.pop_back();
60 }
61 }
62
63 void
64 Adaptation::Config::dumpService(StoreEntry *entry, const char *name) const
65 {
66 typedef Services::iterator SCI;
67 for (SCI i = AllServices().begin(); i != AllServices().end(); ++i) {
68 const ServiceConfig &cfg = (*i)->cfg();
69 storeAppendPrintf(entry, "%s %s_%s %s %d %s\n", name, cfg.key.buf(),
70 cfg.methodStr(), cfg.vectPointStr(), cfg.bypass, cfg.uri.buf());
71 }
72 }
73
74 void
75 Adaptation::Config::finalize()
76 {
77 // create service reps from service configs
78 typedef Vector<ServiceConfig*>::const_iterator VISCI;
79 const Vector<ServiceConfig*> &configs = serviceConfigs;
80 debugs(93,3, "Found " << configs.size() << " service configs.");
81 for (VISCI i = configs.begin(); i != configs.end(); ++i) {
82 ServicePointer s = createService(**i);
83 if (s != NULL)
84 AllServices().push_back(s);
85 }
86
87 debugs(93,3, "Created " << configs.size() <<
88 " message adaptation services.");
89 }
90
91 // poor man for_each
92 template <class Collection>
93 static void
94 FinalizeEach(Collection &collection, const char *label)
95 {
96 typedef typename Collection::iterator CI;
97 for (CI i = collection.begin(); i != collection.end(); ++i)
98 (*i)->finalize();
99
100 debugs(93,2, "Initialized " << collection.size() << ' ' << label);
101 }
102
103 void
104 Adaptation::Config::Finalize()
105 {
106 FinalizeEach(AllServices(), "message adaptation services");
107 FinalizeEach(AllGroups(), "message adaptation service groups");
108 FinalizeEach(AllRules(), "message adaptation access rules");
109 }
110
111 void
112 Adaptation::Config::ParseServiceSet()
113 {
114 ServiceSet *g = new ServiceSet();
115 g->parse();
116 AllGroups().push_back(g);
117 }
118
119 void
120 Adaptation::Config::FreeServiceSet()
121 {
122 while (!AllGroups().empty()) {
123 delete AllGroups().back();
124 AllGroups().pop_back();
125 }
126 }
127
128 void
129 Adaptation::Config::DumpServiceSet(StoreEntry *entry, const char *name)
130 {
131 typedef Groups::iterator GI;
132 for (GI i = AllGroups().begin(); i != AllGroups().end(); ++i)
133 storeAppendPrintf(entry, "%s %s\n", name, (*i)->id.buf());
134 }
135
136 void
137 Adaptation::Config::ParseAccess(ConfigParser &parser)
138 {
139 AccessRule *r = new AccessRule;
140 r->parse(parser);
141 AllRules().push_back(r);
142 }
143
144 void
145 Adaptation::Config::FreeAccess()
146 {
147 while (!AllRules().empty()) {
148 delete AllRules().back();
149 AllRules().pop_back();
150 }
151 }
152
153 void
154 Adaptation::Config::DumpAccess(StoreEntry *entry, const char *name)
155 {
156 LOCAL_ARRAY(char, nom, 64);
157
158 typedef AccessRules::iterator CI;
159 for (CI i = AllRules().begin(); i != AllRules().end(); ++i) {
160 snprintf(nom, 64, "%s %s", name, (*i)->groupId.buf());
161 dump_acl_access(entry, nom, (*i)->acl);
162 }
163 }
164
165 Adaptation::Config::Config()
166 {
167 // XXX: should we init members?
168 }
169
170 // XXX: this is called for ICAP and eCAP configs, but deals mostly
171 // with global arrays shared by those individual configs
172 Adaptation::Config::~Config()
173 {
174 FreeAccess();
175 FreeServiceSet();
176
177 // invalidate each service so that it can be deleted when refcount=0
178 while (!AllServices().empty()) {
179 AllServices().back()->invalidate();
180 AllServices().pop_back();
181 }
182
183 freeService();
184 }