HttpStatus.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
7 */
8
9/* DEBUG: section 28 Access Control */
10
11#include "squid.h"
12#include "acl/FilledChecklist.h"
13#include "acl/HttpStatus.h"
14#include "debug/Stream.h"
15#include "HttpReply.h"
16
17#include <climits>
18
20static int aclHTTPStatusCompare(acl_httpstatus_data * const &a, acl_httpstatus_data * const &b);
22
23acl_httpstatus_data::acl_httpstatus_data(int x) : status1(x), status2(x) { ; }
24
25acl_httpstatus_data::acl_httpstatus_data(int x, int y) : status1(x), status2(y) { ; }
26
27SBuf
29{
30 SBuf rv;
31 if (status2 == INT_MAX)
32 rv.Printf("%d-", status1);
33 else if (status1 == status2)
34 rv.Printf("%d", status1);
35 else
36 rv.Printf("%d-%d", status1, status2);
37 return rv;
38}
39
41{
42 int ret;
43 ret = aclHTTPStatusCompare(b, a);
44
45 if (ret != 0)
46 ret = aclHTTPStatusCompare(a, b);
47
48 if (ret == 0) {
49 const SBuf sa = a->toStr();
50 const SBuf sb = b->toStr();
51 debugs(28, DBG_CRITICAL, "WARNING: '" << sa << "' is a subrange of '" << sb << "'");
52 debugs(28, DBG_CRITICAL, "WARNING: because of this '" << sa << "' is ignored to keep splay tree searching predictable");
53 debugs(28, DBG_CRITICAL, "WARNING: You should probably remove '" << sb << "' from the ACL named '" << AclMatchedName << "'");
54 }
55
56 return ret;
57}
58
59ACLHTTPStatus::ACLHTTPStatus (char const *theClass) : data(nullptr), class_ (theClass)
60{}
61
63{
64 if (data) {
65 data->destroy();
66 delete data;
67 }
68}
69
70char const *
72{
73 return class_;
74}
75
76bool
78{
79 return data->empty();
80}
81
84{
85 int status;
86 status = atoi(t);
87 t = strchr(t, '-');
88
89 if (!t)
90 return new acl_httpstatus_data(status);
91
92 if (*(++t))
93 return new acl_httpstatus_data(status, atoi(t));
94
95 return new acl_httpstatus_data(status, INT_MAX);
96}
97
98void
100{
101 if (!data)
103
105}
106
107void
109{
110 while (char *t = ConfigParser::strtokFile()) {
112 (*curlist)->insert(q, acl_httpstatus_data::compare);
113 }
114}
115
116int
118{
119 return aclMatchHTTPStatus(&data, Filled(checklist)->reply->sline.status());
120}
121
122int
124{
125 acl_httpstatus_data X(status);
126 const acl_httpstatus_data * const * result = (*dataptr)->find(&X, aclHTTPStatusCompare);
127
128 debugs(28, 3, "aclMatchHTTPStatus: '" << status << "' " << (result ? "found" : "NOT found"));
129 return (result != nullptr);
130}
131
132static int
134{
135 if (a->status1 < b->status1)
136 return 1;
137
138 if (a->status1 > b->status2)
139 return -1;
140
141 return 0;
142}
143
147 contents.push_back(node->toStr());
148 }
149};
150
153{
155 data->visit(visitor);
156 return visitor.contents;
157}
158
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
static void aclParseHTTPStatusList(Splay< acl_httpstatus_data * > **curlist)
Definition: HttpStatus.cc:108
static int aclHTTPStatusCompare(acl_httpstatus_data *const &a, acl_httpstatus_data *const &b)
Definition: HttpStatus.cc:133
static acl_httpstatus_data * aclParseHTTPStatusData(const char *t)
Definition: HttpStatus.cc:83
static int aclMatchHTTPStatus(Splay< acl_httpstatus_data * > **dataptr, Http::StatusCode status)
Definition: HttpStatus.cc:123
~ACLHTTPStatus() override
Definition: HttpStatus.cc:62
void parse() override
parses node representation in squid.conf; dies on failures
Definition: HttpStatus.cc:99
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this ACL.
Definition: HttpStatus.cc:117
char const * typeString() const override
Definition: HttpStatus.cc:71
ACLHTTPStatus(char const *)
Definition: HttpStatus.cc:59
char const * class_
Definition: HttpStatus.h:44
SBufList dump() const override
Definition: HttpStatus.cc:152
Splay< acl_httpstatus_data * > * data
Definition: HttpStatus.h:43
bool empty() const override
Definition: HttpStatus.cc:77
static char * strtokFile()
Definition: ConfigParser.cc:65
Definition: SBuf.h:94
SBuf & Printf(const char *fmt,...) PRINTF_FORMAT_ARG2
Definition: SBuf.cc:214
bool empty() const
Definition: splay.h:76
void visit(ValueVisitor &) const
left-to-right visit of all stored Values
void destroy(SPLAYFREE *=DefaultFree)
Definition: splay.h:365
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
#define DBG_CRITICAL
Definition: Stream.h:37
const char * AclMatchedName
Definition: Acl.cc:29
StatusCode
Definition: StatusCode.h:20
std::list< SBuf > SBufList
Definition: forward.h:23
static struct stat sb
Definition: squidclient.cc:71
void operator()(const acl_httpstatus_data *node)
Definition: HttpStatus.cc:146
SBuf toStr() const
Definition: HttpStatus.cc:28
static int compare(acl_httpstatus_data *const &a, acl_httpstatus_data *const &b)
Definition: HttpStatus.cc:40
Definition: parse.c:104
#define INT_MAX
Definition: types.h:70

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors