3 * SQUID Web Proxy Cache http://www.squid-cache.org/
4 * ----------------------------------------------------------
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.
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.
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.
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.
30 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
55 #define ACL_F_REGEX_CASE 'i'
56 #define ACL_F_NO_LOOKUP 'n'
57 #define ACL_F_END '\0'
61 * Used to hold a list of one-letter flags which can be passed as parameters
62 * to acls (eg '-i', '-n' etc)
67 explicit ACLFlags(const ACLFlag flags
[]) : supported_(flags
), flags_(0) {}
68 ACLFlags() : flags_(0) {}
69 bool supported(const ACLFlag f
) const; ///< True if the given flag supported
70 void makeSet(const ACLFlag f
) { flags_
|= flagToInt(f
); } ///< Set the given flag
71 /// Return true if the given flag is set
72 bool isSet(const ACLFlag f
) const { return flags_
& flagToInt(f
);}
73 /// Parse a flags given in the form -[A..Z|a..z]
74 void parseFlags(char * &nextToken
);
75 const char *flagsStr() const; ///< Convert the flags to a string representation
78 /// Convert a flag to a 64bit unsigned integer.
79 /// The characters from 'A' to 'z' represented by the values from 65 to 122.
80 /// They are 57 different characters which can be fit to the bits of an 64bit
82 uint64_t flagToInt(const ACLFlag f
) const {
83 assert('A' <= f
&& f
<= 'z');
84 return ((uint64_t)1 << (f
- 'A'));
87 std::string supported_
; ///< The supported character flags
88 uint64_t flags_
; ///< The flags which is set
90 static const ACLFlag NoFlags
[1]; ///< An empty flags list
98 void *operator new(size_t);
99 void operator delete(void *);
101 static ACL
*Factory (char const *);
102 static void ParseAclLine(ConfigParser
&parser
, ACL
** head
);
103 static void Initialize();
104 static ACL
* FindByName(const char *name
);
107 explicit ACL(const ACLFlag flgs
[]) : cfgline(NULL
), flags(flgs
) {}
109 virtual ACL
*clone()const = 0;
110 virtual void parse() = 0;
111 virtual char const *typeString() const = 0;
112 virtual bool isProxyAuth() const;
113 virtual bool requiresRequest() const;
114 virtual bool requiresReply() const;
115 virtual int match(ACLChecklist
* checklist
) = 0;
116 virtual wordlist
*dump() const = 0;
117 virtual bool empty () const = 0;
118 virtual bool valid () const;
119 int checklistMatches(ACLChecklist
*);
121 int cacheMatchAcl(dlink_list
* cache
, ACLChecklist
*);
122 virtual int matchForCache(ACLChecklist
*checklist
);
124 virtual void prepareForUse() {}
126 char name
[ACL_NAME_SZ
];
129 ACLFlags flags
; ///< The list of given ACL flags
138 Prototype (ACL
const *, char const *);
140 static bool Registered(char const *);
141 static ACL
*Factory (char const *);
145 char const *typeString
;
148 static Vector
<Prototype
const *> * Registry
;
149 static void *Initialized
;
150 typedef Vector
<Prototype
const*>::iterator iterator
;
151 typedef Vector
<Prototype
const*>::const_iterator const_iterator
;
158 // Authorization ACL result states
163 // Authentication ACL result states
164 ACCESS_AUTH_REQUIRED
, // Missing Credentials
168 /// ACL check answer; TODO: Rename to Acl::Answer
172 // not explicit: allow "aclMatchCode to allow_t" conversions (for now)
173 allow_t(const aclMatchCode aCode
): code(aCode
), kind(0) {}
175 allow_t(): code(ACCESS_DUNNO
), kind(0) {}
177 bool operator ==(const aclMatchCode aCode
) const {
178 return code
== aCode
;
181 bool operator !=(const aclMatchCode aCode
) const {
182 return !(*this == aCode
);
185 operator aclMatchCode() const {
189 aclMatchCode code
; ///< ACCESS_* code
190 int kind
; ///< which custom access list verb matched
193 inline std::ostream
&
194 operator <<(std::ostream
&o
, const allow_t a
)
206 case ACCESS_AUTH_REQUIRED
:
207 o
<< "AUTH_REQUIRED";
218 void *operator new(size_t);
219 void operator delete(void *);
226 CBDATA_CLASS(acl_access
);
234 MEMPROXY_CLASS(ACLList
);
237 void negated(bool isNegated
);
238 bool matches (ACLChecklist
*)const;
244 MEMPROXY_CLASS_INLINE(ACLList
);
247 class acl_proxy_auth_match_cache
251 MEMPROXY_CLASS(acl_proxy_auth_match_cache
);
257 MEMPROXY_CLASS_INLINE(acl_proxy_auth_match_cache
);
260 extern const char *AclMatchedName
; /* NULL */
262 #endif /* SQUID_ACL_H */