]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/AtStepData.cc
Source Format Enforcement (#1234)
[thirdparty/squid.git] / src / acl / AtStepData.cc
1 /*
2 * Copyright (C) 1996-2023 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 static inline const char *
20 StepName(const XactionStep xstep)
21 {
22 // keep in sync with XactionStep
23 static const char *StepNames[static_cast<int>(XactionStep::enumEnd_)] = {
24 "[unknown step]"
25 ,"GeneratingCONNECT"
26 #if USE_OPENSSL
27 ,"SslBump1"
28 ,"SslBump2"
29 ,"SslBump3"
30 #endif
31 };
32
33 assert(XactionStep::enumBegin_ <= xstep && xstep < XactionStep::enumEnd_);
34 return StepNames[static_cast<int>(xstep)];
35 }
36
37 static XactionStep
38 StepValue(const char *name)
39 {
40 assert(name);
41
42 for (const auto step: WholeEnum<XactionStep>()) {
43 if (strcasecmp(StepName(step), name) == 0)
44 return static_cast<XactionStep>(step);
45 }
46
47 throw TextException(ToSBuf("unknown at_step step name: ", name), Here());
48 }
49
50 ACLAtStepData::ACLAtStepData()
51 {}
52
53 ACLAtStepData::~ACLAtStepData()
54 {
55 }
56
57 bool
58 ACLAtStepData::match(XactionStep toFind)
59 {
60 const auto found = std::find(values.cbegin(), values.cend(), toFind);
61 return (found != values.cend());
62 }
63
64 SBufList
65 ACLAtStepData::dump() const
66 {
67 SBufList sl;
68 for (const auto value : values)
69 sl.push_back(SBuf(StepName(value)));
70 return sl;
71 }
72
73 void
74 ACLAtStepData::parse()
75 {
76 while (const auto name = ConfigParser::strtokFile()) {
77 const auto step = StepValue(name);
78 if (step == XactionStep::unknown)
79 throw TextException(ToSBuf("prohibited at_step step name: ", name), Here());
80 values.push_back(step);
81 }
82 }
83
84 bool
85 ACLAtStepData::empty() const
86 {
87 return values.empty();
88 }
89