]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/InnerNode.cc
ef4c8a579901499d4fb95d8249b2349ff14c1773
[thirdparty/squid.git] / src / acl / InnerNode.cc
1 /*
2 * Copyright (C) 1996-2016 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/Acl.h"
11 #include "acl/BoolOps.h"
12 #include "acl/Checklist.h"
13 #include "acl/Gadgets.h"
14 #include "acl/InnerNode.h"
15 #include "cache_cf.h"
16 #include "ConfigParser.h"
17 #include "Debug.h"
18 #include "globals.h"
19 #include <algorithm>
20
21 void
22 Acl::InnerNode::prepareForUse()
23 {
24 std::for_each(nodes.begin(), nodes.end(), std::mem_fun(&ACL::prepareForUse));
25 }
26
27 bool
28 Acl::InnerNode::empty() const
29 {
30 return nodes.empty();
31 }
32
33 void
34 Acl::InnerNode::add(ACL *node)
35 {
36 assert(node != NULL);
37 nodes.push_back(node);
38 aclRegister(node);
39 }
40
41 // one call parses one "acl name acltype name1 name2 ..." line
42 // kids use this method to handle [multiple] parse() calls correctly
43 void
44 Acl::InnerNode::lineParse()
45 {
46 // XXX: not precise, may change when looping or parsing multiple lines
47 if (!cfgline)
48 cfgline = xstrdup(config_input_line);
49
50 // expect a list of ACL names, each possibly preceeded by '!' for negation
51
52 while (const char *t = ConfigParser::strtokFile()) {
53 const bool negated = (*t == '!');
54 if (negated)
55 ++t;
56
57 debugs(28, 3, "looking for ACL " << t);
58 ACL *a = ACL::FindByName(t);
59
60 if (a == NULL) {
61 debugs(28, DBG_CRITICAL, "ACL not found: " << t);
62 self_destruct();
63 return;
64 }
65
66 // append(negated ? new NotNode(a) : a);
67 if (negated)
68 add(new NotNode(a));
69 else
70 add(a);
71 }
72
73 return;
74 }
75
76 SBufList
77 Acl::InnerNode::dump() const
78 {
79 SBufList rv;
80 for (Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i)
81 rv.push_back(SBuf((*i)->name));
82 return rv;
83 }
84
85 int
86 Acl::InnerNode::match(ACLChecklist *checklist)
87 {
88 return doMatch(checklist, nodes.begin());
89 }
90
91 bool
92 Acl::InnerNode::resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const
93 {
94 debugs(28, 5, "checking " << name << " at " << (pos-nodes.begin()));
95 const int result = doMatch(checklist, pos);
96 const char *extra = checklist->asyncInProgress() ? " async" : "";
97 debugs(28, 3, "checked: " << name << " = " << result << extra);
98
99 // merges async and failures (-1) into "not matched"
100 return result == 1;
101 }
102