Coverage Report

Created: 2026-10-31 07:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/proxy/ControlBase.h
Line
Count
Source
1
/** @file
2
3
  A brief file description
4
5
  @section license License
6
7
  Licensed to the Apache Software Foundation (ASF) under one
8
  or more contributor license agreements.  See the NOTICE file
9
  distributed with this work for additional information
10
  regarding copyright ownership.  The ASF licenses this file
11
  to you under the Apache License, Version 2.0 (the
12
  "License"); you may not use this file except in compliance
13
  with the License.  You may obtain a copy of the License at
14
15
      http://www.apache.org/licenses/LICENSE-2.0
16
17
  Unless required by applicable law or agreed to in writing, software
18
  distributed under the License is distributed on an "AS IS" BASIS,
19
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
  See the License for the specific language governing permissions and
21
  limitations under the License.
22
 */
23
24
/*****************************************************************************
25
 *
26
 *  ControlBase.h - Base class to process generic modifiers to
27
 *                         ControlMatcher Directives
28
 *
29
 *
30
 ****************************************************************************/
31
32
#pragma once
33
34
#include <memory>
35
#include <vector>
36
37
#include "tscore/ink_platform.h"
38
39
class HttpRequestData;
40
class Tokenizer;
41
struct matcher_line;
42
43
class ControlBase
44
{
45
public:
46
  struct Modifier {
47
    enum class Type {
48
      INVALID,
49
      PORT,
50
      SCHEME,
51
      PREFIX,
52
      SUFFIX,
53
      METHOD,
54
      TIME,
55
      SRC_IP,
56
      IPORT,
57
      TAG,
58
      INTERNAL,
59
    };
60
    /// Destructor - force virtual.
61
    virtual ~Modifier();
62
    /// Return the modifier type.
63
    virtual Type type() const;
64
    /// Return the name for the modifier type.
65
    virtual const char *name() const = 0;
66
    /** Test if the modifier matches the request.
67
        @return @c true if the request is matched, @c false if not.
68
    */
69
    virtual bool check(HttpRequestData *req ///< Request to check.
70
    ) const = 0;
71
    /// Print the mod information.
72
    virtual void print(FILE *f ///< Output stream.
73
    ) const = 0;
74
  };
75
76
  ControlBase();
77
  ~ControlBase();
78
79
  const char *ProcessModifiers(matcher_line *line_info);
80
  bool        CheckModifiers(HttpRequestData *request_data);
81
  bool        CheckForMatch(HttpRequestData *request_data, int last_number);
82
83
  void Print() const;
84
85
  int       line_num = 0;
86
  Modifier *findModOfType(Modifier::Type t) const;
87
88
protected:
89
  /// Get the text for the Scheme modifier, if any.
90
  /// @return The text if present, 0 otherwise.
91
  /// @internal Ugly but it's the only place external access is needed.
92
  const char *getSchemeModText() const;
93
94
private:
95
  using Array = std::vector<std::unique_ptr<Modifier>>;
96
  Array       _mods;
97
  const char *ProcessSrcIp(char *val, void **opaque_ptr);
98
  const char *ProcessTimeOfDay(char *val, void **opaque_ptr);
99
  const char *ProcessPort(char *val, void **opaque_ptr);
100
101
  // Reset to default constructed state, free all allocations.
102
  void clear();
103
};
104
105
0
inline ControlBase::ControlBase() {}
106
107
inline bool
108
ControlBase::CheckForMatch(HttpRequestData *request_data, int last_number)
109
0
{
110
0
  return (last_number < 0 || last_number > this->line_num) && this->CheckModifiers(request_data);
111
0
}