InnerNode.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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 #include "squid.h"
10 #include "acl/Acl.h"
11 #include "acl/BoolOps.h"
12 #include "acl/Checklist.h"
13 #include "acl/Gadgets.h"
14 #include "acl/InnerNode.h"
15 #include "cache_cf.h"
16 #include "ConfigParser.h"
17 #include "Debug.h"
18 #include "globals.h"
19 #include <algorithm>
20 
21 void
23 {
24  for (auto node : nodes)
25  node->prepareForUse();
26 }
27 
28 bool
30 {
31  return nodes.empty();
32 }
33 
34 void
36 {
37  assert(node != NULL);
38  nodes.push_back(node);
40 }
41 
42 // kids use this method to handle [multiple] parse() calls correctly
43 size_t
45 {
46  // XXX: not precise, may change when looping or parsing multiple lines
47  if (!cfgline)
48  cfgline = xstrdup(config_input_line);
49 
50  // expect a list of ACL names, each possibly preceded by '!' for negation
51 
52  size_t count = 0;
53  while (const char *t = ConfigParser::strtokFile()) {
54  const bool negated = (*t == '!');
55  if (negated)
56  ++t;
57 
58  debugs(28, 3, "looking for ACL " << t);
59  ACL *a = ACL::FindByName(t);
60 
61  if (a == NULL) {
62  debugs(28, DBG_CRITICAL, "ACL not found: " << t);
63  self_destruct();
64  return count; // not reached
65  }
66 
67  // append(negated ? new NotNode(a) : a);
68  if (negated)
69  add(new NotNode(a));
70  else
71  add(a);
72 
73  ++count;
74  }
75 
76  return count;
77 }
78 
81 {
82  SBufList rv;
83  for (Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i)
84  rv.push_back(SBuf((*i)->name));
85  return rv;
86 }
87 
88 int
90 {
91  return doMatch(checklist, nodes.begin());
92 }
93 
94 bool
95 Acl::InnerNode::resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
96 {
97  debugs(28, 5, "checking " << name << " at " << (pos-nodes.begin()));
98  const int result = doMatch(checklist, pos);
99  const char *extra = checklist->asyncInProgress() ? " async" : "";
100  debugs(28, 3, "checked: " << name << " = " << result << extra);
101 
102  // merges async and failures (-1) into "not matched"
103  return result == 1;
104 }
105 
Definition: parse.c:104
static char * strtokFile()
Definition: ConfigParser.cc:85
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: InnerNode.cc:89
static ACL * FindByName(const char *name)
Definition: Acl.cc:93
char config_input_line[BUFSIZ]
std::list< SBuf > SBufList
Definition: forward.h:22
Definition: SBuf.h:87
#define xstrdup
void aclRegister(ACL *acl)
Definition: Gadgets.cc:223
void add(ACL *node)
appends the node to the collection and takes control over it
Definition: InnerNode.cc:35
#define DBG_CRITICAL
Definition: Debug.h:45
size_t lineParse()
Definition: InnerNode.cc:44
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:151
void self_destruct(void)
Definition: cache_cf.cc:272
virtual bool empty() const
Definition: InnerNode.cc:29
Implements the "not" or "!" operator.
Definition: BoolOps.h:23
#define NULL
Definition: types.h:166
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:128
#define assert(EX)
Definition: assert.h:19
bool resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
Resumes matching (suspended by an async call) at the given position.
Definition: InnerNode.cc:95
Definition: Acl.h:40
std::vector< ACL * > nodes
children nodes of this intermediate node
Definition: InnerNode.h:53
virtual SBufList dump() const
Definition: InnerNode.cc:80
virtual void prepareForUse()
Definition: InnerNode.cc:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors