Squid Web Cache master
Loading...
Searching...
No Matches
InnerNode.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 "sbuf/SBuf.h"
20#include <algorithm>
21
22void
24{
25 for (auto node : nodes)
26 node->prepareForUse();
27}
28
29bool
31{
32 return nodes.empty();
33}
34
35void
37{
38 assert(node != nullptr);
39 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 // XXX: Performance regression: SBuf will allocate memory.
60 const auto a = Acl::Node::FindByName(SBuf(t));
61
62 if (a == nullptr) {
63 debugs(28, DBG_CRITICAL, "ERROR: ACL not found: " << t);
65 return count; // not reached
66 }
67
68 // append(negated ? new NotNode(a) : a);
69 if (negated)
70 add(new NotNode(a));
71 else
72 add(a);
73
74 ++count;
75 }
76
77 return count;
78}
79
82{
83 SBufList rv;
84 for (const auto &node: nodes)
85 rv.push_back(node->name);
86 return rv;
87}
88
89int
91{
92 return doMatch(checklist, nodes.begin());
93}
94
95bool
96Acl::InnerNode::resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
97{
98 debugs(28, 5, "checking " << name << " at " << (pos-nodes.begin()));
99 const int result = doMatch(checklist, pos);
100 const char *extra = checklist->asyncInProgress() ? " async" : "";
101 debugs(28, 3, "checked: " << name << " = " << result << extra);
102
103 // merges async and failures (-1) into "not matched"
104 return result == 1;
105}
106
#define assert(EX)
Definition assert.h:17
char config_input_line[BUFSIZ]
Definition cache_cf.cc:272
void self_destruct(void)
Definition cache_cf.cc:275
bool asyncInProgress() const
async call has been started and has not finished (or failed) yet
Definition Checklist.h:101
void add(Acl::Node *node)
appends the node to the collection and takes control over it
Definition InnerNode.cc:36
bool empty() const override
Definition InnerNode.cc:30
size_t lineParse()
Definition InnerNode.cc:44
bool resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
Resumes matching (suspended by an async call) at the given position.
Definition InnerNode.cc:96
void prepareForUse() override
Definition InnerNode.cc:23
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this Acl::Node.
Definition InnerNode.cc:90
Nodes nodes
children of this intermediate node
Definition InnerNode.h:51
SBufList dump() const override
Definition InnerNode.cc:81
static Acl::Node * FindByName(const SBuf &)
A configured ACL with a given name or nil.
Definition Acl.cc:159
Implements the "not" or "!" operator.
Definition BoolOps.h:23
static char * strtokFile()
Definition SBuf.h:94
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
#define DBG_CRITICAL
Definition Stream.h:37
#define xstrdup
std::list< SBuf > SBufList
Definition forward.h:23
Definition parse.c:104