2
* $Id: ACLHTTPStatus.cc,v 1.3 2007/04/28 22:26:37 hno Exp $
4
* DEBUG: section 28 Access Control
5
* AUTHOR: Duane Wessels
7
* SQUID Web Proxy Cache http://www.squid-cache.org/
8
* ----------------------------------------------------------
10
* Squid is the result of efforts by numerous individuals from
11
* the Internet community; see the CONTRIBUTORS file for full
12
* details. Many organizations have provided support for Squid's
13
* development; see the SPONSORS file for full details. Squid is
14
* Copyrighted (C) 2001 by the Regents of the University of
15
* California; see the COPYRIGHT file for full details. Squid
16
* incorporates software developed and/or copyrighted by other
17
* sources; see the CREDITS file for full details.
19
* This program is free software; you can redistribute it and/or modify
20
* it under the terms of the GNU General Public License as published by
21
* the Free Software Foundation; either version 2 of the License, or
22
* (at your option) any later version.
24
* This program is distributed in the hope that it will be useful,
25
* but WITHOUT ANY WARRANTY; without even the implied warranty of
26
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
* GNU General Public License for more details.
29
* You should have received a copy of the GNU General Public License
30
* along with this program; if not, write to the Free Software
31
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34
* Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
39
#include <squid_windows.h>
43
#include "ACLHTTPStatus.h"
44
#include "HttpReply.h"
47
static void aclParseHTTPStatusList(SplayNode<acl_httpstatus_data *> **curlist);
48
static int aclHTTPStatusCompare(acl_httpstatus_data * const &a, acl_httpstatus_data * const &b);
49
static int aclMatchHTTPStatus(SplayNode<acl_httpstatus_data*> **dataptr, http_status status);
51
acl_httpstatus_data::acl_httpstatus_data(int x) : status1(x), status2(x) { ; }
53
acl_httpstatus_data::acl_httpstatus_data(int x, int y) : status1(x), status2(y) { ; }
55
void acl_httpstatus_data::toStr(char* buf, int len) const
57
if (status2 == INT_MAX)
58
snprintf(buf, len, "%d-", status1);
59
else if (status1 == status2)
60
snprintf(buf, len, "%d", status1);
62
snprintf(buf, len, "%d-%d", status1, status2);
65
int acl_httpstatus_data::compare(acl_httpstatus_data* const& a, acl_httpstatus_data* const& b)
68
ret = aclHTTPStatusCompare(b, a);
71
ret = aclHTTPStatusCompare(a, b);
76
a->toStr(bufa, sizeof(bufa));
77
b->toStr(bufb, sizeof(bufb));
78
debugs(28, 0, "WARNING: '" << bufa << "' is a subrange of '" << bufb << "'");
79
debugs(28, 0, "WARNING: because of this '" << bufa << "' is ignored to keep splay tree searching predictable");
80
debugs(28, 0, "WARNING: You should probably remove '" << bufb << "' from the ACL named '" << AclMatchedName << "'");
86
ACL::Prototype ACLHTTPStatus::RegistryProtoype(&ACLHTTPStatus::RegistryEntry_, "http_status");
88
ACLHTTPStatus ACLHTTPStatus::RegistryEntry_("http_status");
91
ACLHTTPStatus::clone() const
93
return new ACLHTTPStatus(*this);
96
ACLHTTPStatus::ACLHTTPStatus (char const *theClass) : data(NULL), class_ (theClass)
99
ACLHTTPStatus::ACLHTTPStatus (ACLHTTPStatus const & old) : data(NULL), class_ (old.class_)
101
/* we don't have copy constructors for the data yet */
105
ACLHTTPStatus::~ACLHTTPStatus()
108
data->destroy(SplayNode<acl_httpstatus_data*>::DefaultFree);
112
ACLHTTPStatus::typeString() const
118
ACLHTTPStatus::empty () const
120
return data->empty();
124
aclParseHTTPStatusData(const char *t)
131
return new acl_httpstatus_data(status);
134
return new acl_httpstatus_data(status, atoi(t));
136
return new acl_httpstatus_data(status, INT_MAX);
141
ACLHTTPStatus::parse()
143
aclParseHTTPStatusList (&data);
147
aclParseHTTPStatusList(SplayNode<acl_httpstatus_data *> **curlist)
150
SplayNode<acl_httpstatus_data*> **Top = curlist;
151
acl_httpstatus_data *q = NULL;
153
while ((t = strtokFile())) {
154
if ((q = aclParseHTTPStatusData(t)) == NULL)
157
*Top = (*Top)->insert(q, acl_httpstatus_data::compare);
162
ACLHTTPStatus::match(ACLChecklist *checklist)
164
return aclMatchHTTPStatus(&data, checklist->reply->sline.status);
168
aclMatchHTTPStatus(SplayNode<acl_httpstatus_data*> **dataptr, http_status status)
171
acl_httpstatus_data X(status);
172
SplayNode<acl_httpstatus_data*> **Top = dataptr;
173
*Top = Top[0]->splay(&X, aclHTTPStatusCompare);
175
debugs(28, 3, "aclMatchHTTPStatus: '" << status << "' " << (splayLastResult ? "NOT found" : "found"));
176
return (0 == splayLastResult);
180
aclHTTPStatusCompare(acl_httpstatus_data * const &a, acl_httpstatus_data * const &b)
182
if (a->status1 < b->status1)
185
if (a->status1 > b->status2)
192
aclDumpHTTPStatusListWalkee(acl_httpstatus_data * const &node, void *state)
195
node->toStr(buf, sizeof(buf));
196
wordlistAdd((wordlist **)state, buf);
200
ACLHTTPStatus::dump() const
203
data->walk(aclDumpHTTPStatusListWalkee, &w);