]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/AccessRule.cc
Merge from trunk
[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(const String &aGroupId): id(++LastId), groupId(aGroupId), 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 aclParseAccessLine(parser, &acl);
26 }
27
28 void
29 Adaptation::AccessRule::finalize()
30 {
31 if (!group()) { // no explicit group
32 debugs(93,7, HERE << "no service group: " << groupId);
33 // try to add a one-service group
34 if (FindService(groupId) != NULL) {
35 ServiceGroup *g = new SingleService(groupId);
36 g->finalize(); // explicit groups were finalized before rules
37 AllGroups().push_back(g);
38 }
39 }
40
41 if (!group()) {
42 debugs(93,0, "ERROR: Unknown adaptation service or group name: '" <<
43 groupId << "'"); // TODO: fail on failures
44 }
45 }
46
47 Adaptation::ServiceGroup *
48 Adaptation::AccessRule::group()
49 {
50 return FindGroup(groupId);
51 }
52
53
54 Adaptation::AccessRules &
55 Adaptation::AllRules()
56 {
57 static AccessRules TheRules;
58 return TheRules;
59 }
60
61 // TODO: make AccessRules::find work
62 Adaptation::AccessRule *
63 Adaptation::FindRule(const AccessRule::Id &id)
64 {
65 typedef AccessRules::iterator ARI;
66 for (ARI i = AllRules().begin(); i != AllRules().end(); ++i) {
67 if ((*i)->id == id)
68 return *i;
69 }
70
71 return NULL;
72 }
73
74 Adaptation::AccessRule *
75 Adaptation::FindRuleByGroupId(const String &groupId)
76 {
77 typedef AccessRules::iterator ARI;
78 for (ARI i = AllRules().begin(); i != AllRules().end(); ++i) {
79 if ((*i)->groupId == groupId)
80 return *i;
81 }
82
83 return NULL;
84 }