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