Tree.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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_ACL_TREE_H
10 #define SQUID_ACL_TREE_H
11 
12 #include "acl/BoolOps.h"
13 #include "sbuf/List.h"
14 
15 namespace Acl
16 {
17 
20 class Tree: public OrNode
21 {
22  // XXX: We should use refcounting instead, but it requires making ACLs
23  // refcounted as well. Otherwise, async lookups will reach deleted ACLs.
25 
26 public:
29  template <class ActionToStringConverter>
30  SBufList treeDump(const char *name, ActionToStringConverter converter) const;
31 
33  allow_t winningAction() const;
34 
36  allow_t lastAction() const;
37 
39  void add(ACL *rule, const allow_t &action);
40  void add(ACL *rule);
41 
42 protected:
44  virtual bool bannedAction(ACLChecklist *, Nodes::const_iterator) const override;
45  allow_t actionAt(const Nodes::size_type pos) const;
46 
48  typedef std::vector<allow_t> Actions;
49  Actions actions;
50 };
51 
52 inline const char *
54 {
55  return action.allowed() ? "allow" : "deny";
56 }
57 
58 template <class ActionToStringConverter>
59 inline SBufList
60 Tree::treeDump(const char *prefix, ActionToStringConverter converter) const
61 {
62  SBufList text;
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_ACL_TREE_H */
85 
SBufList treeDump(const char *name, ActionToStringConverter converter) const
Definition: Tree.h:60
Definition: Tree.h:20
Definition: Acl.h:113
Definition: SBuf.h:86
Definition: Acl.h:39
Actions actions
Definition: Tree.h:49
Definition: parse.c:104
Definition: Acl.cc:32
allow_t actionAt(const Nodes::size_type pos) const
computes action that corresponds to the position of the matched rule
Definition: Tree.cc:32
allow_t lastAction() const
what action to use if no nodes matched
Definition: Tree.cc:23
std::list< SBuf > SBufList
Definition: forward.h:22
const char * AllowOrDeny(const allow_t &action)
Definition: Tree.h:53
bool action(int fd, size_t metasize, const char *fn, const char *url, const SquidMetaList &meta)
Definition: purge.cc:311
std::vector< allow_t > Actions
if not empty, contains actions corresponding to InnerNode::nodes
Definition: Tree.h:48
bool allowed() const
Definition: Acl.h:141
void add(ACL *rule, const allow_t &action)
appends and takes control over the rule with a given action
Definition: Tree.cc:44
char name[ACL_NAME_SZ]
Definition: Acl.h:83
allow_t winningAction() const
Returns the corresponding action after a successful tree match.
Definition: Tree.cc:17
CBDATA_CLASS(Tree)
const char * text
Definition: errorpage.cc:79
std::vector< ACL * > nodes
children nodes of this intermediate node
Definition: InnerNode.h:52
virtual bool bannedAction(ACLChecklist *, Nodes::const_iterator) const override
Acl::OrNode API.
Definition: Tree.cc:61

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors