]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/AtStepData.cc
cc3bb80d208fece7a328d83678efe232fb36d82d
[thirdparty/squid.git] / src / acl / AtStepData.cc
1 /*
2 * Copyright (C) 1996-2025 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 #include "squid.h"
10 #include "acl/AtStepData.h"
11 #include "acl/Checklist.h"
12 #include "base/EnumIterator.h"
13 #include "cache_cf.h"
14 #include "ConfigParser.h"
15 #include "debug/Stream.h"
16 #include "sbuf/Stream.h"
17 #include "wordlist.h"
18
19 #include <algorithm>
20
21 static inline const char *
22 StepName(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
39 static XactionStep
40 StepValue(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
52 ACLAtStepData::ACLAtStepData()
53 {}
54
55 ACLAtStepData::~ACLAtStepData()
56 {
57 }
58
59 bool
60 ACLAtStepData::match(XactionStep toFind)
61 {
62 const auto found = std::find(values.cbegin(), values.cend(), toFind);
63 return (found != values.cend());
64 }
65
66 SBufList
67 ACLAtStepData::dump() const
68 {
69 SBufList sl;
70 for (const auto value : values)
71 sl.push_back(SBuf(StepName(value)));
72 return sl;
73 }
74
75 void
76 ACLAtStepData::parse()
77 {
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);
83 }
84 }
85
86 bool
87 ACLAtStepData::empty() const
88 {
89 return values.empty();
90 }
91