AtStepData.cc
Go to the documentation of this file.
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 #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 
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 
53 {}
54 
56 {
57 }
58 
59 bool
61 {
62  const auto found = std::find(values.cbegin(), values.cend(), toFind);
63  return (found != values.cend());
64 }
65 
68 {
69  SBufList sl;
70  for (const auto value : values)
71  sl.push_back(SBuf(StepName(value)));
72  return sl;
73 }
74 
75 void
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
88 {
89  return values.empty();
90 }
91 
#define Here()
source code location of the caller
Definition: Here.h:15
static char * strtokFile()
Definition: ConfigParser.cc:65
std::list< SBuf > SBufList
Definition: forward.h:22
Definition: SBuf.h:93
SBufList dump() const override
Definition: AtStepData.cc:67
static XactionStep StepValue(const char *name)
Definition: AtStepData.cc:40
XactionStep
Definition: XactionStep.h:12
void parse() override
Definition: AtStepData.cc:76
#define assert(EX)
Definition: assert.h:17
static const char * StepName(const XactionStep xstep)
Definition: AtStepData.cc:22
std::list< XactionStep > values
Definition: AtStepData.h:29
an std::runtime_error with thrower location info
Definition: TextException.h:20
~ACLAtStepData() override
Definition: AtStepData.cc:55
SBuf ToSBuf(Args &&... args)
slowly stream-prints all arguments into a freshly allocated SBuf
Definition: Stream.h:63
bool match(XactionStep) override
Definition: AtStepData.cc:60
bool empty() const override
Definition: AtStepData.cc:87

 

Introduction

Documentation

Support

Miscellaneous