]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/Tree.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / Tree.cc
CommitLineData
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
14CBDATA_NAMESPACED_CLASS_INIT(Acl, Tree);
15
6f58d7d7
AR
16allow_t
17Acl::Tree::winningAction() const
18{
19 return actionAt(lastMatch_ - nodes.begin());
20}
21
22allow_t
23Acl::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
31allow_t
32Acl::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
43void
44Acl::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
52void
53Acl::Tree::add(ACL *rule)
54{
55 // either all rules have actions or none
56 assert(actions.empty());
57 InnerNode::add(rule);
58}
59
8966008b 60SBufList
6f58d7d7
AR
61Acl::Tree::treeDump(const char *prefix, const ActionToString &convert) const
62{
8966008b 63 SBufList text;
6f58d7d7
AR
64 Actions::const_iterator action = actions.begin();
65 typedef Nodes::const_iterator NCI;
66 for (NCI node = nodes.begin(); node != nodes.end(); ++node) {
67
8966008b 68 text.push_back(SBuf(prefix));
6f58d7d7
AR
69
70 if (action != actions.end()) {
71 const char *act = convert ? convert[action->kind] :
e936c41c 72 (*action == ACCESS_ALLOWED ? "allow" : "deny");
8966008b 73 text.push_back(act?SBuf(act):SBuf("???"));
6f58d7d7
AR
74 ++action;
75 }
76
524f5ff6 77#if __cplusplus >= 201103L
5a6c57ab 78 text.splice(text.end(), (*node)->dump());
524f5ff6 79#else
7d75c222
FC
80 // temp is needed until c++11 move constructor
81 SBufList temp = (*node)->dump();
82 text.splice(text.end(), temp);
524f5ff6 83#endif
8966008b 84 text.push_back(SBuf("\n"));
6f58d7d7
AR
85 }
86 return text;
87}
f53969cc 88
640fe8fb
CT
89bool
90Acl::Tree::bannedAction(ACLChecklist *checklist, Nodes::const_iterator node) const
91{
92 if (actions.size()) {
93 assert(actions.size() == nodes.size());
94 const Nodes::size_type pos = node - nodes.begin();
95 return checklist->bannedAction(actions.at(pos));
96 }
97 return false;
98}
3a3c066d 99