]>
Commit | Line | Data |
---|---|---|
5dee515e | 1 | /* |
77b1029d | 2 | * Copyright (C) 1996-2020 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 CT |
36 | ACLStrategised(ACLData<MatchType> *, ACLStrategy<MatchType> *, char const *); |
37 | ACLStrategised(ACLStrategised const &&) = delete; | |
62e76326 | 38 | |
5dee515e | 39 | virtual char const *typeString() const; |
4eac3407 CT |
40 | virtual void parseFlags(); |
41 | ||
5dee515e | 42 | virtual bool requiresRequest() const {return matcher->requiresRequest();} |
62e76326 | 43 | |
f201d9ac | 44 | virtual bool requiresReply() const {return matcher->requiresReply();} |
45 | ||
b0dd28ba | 46 | virtual void prepareForUse() { data->prepareForUse();} |
4eac3407 | 47 | virtual const Acl::Options &options() { return matcher->options(); } |
5dee515e | 48 | virtual void parse(); |
49 | virtual int match(ACLChecklist *checklist); | |
b0dd28ba | 50 | virtual int match (M const &); |
8966008b | 51 | virtual SBufList dump() const; |
4b0f5de8 | 52 | virtual bool empty () const; |
65092baf | 53 | virtual bool valid () const; |
62e76326 | 54 | |
55 | private: | |
5dee515e | 56 | ACLData<MatchType> *data; |
57 | char const *type_; | |
b0dd28ba | 58 | ACLStrategy<MatchType> *matcher; |
5dee515e | 59 | }; |
60 | ||
61 | /* implementation follows */ | |
62 | ||
5dee515e | 63 | template <class MatchType> |
64 | ACLStrategised<MatchType>::~ACLStrategised() | |
65 | { | |
00d77d6b | 66 | delete data; |
5dee515e | 67 | } |
68 | ||
69 | template <class MatchType> | |
4eac3407 | 70 | ACLStrategised<MatchType>::ACLStrategised(ACLData<MatchType> *newData, ACLStrategy<MatchType> *theStrategy, char const *theType): data(newData), type_(theType), matcher(theStrategy) |
62e76326 | 71 | {} |
72 | ||
5dee515e | 73 | template <class MatchType> |
4eac3407 CT |
74 | char const * |
75 | ACLStrategised<MatchType>::typeString() const | |
5dee515e | 76 | { |
4eac3407 | 77 | return type_; |
5dee515e | 78 | } |
79 | ||
80 | template <class MatchType> | |
4eac3407 CT |
81 | void |
82 | ACLStrategised<MatchType>::parseFlags() | |
5dee515e | 83 | { |
4eac3407 | 84 | ParseFlags(options(), data->supportedFlags()); |
5dee515e | 85 | } |
86 | ||
87 | template <class MatchType> | |
88 | void | |
89 | ACLStrategised<MatchType>::parse() | |
90 | { | |
91 | data->parse(); | |
92 | } | |
93 | ||
65092baf | 94 | template <class MatchType> |
95 | bool | |
96 | ACLStrategised<MatchType>::empty() const | |
97 | { | |
98 | return data->empty(); | |
99 | } | |
100 | ||
5dee515e | 101 | template <class MatchType> |
102 | int | |
c0941a6a | 103 | ACLStrategised<MatchType>::match(ACLChecklist *cl) |
5dee515e | 104 | { |
af6a12ee AJ |
105 | ACLFilledChecklist *checklist = dynamic_cast<ACLFilledChecklist*>(cl); |
106 | assert(checklist); | |
4eac3407 | 107 | return matcher->match(data, checklist); |
5dee515e | 108 | } |
109 | ||
b0dd28ba | 110 | template <class MatchType> |
111 | int | |
112 | ACLStrategised<MatchType>::match(MatchType const &toFind) | |
113 | { | |
114 | return data->match(toFind); | |
115 | } | |
116 | ||
5dee515e | 117 | template <class MatchType> |
8966008b | 118 | SBufList |
5dee515e | 119 | ACLStrategised<MatchType>::dump() const |
120 | { | |
121 | return data->dump(); | |
122 | } | |
123 | ||
124 | template <class MatchType> | |
125 | bool | |
65092baf | 126 | ACLStrategised<MatchType>::valid () const |
5dee515e | 127 | { |
65092baf | 128 | return matcher->valid(); |
5dee515e | 129 | } |
130 | ||
5dee515e | 131 | #endif /* SQUID_ACLSTRATEGISED_H */ |
f53969cc | 132 |