AllOf.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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 "acl/Gadgets.h"
14#include "cache_cf.h"
15#include "MemBuf.h"
16#include "sbuf/SBuf.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, *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 ACL *oldNode = empty() ? nullptr : nodes.front();
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 MemBuf wholeCtx;
60 wholeCtx.init();
61 wholeCtx.appendf("(%s lines)", name);
62 wholeCtx.terminate();
63
64 Acl::OrNode *newWhole = new Acl::OrNode;
65 newWhole->context(wholeCtx.content(), oldNode->cfgline);
66 newWhole->add(oldNode); // old (i.e. first) line
67 nodes.front() = whole = newWhole;
68 aclRegister(newWhole);
69 } else {
70 // this is the first line for this acl; just use it as is
71 whole = this;
72 }
73
74 assert(whole);
75 const int lineId = whole->childrenCount() + 1;
76
77 MemBuf lineCtx;
78 lineCtx.init();
79 lineCtx.appendf("(%s line #%d)", name, lineId);
80 lineCtx.terminate();
81
82 Acl::AndNode *line = new AndNode;
83 line->context(lineCtx.content(), config_input_line);
84 line->lineParse();
85
86 whole->add(line);
87}
88
#define assert(EX)
Definition: assert.h:17
char config_input_line[BUFSIZ]
Definition: cache_cf.cc:274
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition: Checklist.h:146
bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos, const ACL *child)
Definition: Checklist.cc:81
Definition: Acl.h:46
char * cfgline
Definition: Acl.h:88
void context(const char *name, const char *configuration)
sets user-specified ACL name and squid.conf context
Definition: Acl.cc:180
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 tree node. Manages a collection of child tree nodes.
Definition: InnerNode.h:22
Nodes::size_type childrenCount() const
the number of children nodes
Definition: InnerNode.h:30
size_t lineParse()
Definition: InnerNode.cc:44
void add(ACL *node)
appends the node to the collection and takes control over it
Definition: InnerNode.cc:35
Definition: MemBuf.h:24
void init(mb_size_t szInit, mb_size_t szMax)
Definition: MemBuf.cc:93
char * content()
start of the added data
Definition: MemBuf.h:41
void terminate()
Definition: MemBuf.cc:241
void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Append operation with printf-style arguments.
Definition: Packable.h:61
void aclRegister(ACL *acl)
Definition: Gadgets.cc:221
std::list< SBuf > SBufList
Definition: forward.h:23

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors