]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Acl.h
sourceformat: split protos.h into more specific headers, change many functions' likag...
[thirdparty/squid.git] / src / acl / Acl.h
1 /*
2 *
3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
5 *
6 * Squid is the result of efforts by numerous individuals from
7 * the Internet community; see the CONTRIBUTORS file for full
8 * details. Many organizations have provided support for Squid's
9 * development; see the SPONSORS file for full details. Squid is
10 * Copyrighted (C) 2001 by the Regents of the University of
11 * California; see the COPYRIGHT file for full details. Squid
12 * incorporates software developed and/or copyrighted by other
13 * sources; see the CREDITS file for full details.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
28 *
29 *
30 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
31 */
32
33 #ifndef SQUID_ACL_H
34 #define SQUID_ACL_H
35
36 #include "Array.h"
37 #include "cbdata.h"
38 #include "defines.h"
39 #include "dlink.h"
40 #include "MemPool.h"
41
42 #if HAVE_OSTREAM
43 #include <ostream>
44 #endif
45
46 class ConfigParser;
47 class ACLChecklist;
48 class ACLList;
49
50 /// \ingroup ACLAPI
51 class ACL
52 {
53
54 public:
55 void *operator new(size_t);
56 void operator delete(void *);
57
58 static ACL *Factory (char const *);
59 static void ParseAclLine(ConfigParser &parser, ACL ** head);
60 static void Initialize();
61 static ACL* FindByName(const char *name);
62
63 ACL();
64 virtual ~ACL();
65 virtual ACL *clone()const = 0;
66 virtual void parse() = 0;
67 virtual char const *typeString() const = 0;
68 virtual bool isProxyAuth() const;
69 virtual bool requiresRequest() const;
70 virtual bool requiresReply() const;
71 virtual int match(ACLChecklist * checklist) = 0;
72 virtual wordlist *dump() const = 0;
73 virtual bool empty () const = 0;
74 virtual bool valid () const;
75 int checklistMatches(ACLChecklist *);
76
77 int cacheMatchAcl(dlink_list * cache, ACLChecklist *);
78 virtual int matchForCache(ACLChecklist *checklist);
79
80 virtual void prepareForUse() {}
81
82 char name[ACL_NAME_SZ];
83 char *cfgline;
84 ACL *next;
85
86 public:
87
88 class Prototype
89 {
90
91 public:
92 Prototype ();
93 Prototype (ACL const *, char const *);
94 ~Prototype();
95 static bool Registered(char const *);
96 static ACL *Factory (char const *);
97
98 private:
99 ACL const*prototype;
100 char const *typeString;
101
102 private:
103 static Vector<Prototype const *> * Registry;
104 static void *Initialized;
105 typedef Vector<Prototype const*>::iterator iterator;
106 typedef Vector<Prototype const*>::const_iterator const_iterator;
107 void registerMe();
108 };
109 };
110
111 /// \ingroup ACLAPI
112 typedef enum {
113 // Authorization ACL result states
114 ACCESS_DENIED,
115 ACCESS_ALLOWED,
116 ACCESS_DUNNO,
117
118 // Authentication ACL result states
119 ACCESS_AUTH_REQUIRED, // Missing Credentials
120 } aclMatchCode;
121
122 /// \ingroup ACLAPI
123 /// ACL check answer; TODO: Rename to Acl::Answer
124 class allow_t
125 {
126 public:
127 // not explicit: allow "aclMatchCode to allow_t" conversions (for now)
128 allow_t(const aclMatchCode aCode): code(aCode), kind(0) {}
129
130 allow_t(): code(ACCESS_DUNNO), kind(0) {}
131
132 bool operator ==(const aclMatchCode aCode) const {
133 return code == aCode;
134 }
135
136 bool operator !=(const aclMatchCode aCode) const {
137 return !(*this == aCode);
138 }
139
140 operator aclMatchCode() const {
141 return code;
142 }
143
144 aclMatchCode code; ///< ACCESS_* code
145 int kind; ///< which custom access list verb matched
146 };
147
148 inline std::ostream &
149 operator <<(std::ostream &o, const allow_t a)
150 {
151 switch (a) {
152 case ACCESS_DENIED:
153 o << "DENIED";
154 break;
155 case ACCESS_ALLOWED:
156 o << "ALLOWED";
157 break;
158 case ACCESS_DUNNO:
159 o << "DUNNO";
160 break;
161 case ACCESS_AUTH_REQUIRED:
162 o << "AUTH_REQUIRED";
163 break;
164 }
165 return o;
166 }
167
168 /// \ingroup ACLAPI
169 class acl_access
170 {
171
172 public:
173 void *operator new(size_t);
174 void operator delete(void *);
175 allow_t allow;
176 ACLList *aclList;
177 char *cfgline;
178 acl_access *next;
179
180 private:
181 CBDATA_CLASS(acl_access);
182 };
183
184 /// \ingroup ACLAPI
185 class ACLList
186 {
187
188 public:
189 MEMPROXY_CLASS(ACLList);
190
191 ACLList();
192 void negated(bool isNegated);
193 bool matches (ACLChecklist *)const;
194 int op;
195 ACL *_acl;
196 ACLList *next;
197 };
198
199 MEMPROXY_CLASS_INLINE(ACLList);
200
201 /// \ingroup ACLAPI
202 class acl_proxy_auth_match_cache
203 {
204
205 public:
206 MEMPROXY_CLASS(acl_proxy_auth_match_cache);
207 dlink_node link;
208 int matchrv;
209 void *acl_data;
210 };
211
212 MEMPROXY_CLASS_INLINE(acl_proxy_auth_match_cache);
213
214 /// \ingroup ACLAPI
215 extern const char *AclMatchedName; /* NULL */
216
217 #endif /* SQUID_ACL_H */