HttpStatus.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 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.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 ACL *
61 {
62  return new ACLHTTPStatus(*this);
63 }
64 
65 ACLHTTPStatus::ACLHTTPStatus (char const *theClass) : data(NULL), class_ (theClass)
66 {}
67 
68 ACLHTTPStatus::ACLHTTPStatus (ACLHTTPStatus const & old) : data(NULL), class_ (old.class_)
69 {
70  /* we don't have copy constructors for the data yet */
71  assert(!old.data);
72 }
73 
75 {
76  if (data) {
77  data->destroy();
78  delete data;
79  }
80 }
81 
82 char const *
84 {
85  return class_;
86 }
87 
88 bool
90 {
91  return data->empty();
92 }
93 
95 aclParseHTTPStatusData(const char *t)
96 {
97  int status;
98  status = atoi(t);
99  t = strchr(t, '-');
100 
101  if (!t)
102  return new acl_httpstatus_data(status);
103 
104  if (*(++t))
105  return new acl_httpstatus_data(status, atoi(t));
106 
107  return new acl_httpstatus_data(status, INT_MAX);
108 }
109 
110 void
112 {
113  if (!data)
115 
117 }
118 
119 void
121 {
122  while (char *t = ConfigParser::strtokFile()) {
124  (*curlist)->insert(q, acl_httpstatus_data::compare);
125  }
126 }
127 
128 int
130 {
131  return aclMatchHTTPStatus(&data, Filled(checklist)->reply->sline.status());
132 }
133 
134 int
136 {
137  acl_httpstatus_data X(status);
138  const acl_httpstatus_data * const * result = (*dataptr)->find(&X, aclHTTPStatusCompare);
139 
140  debugs(28, 3, "aclMatchHTTPStatus: '" << status << "' " << (result ? "found" : "NOT found"));
141  return (result != NULL);
142 }
143 
144 static int
146 {
147  if (a->status1 < b->status1)
148  return 1;
149 
150  if (a->status1 > b->status2)
151  return -1;
152 
153  return 0;
154 }
155 
159  contents.push_back(node->toStr());
160  }
161 };
162 
163 SBufList
165 {
166  HttpStatusAclDumpVisitor visitor;
167  data->visit(visitor);
168  return visitor.contents;
169 }
170 
#define assert(EX)
Definition: assert.h:17
acl_httpstatus_data * aclParseHTTPStatusData(const char *t)
Definition: HttpStatus.cc:95
Definition: SBuf.h:87
ACLFilledChecklist * Filled(ACLChecklist *checklist)
convenience and safety wrapper for dynamic_cast<ACLFilledChecklist*>
static int aclHTTPStatusCompare(acl_httpstatus_data *const &a, acl_httpstatus_data *const &b)
Definition: HttpStatus.cc:145
Definition: Acl.h:39
static struct stat sb
Definition: squidclient.cc:75
Splay< acl_httpstatus_data * > * data
Definition: HttpStatus.h:46
#define DBG_CRITICAL
Definition: Debug.h:44
virtual void parse()
parses node represenation in squid.conf; dies on failures
Definition: HttpStatus.cc:111
virtual int match(ACLChecklist *checklist)
Matches the actual data in checklist against this ACL.
Definition: HttpStatus.cc:129
char const * class_
Definition: HttpStatus.h:47
void const char HLPCB void * data
Definition: stub_helper.cc:16
Definition: parse.c:104
StatusCode
Definition: StatusCode.h:20
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
static int aclMatchHTTPStatus(Splay< acl_httpstatus_data * > **dataptr, Http::StatusCode status)
Definition: HttpStatus.cc:135
virtual SBufList dump() const
Definition: HttpStatus.cc:164
SBuf & Printf(const char *fmt,...)
Definition: SBuf.cc:236
SBuf toStr() const
Definition: HttpStatus.cc:28
void operator()(const acl_httpstatus_data *node)
Definition: HttpStatus.cc:158
const char * AclMatchedName
Definition: Acl.cc:30
std::list< SBuf > SBufList
Definition: forward.h:26
virtual bool empty() const
Definition: HttpStatus.cc:89
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
static int compare(acl_httpstatus_data *const &a, acl_httpstatus_data *const &b)
Definition: HttpStatus.cc:40
static char * strtokFile()
Definition: ConfigParser.cc:82
static void aclParseHTTPStatusList(Splay< acl_httpstatus_data * > **curlist)
Definition: HttpStatus.cc:120
void destroy(SPLAYFREE *=SplayNode< V >::DefaultFree)
Definition: splay.h:347
int a
Definition: membanger.c:50
ACLHTTPStatus(char const *)
Definition: HttpStatus.cc:65
#define INT_MAX
Definition: types.h:76
virtual ACL * clone() const
Definition: HttpStatus.cc:60
virtual char const * typeString() const
Definition: HttpStatus.cc:83
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors