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