]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Tree.cc
Merged from trunk r13474.
[thirdparty/squid.git] / src / acl / Tree.cc
1 #include "squid.h"
2 #include "acl/Tree.h"
3 #include "wordlist.h"
4
5 CBDATA_NAMESPACED_CLASS_INIT(Acl, Tree);
6
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 {
25 assert(pos < nodes.size());
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
51 SBufList
52 Acl::Tree::treeDump(const char *prefix, const ActionToString &convert) const
53 {
54 SBufList text;
55 Actions::const_iterator action = actions.begin();
56 typedef Nodes::const_iterator NCI;
57 for (NCI node = nodes.begin(); node != nodes.end(); ++node) {
58
59 text.push_back(SBuf(prefix));
60
61 if (action != actions.end()) {
62 const char *act = convert ? convert[action->kind] :
63 (*action == ACCESS_ALLOWED ? "allow" : "deny");
64 text.push_back(act?SBuf(act):SBuf("???"));
65 ++action;
66 }
67
68 // temp is needed until c++11 move constructor
69 SBufList temp = (*node)->dump();
70 text.splice(text.end(), temp);
71 text.push_back(SBuf("\n"));
72 }
73 return text;
74 }