HttpStatus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2022 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 
20 static int aclHTTPStatusCompare(acl_httpstatus_data * const &a, acl_httpstatus_data * const &b);
22 
23 acl_httpstatus_data::acl_httpstatus_data(int x) : status1(x), status2(x) { ; }
24 
25 acl_httpstatus_data::acl_httpstatus_data(int x, int y) : status1(x), status2(y) { ; }
26 
27 SBuf
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 
59 ACLHTTPStatus::ACLHTTPStatus (char const *theClass) : data(nullptr), class_ (theClass)
60 {}
61 
63 {
64  if (data) {
65  data->destroy();
66  delete data;
67  }
68 }
69 
70 char const *
72 {
73  return class_;
74 }
75 
76 bool
78 {
79  return data->empty();
80 }
81 
82 static acl_httpstatus_data*
83 aclParseHTTPStatusData(const char *t)
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 
98 void
100 {
101  if (!data)
103 
105 }
106 
107 void
109 {
110  while (char *t = ConfigParser::strtokFile()) {
112  (*curlist)->insert(q, acl_httpstatus_data::compare);
113  }
114 }
115 
116 int
118 {
119  return aclMatchHTTPStatus(&data, Filled(checklist)->reply->sline.status());
120 }
121 
122 int
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 
132 static 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 
151 SBufList
153 {
154  HttpStatusAclDumpVisitor visitor;
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 acl_httpstatus_data * aclParseHTTPStatusData(const char *t)
Definition: HttpStatus.cc:83
static int aclHTTPStatusCompare(acl_httpstatus_data *const &a, acl_httpstatus_data *const &b)
Definition: HttpStatus.cc:133
static int aclMatchHTTPStatus(Splay< acl_httpstatus_data * > **dataptr, Http::StatusCode status)
Definition: HttpStatus.cc:123
virtual void parse()
parses node representation in squid.conf; dies on failures
Definition: HttpStatus.cc:99
ACLHTTPStatus(char const *)
Definition: HttpStatus.cc:59
char const * class_
Definition: HttpStatus.h:44
virtual SBufList dump() const
Definition: HttpStatus.cc:152
virtual char const * typeString() const
Definition: HttpStatus.cc:71
Splay< acl_httpstatus_data * > * data
Definition: HttpStatus.h:43
virtual bool empty() const
Definition: HttpStatus.cc:77
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: HttpStatus.cc:117
static char * strtokFile()
Definition: ConfigParser.cc:64
Definition: SBuf.h:94
SBuf & Printf(const char *fmt,...)
Definition: SBuf.cc:214
void visit(Visitor &v) const
recursively visit all nodes, in left-to-right order
Definition: splay.h:276
bool empty() const
Definition: splay.h:80
void destroy(SPLAYFREE *=SplayNode< V >::DefaultFree)
Definition: splay.h:347
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
const char * AclMatchedName
Definition: Acl.cc:29
StatusCode
Definition: StatusCode.h:20
std::list< SBuf > SBufList
Definition: forward.h:22
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:76

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors