]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Tree.cc
2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
10 #include "acl/Checklist.h"
14 CBDATA_NAMESPACED_CLASS_INIT(Acl
, Tree
);
17 Acl::Tree::winningAction() const
19 return actionAt(lastMatch_
- nodes
.begin());
23 Acl::Tree::lastAction() const
27 return actions
.back();
30 /// computes action that corresponds to the position of the matched rule
32 Acl::Tree::actionAt(const Nodes::size_type pos
) const
34 assert(pos
< nodes
.size());
36 assert(actions
.size() == nodes
.size());
39 // default for matched rules in trees without actions
40 return ACCESS_ALLOWED
;
44 Acl::Tree::add(ACL
*rule
, const allow_t
&action
)
46 // either all rules have actions or none
47 assert(nodes
.size() == actions
.size());
49 actions
.push_back(action
);
53 Acl::Tree::add(ACL
*rule
)
55 // either all rules have actions or none
56 assert(actions
.empty());
61 Acl::Tree::treeDump(const char *prefix
, const ActionToString
&convert
) const
64 Actions::const_iterator action
= actions
.begin();
65 typedef Nodes::const_iterator NCI
;
66 for (NCI node
= nodes
.begin(); node
!= nodes
.end(); ++node
) {
68 text
.push_back(SBuf(prefix
));
70 if (action
!= actions
.end()) {
71 const char *act
= convert
? convert
[action
->kind
] :
72 (*action
== ACCESS_ALLOWED
? "allow" : "deny");
73 text
.push_back(act
?SBuf(act
):SBuf("???"));
77 #if __cplusplus >= 201103L
78 text
.splice(text
.end(), (*node
)->dump());
80 // temp is needed until c++11 move constructor
81 SBufList temp
= (*node
)->dump();
82 text
.splice(text
.end(), temp
);
84 text
.push_back(SBuf("\n"));
90 Acl::Tree::bannedAction(ACLChecklist
*checklist
, Nodes::const_iterator node
) const
93 assert(actions
.size() == nodes
.size());
94 const Nodes::size_type pos
= node
- nodes
.begin();
95 return checklist
->bannedAction(actions
.at(pos
));