InnerNode.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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/Stream.h"
18#include "globals.h"
19#include <algorithm>
20
21void
23{
24 for (auto node : nodes)
25 node->prepareForUse();
26}
27
28bool
30{
31 return nodes.empty();
32}
33
34void
36{
37 assert(node != nullptr);
38 nodes.push_back(node);
40}
41
42// kids use this method to handle [multiple] parse() calls correctly
43size_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 == nullptr) {
62 debugs(28, DBG_CRITICAL, "ERROR: ACL not found: " << t);
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
88int
90{
91 return doMatch(checklist, nodes.begin());
92}
93
94bool
95Acl::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
#define assert(EX)
Definition: assert.h:19
char config_input_line[BUFSIZ]
Definition: cache_cf.cc:273
void self_destruct(void)
Definition: cache_cf.cc:276
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition: Checklist.h:151
Definition: Acl.h:40
static ACL * FindByName(const char *name)
Definition: Acl.cc:92
virtual void prepareForUse()
Definition: InnerNode.cc:22
std::vector< ACL * > nodes
children nodes of this intermediate node
Definition: InnerNode.h:53
size_t lineParse()
Definition: InnerNode.cc:44
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: InnerNode.cc:89
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
virtual bool empty() const
Definition: InnerNode.cc:29
virtual SBufList dump() const
Definition: InnerNode.cc:80
void add(ACL *node)
appends the node to the collection and takes control over it
Definition: InnerNode.cc:35
Implements the "not" or "!" operator.
Definition: BoolOps.h:23
static char * strtokFile()
Definition: ConfigParser.cc:64
Definition: SBuf.h:94
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
void aclRegister(ACL *acl)
Definition: Gadgets.cc:224
#define xstrdup
std::list< SBuf > SBufList
Definition: forward.h:23
Definition: parse.c:104

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors