]>
Commit | Line | Data |
---|---|---|
6f58d7d7 AR |
1 | #include "squid.h" |
2 | #include "acl/Tree.h" | |
3 | #include "wordlist.h" | |
4 | ||
5 | CBDATA_NAMESPACED_CLASS_INIT(Acl, Tree); | |
6 | ||
6f58d7d7 AR |
7 | allow_t |
8 | Acl::Tree::winningAction() const | |
9 | { | |
10 | return actionAt(lastMatch_ - nodes.begin()); | |
11 | } | |
12 | ||
13 | allow_t | |
14 | Acl::Tree::lastAction() const | |
15 | { | |
16 | if (actions.empty()) | |
17 | return ACCESS_DUNNO; | |
18 | return actions.back(); | |
19 | } | |
20 | ||
21 | /// computes action that corresponds to the position of the matched rule | |
22 | allow_t | |
23 | Acl::Tree::actionAt(const Nodes::size_type pos) const | |
24 | { | |
3e3aefda | 25 | assert(pos < nodes.size()); |
6f58d7d7 AR |
26 | if (actions.size()) { |
27 | assert(actions.size() == nodes.size()); | |
28 | return actions[pos]; | |
29 | } | |
30 | // default for matched rules in trees without actions | |
31 | return ACCESS_ALLOWED; | |
32 | } | |
33 | ||
34 | void | |
35 | Acl::Tree::add(ACL *rule, const allow_t &action) | |
36 | { | |
37 | // either all rules have actions or none | |
38 | assert(nodes.size() == actions.size()); | |
39 | InnerNode::add(rule); | |
40 | actions.push_back(action); | |
41 | } | |
42 | ||
43 | void | |
44 | Acl::Tree::add(ACL *rule) | |
45 | { | |
46 | // either all rules have actions or none | |
47 | assert(actions.empty()); | |
48 | InnerNode::add(rule); | |
49 | } | |
50 | ||
8966008b | 51 | SBufList |
6f58d7d7 AR |
52 | Acl::Tree::treeDump(const char *prefix, const ActionToString &convert) const |
53 | { | |
8966008b | 54 | SBufList text; |
6f58d7d7 AR |
55 | Actions::const_iterator action = actions.begin(); |
56 | typedef Nodes::const_iterator NCI; | |
57 | for (NCI node = nodes.begin(); node != nodes.end(); ++node) { | |
58 | ||
8966008b | 59 | text.push_back(SBuf(prefix)); |
6f58d7d7 AR |
60 | |
61 | if (action != actions.end()) { | |
62 | const char *act = convert ? convert[action->kind] : | |
e936c41c | 63 | (*action == ACCESS_ALLOWED ? "allow" : "deny"); |
8966008b | 64 | text.push_back(act?SBuf(act):SBuf("???")); |
6f58d7d7 AR |
65 | ++action; |
66 | } | |
67 | ||
7d75c222 FC |
68 | // temp is needed until c++11 move constructor |
69 | SBufList temp = (*node)->dump(); | |
70 | text.splice(text.end(), temp); | |
8966008b | 71 | text.push_back(SBuf("\n")); |
6f58d7d7 AR |
72 | } |
73 | return text; | |
74 | } |