]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/HasComponentData.cc
Source Format Enforcement (#963)
[thirdparty/squid.git] / src / acl / HasComponentData.cc
CommitLineData
5ec4cffe 1/*
bf95c10a 2 * Copyright (C) 1996-2022 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{
1dc0221b 26 const auto tok = ConfigParser::strtokFile();
5ec4cffe
EB
27 if (!tok) {
28 debugs(28, DBG_CRITICAL, "FATAL: \"has\" acl argument missing");
29 self_destruct();
30 return;
31 }
1dc0221b
EB
32
33 parseComponent(tok);
34
35 if (ConfigParser::strtokFile()) {
5ec4cffe
EB
36 debugs(28, DBG_CRITICAL, "FATAL: multiple components not supported for \"has\" acl");
37 self_destruct();
38 return;
39 }
5ec4cffe
EB
40}
41
42bool
43ACLHasComponentData::match(ACLChecklist *checklist)
44{
45 for (const auto method: componentMethods)
46 if (method && (checklist->*method)())
47 return true;
48 return false;
49}
50
51SBufList
52ACLHasComponentData::dump() const
53{
54 SBufList sl;
55 if (componentMethods.at(coRequest))
56 sl.push_back(RequestStr);
57 if (componentMethods.at(coResponse))
58 sl.push_back(ResponseStr);
59 if (componentMethods.at(coAle))
60 sl.push_back(AleStr);
61 return sl;
62}
63
64void
65ACLHasComponentData::parseComponent(const char *token)
66{
67 if (RequestStr.cmp(token) == 0)
68 componentMethods[coRequest] = &ACLChecklist::hasRequest;
69 else if (ResponseStr.cmp(token) == 0)
70 componentMethods[coResponse] = &ACLChecklist::hasReply;
71 else if (AleStr.cmp(token) == 0)
72 componentMethods[coAle] = &ACLChecklist::hasAle;
73 else {
74 debugs(28, DBG_CRITICAL, "FATAL: unsupported component '" << token << "' for 'has' acl");
75 self_destruct();
76 }
77}
78