]>
Commit | Line | Data |
---|---|---|
5dee515e | 1 | |
2 | /* | |
62e76326 | 3 | * $Id: ACLStrategised.h,v 1.2 2003/02/21 22:50:04 robertc Exp $ |
5dee515e | 4 | * |
5 | * | |
6 | * SQUID Web Proxy Cache http://www.squid-cache.org/ | |
7 | * ---------------------------------------------------------- | |
8 | * | |
9 | * Squid is the result of efforts by numerous individuals from | |
10 | * the Internet community; see the CONTRIBUTORS file for full | |
11 | * details. Many organizations have provided support for Squid's | |
12 | * development; see the SPONSORS file for full details. Squid is | |
13 | * Copyrighted (C) 2001 by the Regents of the University of | |
14 | * California; see the COPYRIGHT file for full details. Squid | |
15 | * incorporates software developed and/or copyrighted by other | |
16 | * sources; see the CREDITS file for full details. | |
17 | * | |
18 | * This program is free software; you can redistribute it and/or modify | |
19 | * it under the terms of the GNU General Public License as published by | |
20 | * the Free Software Foundation; either version 2 of the License, or | |
21 | * (at your option) any later version. | |
22 | * | |
23 | * This program is distributed in the hope that it will be useful, | |
24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
26 | * GNU General Public License for more details. | |
27 | * | |
28 | * You should have received a copy of the GNU General Public License | |
29 | * along with this program; if not, write to the Free Software | |
30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. | |
31 | * | |
32 | * | |
33 | * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org> | |
34 | */ | |
35 | ||
36 | #ifndef SQUID_ACLSTRATEGISED_H | |
37 | #define SQUID_ACLSTRATEGISED_H | |
38 | #include "ACL.h" | |
39 | #include "ACLData.h" | |
40 | #include "ACLMatchStrategy.h" | |
41 | ||
42 | template <class M> | |
62e76326 | 43 | |
44 | class ACLStrategised : public ACL | |
45 | { | |
46 | ||
47 | public: | |
5dee515e | 48 | typedef M MatchType; |
49 | void *operator new(size_t); | |
50 | void operator delete(void *); | |
51 | virtual void deleteSelf() const; | |
52 | ||
53 | ~ACLStrategised(); | |
54 | ACLStrategised(ACLData<MatchType> *, ACLMatchStrategy<MatchType> *, char const *); | |
55 | ACLStrategised (ACLStrategised const &); | |
56 | ACLStrategised &operator= (ACLStrategised const &); | |
62e76326 | 57 | |
5dee515e | 58 | virtual char const *typeString() const; |
59 | virtual squid_acl aclType() const { return ACL_DERIVED;} | |
62e76326 | 60 | |
5dee515e | 61 | virtual bool requiresRequest() const {return matcher->requiresRequest();} |
62e76326 | 62 | |
5dee515e | 63 | virtual void parse(); |
64 | virtual int match(ACLChecklist *checklist); | |
65 | virtual wordlist *dump() const; | |
66 | virtual bool valid () const; | |
67 | virtual ACL *clone()const; | |
62e76326 | 68 | |
69 | private: | |
5dee515e | 70 | static MemPool *Pool; |
71 | ACLData<MatchType> *data; | |
72 | char const *type_; | |
73 | ACLMatchStrategy<MatchType> *matcher; | |
74 | }; | |
75 | ||
76 | /* implementation follows */ | |
77 | ||
78 | template <class MatchType> | |
79 | MemPool *ACLStrategised<MatchType>::Pool(NULL); | |
80 | ||
81 | template <class MatchType> | |
82 | void * | |
83 | ACLStrategised<MatchType>::operator new (size_t byteCount) | |
84 | { | |
85 | /* derived classes with different sizes must implement their own new */ | |
86 | assert (byteCount == sizeof (ACLStrategised<MatchType>)); | |
62e76326 | 87 | |
5dee515e | 88 | if (!Pool) |
62e76326 | 89 | Pool = memPoolCreate("ACLStrategised", sizeof (ACLStrategised<MatchType>)); |
90 | ||
5dee515e | 91 | return memPoolAlloc(Pool); |
92 | } | |
93 | ||
94 | template <class MatchType> | |
95 | void | |
96 | ACLStrategised<MatchType>::operator delete (void *address) | |
97 | { | |
98 | memPoolFree (Pool, address); | |
99 | } | |
100 | ||
101 | template <class MatchType> | |
102 | void | |
103 | ACLStrategised<MatchType>::deleteSelf() const | |
104 | { | |
105 | delete this; | |
106 | } | |
107 | ||
108 | template <class MatchType> | |
109 | ACLStrategised<MatchType>::~ACLStrategised() | |
110 | { | |
111 | data->deleteSelf(); | |
112 | } | |
113 | ||
114 | template <class MatchType> | |
115 | ACLStrategised<MatchType>::ACLStrategised(ACLData<MatchType> *newData, ACLMatchStrategy<MatchType> *theStrategy, char const *theType) : data (newData), type_(theType), matcher(theStrategy) {} | |
62e76326 | 116 | |
5dee515e | 117 | template <class MatchType> |
118 | ACLStrategised<MatchType>::ACLStrategised (ACLStrategised const &old) : data (old.data->clone()), type_(old.type_), matcher (old.matcher) | |
62e76326 | 119 | {} |
120 | ||
5dee515e | 121 | template <class MatchType> |
122 | ACLStrategised<MatchType> & | |
123 | ACLStrategised<MatchType>::operator= (ACLStrategised const &rhs) | |
124 | { | |
125 | data = rhs.data->clone(); | |
126 | type_ = rhs.type_; | |
127 | matcher = rhs.matcher; | |
128 | return *this; | |
129 | } | |
130 | ||
131 | template <class MatchType> | |
132 | char const * | |
133 | ACLStrategised<MatchType>::typeString() const | |
134 | { | |
135 | return type_; | |
136 | } | |
137 | ||
138 | template <class MatchType> | |
139 | void | |
140 | ACLStrategised<MatchType>::parse() | |
141 | { | |
142 | data->parse(); | |
143 | } | |
144 | ||
145 | template <class MatchType> | |
146 | int | |
147 | ACLStrategised<MatchType>::match(ACLChecklist *checklist) | |
148 | { | |
149 | return matcher->match(data, checklist); | |
150 | } | |
151 | ||
152 | template <class MatchType> | |
153 | wordlist * | |
154 | ACLStrategised<MatchType>::dump() const | |
155 | { | |
156 | return data->dump(); | |
157 | } | |
158 | ||
159 | template <class MatchType> | |
160 | bool | |
161 | ACLStrategised<MatchType>::valid () const | |
162 | { | |
163 | return data != NULL; | |
164 | } | |
165 | ||
166 | template <class MatchType> | |
167 | ACL * | |
168 | ACLStrategised<MatchType>::clone() const | |
169 | { | |
170 | return new ACLStrategised(*this); | |
171 | } | |
172 | ||
173 | #endif /* SQUID_ACLSTRATEGISED_H */ |