]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
bbc27441 AJ |
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 | ||
6f58d7d7 AR |
9 | #include "squid.h" |
10 | #include "acl/Acl.h" | |
11 | #include "acl/BoolOps.h" | |
12 | #include "acl/Checklist.h" | |
855a0107 | 13 | #include "acl/Gadgets.h" |
6f58d7d7 AR |
14 | #include "acl/InnerNode.h" |
15 | #include "cache_cf.h" | |
16 | #include "ConfigParser.h" | |
17 | #include "Debug.h" | |
18 | #include "globals.h" | |
6f58d7d7 AR |
19 | #include <algorithm> |
20 | ||
6f58d7d7 AR |
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); | |
855a0107 | 38 | aclRegister(node); |
6f58d7d7 AR |
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 | ||
8966008b | 76 | SBufList |
6f58d7d7 AR |
77 | Acl::InnerNode::dump() const |
78 | { | |
8966008b | 79 | SBufList rv; |
6f58d7d7 | 80 | for (Nodes::const_iterator i = nodes.begin(); i != nodes.end(); ++i) |
8966008b FC |
81 | rv.push_back(SBuf((*i)->name)); |
82 | return rv; | |
6f58d7d7 AR |
83 | } |
84 | ||
85 | int | |
86 | Acl::InnerNode::match(ACLChecklist *checklist) | |
87 | { | |
88 | return doMatch(checklist, nodes.begin()); | |
89 | } | |
90 | ||
91 | bool | |
d6d0eb11 | 92 | Acl::InnerNode::resumeMatchingAt(ACLChecklist *checklist, Acl::Nodes::const_iterator pos) const |
6f58d7d7 AR |
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 | } | |
f53969cc | 102 |