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