HttpHeaderData.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/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  debugs(28, 3, "aclHeaderData::match: checking '" << hdrName << "'");
42 
43  String value;
45  if (!hdr.has(hdrId))
46  return false;
47  value = hdr.getStrOrList(hdrId);
48  } else {
49  if (!hdr.hasNamed(hdrName, &value))
50  return false;
51  }
52 
53  auto cvalue = StringToSBuf(value);
54  return regex_rule->match(cvalue.c_str());
55 }
56 
59 {
60  SBufList sl;
61  sl.push_back(SBuf(hdrName));
62  sl.splice(sl.end(), regex_rule->dump());
63  return sl;
64 }
65 
66 const Acl::Options &
68 {
69  return regex_rule->lineOptions();
70 }
71 
72 void
74 {
75  Acl::SetKey(hdrName, "header-name", ConfigParser::strtokFile());
77  regex_rule->parse();
78 }
79 
80 bool
82 {
84 }
85 
virtual const Acl::Options & lineOptions()
supported ACL "line" options (e.g., "-i")
Definition: Data.h:26
std::vector< const Option * > Options
Definition: Options.h:217
static char * strtokFile()
Definition: ConfigParser.cc:65
bool isEmpty() const
Definition: SBuf.h:435
std::list< SBuf > SBufList
Definition: forward.h:22
Definition: SBuf.h:93
void parse() override
Http::HdrType hdrId
void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey)
Definition: Acl.cc:100
~ACLHTTPHeaderData() override
Definition: forward.h:17
String getStrOrList(Http::HdrType id) const
Definition: HttpHeader.cc:822
bool match(const HttpHeader &) override
ACLData< char const * > * regex_rule
const Acl::Options & lineOptions() override
supported ACL "line" options (e.g., "-i")
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
Definition: StringConvert.h:17
bool hasNamed(const SBuf &s, String *value=nullptr) const
Definition: HttpHeader.cc:865
const HeaderTableRecord & lookup(const char *buf, const std::size_t len) const
look record type up by name (C-string and length)
SBufList dump() const override
const HeaderLookupTable_t HeaderLookupTable
virtual void parse()=0
int has(Http::HdrType id) const
Definition: HttpHeader.cc:937
virtual bool match(M)=0
virtual bool empty() const =0
bool empty() const override
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
virtual SBufList dump() const =0

 

Introduction

Documentation

Support

Miscellaneous