]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/Node.h
Upgrade Acl::Node::name to SBuf; remove AclMatchedName global (#1766)
[thirdparty/squid.git] / src / acl / Node.h
CommitLineData
922513e5
FC
1/*
2 * Copyright (C) 1996-2023 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_NODE_H
10#define SQUID_SRC_ACL_NODE_H
11
12#include "acl/forward.h"
13#include "acl/Options.h"
14#include "dlink.h"
25aa6c9a 15#include "sbuf/SBuf.h"
922513e5
FC
16
17class ConfigParser;
18
19namespace Acl {
20
21/// A configurable condition. A node in the ACL expression tree.
22/// Can evaluate itself in FilledChecklist context.
23/// Does not change during evaluation.
24/// \ingroup ACLAPI
25class Node
26{
27
28public:
29 void *operator new(size_t);
30 void operator delete(void *);
31
32 static void ParseAclLine(ConfigParser &parser, Acl::Node **head);
33 static void Initialize();
25aa6c9a
AR
34
35 /// A configured ACL with a given name or nil.
36 static Acl::Node *FindByName(const SBuf &);
37 /// \copydoc FindByName()
38 /// \deprecated Use to avoid performance regressions; remove with the last caller.
922513e5
FC
39 static Acl::Node *FindByName(const char *name);
40
41 Node();
42 Node(Node &&) = delete; // no copying of any kind
43 virtual ~Node();
44
45 /// sets user-specified ACL name and squid.conf context
25aa6c9a 46 void context(const SBuf &aName, const char *configuration);
922513e5
FC
47
48 /// Orchestrates matching checklist against the Acl::Node using match(),
49 /// after checking preconditions and while providing debugging.
50 /// \return true if and only if there was a successful match.
51 /// Updates the checklist state on match, async, and failure.
52 bool matches(ACLChecklist *checklist) const;
53
54 /// configures Acl::Node options, throwing on configuration errors
55 void parseFlags();
56
57 /// parses node representation in squid.conf; dies on failures
58 virtual void parse() = 0;
59 virtual char const *typeString() const = 0;
60 virtual bool isProxyAuth() const;
61 virtual SBufList dump() const = 0;
62 virtual bool empty() const = 0;
63 virtual bool valid() const;
64
65 int cacheMatchAcl(dlink_list *cache, ACLChecklist *);
66 virtual int matchForCache(ACLChecklist *checklist);
67
68 virtual void prepareForUse() {}
69
70 // TODO: Find a way to make options() and this method constant
71 /// Prints aggregated "acl" (or similar) directive configuration, including
72 /// the given directive name, ACL name, ACL type, and ACL parameters. The
73 /// printed parameters are collected from all same-name "acl" directives.
74 void dumpWhole(const char *directiveName, std::ostream &);
75
25aa6c9a
AR
76 /// Either aclname parameter from the explicitly configured acl directive or
77 /// a label generated for an internal ACL tree node. All Node objects
78 /// corresponding to one Squid configuration have unique names.
79 /// See also: context() and FindByName().
80 SBuf name;
81
922513e5
FC
82 char *cfgline;
83 Acl::Node *next; // XXX: remove or at least use refcounting
84 bool registered; ///< added to the global list of ACLs via aclRegister()
85
86private:
87 /// Matches the actual data in checklist against this Acl::Node.
88 virtual int match(ACLChecklist *checklist) = 0; // XXX: missing const
89
90 /// whether our (i.e. shallow) match() requires checklist to have a AccessLogEntry
91 virtual bool requiresAle() const;
92 /// whether our (i.e. shallow) match() requires checklist to have a request
93 virtual bool requiresRequest() const;
94 /// whether our (i.e. shallow) match() requires checklist to have a reply
95 virtual bool requiresReply() const;
96
97 // TODO: Rename to globalOptions(); these are not the only supported options
98 /// \returns (linked) 'global' Options supported by this Acl::Node
99 virtual const Acl::Options &options() { return Acl::NoOptions(); }
100
101 /// \returns (linked) "line" Options supported by this Acl::Node
102 /// \see Acl::Node::options()
103 virtual const Acl::Options &lineOptions() { return Acl::NoOptions(); }
b5818136 104
25aa6c9a 105 static void ParseNamed(ConfigParser &, Node **head, const SBuf &name);
922513e5
FC
106};
107
108} // namespace Acl
109
110#endif /* SQUID_SRC_ACL_NODE_H */