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