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
38bool
40{
41 if (hdr == nullptr)
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
69const Acl::Options &
71{
72 return regex_rule->lineOptions();
73}
74
75void
77{
81}
82
83bool
85{
87}
88
SBuf StringToSBuf(const String &s)
create a new SBuf from a String by copying contents
Definition: StringConvert.h:17
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
~ACLHTTPHeaderData() override
SBufList dump() const override
ACLData< char const * > * regex_rule
Http::HdrType hdrId
void parse() override
bool match(HttpHeader *hdr) override
bool empty() const override
const Acl::Options & lineOptions() override
supported ACL "line" options (e.g., "-i")
static char * strtokFile()
Definition: ConfigParser.cc:65
String getStrOrList(Http::HdrType id) const
Definition: HttpHeader.cc:823
int has(Http::HdrType id) const
Definition: HttpHeader.cc:938
bool hasNamed(const SBuf &s, String *value=nullptr) const
Definition: HttpHeader.cc:866
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
bool isEmpty() const
Definition: SBuf.h:431
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:194
void SetKey(SBuf &keyStorage, const char *keyParameterName, const char *newKey)
Definition: Acl.cc:79
std::vector< const Option * > Options
Definition: Options.h:214
Definition: forward.h:18
const HeaderLookupTable_t HeaderLookupTable
std::list< SBuf > SBufList
Definition: forward.h:23

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors