2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "acl/FilledChecklist.h"
37 #include "acl/HttpStatus.h"
40 #include "HttpReply.h"
45 static void aclParseHTTPStatusList(SplayNode
<acl_httpstatus_data
*> **curlist
);
46 static int aclHTTPStatusCompare(acl_httpstatus_data
* const &a
, acl_httpstatus_data
* const &b
);
47 static int aclMatchHTTPStatus(SplayNode
<acl_httpstatus_data
*> **dataptr
, Http::StatusCode status
);
49 acl_httpstatus_data::acl_httpstatus_data(int x
) : status1(x
), status2(x
) { ; }
51 acl_httpstatus_data::acl_httpstatus_data(int x
, int y
) : status1(x
), status2(y
) { ; }
53 void acl_httpstatus_data::toStr(char* buf
, int len
) const
55 if (status2
== INT_MAX
)
56 snprintf(buf
, len
, "%d-", status1
);
57 else if (status1
== status2
)
58 snprintf(buf
, len
, "%d", status1
);
60 snprintf(buf
, len
, "%d-%d", status1
, status2
);
63 int acl_httpstatus_data::compare(acl_httpstatus_data
* const& a
, acl_httpstatus_data
* const& b
)
66 ret
= aclHTTPStatusCompare(b
, a
);
69 ret
= aclHTTPStatusCompare(a
, b
);
74 a
->toStr(bufa
, sizeof(bufa
));
75 b
->toStr(bufb
, sizeof(bufb
));
76 debugs(28, DBG_CRITICAL
, "WARNING: '" << bufa
<< "' is a subrange of '" << bufb
<< "'");
77 debugs(28, DBG_CRITICAL
, "WARNING: because of this '" << bufa
<< "' is ignored to keep splay tree searching predictable");
78 debugs(28, DBG_CRITICAL
, "WARNING: You should probably remove '" << bufb
<< "' from the ACL named '" << AclMatchedName
<< "'");
85 ACLHTTPStatus::clone() const
87 return new ACLHTTPStatus(*this);
90 ACLHTTPStatus::ACLHTTPStatus (char const *theClass
) : data(NULL
), class_ (theClass
)
93 ACLHTTPStatus::ACLHTTPStatus (ACLHTTPStatus
const & old
) : data(NULL
), class_ (old
.class_
)
95 /* we don't have copy constructors for the data yet */
99 ACLHTTPStatus::~ACLHTTPStatus()
102 data
->destroy(SplayNode
<acl_httpstatus_data
*>::DefaultFree
);
106 ACLHTTPStatus::typeString() const
112 ACLHTTPStatus::empty () const
114 return data
->empty();
118 aclParseHTTPStatusData(const char *t
)
125 return new acl_httpstatus_data(status
);
128 return new acl_httpstatus_data(status
, atoi(t
));
130 return new acl_httpstatus_data(status
, INT_MAX
);
134 ACLHTTPStatus::parse()
136 aclParseHTTPStatusList (&data
);
140 aclParseHTTPStatusList(SplayNode
<acl_httpstatus_data
*> **curlist
)
143 SplayNode
<acl_httpstatus_data
*> **Top
= curlist
;
144 acl_httpstatus_data
*q
= NULL
;
146 while ((t
= strtokFile())) {
147 if ((q
= aclParseHTTPStatusData(t
)) == NULL
)
150 *Top
= (*Top
)->insert(q
, acl_httpstatus_data::compare
);
155 ACLHTTPStatus::match(ACLChecklist
*checklist
)
157 return aclMatchHTTPStatus(&data
, Filled(checklist
)->reply
->sline
.status());
161 aclMatchHTTPStatus(SplayNode
<acl_httpstatus_data
*> **dataptr
, const Http::StatusCode status
)
164 acl_httpstatus_data
X(status
);
165 SplayNode
<acl_httpstatus_data
*> **Top
= dataptr
;
166 *Top
= Top
[0]->splay(&X
, aclHTTPStatusCompare
);
168 debugs(28, 3, "aclMatchHTTPStatus: '" << status
<< "' " << (splayLastResult
? "NOT found" : "found"));
169 return (0 == splayLastResult
);
173 aclHTTPStatusCompare(acl_httpstatus_data
* const &a
, acl_httpstatus_data
* const &b
)
175 if (a
->status1
< b
->status1
)
178 if (a
->status1
> b
->status2
)
185 aclDumpHTTPStatusListWalkee(acl_httpstatus_data
* const &node
, void *state
)
188 node
->toStr(buf
, sizeof(buf
));
189 wordlistAdd((wordlist
**)state
, buf
);
193 ACLHTTPStatus::dump() const
196 data
->walk(aclDumpHTTPStatusListWalkee
, &w
);