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

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors