HttpHeaderData.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/Acl.h"
13 #include "acl/Checklist.h"
14 #include "acl/HttpHeaderData.h"
15 #include "acl/RegexData.h"
16 #include "base/RegexPattern.h"
17 #include "cache_cf.h"
18 #include "ConfigParser.h"
19 #include "debug/Stream.h"
20 #include "HttpHeaderTools.h"
21 #include "sbuf/SBuf.h"
22 #include "sbuf/StringConvert.h"
23 
24 /* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
25  * selected header from a given request.
26  *
27  * TODO: This can be generalised by making the type of the regex_rule into a
28  * template parameter - so that we can use different rules types in future.
29  */
31 {}
32 
34 {
35  delete regex_rule;
36 }
37 
38 bool
40 {
41  if (hdr == NULL)
42  return false;
43 
44  debugs(28, 3, "aclHeaderData::match: checking '" << hdrName << "'");
45 
46  String value;
48  if (!hdr->has(hdrId))
49  return false;
50  value = hdr->getStrOrList(hdrId);
51  } else {
52  if (!hdr->hasNamed(hdrName, &value))
53  return false;
54  }
55 
56  auto cvalue = StringToSBuf(value);
57  return regex_rule->match(cvalue.c_str());
58 }
59 
62 {
63  SBufList sl;
64  sl.push_back(SBuf(hdrName));
65  sl.splice(sl.end(), regex_rule->dump());
66  return sl;
67 }
68 
69 const Acl::Options &
71 {
72  return regex_rule->lineOptions();
73 }
74 
75 void
77 {
78  char* t = ConfigParser::strtokFile();
79  if (!t) {
80  debugs(28, DBG_CRITICAL, "ERROR: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
81  debugs(28, DBG_CRITICAL, "ERROR: Missing header name in ACL");
82  return;
83  }
84 
85  if (hdrName.isEmpty()) {
86  hdrName = t;
88  } else if (hdrName.caseCmp(t) != 0) {
89  debugs(28, DBG_CRITICAL, "ERROR: " << cfg_filename << " line " << config_lineno << ": " << config_input_line);
90  debugs(28, DBG_CRITICAL, "ERROR: ACL cannot match both " << hdrName << " and " << t << " headers. Use 'anyof' ACL instead.");
91  return;
92  }
93 
94  regex_rule->parse();
95 }
96 
97 bool
99 {
101 }
102 
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
Definition: StringConvert.h:17
char config_input_line[BUFSIZ]
Definition: cache_cf.cc:273
const char * cfg_filename
Definition: cache_cf.cc:271
int config_lineno
Definition: cache_cf.cc:272
virtual void parse()=0
virtual SBufList dump() const =0
virtual bool match(M)=0
virtual bool empty() const =0
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
Definition: Data.h:26
virtual bool match(HttpHeader *hdr)
ACLData< char const * > * regex_rule
Http::HdrType hdrId
virtual void parse()
virtual bool empty() const
virtual ~ACLHTTPHeaderData()
virtual SBufList dump() const
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
static char * strtokFile()
Definition: ConfigParser.cc:64
bool hasNamed(const SBuf &s, String *value=0) const
Definition: HttpHeader.cc:919
String getStrOrList(Http::HdrType id) const
Definition: HttpHeader.cc:876
int has(Http::HdrType id) const
Definition: HttpHeader.cc:991
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
Definition: SBuf.h:94
int caseCmp(const SBuf &S, const size_type n) const
shorthand version for case-insensitive compare()
Definition: SBuf.h:283
bool isEmpty() const
Definition: SBuf.h:431
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:196
#define DBG_CRITICAL
Definition: Stream.h:40
std::vector< const Option * > Options
Definition: Options.h:214
Definition: forward.h:22
const HeaderLookupTable_t HeaderLookupTable
std::list< SBuf > SBufList
Definition: forward.h:22
#define NULL
Definition: types.h:166

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors