]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/BoolOps.cc
2 * Copyright (C) 1996-2020 The Squid Software Foundation and contributors
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.
10 #include "acl/BoolOps.h"
11 #include "acl/Checklist.h"
13 #include "sbuf/SBuf.h"
17 Acl::NotNode::NotNode(ACL
*acl
)
20 Must(strlen(acl
->name
) <= sizeof(name
)-2);
23 xstrncpy(&name
[1], acl
->name
, sizeof(name
)-1); // -1 for '!'
30 // Not implemented: by the time an upper level parser discovers
31 // an '!' operator, there is nothing left for us to parse.
36 Acl::NotNode::doMatch(ACLChecklist
*checklist
, Nodes::const_iterator start
) const
38 assert(start
== nodes
.begin()); // we only have one node
40 if (checklist
->matchChild(this, start
, *start
))
41 return 0; // converting match into mismatch
43 if (!checklist
->keepMatching())
44 return -1; // suspend on async calls and stop on failures
46 return 1; // converting mismatch into match
50 Acl::NotNode::typeString() const
56 Acl::NotNode::clone() const
58 // Not implemented: we are not a named ACL type in squid.conf so nobody
59 // should try to create a NotNode instance by ACL type name (which is
60 // what clone() API is for -- it does not really clone anything).
66 Acl::NotNode::dump() const
69 text
.push_back(SBuf(name
));
76 Acl::AndNode::typeString() const
82 Acl::AndNode::clone() const
88 Acl::AndNode::doMatch(ACLChecklist
*checklist
, Nodes::const_iterator start
) const
90 // find the first node that does not match
91 for (Nodes::const_iterator i
= start
; i
!= nodes
.end(); ++i
) {
92 if (!checklist
->matchChild(this, i
, *i
))
93 return checklist
->keepMatching() ? 0 : -1;
96 // one and not zero on empty because in math empty product equals identity
97 return 1; // no mismatches found (i.e., all kids matched)
101 Acl::AndNode::parse()
103 // Not implemented: AndNode cannot be configured directly. See Acl::AllOf.
110 Acl::OrNode::typeString() const
116 Acl::OrNode::clone() const
122 Acl::OrNode::bannedAction(ACLChecklist
*, Nodes::const_iterator
) const
128 Acl::OrNode::doMatch(ACLChecklist
*checklist
, Nodes::const_iterator start
) const
130 lastMatch_
= nodes
.end();
132 // find the first node that matches, but stop if things go wrong
133 for (Nodes::const_iterator i
= start
; i
!= nodes
.end(); ++i
) {
134 if (bannedAction(checklist
, i
))
136 if (checklist
->matchChild(this, i
, *i
)) {
141 if (!checklist
->keepMatching())
142 return -1; // suspend on async calls and stop on failures
145 // zero and not one on empty because in math empty sum equals zero
146 return 0; // all nodes mismatched
152 // Not implemented: OrNode cannot be configured directly. See Acl::AnyOf.