]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/AtStepData.cc
CI: Upgrade GitHub Setup Node and CodeQL actions to Node 20 (#1845)
[thirdparty/squid.git] / src / acl / AtStepData.cc
CommitLineData
bbc27441 1/*
b8ae064d 2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
bbc27441
AJ
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
5d65362c 9#include "squid.h"
8693472e 10#include "acl/AtStepData.h"
40f1e76d 11#include "acl/Checklist.h"
090f1d3c 12#include "base/EnumIterator.h"
5d65362c 13#include "cache_cf.h"
16c5ad96 14#include "ConfigParser.h"
675b8408 15#include "debug/Stream.h"
090f1d3c 16#include "sbuf/Stream.h"
5d65362c
CT
17#include "wordlist.h"
18
0002264b
FC
19#include <algorithm>
20
090f1d3c
CT
21static inline const char *
22StepName(const XactionStep xstep)
23{
24 // keep in sync with XactionStep
25 static const char *StepNames[static_cast<int>(XactionStep::enumEnd_)] = {
26 "[unknown step]"
27 ,"GeneratingCONNECT"
28#if USE_OPENSSL
29 ,"SslBump1"
30 ,"SslBump2"
31 ,"SslBump3"
32#endif
33 };
34
35 assert(XactionStep::enumBegin_ <= xstep && xstep < XactionStep::enumEnd_);
36 return StepNames[static_cast<int>(xstep)];
37}
38
39static XactionStep
40StepValue(const char *name)
41{
42 assert(name);
43
44 for (const auto step: WholeEnum<XactionStep>()) {
45 if (strcasecmp(StepName(step), name) == 0)
46 return static_cast<XactionStep>(step);
47 }
48
49 throw TextException(ToSBuf("unknown at_step step name: ", name), Here());
50}
51
5d65362c
CT
52ACLAtStepData::ACLAtStepData()
53{}
54
5d65362c
CT
55ACLAtStepData::~ACLAtStepData()
56{
57}
58
59bool
090f1d3c 60ACLAtStepData::match(XactionStep toFind)
5d65362c 61{
090f1d3c
CT
62 const auto found = std::find(values.cbegin(), values.cend(), toFind);
63 return (found != values.cend());
5d65362c
CT
64}
65
66SBufList
67ACLAtStepData::dump() const
68{
69 SBufList sl;
090f1d3c
CT
70 for (const auto value : values)
71 sl.push_back(SBuf(StepName(value)));
5d65362c
CT
72 return sl;
73}
74
75void
76ACLAtStepData::parse()
77{
090f1d3c
CT
78 while (const auto name = ConfigParser::strtokFile()) {
79 const auto step = StepValue(name);
80 if (step == XactionStep::unknown)
81 throw TextException(ToSBuf("prohibited at_step step name: ", name), Here());
82 values.push_back(step);
5d65362c
CT
83 }
84}
85
86bool
87ACLAtStepData::empty() const
88{
89 return values.empty();
90}
91