BoolOps.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/BoolOps.h"
11#include "acl/Checklist.h"
12#include "debug/Stream.h"
13#include "sbuf/SBuf.h"
14
15/* Acl::NotNode */
16
18{
19 assert(acl);
20 Must(strlen(acl->name) <= sizeof(name)-2);
21 name[0] = '!';
22 name[1] = '\0';
23 xstrncpy(&name[1], acl->name, sizeof(name)-1); // -1 for '!'
24 add(acl);
25}
26
27void
29{
30 // Not implemented: by the time an upper level parser discovers
31 // an '!' operator, there is nothing left for us to parse.
32 assert(false);
33}
34
35int
36Acl::NotNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
37{
38 assert(start == nodes.begin()); // we only have one node
39
40 if (checklist->matchChild(this, start, *start))
41 return 0; // converting match into mismatch
42
43 if (!checklist->keepMatching())
44 return -1; // suspend on async calls and stop on failures
45
46 return 1; // converting mismatch into match
47}
48
49char const *
51{
52 return "!";
53}
54
57{
59 text.push_back(SBuf(name));
60 return text;
61}
62
63/* Acl::AndNode */
64
65char const *
67{
68 return "and";
69}
70
71int
72Acl::AndNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
73{
74 // find the first node that does not match
75 for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
76 if (!checklist->matchChild(this, i, *i))
77 return checklist->keepMatching() ? 0 : -1;
78 }
79
80 // one and not zero on empty because in math empty product equals identity
81 return 1; // no mismatches found (i.e., all kids matched)
82}
83
84void
86{
87 // Not implemented: AndNode cannot be configured directly. See Acl::AllOf.
88 assert(false);
89}
90
91/* Acl::OrNode */
92
93char const *
95{
96 return "any-of";
97}
98
99bool
100Acl::OrNode::bannedAction(ACLChecklist *, Nodes::const_iterator) const
101{
102 return false;
103}
104
105int
106Acl::OrNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
107{
108 lastMatch_ = nodes.end();
109
110 // find the first node that matches, but stop if things go wrong
111 for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
112 if (bannedAction(checklist, i))
113 continue;
114 if (checklist->matchChild(this, i, *i)) {
115 lastMatch_ = i;
116 return 1;
117 }
118
119 if (!checklist->keepMatching())
120 return -1; // suspend on async calls and stop on failures
121 }
122
123 // zero and not one on empty because in math empty sum equals zero
124 return 0; // all nodes mismatched
125}
126
127void
129{
130 // Not implemented: OrNode cannot be configured directly. See Acl::AnyOf.
131 assert(false);
132}
133
#define Must(condition)
Definition: TextException.h:75
#define assert(EX)
Definition: assert.h:17
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 name[ACL_NAME_SZ]
Definition: Acl.h:87
void parse() override
parses node representation in squid.conf; dies on failures
Definition: BoolOps.cc:85
char const * typeString() const override
Definition: BoolOps.cc:66
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition: BoolOps.cc:72
void add(ACL *node)
appends the node to the collection and takes control over it
Definition: InnerNode.cc:35
SBufList dump() const override
Definition: BoolOps.cc:56
char const * typeString() const override
Definition: BoolOps.cc:50
void parse() override
parses node representation in squid.conf; dies on failures
Definition: BoolOps.cc:28
NotNode(ACL *acl)
Definition: BoolOps.cc:17
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition: BoolOps.cc:36
void parse() override
parses node representation in squid.conf; dies on failures
Definition: BoolOps.cc:128
char const * typeString() const override
Definition: BoolOps.cc:94
virtual bool bannedAction(ACLChecklist *, Nodes::const_iterator) const
Definition: BoolOps.cc:100
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition: BoolOps.cc:106
Definition: SBuf.h:94
std::list< SBuf > SBufList
Definition: forward.h:23
SBuf text("GET http://resource.com/path HTTP/1.1\r\n" "Host: resource.com\r\n" "Cookie: laijkpk3422r j1noin \r\n" "\r\n")
char * xstrncpy(char *dst, const char *src, size_t n)
Definition: xstring.cc:37

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors