]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/HttpHeaderData.cc
Boilerplate: update copyright blurbs on src/
[thirdparty/squid.git] / src / acl / HttpHeaderData.cc
CommitLineData
00634927 1/*
bbc27441 2 * Copyright (C) 1996-2014 The Squid Software Foundation and contributors
00634927 3 *
bbc27441
AJ
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.
00634927 7 */
8
bbc27441
AJ
9/* DEBUG: section 28 Access Control */
10
582c2af2 11#include "squid.h"
3ad63615 12#include "acl/Acl.h"
602d9612
A
13#include "acl/Checklist.h"
14#include "acl/HttpHeaderData.h"
3ad63615 15#include "acl/RegexData.h"
06390e4b 16#include "cache_cf.h"
00634927 17#include "ConfigParser.h"
602d9612 18#include "Debug.h"
a5bac1d2 19#include "HttpHeaderTools.h"
0c2041c8 20#include "SBuf.h"
00634927 21
7df0bfd7 22/* Construct an ACLHTTPHeaderData that uses an ACLRegex rule with the value of the
23 * selected header from a given request.
24 *
26ac0430 25 * TODO: This can be generalised by making the type of the regex_rule into a
7df0bfd7 26 * template parameter - so that we can use different rules types in future.
27 */
28ACLHTTPHeaderData::ACLHTTPHeaderData() : hdrId(HDR_BAD_HDR), regex_rule(new ACLRegexData)
29{}
00634927 30
31ACLHTTPHeaderData::~ACLHTTPHeaderData()
32{
7df0bfd7 33 delete regex_rule;
00634927 34}
35
36bool
37ACLHTTPHeaderData::match(HttpHeader* hdr)
38{
39 if (hdr == NULL)
40 return false;
41
5b4117d8 42 debugs(28, 3, "aclHeaderData::match: checking '" << hdrName << "'");
00634927 43
b2c44718
AR
44 String value;
45 if (hdrId != HDR_BAD_HDR) {
46 if (!hdr->has(hdrId))
47 return false;
48 value = hdr->getStrOrList(hdrId);
49 } else {
50 if (!hdr->getByNameIfPresent(hdrName.termedBuf(), value))
51 return false;
52 }
00634927 53
dd3a64b0 54 SBuf cvalue(value);
b38b26cb 55 return regex_rule->match(cvalue.c_str());
00634927 56}
57
8966008b 58SBufList
4f8ca96e 59ACLHTTPHeaderData::dump() const
00634927 60{
8966008b
FC
61 SBufList sl;
62 sl.push_back(SBuf(hdrName));
7d75c222
FC
63 // temp is needed until c++11 move-constructor
64 SBufList temp = regex_rule->dump();
65 sl.splice(sl.end(), temp);
8966008b 66 return sl;
00634927 67}
68
00634927 69void
70ACLHTTPHeaderData::parse()
71{
72 char* t = strtokFile();
73 assert (t != NULL);
74 hdrName = t;
5b4117d8 75 hdrId = httpHeaderIdByNameDef(hdrName.rawBuf(), hdrName.size());
7df0bfd7 76 regex_rule->parse();
00634927 77}
78
79bool
80ACLHTTPHeaderData::empty() const
81{
a1377698 82 return (hdrId == HDR_BAD_HDR && hdrName.size()==0) || regex_rule->empty();
00634927 83}
84
85ACLData<HttpHeader*> *
86ACLHTTPHeaderData::clone() const
87{
88 /* Header's don't clone yet. */
7df0bfd7 89 ACLHTTPHeaderData * result = new ACLHTTPHeaderData;
90 result->regex_rule = regex_rule->clone();
91 result->hdrId = hdrId;
92 result->hdrName = hdrName;
93 return result;
00634927 94}