]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/BoolOps.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / BoolOps.cc
CommitLineData
bbc27441 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
bbc27441
AJ
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
b6095d3e
AR
9#include "squid.h"
10#include "acl/BoolOps.h"
11#include "acl/Checklist.h"
12#include "Debug.h"
b6095d3e 13
b6095d3e
AR
14/* Acl::NotNode */
15
16Acl::NotNode::NotNode(ACL *acl)
17{
18 assert(acl);
19 name[0] = '!';
428cf7bc 20 name[1] = '\0';
b6095d3e
AR
21 strncat(&name[1], acl->name, sizeof(name)-1-1);
22 add(acl);
23}
24
25void
26Acl::NotNode::parse()
27{
28 // Not implemented: by the time an upper level parser discovers
29 // an '!' operator, there is nothing left for us to parse.
e936c41c 30 assert(false);
b6095d3e
AR
31}
32
33int
34Acl::NotNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
35{
36 assert(start == nodes.begin()); // we only have one node
37
38 if (checklist->matchChild(this, start, *start))
39 return 0; // converting match into mismatch
40
41 if (!checklist->keepMatching())
42 return -1; // suspend on async calls and stop on failures
43
44 return 1; // converting mismatch into match
45}
46
47char const *
48Acl::NotNode::typeString() const
49{
50 return "!";
51}
52
53ACL *
54Acl::NotNode::clone() const
55{
56 // Not implemented: we are not a named ACL type in squid.conf so nobody
57 // should try to create a NotNode instance by ACL type name (which is
58 // what clone() API is for -- it does not really clone anything).
59 assert(false);
60 return NULL;
61}
62
8966008b 63SBufList
b6095d3e
AR
64Acl::NotNode::dump() const
65{
8966008b
FC
66 SBufList text;
67 text.push_back(SBuf(name));
b6095d3e
AR
68 return text;
69}
70
b6095d3e
AR
71/* Acl::AndNode */
72
73char const *
74Acl::AndNode::typeString() const
75{
76 return "and";
77}
78
79ACL *
80Acl::AndNode::clone() const
81{
82 return new AndNode;
83}
84
85int
86Acl::AndNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
87{
88 // find the first node that does not match
89 for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
90 if (!checklist->matchChild(this, i, *i))
91 return checklist->keepMatching() ? 0 : -1;
92 }
93
94 // one and not zero on empty because in math empty product equals identity
95 return 1; // no mismatches found (i.e., all kids matched)
96}
97
98void
99Acl::AndNode::parse()
100{
101 // Not implemented: AndNode cannot be configured directly. See Acl::AllOf.
e936c41c 102 assert(false);
b6095d3e
AR
103}
104
b6095d3e
AR
105/* Acl::OrNode */
106
107char const *
108Acl::OrNode::typeString() const
109{
110 return "any-of";
111}
112
113ACL *
114Acl::OrNode::clone() const
115{
116 return new OrNode;
117}
118
640fe8fb
CT
119bool
120Acl::OrNode::bannedAction(ACLChecklist *, Nodes::const_iterator) const
121{
122 return false;
123}
124
b6095d3e
AR
125int
126Acl::OrNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
127{
128 lastMatch_ = nodes.end();
129
130 // find the first node that matches, but stop if things go wrong
131 for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
640fe8fb
CT
132 if (bannedAction(checklist, i))
133 continue;
b6095d3e
AR
134 if (checklist->matchChild(this, i, *i)) {
135 lastMatch_ = i;
136 return 1;
137 }
138
139 if (!checklist->keepMatching())
140 return -1; // suspend on async calls and stop on failures
141 }
142
143 // zero and not one on empty because in math empty sum equals zero
144 return 0; // all nodes mismatched
145}
146
147void
148Acl::OrNode::parse()
149{
150 // Not implemented: OrNode cannot be configured directly. See Acl::AnyOf.
151 assert(false);
152}
f53969cc 153