]>
Commit | Line | Data |
---|---|---|
bbc27441 AJ |
1 | /* |
2 | * Copyright (C) 1996-2014 The Squid Software Foundation and contributors | |
3 | * | |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
582c2af2 | 9 | #include "squid.h" |
3ad63615 | 10 | #include "acl/Gadgets.h" |
118a7b00 | 11 | #include "acl/Tree.h" |
62c7f90e AR |
12 | #include "adaptation/AccessRule.h" |
13 | #include "adaptation/Service.h" | |
14 | #include "adaptation/ServiceGroups.h" | |
a7458115 | 15 | #include "ConfigParser.h" |
582c2af2 | 16 | #include "Debug.h" |
62c7f90e AR |
17 | |
18 | int Adaptation::AccessRule::LastId = 0; | |
19 | ||
287bbe9a | 20 | Adaptation::AccessRule::AccessRule(const String &aGroupId): id(++LastId), groupId(aGroupId), acl(NULL) |
62c7f90e AR |
21 | { |
22 | } | |
23 | ||
24 | Adaptation::AccessRule::~AccessRule() | |
25 | { | |
118a7b00 | 26 | delete acl; |
62c7f90e AR |
27 | } |
28 | ||
29 | void | |
30 | Adaptation::AccessRule::parse(ConfigParser &parser) | |
31 | { | |
6f58d7d7 | 32 | aclParseAccessLine("adaptation_access", parser, &acl); |
62c7f90e AR |
33 | } |
34 | ||
35 | void | |
36 | Adaptation::AccessRule::finalize() | |
37 | { | |
26ac0430 | 38 | if (!group()) { // no explicit group |
bed1aa51 AR |
39 | debugs(93,7, HERE << "no service group: " << groupId); |
40 | // try to add a one-service group | |
41 | if (FindService(groupId) != NULL) { | |
a22e6cd3 | 42 | ServiceGroupPointer g = new SingleService(groupId); |
bed1aa51 AR |
43 | g->finalize(); // explicit groups were finalized before rules |
44 | AllGroups().push_back(g); | |
45 | } | |
46 | } | |
47 | ||
62c7f90e | 48 | if (!group()) { |
fa84c01d | 49 | debugs(93, DBG_CRITICAL, "ERROR: Unknown adaptation service or group name: '" << |
26ac0430 | 50 | groupId << "'"); // TODO: fail on failures |
bed1aa51 | 51 | } |
62c7f90e AR |
52 | } |
53 | ||
a22e6cd3 | 54 | Adaptation::ServiceGroupPointer |
62c7f90e AR |
55 | Adaptation::AccessRule::group() |
56 | { | |
57 | return FindGroup(groupId); | |
58 | } | |
59 | ||
62c7f90e AR |
60 | Adaptation::AccessRules & |
61 | Adaptation::AllRules() | |
62 | { | |
28b58ffc CT |
63 | static AccessRules *TheRules = new AccessRules; |
64 | return *TheRules; | |
62c7f90e AR |
65 | } |
66 | ||
67 | // TODO: make AccessRules::find work | |
68 | Adaptation::AccessRule * | |
69 | Adaptation::FindRule(const AccessRule::Id &id) | |
70 | { | |
71 | typedef AccessRules::iterator ARI; | |
72 | for (ARI i = AllRules().begin(); i != AllRules().end(); ++i) { | |
73 | if ((*i)->id == id) | |
74 | return *i; | |
75 | } | |
76 | ||
77 | return NULL; | |
78 | } | |
287bbe9a CT |
79 | |
80 | Adaptation::AccessRule * | |
81 | Adaptation::FindRuleByGroupId(const String &groupId) | |
82 | { | |
83 | typedef AccessRules::iterator ARI; | |
84 | for (ARI i = AllRules().begin(); i != AllRules().end(); ++i) { | |
85 | if ((*i)->groupId == groupId) | |
86 | return *i; | |
87 | } | |
88 | ||
89 | return NULL; | |
90 | } | |
f53969cc | 91 |