Checklist.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2018 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 
16 class HttpRequest;
17 
19 typedef void ACLCB(allow_t, void *);
20 
27 {
28 
29 public:
30 
46  class AsyncState
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  virtual void checkForAsync(ACLChecklist *) const;
60  virtual ~NullState() {}
61 
62  private:
64  };
65 
66 public:
67  ACLChecklist();
68  virtual ~ACLChecklist();
69 
91 
112  allow_t const & fastCheck();
113 
135  allow_t 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 allow_t &newAnswer, const char *reason);
155 
156  const allow_t &currentAnswer() const { return allow_; }
157 
159  bool bannedAction(const allow_t &action) const;
161  void banAction(const allow_t &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 
185 private:
187  void checkCallback(allow_t answer);
188 
189  void matchAndFinish();
190 
191  void changeState(AsyncState *);
192  AsyncState *asyncState() const;
193 
195 public:
196 
199 
202  void resumeNonBlockingCheck(AsyncState *state);
203 
204 private: /* internal methods */
207  {
208  public:
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 = NULL; }
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 
229  bool occupied_;
230  bool finished_;
232 
238  unsigned asyncLoopDepth_;
239 
240  bool callerGone();
241 
243  std::stack<Breadcrumb> matchPath;
245  std::vector<allow_t> bannedActions_;
246 };
247 
248 #endif /* SQUID_ACLCHECKLIST_H */
249 
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:238
bool finished_
Definition: Checklist.h:230
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:151
bool occupied_
whether a check (fast or non-blocking) is in progress
Definition: Checklist.h:229
Acl::Nodes::const_iterator position
child position inside parent
Definition: Checklist.h:215
Definition: Tree.h:20
std::stack< Breadcrumb > matchPath
suspended (due to an async lookup) matches() in the ACL tree
Definition: Checklist.h:243
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
NodeMatchingResult
possible outcomes when trying to match a single ACL node in a list
Definition: Checklist.h:219
Definition: Acl.h:113
virtual void verifyAle() const =0
warns if there are uninitialized ALE components and fills them
void banAction(const allow_t &action)
add action to the list of banned actions
Definition: Checklist.cc:402
Definition: Acl.h:39
virtual bool hasAle() const =0
ACLCB * callback
Definition: Checklist.h:197
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition: Checklist.h:146
std::vector< allow_t > bannedActions_
the list of actions which must ignored during acl checks
Definition: Checklist.h:245
bool operator!=(const Breadcrumb &b) const
Definition: Checklist.h:212
An intermediate ACL tree node. Manages a collection of child tree nodes.
Definition: InnerNode.h:21
void * callback_data
Definition: Checklist.h:198
void checkCallback(allow_t answer)
Calls non-blocking check callback with the answer and destroys self.
Definition: Checklist.cc:159
#define cbdataReference(var)
Definition: cbdata.h:341
const Acl::Tree * accessList
Definition: Checklist.h:194
static NullState _instance
Definition: Checklist.h:63
bool goAsync(AsyncState *)
Definition: Checklist.cc:115
Position of a child node within an ACL tree.
Definition: Checklist.h:206
virtual bool hasRequest() const =0
virtual void checkForAsync(ACLChecklist *) const =0
void calcImplicitAnswer()
Definition: Checklist.cc:371
static NullState * Instance()
Definition: Checklist.cc:201
void changeState(AsyncState *)
Definition: Checklist.cc:215
virtual void checkForAsync(ACLChecklist *) const
Definition: Checklist.cc:207
const allow_t & currentAnswer() const
Definition: Checklist.h:156
const Acl::InnerNode * parent
intermediate node in the ACL tree
Definition: Checklist.h:214
void markFinished(const allow_t &newAnswer, const char *reason)
Definition: Checklist.cc:58
bool bannedAction(const allow_t &action) const
whether the action is banned or not
Definition: Checklist.cc:394
AsyncState * asyncState() const
Definition: Checklist.cc:227
unsigned asyncLoopDepth_
how many times the current async state has resumed
Definition: Checklist.h:238
bool action(int fd, size_t metasize, const char *fn, const char *url, const SquidMetaList &meta)
Definition: purge.cc:311
virtual ~ACLChecklist()
Definition: Checklist.cc:191
void resumeNonBlockingCheck(AsyncState *state)
Definition: Checklist.cc:262
virtual void syncAle(HttpRequest *adaptedRequest, const char *logUri) const =0
assigns uninitialized adapted_request and url ALE components
allow_t const & fastCheck()
Definition: Checklist.cc:336
void completeNonBlocking()
Definition: Checklist.cc:46
AsyncStage asyncStage_
Definition: Checklist.h:234
virtual bool hasReply() const =0
bool callerGone()
Definition: Checklist.cc:388
const Acl::Tree * changeAcl(const Acl::Tree *t)
Definition: Checklist.h:176
void preCheck(const char *what)
prepare for checking ACLs; called once per check
Definition: Checklist.cc:68
void matchAndFinish()
performs (or resumes) an ACL tree match and, if successful, sets the action
Definition: Checklist.cc:292
bool prepNonBlocking()
common parts of nonBlockingCheck() and resumeNonBlockingCheck()
Definition: Checklist.cc:21
bool asyncCaller_
whether the caller supports async/slow ACLs
Definition: Checklist.h:228
Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos)
Definition: Checklist.h:210
bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos, const ACL *child)
Definition: Checklist.cc:82
void ACLCB(allow_t, void *)
ACL checklist callback.
Definition: Checklist.h:19
Breadcrumb matchLoc_
location of the node running matches() now
Definition: Checklist.h:236
Breadcrumb asyncLoc_
currentNode_ that called goAsync()
Definition: Checklist.h:237
#define NULL
Definition: types.h:166
AsyncState * state_
Definition: Checklist.h:235
allow_t allow_
Definition: Checklist.h:231
bool operator==(const Breadcrumb &b) const
Definition: Checklist.h:211
bool finished() const
whether markFinished() was called
Definition: Checklist.h:149

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors