Squid Web Cache master
Loading...
Searching...
No Matches
AllOf.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/AllOf.h"
11#include "acl/BoolOps.h"
12#include "acl/Checklist.h"
13#include "cache_cf.h"
14#include "MemBuf.h"
15#include "sbuf/SBuf.h"
16#include "sbuf/Stream.h"
17
18char const *
20{
21 return "all-of";
22}
23
26{
27 return empty() ? SBufList() : nodes.front()->dump();
28}
29
30int
31Acl::AllOf::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
32{
33 assert(start == nodes.begin()); // we only have one node
34
35 // avoid dereferencing invalid start
36 if (empty())
37 return 1; // not 0 because in math empty product equals identity
38
39 if (checklist->matchChild(this, start))
40 return 1; // match
41
42 return checklist->keepMatching() ? 0 : -1;
43}
44
45// called once per "acl name all-of name1 name2 ...." line
46void
48{
49 Acl::InnerNode *whole = nullptr;
50 const auto oldNode = empty() ? nullptr : nodes.front().getRaw();
51
52 // optimization: this logic reduces subtree hight (number of tree levels)
53 if (Acl::OrNode *oldWhole = dynamic_cast<Acl::OrNode*>(oldNode)) {
54 // this acl saw multiple lines before; add another one to the old node
55 whole = oldWhole;
56 } else if (oldNode) {
57 // this acl saw a single line before; create a new OR inner node
58
59 Acl::OrNode *newWhole = new Acl::OrNode;
60 newWhole->context(ToSBuf('(', name, " lines)"), oldNode->cfgline);
61 newWhole->add(oldNode); // old (i.e. first) line
62 nodes.front() = whole = newWhole;
63 } else {
64 // this is the first line for this acl; just use it as is
65 whole = this;
66 }
67
68 assert(whole);
69 const int lineId = whole->childrenCount() + 1;
70
71 Acl::AndNode *line = new AndNode;
72 line->context(ToSBuf('(', name, " line #", lineId, ')'), config_input_line);
73 line->lineParse();
74
75 whole->add(line);
76}
77
#define assert(EX)
Definition assert.h:17
char config_input_line[BUFSIZ]
Definition cache_cf.cc:272
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition Checklist.h:96
bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos)
Definition Checklist.cc:70
void parse() override
parses node representation in squid.conf; dies on failures
Definition AllOf.cc:47
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition AllOf.cc:31
char const * typeString() const override
Definition AllOf.cc:19
SBufList dump() const override
Definition AllOf.cc:25
An intermediate Acl::Node tree node. Manages a collection of child tree nodes.
Definition InnerNode.h:23
Nodes::size_type childrenCount() const
the number of children nodes
Definition InnerNode.h:29
void add(Acl::Node *node)
appends the node to the collection and takes control over it
Definition InnerNode.cc:36
size_t lineParse()
Definition InnerNode.cc:44
void context(const SBuf &aName, const char *configuration)
sets user-specified ACL name and squid.conf context
Definition Acl.cc:220
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition Stream.h:63
std::list< SBuf > SBufList
Definition forward.h:23