]>
Commit | Line | Data |
---|---|---|
5dee515e | 1 | /* |
bf95c10a | 2 | * Copyright (C) 1996-2022 The Squid Software Foundation and contributors |
5dee515e | 3 | * |
bbc27441 AJ |
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. | |
5dee515e | 7 | */ |
8 | ||
9 | #ifndef SQUID_ACLSTRATEGISED_H | |
10 | #define SQUID_ACLSTRATEGISED_H | |
ed6e9fb9 | 11 | |
c0941a6a AR |
12 | #include "acl/Acl.h" |
13 | #include "acl/Data.h" | |
c0941a6a | 14 | #include "acl/FilledChecklist.h" |
602d9612 | 15 | #include "acl/Strategy.h" |
5dee515e | 16 | |
4eac3407 CT |
17 | // XXX: Replace with a much simpler abstract ACL child class without the |
18 | // ACLStrategy parameter (and associated call forwarding). Duplicating key | |
19 | // portions of the ACL class API in ACLStrategy is not needed because | |
20 | // ACLStrategy is unused outside the ACLStrategised context. Existing classes | |
21 | // like ACLExtUser, ACLProxyAuth, and ACLIdent seem to confirm this assertion. | |
22 | // It also requires forwarding ACL info to ACLStrategy as method parameters. | |
23 | ||
24 | /// Splits the ACL API into two individually configurable components: | |
25 | /// * ACLStrategy that usually extracts information from the current transaction | |
26 | /// * ACLData that usually matches information against admin-configured values | |
5dee515e | 27 | template <class M> |
62e76326 | 28 | class ACLStrategised : public ACL |
29 | { | |
ed6e9fb9 | 30 | MEMPROXY_CLASS(ACLStrategised); |
62e76326 | 31 | |
32 | public: | |
5dee515e | 33 | typedef M MatchType; |
5dee515e | 34 | |
35 | ~ACLStrategised(); | |
4eac3407 | 36 | ACLStrategised(ACLData<MatchType> *, ACLStrategy<MatchType> *, char const *); |
62e76326 | 37 | |
5dee515e | 38 | virtual char const *typeString() const; |
4eac3407 | 39 | |
5dee515e | 40 | virtual bool requiresRequest() const {return matcher->requiresRequest();} |
62e76326 | 41 | |
f201d9ac | 42 | virtual bool requiresReply() const {return matcher->requiresReply();} |
43 | ||
b0dd28ba | 44 | virtual void prepareForUse() { data->prepareForUse();} |
5dee515e | 45 | virtual void parse(); |
46 | virtual int match(ACLChecklist *checklist); | |
b0dd28ba | 47 | virtual int match (M const &); |
8966008b | 48 | virtual SBufList dump() const; |
4b0f5de8 | 49 | virtual bool empty () const; |
65092baf | 50 | virtual bool valid () const; |
62e76326 | 51 | |
52 | private: | |
8d76389c EB |
53 | /* ACL API */ |
54 | virtual const Acl::Options &options() { return matcher->options(); } | |
55 | virtual const Acl::Options &lineOptions() { return data->lineOptions(); } | |
56 | ||
5dee515e | 57 | ACLData<MatchType> *data; |
58 | char const *type_; | |
b0dd28ba | 59 | ACLStrategy<MatchType> *matcher; |
5dee515e | 60 | }; |
61 | ||
62 | /* implementation follows */ | |
63 | ||
5dee515e | 64 | template <class MatchType> |
65 | ACLStrategised<MatchType>::~ACLStrategised() | |
66 | { | |
00d77d6b | 67 | delete data; |
0f04d0e8 | 68 | delete matcher; |
5dee515e | 69 | } |
70 | ||
71 | template <class MatchType> | |
4eac3407 | 72 | ACLStrategised<MatchType>::ACLStrategised(ACLData<MatchType> *newData, ACLStrategy<MatchType> *theStrategy, char const *theType): data(newData), type_(theType), matcher(theStrategy) |
62e76326 | 73 | {} |
74 | ||
5dee515e | 75 | template <class MatchType> |
4eac3407 CT |
76 | char const * |
77 | ACLStrategised<MatchType>::typeString() const | |
5dee515e | 78 | { |
4eac3407 | 79 | return type_; |
5dee515e | 80 | } |
81 | ||
5dee515e | 82 | template <class MatchType> |
83 | void | |
84 | ACLStrategised<MatchType>::parse() | |
85 | { | |
86 | data->parse(); | |
87 | } | |
88 | ||
65092baf | 89 | template <class MatchType> |
90 | bool | |
91 | ACLStrategised<MatchType>::empty() const | |
92 | { | |
93 | return data->empty(); | |
94 | } | |
95 | ||
5dee515e | 96 | template <class MatchType> |
97 | int | |
c0941a6a | 98 | ACLStrategised<MatchType>::match(ACLChecklist *cl) |
5dee515e | 99 | { |
af6a12ee AJ |
100 | ACLFilledChecklist *checklist = dynamic_cast<ACLFilledChecklist*>(cl); |
101 | assert(checklist); | |
4eac3407 | 102 | return matcher->match(data, checklist); |
5dee515e | 103 | } |
104 | ||
b0dd28ba | 105 | template <class MatchType> |
106 | int | |
107 | ACLStrategised<MatchType>::match(MatchType const &toFind) | |
108 | { | |
109 | return data->match(toFind); | |
110 | } | |
111 | ||
5dee515e | 112 | template <class MatchType> |
8966008b | 113 | SBufList |
5dee515e | 114 | ACLStrategised<MatchType>::dump() const |
115 | { | |
116 | return data->dump(); | |
117 | } | |
118 | ||
119 | template <class MatchType> | |
120 | bool | |
65092baf | 121 | ACLStrategised<MatchType>::valid () const |
5dee515e | 122 | { |
65092baf | 123 | return matcher->valid(); |
5dee515e | 124 | } |
125 | ||
5dee515e | 126 | #endif /* SQUID_ACLSTRATEGISED_H */ |
f53969cc | 127 |