]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/Tree.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / Tree.cc
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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
640fe8fb
CT
60bool
61Acl::Tree::bannedAction(ACLChecklist *checklist, Nodes::const_iterator node) const
62{
63 if (actions.size()) {
64 assert(actions.size() == nodes.size());
65 const Nodes::size_type pos = node - nodes.begin();
66 return checklist->bannedAction(actions.at(pos));
67 }
68 return false;
69}
3a3c066d 70