]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/InnerNode.cc
Upgrade Acl::Node::name to SBuf; remove AclMatchedName global (#1766)
[thirdparty/squid.git] / src / acl / InnerNode.cc
CommitLineData
bbc27441 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
bbc27441
AJ
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
6f58d7d7
AR
9#include "squid.h"
10#include "acl/Acl.h"
11#include "acl/BoolOps.h"
12#include "acl/Checklist.h"
855a0107 13#include "acl/Gadgets.h"
6f58d7d7
AR
14#include "acl/InnerNode.h"
15#include "cache_cf.h"
16#include "ConfigParser.h"
675b8408 17#include "debug/Stream.h"
6f58d7d7 18#include "globals.h"
45b2c8c3 19#include "sbuf/SBuf.h"
6f58d7d7
AR
20#include <algorithm>
21
6f58d7d7
AR
22void
23Acl::InnerNode::prepareForUse()
24{
b7c260f4
AJ
25 for (auto node : nodes)
26 node->prepareForUse();
6f58d7d7
AR
27}
28
29bool
30Acl::InnerNode::empty() const
31{
32 return nodes.empty();
33}
34
35void
922513e5 36Acl::InnerNode::add(Acl::Node *node)
6f58d7d7 37{
aee3523a 38 assert(node != nullptr);
6f58d7d7 39 nodes.push_back(node);
855a0107 40 aclRegister(node);
6f58d7d7
AR
41}
42
6f58d7d7 43// kids use this method to handle [multiple] parse() calls correctly
e227da8d 44size_t
6f58d7d7
AR
45Acl::InnerNode::lineParse()
46{
47 // XXX: not precise, may change when looping or parsing multiple lines
48 if (!cfgline)
49 cfgline = xstrdup(config_input_line);
50
2f8abb64 51 // expect a list of ACL names, each possibly preceded by '!' for negation
6f58d7d7 52
e227da8d 53 size_t count = 0;
6f58d7d7
AR
54 while (const char *t = ConfigParser::strtokFile()) {
55 const bool negated = (*t == '!');
56 if (negated)
57 ++t;
58
59 debugs(28, 3, "looking for ACL " << t);
922513e5 60 auto *a = Acl::Node::FindByName(t);
6f58d7d7 61
aee3523a 62 if (a == nullptr) {
d816f28d 63 debugs(28, DBG_CRITICAL, "ERROR: ACL not found: " << t);
6f58d7d7 64 self_destruct();
e227da8d 65 return count; // not reached
6f58d7d7
AR
66 }
67
68 // append(negated ? new NotNode(a) : a);
69 if (negated)
70 add(new NotNode(a));
71 else
72 add(a);
e227da8d
AR
73
74 ++count;
6f58d7d7
AR
75 }
76
e227da8d 77 return count;
6f58d7d7
AR
78}
79
8966008b 80SBufList
6f58d7d7
AR
81Acl::InnerNode::dump() const
82{
8966008b 83 SBufList rv;
25aa6c9a
AR
84 for (const auto &node: nodes)
85 rv.push_back(node->name);
8966008b 86 return rv;
6f58d7d7
AR
87}
88
89int
90Acl::InnerNode::match(ACLChecklist *checklist)
91{
92 return doMatch(checklist, nodes.begin());
93}
94
95bool
d6d0eb11 96Acl::InnerNode::resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
6f58d7d7
AR
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}
f53969cc 106