Checklist.h
Go to the documentation of this file.
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_ACLCHECKLIST_H
10#define SQUID_ACLCHECKLIST_H
11
12#include "acl/InnerNode.h"
13#include <stack>
14#include <vector>
15
16class HttpRequest;
17
19typedef void ACLCB(Acl::Answer, void *);
20
27{
28
29public:
30
47 {
48
49 public:
50 virtual void checkForAsync(ACLChecklist *) const = 0;
51 virtual ~AsyncState() {}
52 };
53
54 class NullState : public AsyncState
55 {
56
57 public:
58 static NullState *Instance();
59 void checkForAsync(ACLChecklist *) const override;
60 ~NullState() override {}
61
62 private:
64 };
65
66public:
68 virtual ~ACLChecklist();
69
91
112 Acl::Answer const & fastCheck();
113
135 Acl::Answer const & fastCheck(const Acl::Tree *list);
136
139 bool goAsync(AsyncState *);
140
143 bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos, const ACL *child);
144
146 bool keepMatching() const { return !finished() && !asyncInProgress(); }
147
149 bool finished() const { return finished_; }
151 bool asyncInProgress() const { return asyncStage_ != asyncNone; }
154 void markFinished(const Acl::Answer &newAnswer, const char *reason);
155
156 const Acl::Answer &currentAnswer() const { return answer_; }
157
159 bool bannedAction(const Acl::Answer &action) const;
161 void banAction(const Acl::Answer &action);
162
163 // XXX: ACLs that need request or reply have to use ACLFilledChecklist and
164 // should do their own checks so that we do not have to povide these two
165 // for ACL::checklistMatches to use
166 virtual bool hasRequest() const = 0;
167 virtual bool hasReply() const = 0;
168 virtual bool hasAle() const = 0;
170 virtual void syncAle(HttpRequest *adaptedRequest, const char *logUri) const = 0;
172 virtual void verifyAle() const = 0;
173
176 const Acl::Tree *changeAcl(const Acl::Tree *t) {
177 const Acl::Tree *old = accessList;
178 if (t != accessList) {
181 }
182 return old;
183 }
184
185private:
187 void checkCallback(Acl::Answer answer);
188
189 void matchAndFinish();
190
191 void changeState(AsyncState *);
192 AsyncState *asyncState() const;
193
195public:
196
199
203
204private: /* internal methods */
207 {
208 public:
209 Breadcrumb(): parent(nullptr) {}
210 Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos): parent(aParent), position(aPos) {}
211 bool operator ==(const Breadcrumb &b) const { return parent == b.parent && (!parent || position == b.position); }
212 bool operator !=(const Breadcrumb &b) const { return !this->operator ==(b); }
213 void clear() { parent = nullptr; }
215 Acl::Nodes::const_iterator position;
216 };
217
221
223 void preCheck(const char *what);
224 bool prepNonBlocking();
225 void completeNonBlocking();
226 void calcImplicitAnswer();
227
232
239
240 bool callerGone();
241
243 std::stack<Breadcrumb> matchPath;
245 std::vector<Acl::Answer> bannedActions_;
246};
247
248#endif /* SQUID_ACLCHECKLIST_H */
249
void ACLCB(Acl::Answer, void *)
ACL checklist callback.
Definition: Checklist.h:19
#define cbdataReferenceDone(var)
Definition: cbdata.h:352
#define cbdataReference(var)
Definition: cbdata.h:343
virtual void checkForAsync(ACLChecklist *) const =0
Position of a child node within an ACL tree.
Definition: Checklist.h:207
bool operator==(const Breadcrumb &b) const
Definition: Checklist.h:211
Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos)
Definition: Checklist.h:210
const Acl::InnerNode * parent
intermediate node in the ACL tree
Definition: Checklist.h:214
bool operator!=(const Breadcrumb &b) const
Definition: Checklist.h:212
Acl::Nodes::const_iterator position
child position inside parent
Definition: Checklist.h:215
~NullState() override
Definition: Checklist.h:60
void checkForAsync(ACLChecklist *) const override
Definition: Checklist.cc:206
static NullState _instance
Definition: Checklist.h:63
static NullState * Instance()
Definition: Checklist.cc:200
AsyncStage asyncStage_
Definition: Checklist.h:234
void markFinished(const Acl::Answer &newAnswer, const char *reason)
Definition: Checklist.cc:57
void completeNonBlocking()
Definition: Checklist.cc:45
bool goAsync(AsyncState *)
Definition: Checklist.cc:114
void banAction(const Acl::Answer &action)
add action to the list of banned actions
Definition: Checklist.cc:395
std::vector< Acl::Answer > bannedActions_
the list of actions which must ignored during acl checks
Definition: Checklist.h:245
AsyncState * state_
Definition: Checklist.h:235
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:236
AsyncState * asyncState() const
Definition: Checklist.cc:226
void preCheck(const char *what)
prepare for checking ACLs; called once per check
Definition: Checklist.cc:67
const Acl::Tree * changeAcl(const Acl::Tree *t)
Definition: Checklist.h:176
void checkCallback(Acl::Answer answer)
Calls non-blocking check callback with the answer and destroys self.
Definition: Checklist.cc:158
Acl::Answer const & fastCheck()
Definition: Checklist.cc:332
bool asyncCaller_
whether the caller supports async/slow ACLs
Definition: Checklist.h:228
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition: Checklist.h:146
NodeMatchingResult
possible outcomes when trying to match a single ACL node in a list
Definition: Checklist.h:219
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:237
const Acl::Tree * accessList
Definition: Checklist.h:194
bool finished() const
whether markFinished() was called
Definition: Checklist.h:149
bool occupied_
whether a check (fast or non-blocking) is in progress
Definition: Checklist.h:229
void resumeNonBlockingCheck(AsyncState *state)
Definition: Checklist.cc:261
std::stack< Breadcrumb > matchPath
suspended (due to an async lookup) matches() in the ACL tree
Definition: Checklist.h:243
bool prepNonBlocking()
common parts of nonBlockingCheck() and resumeNonBlockingCheck()
Definition: Checklist.cc:20
bool bannedAction(const Acl::Answer &action) const
whether the action is banned or not
Definition: Checklist.cc:387
void matchAndFinish()
performs (or resumes) an ACL tree match and, if successful, sets the action
Definition: Checklist.cc:291
unsigned asyncLoopDepth_
how many times the current async state has resumed
Definition: Checklist.h:238
virtual bool hasReply() const =0
void * callback_data
Definition: Checklist.h:198
bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos, const ACL *child)
Definition: Checklist.cc:81
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:151
void changeState(AsyncState *)
Definition: Checklist.cc:214
ACLCB * callback
Definition: Checklist.h:197
bool finished_
Definition: Checklist.h:230
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:237
virtual bool hasRequest() const =0
Acl::Answer answer_
Definition: Checklist.h:231
void calcImplicitAnswer()
Definition: Checklist.cc:363
virtual ~ACLChecklist()
Definition: Checklist.cc:190
bool callerGone()
Definition: Checklist.cc:381
const Acl::Answer & currentAnswer() const
Definition: Checklist.h:156
Definition: Acl.h:46
An intermediate ACL tree node. Manages a collection of child tree nodes.
Definition: InnerNode.h:22
Definition: Tree.h:21
static bool action(int fd, size_t metasize, const char *fn, const char *url, const SquidMetaList &meta)
Definition: purge.cc:315

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors