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