HttpHeaderData.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/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 "sbuf/SBuf.h"
21 #include "sbuf/StringConvert.h"
22 
23 /* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
24  * selected header from a given request.
25  *
26  * TODO: This can be generalised by making the type of the regex_rule into a
27  * template parameter - so that we can use different rules types in future.
28  */
30 {}
31 
33 {
34  delete regex_rule;
35 }
36 
37 bool
39 {
40  debugs(28, 3, "aclHeaderData::match: checking '" << hdrName << "'");
41 
42  String value;
44  if (!hdr.has(hdrId))
45  return false;
46  value = hdr.getStrOrList(hdrId);
47  } else {
48  if (!hdr.hasNamed(hdrName, &value))
49  return false;
50  }
51 
52  auto cvalue = StringToSBuf(value);
53  return regex_rule->match(cvalue.c_str());
54 }
55 
58 {
59  SBufList sl;
60  sl.push_back(SBuf(hdrName));
61  sl.splice(sl.end(), regex_rule->dump());
62  return sl;
63 }
64 
65 const Acl::Options &
67 {
68  return regex_rule->lineOptions();
69 }
70 
71 void
73 {
74  Acl::SetKey(hdrName, "header-name", ConfigParser::strtokFile());
76  regex_rule->parse();
77 }
78 
79 bool
81 {
83 }
84 
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:955
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:998
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:1070
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