Squid Web Cache master
Loading...
Searching...
No Matches
Tree.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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#ifndef SQUID_SRC_ACL_TREE_H
10#define SQUID_SRC_ACL_TREE_H
11
12#include "acl/Acl.h"
13#include "acl/BoolOps.h"
14#include "cbdata.h"
15#include "sbuf/List.h"
16
17namespace Acl
18{
19
22class Tree: public OrNode
23{
25
26public:
29 template <class ActionToStringConverter>
30 SBufList treeDump(const char *name, ActionToStringConverter converter) const;
31
33 Answer winningAction() const;
34
36 Answer lastAction() const;
37
39 void add(Acl::Node *rule, const Answer &action);
40 void add(Acl::Node *rule);
41
42protected:
44 bool bannedAction(ACLChecklist *, Nodes::const_iterator) const override;
45 Answer actionAt(const Nodes::size_type pos) const;
46
48 typedef std::vector<Answer> Actions;
50};
51
52inline const char *
53AllowOrDeny(const Answer &action)
54{
55 return action.allowed() ? "allow" : "deny";
56}
57
58template <class ActionToStringConverter>
59inline SBufList
60Tree::treeDump(const char *prefix, ActionToStringConverter converter) const
61{
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 static const SBuf DefaultActString("???");
71 const char *act = converter(*action);
72 text.push_back(act ? SBuf(act) : DefaultActString);
73 ++action;
74 }
75
76 text.splice(text.end(), (*node)->dump());
77 text.push_back(SBuf("\n"));
78 }
79 return text;
80}
81
82} // namespace Acl
83
84#endif /* SQUID_SRC_ACL_TREE_H */
85
bool allowed() const
Definition Acl.h:82
Nodes nodes
children of this intermediate node
Definition InnerNode.h:51
SBuf name
Definition Node.h:81
bool bannedAction(ACLChecklist *, Nodes::const_iterator) const override
Acl::OrNode API.
Definition Tree.cc:59
Answer actionAt(const Nodes::size_type pos) const
computes action that corresponds to the position of the matched rule
Definition Tree.cc:30
void add(Acl::Node *rule, const Answer &action)
appends and takes control over the rule with a given action
Definition Tree.cc:42
Answer winningAction() const
Returns the corresponding action after a successful tree match.
Definition Tree.cc:15
std::vector< Answer > Actions
if not empty, contains actions corresponding to InnerNode::nodes
Definition Tree.h:48
Actions actions
Definition Tree.h:49
Answer lastAction() const
what action to use if no nodes matched
Definition Tree.cc:21
MEMPROXY_CLASS(Tree)
SBufList treeDump(const char *name, ActionToStringConverter converter) const
Definition Tree.h:60
Definition SBuf.h:94
void push_back(char)
Append a single character. The character may be NUL (\0).
Definition SBuf.cc:208
const_iterator begin() const
Definition SBuf.h:587
const_iterator end() const
Definition SBuf.h:591
Definition Acl.cc:33
const char * AllowOrDeny(const Answer &action)
Definition Tree.h:53
std::list< SBuf > SBufList
Definition forward.h:23
Definition parse.c:104
SBuf text("GET http://resource.com/path HTTP/1.1\r\n" "Host: resource.com\r\n" "Cookie: laijkpk3422r j1noin \r\n" "\r\n")