]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/Tree.cc
Boilerplate: update copyright blurbs on Squid helpers
[thirdparty/squid.git] / src / acl / Tree.cc
CommitLineData
6f58d7d7
AR
1#include "squid.h"
2#include "acl/Tree.h"
3#include "wordlist.h"
4
5CBDATA_NAMESPACED_CLASS_INIT(Acl, Tree);
6
6f58d7d7
AR
7allow_t
8Acl::Tree::winningAction() const
9{
10 return actionAt(lastMatch_ - nodes.begin());
11}
12
13allow_t
14Acl::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
22allow_t
23Acl::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
34void
35Acl::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
43void
44Acl::Tree::add(ACL *rule)
45{
46 // either all rules have actions or none
47 assert(actions.empty());
48 InnerNode::add(rule);
49}
50
8966008b 51SBufList
6f58d7d7
AR
52Acl::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}