]> git.ipfire.org Git - thirdparty/squid.git/blame_incremental - src/acl/AtStepData.cc
Bug 5498: cachemgr documentation improvements (#2109)
[thirdparty/squid.git] / src / acl / AtStepData.cc
... / ...
CommitLineData
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
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
52ACLAtStepData::ACLAtStepData()
53{}
54
55ACLAtStepData::~ACLAtStepData()
56{
57}
58
59bool
60ACLAtStepData::match(XactionStep toFind)
61{
62 const auto found = std::find(values.cbegin(), values.cend(), toFind);
63 return (found != values.cend());
64}
65
66SBufList
67ACLAtStepData::dump() const
68{
69 SBufList sl;
70 for (const auto value : values)
71 sl.push_back(SBuf(StepName(value)));
72 return sl;
73}
74
75void
76ACLAtStepData::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
86bool
87ACLAtStepData::empty() const
88{
89 return values.empty();
90}
91