2 * Copyright (C) 1996-2021 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.
9 #ifndef SQUID_ACL_TREE_H
10 #define SQUID_ACL_TREE_H
12 #include "acl/BoolOps.h"
13 #include "sbuf/List.h"
18 /// An ORed set of rules at the top of the ACL expression tree, providing two
19 /// unique properties: cbdata protection and optional rule actions.
20 class Tree
: public OrNode
22 // XXX: We should use refcounting instead, but it requires making ACLs
23 // refcounted as well. Otherwise, async lookups will reach deleted ACLs.
27 /// dumps <name, action, rule, new line> tuples
28 /// the supplied converter maps action.kind to a string
29 template <class ActionToStringConverter
>
30 SBufList
treeDump(const char *name
, ActionToStringConverter converter
) const;
32 /// Returns the corresponding action after a successful tree match.
33 Answer
winningAction() const;
35 /// what action to use if no nodes matched
36 Answer
lastAction() const;
38 /// appends and takes control over the rule with a given action
39 void add(ACL
*rule
, const Answer
&action
);
40 void add(ACL
*rule
); ///< same as InnerNode::add()
44 virtual bool bannedAction(ACLChecklist
*, Nodes::const_iterator
) const override
;
45 Answer
actionAt(const Nodes::size_type pos
) const;
47 /// if not empty, contains actions corresponding to InnerNode::nodes
48 typedef std::vector
<Answer
> Actions
;
53 AllowOrDeny(const Answer
&action
)
55 return action
.allowed() ? "allow" : "deny";
58 template <class ActionToStringConverter
>
60 Tree::treeDump(const char *prefix
, ActionToStringConverter converter
) const
63 Actions::const_iterator action
= actions
.begin();
64 typedef Nodes::const_iterator NCI
;
65 for (NCI node
= nodes
.begin(); node
!= nodes
.end(); ++node
) {
67 text
.push_back(SBuf(prefix
));
69 if (action
!= actions
.end()) {
70 static const SBuf
DefaultActString("???");
71 const char *act
= converter(*action
);
72 text
.push_back(act
? SBuf(act
) : DefaultActString
);
76 text
.splice(text
.end(), (*node
)->dump());
77 text
.push_back(SBuf("\n"));
84 #endif /* SQUID_ACL_TREE_H */