]>
Commit | Line | Data |
---|---|---|
64bdef96 AR |
1 | |
2 | /* | |
262a0e14 | 3 | * $Id$ |
64bdef96 AR |
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. | |
26ac0430 | 21 | * |
64bdef96 AR |
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. | |
26ac0430 | 26 | * |
64bdef96 AR |
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" | |
3ad63615 | 37 | #include "acl/Gadgets.h" |
64bdef96 | 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" | |
3ff65596 | 44 | #include "adaptation/History.h" |
64bdef96 AR |
45 | |
46 | ||
8f361c50 | 47 | bool Adaptation::Config::Enabled = false; |
3ff65596 | 48 | char *Adaptation::Config::masterx_shared_name = NULL; |
8f361c50 | 49 | |
64bdef96 AR |
50 | void |
51 | Adaptation::Config::parseService() | |
52 | { | |
53 | ServiceConfig *cfg = new ServiceConfig; | |
54 | cfg->parse(); | |
55 | serviceConfigs.push_back(cfg); | |
56 | } | |
57 | ||
58 | void | |
59 | Adaptation::Config::freeService() | |
60 | { | |
62c7f90e AR |
61 | while (!serviceConfigs.empty()) { |
62 | delete serviceConfigs.back(); | |
63 | serviceConfigs.pop_back(); | |
b6b637eb | 64 | } |
64bdef96 AR |
65 | } |
66 | ||
67 | void | |
68 | Adaptation::Config::dumpService(StoreEntry *entry, const char *name) const | |
69 | { | |
70 | typedef Services::iterator SCI; | |
71 | for (SCI i = AllServices().begin(); i != AllServices().end(); ++i) { | |
72 | const ServiceConfig &cfg = (*i)->cfg(); | |
b4197865 | 73 | storeAppendPrintf(entry, "%s " SQUIDSTRINGPH "_%s %s %d " SQUIDSTRINGPH "\n", |
af6a12ee AJ |
74 | name, |
75 | SQUIDSTRINGPRINT(cfg.key), | |
76 | cfg.methodStr(), cfg.vectPointStr(), cfg.bypass, | |
77 | SQUIDSTRINGPRINT(cfg.uri)); | |
64bdef96 AR |
78 | } |
79 | } | |
80 | ||
81 | void | |
82 | Adaptation::Config::finalize() | |
83 | { | |
84 | // create service reps from service configs | |
85 | typedef Vector<ServiceConfig*>::const_iterator VISCI; | |
86 | const Vector<ServiceConfig*> &configs = serviceConfigs; | |
192378eb | 87 | debugs(93,3, HERE << "Found " << configs.size() << " service configs."); |
62c7f90e | 88 | for (VISCI i = configs.begin(); i != configs.end(); ++i) { |
26ac0430 AJ |
89 | const ServiceConfig &cfg = **i; |
90 | if (FindService(cfg.key) != NULL) { | |
91 | debugs(93,0, "ERROR: Duplicate adaptation service name: " << | |
92 | cfg.key); | |
93 | continue; // TODO: make fatal | |
94 | } | |
62c7f90e | 95 | ServicePointer s = createService(**i); |
64bdef96 | 96 | if (s != NULL) |
62c7f90e | 97 | AllServices().push_back(s); |
64bdef96 AR |
98 | } |
99 | ||
192378eb | 100 | debugs(93,3, HERE << "Created " << configs.size() << |
26ac0430 | 101 | " message adaptation services."); |
64bdef96 AR |
102 | } |
103 | ||
62c7f90e AR |
104 | // poor man for_each |
105 | template <class Collection> | |
106 | static void | |
107 | FinalizeEach(Collection &collection, const char *label) | |
64bdef96 | 108 | { |
62c7f90e AR |
109 | typedef typename Collection::iterator CI; |
110 | for (CI i = collection.begin(); i != collection.end(); ++i) | |
111 | (*i)->finalize(); | |
64bdef96 | 112 | |
192378eb | 113 | debugs(93,2, HERE << "Initialized " << collection.size() << ' ' << label); |
64bdef96 AR |
114 | } |
115 | ||
116 | void | |
8f361c50 | 117 | Adaptation::Config::Finalize(bool enabled) |
64bdef96 | 118 | { |
8f361c50 AR |
119 | Enabled = enabled; |
120 | debugs(93,1, "Adaptation support is " << (Enabled ? "on" : "off.")); | |
121 | ||
3ff65596 | 122 | History::Configure(); |
62c7f90e AR |
123 | FinalizeEach(AllServices(), "message adaptation services"); |
124 | FinalizeEach(AllGroups(), "message adaptation service groups"); | |
125 | FinalizeEach(AllRules(), "message adaptation access rules"); | |
126 | } | |
64bdef96 AR |
127 | |
128 | void | |
62c7f90e | 129 | Adaptation::Config::ParseServiceSet() |
64bdef96 | 130 | { |
62c7f90e AR |
131 | ServiceSet *g = new ServiceSet(); |
132 | g->parse(); | |
133 | AllGroups().push_back(g); | |
64bdef96 AR |
134 | } |
135 | ||
136 | void | |
62c7f90e | 137 | Adaptation::Config::FreeServiceSet() |
64bdef96 | 138 | { |
62c7f90e | 139 | while (!AllGroups().empty()) { |
b6b637eb AR |
140 | delete AllGroups().back(); |
141 | AllGroups().pop_back(); | |
142 | } | |
64bdef96 AR |
143 | } |
144 | ||
145 | void | |
62c7f90e | 146 | Adaptation::Config::DumpServiceSet(StoreEntry *entry, const char *name) |
64bdef96 | 147 | { |
62c7f90e AR |
148 | typedef Groups::iterator GI; |
149 | for (GI i = AllGroups().begin(); i != AllGroups().end(); ++i) | |
2c1fd837 | 150 | storeAppendPrintf(entry, "%s " SQUIDSTRINGPH "\n", name, SQUIDSTRINGPRINT((*i)->id)); |
62c7f90e | 151 | } |
64bdef96 | 152 | |
62c7f90e AR |
153 | void |
154 | Adaptation::Config::ParseAccess(ConfigParser &parser) | |
155 | { | |
287bbe9a CT |
156 | String groupId; |
157 | ConfigParser::ParseString(&groupId); | |
158 | AccessRule *r; | |
899fad67 | 159 | if (!(r=FindRuleByGroupId(groupId))) { |
af6a12ee AJ |
160 | r = new AccessRule(groupId); |
161 | AllRules().push_back(r); | |
899fad67 | 162 | } |
62c7f90e | 163 | r->parse(parser); |
62c7f90e | 164 | } |
64bdef96 AR |
165 | |
166 | void | |
62c7f90e | 167 | Adaptation::Config::FreeAccess() |
64bdef96 | 168 | { |
62c7f90e AR |
169 | while (!AllRules().empty()) { |
170 | delete AllRules().back(); | |
171 | AllRules().pop_back(); | |
b6b637eb | 172 | } |
64bdef96 AR |
173 | } |
174 | ||
175 | void | |
62c7f90e | 176 | Adaptation::Config::DumpAccess(StoreEntry *entry, const char *name) |
64bdef96 AR |
177 | { |
178 | LOCAL_ARRAY(char, nom, 64); | |
179 | ||
62c7f90e AR |
180 | typedef AccessRules::iterator CI; |
181 | for (CI i = AllRules().begin(); i != AllRules().end(); ++i) { | |
2c1fd837 | 182 | snprintf(nom, 64, "%s " SQUIDSTRINGPH, name, SQUIDSTRINGPRINT((*i)->groupId)); |
62c7f90e | 183 | dump_acl_access(entry, nom, (*i)->acl); |
b6b637eb | 184 | } |
64bdef96 AR |
185 | } |
186 | ||
187 | Adaptation::Config::Config() | |
188 | { | |
189 | // XXX: should we init members? | |
190 | } | |
191 | ||
26ac0430 | 192 | // XXX: this is called for ICAP and eCAP configs, but deals mostly |
62c7f90e | 193 | // with global arrays shared by those individual configs |
64bdef96 AR |
194 | Adaptation::Config::~Config() |
195 | { | |
5e029ec3 CT |
196 | FreeAccess(); |
197 | FreeServiceSet(); | |
198 | ||
199 | // invalidate each service so that it can be deleted when refcount=0 | |
200 | while (!AllServices().empty()) { | |
201 | AllServices().back()->invalidate(); | |
202 | AllServices().pop_back(); | |
203 | } | |
204 | ||
62c7f90e | 205 | freeService(); |
64bdef96 | 206 | } |