]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/AccessRule.cc
eCAP support, part 1: Loadable modules and ICAP-independent Squid core.
[thirdparty/squid.git] / src / adaptation / AccessRule.cc
1 #include "squid.h"
2 #include "structs.h"
3
4 #include "ConfigParser.h"
5 #include "ACL.h"
6 #include "adaptation/AccessRule.h"
7 #include "adaptation/Service.h"
8 #include "adaptation/ServiceGroups.h"
9
10
11 int Adaptation::AccessRule::LastId = 0;
12
13 Adaptation::AccessRule::AccessRule(): id(++LastId), acl(NULL)
14 {
15 }
16
17 Adaptation::AccessRule::~AccessRule()
18 {
19 // XXX: leaking acls here?
20 }
21
22 void
23 Adaptation::AccessRule::parse(ConfigParser &parser)
24 {
25 ConfigParser::ParseString(&groupId);
26 aclParseAccessLine(parser, &acl);
27 }
28
29 void
30 Adaptation::AccessRule::finalize()
31 {
32 if (!group()) { // no explicit group
33 debugs(93,7, HERE << "no service group: " << groupId);
34 // try to add a one-service group
35 if (FindService(groupId) != NULL) {
36 ServiceGroup *g = new SingleService(groupId);
37 g->finalize(); // explicit groups were finalized before rules
38 AllGroups().push_back(g);
39 }
40 }
41
42 if (!group()) {
43 debugs(93,0, "ERROR: Unknown adaptation service or group name: '" <<
44 groupId << "'"); // TODO: fail on failures
45 }
46 }
47
48 Adaptation::ServiceGroup *
49 Adaptation::AccessRule::group()
50 {
51 return FindGroup(groupId);
52 }
53
54
55 Adaptation::AccessRules &
56 Adaptation::AllRules()
57 {
58 static AccessRules TheRules;
59 return TheRules;
60 }
61
62 // TODO: make AccessRules::find work
63 Adaptation::AccessRule *
64 Adaptation::FindRule(const AccessRule::Id &id)
65 {
66 typedef AccessRules::iterator ARI;
67 for (ARI i = AllRules().begin(); i != AllRules().end(); ++i) {
68 if ((*i)->id == id)
69 return *i;
70 }
71
72 return NULL;
73 }