Checklist.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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 
17 typedef void ACLCB(allow_t, void *);
18 
25 {
26 
27 public:
28 
44  class AsyncState
45  {
46 
47  public:
48  virtual void checkForAsync(ACLChecklist *) const = 0;
49  virtual ~AsyncState() {}
50  };
51 
52  class NullState : public AsyncState
53  {
54 
55  public:
56  static NullState *Instance();
57  virtual void checkForAsync(ACLChecklist *) const;
58  virtual ~NullState() {}
59 
60  private:
62  };
63 
64 public:
65  ACLChecklist();
66  virtual ~ACLChecklist();
67 
89 
110  allow_t const & fastCheck();
111 
133  allow_t const & fastCheck(const Acl::Tree *list);
134 
137  bool goAsync(AsyncState *);
138 
141  bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos, const ACL *child);
142 
144  bool keepMatching() const { return !finished() && !asyncInProgress(); }
145 
147  bool finished() const { return finished_; }
149  bool asyncInProgress() const { return asyncStage_ != asyncNone; }
152  void markFinished(const allow_t &newAnswer, const char *reason);
153 
154  const allow_t &currentAnswer() const { return allow_; }
155 
157  bool bannedAction(const allow_t &action) const;
159  void banAction(const allow_t &action);
160 
161  // XXX: ACLs that need request or reply have to use ACLFilledChecklist and
162  // should do their own checks so that we do not have to povide these two
163  // for ACL::checklistMatches to use
164  virtual bool hasRequest() const = 0;
165  virtual bool hasReply() const = 0;
166  virtual bool hasAle() const = 0;
167  virtual void syncAle() const = 0;
168 
171  const Acl::Tree *changeAcl(const Acl::Tree *t) {
172  const Acl::Tree *old = accessList;
173  if (t != accessList) {
176  }
177  return old;
178  }
179 
180 private:
182  void checkCallback(allow_t answer);
183 
184  void matchAndFinish();
185 
186  void changeState(AsyncState *);
187  AsyncState *asyncState() const;
188 
190 public:
191 
194 
197  void resumeNonBlockingCheck(AsyncState *state);
198 
199 private: /* internal methods */
202  {
203  public:
205  Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos): parent(aParent), position(aPos) {}
206  bool operator ==(const Breadcrumb &b) const { return parent == b.parent && (!parent || position == b.position); }
207  bool operator !=(const Breadcrumb &b) const { return !this->operator ==(b); }
208  void clear() { parent = NULL; }
210  Acl::Nodes::const_iterator position;
211  };
212 
216 
218  void preCheck(const char *what);
219  bool prepNonBlocking();
220  void completeNonBlocking();
221  void calcImplicitAnswer();
222 
224  bool occupied_;
225  bool finished_;
227 
233  unsigned asyncLoopDepth_;
234 
235  bool callerGone();
236 
238  std::stack<Breadcrumb> matchPath;
240  std::vector<allow_t> bannedActions_;
241 };
242 
243 #endif /* SQUID_ACLCHECKLIST_H */
244 
void nonBlockingCheck(ACLCB *callback, void *callback_data)
Definition: Checklist.cc:238
bool finished_
Definition: Checklist.h:225
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:149
bool occupied_
whether a check (fast or non-blocking) is in progress
Definition: Checklist.h:224
Acl::Nodes::const_iterator position
child position inside parent
Definition: Checklist.h:210
Definition: Tree.h:20
std::stack< Breadcrumb > matchPath
suspended (due to an async lookup) matches() in the ACL tree
Definition: Checklist.h:238
virtual void syncAle() const =0
#define cbdataReferenceDone(var)
Definition: cbdata.h:350
NodeMatchingResult
possible outcomes when trying to match a single ACL node in a list
Definition: Checklist.h:214
Definition: Acl.h:113
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:192
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition: Checklist.h:144
std::vector< allow_t > bannedActions_
the list of actions which must ignored during acl checks
Definition: Checklist.h:240
bool operator!=(const Breadcrumb &b) const
Definition: Checklist.h:207
An intermediate ACL tree node. Manages a collection of child tree nodes.
Definition: InnerNode.h:21
void * callback_data
Definition: Checklist.h:193
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:189
static NullState _instance
Definition: Checklist.h:61
bool goAsync(AsyncState *)
Definition: Checklist.cc:115
Position of a child node within an ACL tree.
Definition: Checklist.h:201
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:154
const Acl::InnerNode * parent
intermediate node in the ACL tree
Definition: Checklist.h:209
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:233
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
allow_t const & fastCheck()
Definition: Checklist.cc:336
void completeNonBlocking()
Definition: Checklist.cc:46
AsyncStage asyncStage_
Definition: Checklist.h:229
virtual bool hasReply() const =0
bool callerGone()
Definition: Checklist.cc:388
const Acl::Tree * changeAcl(const Acl::Tree *t)
Definition: Checklist.h:171
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:223
Breadcrumb(const Acl::InnerNode *aParent, Acl::Nodes::const_iterator aPos)
Definition: Checklist.h:205
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:17
Breadcrumb matchLoc_
location of the node running matches() now
Definition: Checklist.h:231
Breadcrumb asyncLoc_
currentNode_ that called goAsync()
Definition: Checklist.h:232
#define NULL
Definition: types.h:166
AsyncState * state_
Definition: Checklist.h:230
allow_t allow_
Definition: Checklist.h:226
bool operator==(const Breadcrumb &b) const
Definition: Checklist.h:206
bool finished() const
whether markFinished() was called
Definition: Checklist.h:147

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors