Squid Web Cache v8/master
Loading...
Searching...
No Matches
Checklist.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_CHECKLIST_H
10#define SQUID_SRC_ACL_CHECKLIST_H
11
12#include "acl/Acl.h"
13#include "acl/InnerNode.h"
14#include "cbdata.h"
15
16#include <optional>
17#include <stack>
18#include <vector>
19
20class HttpRequest;
21
23typedef void ACLCB(Acl::Answer, void *);
24
31{
32
33public:
34
36 using AsyncStarter = void (ACLFilledChecklist &, const Acl::Node &);
37
38public:
40 virtual ~ACLChecklist();
41
62 Acl::Answer const & fastCheck();
63
85 const Acl::Answer &fastCheck(const ACLList *);
86
89 bool goAsync(AsyncStarter, const Acl::Node &);
90
93 bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos);
94
96 bool keepMatching() const { return !finished() && !asyncInProgress(); }
97
99 bool finished() const { return finished_; }
101 bool asyncInProgress() const { return asyncStage_ != asyncNone; }
104 void markFinished(const Acl::Answer &newAnswer, const char *reason);
105
106 const Acl::Answer &currentAnswer() const { return answer_; }
107
109 bool bannedAction(const Acl::Answer &action) const;
111 void banAction(const Acl::Answer &action);
112
113 // XXX: ACLs that need request or reply have to use ACLFilledChecklist and
114 // should do their own checks so that we do not have to povide these two
115 // for ACL::checklistMatches to use
116 virtual bool hasRequest() const = 0;
117 virtual bool hasReply() const = 0;
118 virtual bool hasAle() const = 0;
120 virtual void syncAle(HttpRequest *adaptedRequest, const char *logUri) const = 0;
122 virtual void verifyAle() const = 0;
123
125 void changeAcl(const acl_access *);
126
128 void setLastCheckedName(const SBuf &name) { lastCheckedName_ = name; }
129
130protected:
152
153private:
156 void checkCallback(const char *abortReason);
157
158 void matchAndFinish();
159
163
165
166public:
167
170
174
175private: /* internal methods */
178 {
179 public:
180 Breadcrumb(): parent(nullptr) {}
181 Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos): parent(aParent), position(aPos) {}
182 bool operator ==(const Breadcrumb &b) const { return parent == b.parent && (!parent || position == b.position); }
183 bool operator !=(const Breadcrumb &b) const { return !this->operator ==(b); }
184 void clear() { parent = nullptr; }
186 Acl::Nodes::const_iterator position;
187 };
188
192
194 void preCheck(const char *what);
195 bool prepNonBlocking();
196 void completeNonBlocking();
197 void calcImplicitAnswer();
198
203
209
210 bool callerGone();
211
213 std::stack<Breadcrumb> matchPath;
215 std::vector<Acl::Answer> bannedActions_;
216
218 std::optional<SBuf> lastCheckedName_;
219};
220
221#endif /* SQUID_SRC_ACL_CHECKLIST_H */
222
void ACLCB(Acl::Answer, void *)
ACL checklist callback.
Definition Checklist.h:23
Position of a child node within an Acl::Node tree.
Definition Checklist.h:178
bool operator==(const Breadcrumb &b) const
Definition Checklist.h:182
Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos)
Definition Checklist.h:181
RefCount< const Acl::InnerNode > parent
intermediate node in the ACL tree
Definition Checklist.h:185
bool operator!=(const Breadcrumb &b) const
Definition Checklist.h:183
Acl::Nodes::const_iterator position
child position inside parent
Definition Checklist.h:186
AsyncStage asyncStage_
Definition Checklist.h:205
void markFinished(const Acl::Answer &newAnswer, const char *reason)
Definition Checklist.cc:45
void completeNonBlocking()
Definition Checklist.cc:34
void banAction(const Acl::Answer &action)
add action to the list of banned actions
Definition Checklist.cc:358
std::vector< Acl::Answer > bannedActions_
the list of actions which must ignored during acl checks
Definition Checklist.h:215
virtual void syncAle(HttpRequest *adaptedRequest, const char *logUri) const =0
assigns uninitialized adapted_request and url ALE components
Breadcrumb matchLoc_
location of the node running matches() now
Definition Checklist.h:206
void resumeNonBlockingCheck()
Definition Checklist.cc:230
void preCheck(const char *what)
prepare for checking ACLs; called once per check
Definition Checklist.cc:56
Acl::Answer const & fastCheck()
Definition Checklist.cc:298
bool asyncCaller_
whether the caller supports async/slow ACLs
Definition Checklist.h:199
void(ACLFilledChecklist &, const Acl::Node &) AsyncStarter
a function that initiates asynchronous ACL checks; see goAsync()
Definition Checklist.h:36
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition Checklist.h:96
NodeMatchingResult
possible outcomes when trying to match a single ACL node in a list
Definition Checklist.h:190
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition Checklist.cc:206
bool finished() const
whether markFinished() was called
Definition Checklist.h:99
bool occupied_
whether a check (fast or non-blocking) is in progress
Definition Checklist.h:200
bool goAsync(AsyncStarter, const Acl::Node &)
Definition Checklist.cc:104
void changeAcl(const acl_access *)
change the current ACL list
Definition Checklist.cc:187
Acl::TreePointer swapAcl(const acl_access *)
change the current ACL list
Definition Checklist.cc:193
bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos)
Definition Checklist.cc:70
std::stack< Breadcrumb > matchPath
suspended (due to an async lookup) matches() in the ACL tree
Definition Checklist.h:213
bool prepNonBlocking()
common parts of nonBlockingCheck() and resumeNonBlockingCheck()
Definition Checklist.cc:21
bool bannedAction(const Acl::Answer &action) const
whether the action is banned or not
Definition Checklist.cc:350
Acl::TreePointer accessList
Definition Checklist.h:164
void matchAndFinish()
performs (or resumes) an ACL tree match and, if successful, sets the action
Definition Checklist.cc:257
unsigned asyncLoopDepth_
how many times the current async state has resumed
Definition Checklist.h:208
virtual bool hasReply() const =0
void setLastCheckedName(const SBuf &name)
remember the name of the last ACL being evaluated
Definition Checklist.h:128
void * callback_data
Definition Checklist.h:169
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition Checklist.h:101
ACLCB * callback
Definition Checklist.h:168
virtual void verifyAle() const =0
warns if there are uninitialized ALE components and fills them
virtual bool hasAle() const =0
Breadcrumb asyncLoc_
currentNode_ that called goAsync()
Definition Checklist.h:207
virtual bool hasRequest() const =0
Acl::Answer answer_
Definition Checklist.h:202
void calcImplicitAnswer()
Definition Checklist.cc:326
virtual ~ACLChecklist()
Definition Checklist.cc:180
void checkCallback(const char *abortReason)
Definition Checklist.cc:146
bool callerGone()
Definition Checklist.cc:344
const Acl::Answer & currentAnswer() const
Definition Checklist.h:106
std::optional< SBuf > lastCheckedName_
the name of the last evaluated ACL (if any ACLs were evaluated)
Definition Checklist.h:218
An intermediate Acl::Node tree node. Manages a collection of child tree nodes.
Definition InnerNode.h:23
Definition SBuf.h:94