]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/HasComponentData.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / acl / HasComponentData.cc
CommitLineData
5ec4cffe 1/*
5b74111a 2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
5ec4cffe
EB
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#include "squid.h"
10#include "acl/HasComponentData.h"
11#include "cache_cf.h"
12#include "ConfigParser.h"
13#include "sbuf/Algorithms.h"
14
5ec4cffe
EB
15const SBuf ACLHasComponentData::RequestStr("request");
16const SBuf ACLHasComponentData::ResponseStr("response");
17const SBuf ACLHasComponentData::AleStr("ALE");
18
19ACLHasComponentData::ACLHasComponentData()
20 : componentMethods(coEnd, nullptr)
21{ }
22
23void
24ACLHasComponentData::parse()
25{
26 const char *tok = ConfigParser::NextToken();
27 if (!tok) {
28 debugs(28, DBG_CRITICAL, "FATAL: \"has\" acl argument missing");
29 self_destruct();
30 return;
31 }
32 if (ConfigParser::PeekAtToken()) {
33 debugs(28, DBG_CRITICAL, "FATAL: multiple components not supported for \"has\" acl");
34 self_destruct();
35 return;
36 }
37 parseComponent(tok);
38}
39
40bool
41ACLHasComponentData::match(ACLChecklist *checklist)
42{
43 for (const auto method: componentMethods)
44 if (method && (checklist->*method)())
45 return true;
46 return false;
47}
48
49SBufList
50ACLHasComponentData::dump() const
51{
52 SBufList sl;
53 if (componentMethods.at(coRequest))
54 sl.push_back(RequestStr);
55 if (componentMethods.at(coResponse))
56 sl.push_back(ResponseStr);
57 if (componentMethods.at(coAle))
58 sl.push_back(AleStr);
59 return sl;
60}
61
62void
63ACLHasComponentData::parseComponent(const char *token)
64{
65 if (RequestStr.cmp(token) == 0)
66 componentMethods[coRequest] = &ACLChecklist::hasRequest;
67 else if (ResponseStr.cmp(token) == 0)
68 componentMethods[coResponse] = &ACLChecklist::hasReply;
69 else if (AleStr.cmp(token) == 0)
70 componentMethods[coAle] = &ACLChecklist::hasAle;
71 else {
72 debugs(28, DBG_CRITICAL, "FATAL: unsupported component '" << token << "' for 'has' acl");
73 self_destruct();
74 }
75}
76
77ACLData<ACLChecklist *> *
78ACLHasComponentData::clone() const
79{
80 return new ACLHasComponentData(*this);
81}
82