source: squid-ssl/trunk/fuentes/src/acl/BoolOps.cc @ 5495

Last change on this file since 5495 was 5495, checked in by Juanma, 2 years ago

Initial release

File size: 3.3 KB
Line 
1/*
2 * Copyright (C) 1996-2015 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.h"
13
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.
29    assert(false);
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
62SBufList
63Acl::NotNode::dump() const
64{
65    SBufList text;
66    text.push_back(SBuf(name));
67    return text;
68}
69
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.
101    assert(false);
102}
103
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
118bool
119Acl::OrNode::bannedAction(ACLChecklist *, Nodes::const_iterator) const
120{
121    return false;
122}
123
124int
125Acl::OrNode::doMatch(ACLChecklist *checklist, Nodes::const_iterator start) const
126{
127    lastMatch_ = nodes.end();
128
129    // find the first node that matches, but stop if things go wrong
130    for (Nodes::const_iterator i = start; i != nodes.end(); ++i) {
131        if (bannedAction(checklist, i))
132            continue;
133        if (checklist->matchChild(this, i, *i)) {
134            lastMatch_ = i;
135            return 1;
136        }
137
138        if (!checklist->keepMatching())
139            return -1; // suspend on async calls and stop on failures
140    }
141
142    // zero and not one on empty because in math empty sum equals zero
143    return 0; // all nodes mismatched
144}
145
146void
147Acl::OrNode::parse()
148{
149    // Not implemented: OrNode cannot be configured directly. See Acl::AnyOf.
150    assert(false);
151}
152
Note: See TracBrowser for help on using the repository browser.