InnerNode.cc
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 #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);
39  aclRegister(node);
40 }
41 
42 // one call parses one "acl name acltype name1 name2 ..." line
43 // kids use this method to handle [multiple] parse() calls correctly
44 void
46 {
47  // XXX: not precise, may change when looping or parsing multiple lines
48  if (!cfgline)
49  cfgline = xstrdup(config_input_line);
50 
51  // expect a list of ACL names, each possibly preceeded by '!' for negation
52 
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;
65  }
66 
67  // append(negated ? new NotNode(a) : a);
68  if (negated)
69  add(new NotNode(a));
70  else
71  add(a);
72  }
73 
74  return;
75 }
76 
79 {
80  SBufList rv;
81  for (Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i)
82  rv.push_back(SBuf((*i)->name));
83  return rv;
84 }
85 
86 int
88 {
89  return doMatch(checklist, nodes.begin());
90 }
91 
92 bool
93 Acl::InnerNode::resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
94 {
95  debugs(28, 5, "checking " << name << " at " << (pos-nodes.begin()));
96  const int result = doMatch(checklist, pos);
97  const char *extra = checklist->asyncInProgress() ? " async" : "";
98  debugs(28, 3, "checked: " << name << " = " << result << extra);
99 
100  // merges async and failures (-1) into "not matched"
101  return result == 1;
102 }
103 
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:149
#define assert(EX)
Definition: assert.h:17
Definition: SBuf.h:87
virtual bool empty() const
Definition: InnerNode.cc:29
void self_destruct(void)
Definition: cache_cf.cc:255
int i
Definition: membanger.c:49
#define xstrdup
Definition: Acl.h:39
#define DBG_CRITICAL
Definition: Debug.h:44
Definition: parse.c:104
void add(ACL *node)
appends the node to the collection and takes control over it
Definition: InnerNode.cc:35
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
Implements the "not" or "!" operator.
Definition: BoolOps.h:22
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: InnerNode.cc:87
static ACL * FindByName(const char *name)
Definition: Acl.cc:93
void lineParse()
parses one "acl name type acl1 acl2..." line, appending to nodes
Definition: InnerNode.cc:45
std::list< SBuf > SBufList
Definition: forward.h:26
void aclRegister(ACL *acl)
Definition: Gadgets.cc:229
char config_input_line[BUFSIZ]
static char * strtokFile()
Definition: ConfigParser.cc:82
virtual SBufList dump() const
Definition: InnerNode.cc:78
int a
Definition: membanger.c:50
bool resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
Resumes matching (suspended by an async call) at the given position.
Definition: InnerNode.cc:93
#define NULL
Definition: types.h:166
std::vector< ACL * > nodes
children nodes of this intermediate node
Definition: InnerNode.h:52
virtual void prepareForUse()
Definition: InnerNode.cc:22

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors