]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
ef57eb7b | 2 | * Copyright (C) 1996-2016 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
6f58d7d7 | 9 | #include "squid.h" |
640fe8fb | 10 | #include "acl/Checklist.h" |
6f58d7d7 AR |
11 | #include "acl/Tree.h" |
12 | #include "wordlist.h" | |
13 | ||
14 | CBDATA_NAMESPACED_CLASS_INIT(Acl, Tree); | |
15 | ||
6f58d7d7 AR |
16 | allow_t |
17 | Acl::Tree::winningAction() const | |
18 | { | |
19 | return actionAt(lastMatch_ - nodes.begin()); | |
20 | } | |
21 | ||
22 | allow_t | |
23 | Acl::Tree::lastAction() const | |
24 | { | |
25 | if (actions.empty()) | |
26 | return ACCESS_DUNNO; | |
27 | return actions.back(); | |
28 | } | |
29 | ||
30 | /// computes action that corresponds to the position of the matched rule | |
31 | allow_t | |
32 | Acl::Tree::actionAt(const Nodes::size_type pos) const | |
33 | { | |
3e3aefda | 34 | assert(pos < nodes.size()); |
6f58d7d7 AR |
35 | if (actions.size()) { |
36 | assert(actions.size() == nodes.size()); | |
37 | return actions[pos]; | |
38 | } | |
39 | // default for matched rules in trees without actions | |
40 | return ACCESS_ALLOWED; | |
41 | } | |
42 | ||
43 | void | |
44 | Acl::Tree::add(ACL *rule, const allow_t &action) | |
45 | { | |
46 | // either all rules have actions or none | |
47 | assert(nodes.size() == actions.size()); | |
48 | InnerNode::add(rule); | |
49 | actions.push_back(action); | |
50 | } | |
51 | ||
52 | void | |
53 | Acl::Tree::add(ACL *rule) | |
54 | { | |
55 | // either all rules have actions or none | |
56 | assert(actions.empty()); | |
57 | InnerNode::add(rule); | |
58 | } | |
59 | ||
640fe8fb CT |
60 | bool |
61 | Acl::Tree::bannedAction(ACLChecklist *checklist, Nodes::const_iterator node) const | |
62 | { | |
63 | if (actions.size()) { | |
64 | assert(actions.size() == nodes.size()); | |
65 | const Nodes::size_type pos = node - nodes.begin(); | |
66 | return checklist->bannedAction(actions.at(pos)); | |
67 | } | |
68 | return false; | |
69 | } | |
3a3c066d | 70 |