Squid Web Cache master
Loading...
Searching...
No Matches
HttpStatus.cc
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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 "acl/SplayInserter.h"
15#include "debug/Stream.h"
16#include "HttpReply.h"
17
18#include <algorithm>
19#include <climits>
20
22static int aclHTTPStatusCompare(acl_httpstatus_data * const &a, acl_httpstatus_data * const &b);
24
25acl_httpstatus_data::acl_httpstatus_data(int x) : status1(x), status2(x) { ; }
26
27acl_httpstatus_data::acl_httpstatus_data(int x, int y) : status1(x), status2(y) { ; }
28
29SBuf
31{
32 SBuf rv;
33 if (status2 == INT_MAX)
34 rv.Printf("%d-", status1);
35 else if (status1 == status2)
36 rv.Printf("%d", status1);
37 else
38 rv.Printf("%d-%d", status1, status2);
39 return rv;
40}
41
42template <>
43int
48
49template <>
50bool
52{
53 return b->status1 <= a->status1 && a->status2 <= b->status2;
54}
55
56template <>
59{
60 const auto minLeft = std::min(a->status1, b->status1);
61 const auto maxRight = std::max(a->status2, b->status2);
62 return new acl_httpstatus_data(minLeft, maxRight);
63}
64
66static std::ostream &
67operator <<(std::ostream &os, const acl_httpstatus_data *status)
68{
69 if (status)
70 os << status->toStr();
71 return os;
72}
73
74ACLHTTPStatus::ACLHTTPStatus (char const *theClass) : data(nullptr), class_ (theClass)
75{}
76
78{
79 if (data) {
80 data->destroy();
81 delete data;
82 }
83}
84
85char const *
87{
88 return class_;
89}
90
91bool
93{
94 return data->empty();
95}
96
99{
100 int status;
101 status = atoi(t);
102 t = strchr(t, '-');
103
104 if (!t)
105 return new acl_httpstatus_data(status);
106
107 if (*(++t))
108 return new acl_httpstatus_data(status, atoi(t));
109
110 return new acl_httpstatus_data(status, INT_MAX);
111}
112
113void
121
122void
130
131int
133{
134 return aclMatchHTTPStatus(&data, Filled(checklist)->reply().sline.status());
135}
136
137int
139{
140 acl_httpstatus_data X(status);
141 const acl_httpstatus_data * const * result = (*dataptr)->find(&X, aclHTTPStatusCompare);
142
143 debugs(28, 3, "aclMatchHTTPStatus: '" << status << "' " << (result ? "found" : "NOT found"));
144 return (result != nullptr);
145}
146
147static int
149{
150 if (a->status2 < b->status1)
151 return 1; // the entire range a is to the left of range b
152
153 if (a->status1 > b->status2)
154 return -1; // the entire range a is to the right of range b
155
156 return 0; // equal or partially overlapping ranges
157}
158
162 contents.push_back(node->toStr());
163 }
164};
165
168{
170 data->visit(visitor);
171 return visitor.contents;
172}
173
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
static void aclParseHTTPStatusList(Splay< acl_httpstatus_data * > **curlist)
static int aclHTTPStatusCompare(acl_httpstatus_data *const &a, acl_httpstatus_data *const &b)
static std::ostream & operator<<(std::ostream &os, const acl_httpstatus_data *status)
reports acl_httpstatus_data using squid.conf http_status ACL value format
Definition HttpStatus.cc:67
static acl_httpstatus_data * aclParseHTTPStatusData(const char *t)
Definition HttpStatus.cc:98
static int aclMatchHTTPStatus(Splay< acl_httpstatus_data * > **dataptr, Http::StatusCode status)
~ACLHTTPStatus() override
Definition HttpStatus.cc:77
void parse() override
parses node representation in squid.conf; dies on failures
int match(ACLChecklist *checklist) override
Matches the actual data in checklist against this Acl::Node.
char const * typeString() const override
Definition HttpStatus.cc:86
ACLHTTPStatus(char const *)
Definition HttpStatus.cc:74
char const * class_
Definition HttpStatus.h:42
SBufList dump() const override
Splay< acl_httpstatus_data * > * data
Definition HttpStatus.h:41
bool empty() const override
Definition HttpStatus.cc:92
static Value MakeCombinedValue(const Value &a, const Value &b)
static int Compare(const Value &a, const Value &b)
static bool IsSubset(const Value &a, const Value &b)
static void Merge(Splay< Value > &, Value &&)
static char * strtokFile()
Definition SBuf.h:94
SBuf & Printf(const char *fmt,...) PRINTF_FORMAT_ARG2
Definition SBuf.cc:214
Definition splay.h:50
bool empty() const
Definition splay.h:78
void visit(ValueVisitor &) const
left-to-right visit of all stored Values
void destroy(SPLAYFREE *=DefaultFree)
Definition splay.h:369
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
StatusCode
Definition StatusCode.h:20
std::list< SBuf > SBufList
Definition forward.h:23
void operator()(const acl_httpstatus_data *node)
SBuf toStr() const
Definition HttpStatus.cc:30
Definition parse.c:104
#define INT_MAX
Definition types.h:70