Squid Web Cache v8/master
Loading...
Searching...
No Matches
BoolOps.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/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 name.reserveCapacity(1 + acl->name.length());
21 name.append('!');
22 name.append(acl->name);
23 add(acl);
24}
25
26void
28{
29 // Not implemented: by the time an upper level parser discovers
30 // an '!' operator, there is nothing left for us to parse.
31 assert(false);
32}
33
34int
35Acl::NotNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
36{
37 assert(start == nodes.begin()); // we only have one node
38
39 if (checklist->matchChild(this, start))
40 return 0; // converting match into mismatch
41
42 if (!checklist->keepMatching())
43 return -1; // suspend on async calls and stop on failures
44
45 return 1; // converting mismatch into match
46}
47
48char const *
50{
51 return "!";
52}
53
56{
58 text.push_back(name);
59 return text;
60}
61
62/* Acl::AndNode */
63
64char const *
66{
67 return "and";
68}
69
70int
71Acl::AndNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
72{
73 // find the first node that does not match
74 for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
75 if (!checklist->matchChild(this, i))
76 return checklist->keepMatching() ? 0 : -1;
77 }
78
79 // one and not zero on empty because in math empty product equals identity
80 return 1; // no mismatches found (i.e., all kids matched)
81}
82
83void
85{
86 // Not implemented: AndNode cannot be configured directly. See Acl::AllOf.
87 assert(false);
88}
89
90/* Acl::OrNode */
91
92char const *
94{
95 return "any-of";
96}
97
98bool
99Acl::OrNode::bannedAction(ACLChecklist *, Nodes::const_iterator) const
100{
101 return false;
102}
103
104int
105Acl::OrNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
106{
107 lastMatch_ = nodes.end();
108
109 // find the first node that matches, but stop if things go wrong
110 for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
111 if (bannedAction(checklist, i))
112 continue;
113 if (checklist->matchChild(this, i)) {
114 lastMatch_ = i;
115 return 1;
116 }
117
118 if (!checklist->keepMatching())
119 return -1; // suspend on async calls and stop on failures
120 }
121
122 // zero and not one on empty because in math empty sum equals zero
123 return 0; // all nodes mismatched
124}
125
126void
128{
129 // Not implemented: OrNode cannot be configured directly. See Acl::AnyOf.
130 assert(false);
131}
132
#define assert(EX)
Definition assert.h:17
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 BoolOps.cc:84
char const * typeString() const override
Definition BoolOps.cc:65
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition BoolOps.cc:71
void add(Acl::Node *node)
appends the node to the collection and takes control over it
Definition InnerNode.cc:36
SBuf name
Definition Node.h:81
NotNode(Acl::Node *acl)
Definition BoolOps.cc:17
SBufList dump() const override
Definition BoolOps.cc:55
char const * typeString() const override
Definition BoolOps.cc:49
void parse() override
parses node representation in squid.conf; dies on failures
Definition BoolOps.cc:27
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition BoolOps.cc:35
void parse() override
parses node representation in squid.conf; dies on failures
Definition BoolOps.cc:127
char const * typeString() const override
Definition BoolOps.cc:93
virtual bool bannedAction(ACLChecklist *, Nodes::const_iterator) const
Definition BoolOps.cc:99
int doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const override
Definition BoolOps.cc:105
void push_back(char)
Append a single character. The character may be NUL (\0).
Definition SBuf.cc:208
void reserveCapacity(size_type minCapacity)
Definition SBuf.cc:105
size_type length() const
Returns the number of bytes stored in SBuf.
Definition SBuf.h:419
SBuf & append(const SBuf &S)
Definition SBuf.cc:185
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")