AllOf.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/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 
17 char const *
19 {
20  return "all-of";
21 }
22 
25 {
26  return empty() ? SBufList() : nodes.front()->dump();
27 }
28 
29 int
30 Acl::AllOf::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
31 {
32  assert(start == nodes.begin()); // we only have one node
33 
34  // avoid dereferencing invalid start
35  if (empty())
36  return 1; // not 0 because in math empty product equals identity
37 
38  if (checklist->matchChild(this, start, *start))
39  return 1; // match
40 
41  return checklist->keepMatching() ? 0 : -1;
42 }
43 
44 // called once per "acl name all-of name1 name2 ...." line
45 void
47 {
48  Acl::InnerNode *whole = NULL;
49  ACL *oldNode = empty() ? NULL : nodes.front();
50 
51  // optimization: this logic reduces subtree hight (number of tree levels)
52  if (Acl::OrNode *oldWhole = dynamic_cast<Acl::OrNode*>(oldNode)) {
53  // this acl saw multiple lines before; add another one to the old node
54  whole = oldWhole;
55  } else if (oldNode) {
56  // this acl saw a single line before; create a new OR inner node
57 
58  MemBuf wholeCtx;
59  wholeCtx.init();
60  wholeCtx.appendf("(%s lines)", name);
61  wholeCtx.terminate();
62 
63  Acl::OrNode *newWhole = new Acl::OrNode;
64  newWhole->context(wholeCtx.content(), oldNode->cfgline);
65  newWhole->add(oldNode); // old (i.e. first) line
66  nodes.front() = whole = newWhole;
67  } else {
68  // this is the first line for this acl; just use it as is
69  whole = this;
70  }
71 
72  assert(whole);
73  const int lineId = whole->childrenCount() + 1;
74 
75  MemBuf lineCtx;
76  lineCtx.init();
77  lineCtx.appendf("(%s line #%d)", name, lineId);
78  lineCtx.terminate();
79 
80  Acl::AndNode *line = new AndNode;
81  line->context(lineCtx.content(), config_input_line);
82  line->lineParse();
83 
84  whole->add(line);
85 }
86 
void terminate()
Definition: MemBuf.cc:241
void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Append operation with printf-style arguments.
Definition: Packable.h:61
std::list< SBuf > SBufList
Definition: forward.h:22
bool keepMatching() const
Whether we should continue to match tree nodes or stop/pause.
Definition: Checklist.h:146
void init(mb_size_t szInit, mb_size_t szMax)
Definition: MemBuf.cc:93
void add(ACL *node)
appends the node to the collection and takes control over it
Definition: InnerNode.cc:35
An intermediate ACL tree node. Manages a collection of child tree nodes.
Definition: InnerNode.h:22
size_t lineParse()
Definition: InnerNode.cc:44
Nodes::size_type childrenCount() const
the number of children nodes
Definition: InnerNode.h:30
#define NULL
Definition: types.h:166
Definition: MemBuf.h:24
virtual char const * typeString() const
Definition: AllOf.cc:18
virtual SBufList dump() const
Definition: AllOf.cc:24
#define assert(EX)
Definition: assert.h:19
void context(const char *name, const char *configuration)
sets user-specified ACL name and squid.conf context
Definition: Acl.cc:154
Definition: Acl.h:40
char * cfgline
Definition: Acl.h:82
char * content()
start of the added data
Definition: MemBuf.h:41
bool matchChild(const Acl::InnerNode *parent, Acl::Nodes::const_iterator pos, const ACL *child)
Definition: Checklist.cc:81
virtual int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
Definition: AllOf.cc:30
char config_input_line[BUFSIZ]
Definition: cache_cf.cc:273
virtual void parse()
parses node representation in squid.conf; dies on failures
Definition: AllOf.cc:46

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors