Coverage Report

Created: 2026-06-27 06:21

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/trafficserver/include/tscore/Version.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
  Version.h
27
28
29
  **************************************************************************/
30
31
#pragma once
32
33
namespace ts
34
{
35
/** Container for standard two part version number.
36
 */
37
struct VersionNumber {
38
  /// Construct invalid (0.0) version.
39
  constexpr VersionNumber() = default;
40
41
  /// Construct explicit version.
42
  constexpr explicit VersionNumber(unsigned short major, unsigned short minor = 0);
43
44
  // Can't use unadorned "major" because that's a macro.
45
  unsigned short _major = 0; ///< Major version.
46
  unsigned short _minor = 0; ///< Minor version.
47
};
48
49
inline constexpr VersionNumber::VersionNumber(unsigned short major, unsigned short minor) : _major(major), _minor(minor) {}
50
51
inline bool
52
operator<(VersionNumber const &lhs, VersionNumber const &rhs)
53
0
{
54
0
  return lhs._major < rhs._major || (lhs._major == rhs._major && lhs._minor < rhs._minor);
55
0
}
56
57
inline bool
58
operator==(VersionNumber const &lhs, VersionNumber const &rhs)
59
0
{
60
0
  return lhs._major == rhs._major && lhs._minor == rhs._minor;
61
0
}
62
63
inline bool
64
operator!=(VersionNumber const &lhs, VersionNumber const &rhs)
65
0
{
66
0
  return !(lhs == rhs);
67
0
}
68
69
inline bool
70
operator>(VersionNumber const &lhs, VersionNumber const &rhs)
71
0
{
72
0
  return rhs < lhs;
73
0
}
74
75
inline bool
76
operator<=(VersionNumber const &lhs, VersionNumber const &rhs)
77
0
{
78
0
  return !(lhs > rhs);
79
0
}
80
81
inline bool
82
operator>=(VersionNumber const &lhs, VersionNumber const &rhs)
83
0
{
84
0
  return !(rhs > lhs);
85
0
}
86
87
struct Version {
88
  VersionNumber cacheDB;
89
  VersionNumber cacheDir;
90
};
91
92
/// Container for a module version.
93
struct ModuleVersion {
94
  /// Type of module.
95
  enum Type : unsigned char { PUBLIC, PRIVATE };
96
97
  constexpr ModuleVersion(unsigned char major, unsigned char minor, Type type = PUBLIC);
98
  constexpr ModuleVersion(ModuleVersion const &base, Type type);
99
100
  /** Check if @a that is a version compatible with @a this.
101
   *
102
   * @param that Version to check against.
103
   * @return @a true if @a that is compatible with @a this, @c false otherwise.
104
   */
105
  bool check(ModuleVersion const &that);
106
107
  Type          _type  = PUBLIC; ///< The numeric value of the module version.
108
  unsigned char _major = 0;      ///< Major version.
109
  unsigned char _minor = 0;
110
};
111
112
inline constexpr ModuleVersion::ModuleVersion(unsigned char major, unsigned char minor, ts::ModuleVersion::Type type)
113
  : _type(type), _major(major), _minor(minor)
114
{
115
}
116
117
inline constexpr ModuleVersion::ModuleVersion(ModuleVersion const &base, ts::ModuleVersion::Type type)
118
  : _type(type), _major(base._major), _minor(base._minor)
119
{
120
}
121
122
inline bool
123
ModuleVersion::check(ModuleVersion const &that)
124
0
{
125
0
  switch (_type) {
126
0
  case PUBLIC:
127
0
    return _major == that._major && _minor <= that._minor;
128
0
  case PRIVATE:
129
0
    return _major == that._major && _minor == that._minor;
130
0
  }
131
0
  return false;
132
0
};
133
134
} // namespace ts
135
136
class AppVersionInfo
137
{
138
private:
139
  int  defined;
140
  char PkgStr[128];
141
  char AppStr[128];
142
  char VersionStr[128];
143
  char BldNumStr[128];
144
  char BldTimeStr[128];
145
  char BldDateStr[128];
146
  char BldMachineStr[128];
147
  char BldPersonStr[128];
148
  char BldCompileFlagsStr[128];
149
  char FullVersionInfoStr[256];
150
151
public:
152
  AppVersionInfo();
153
  void setup(const char *pkg_name, const char *app_name, const char *app_version, const char *build_date, const char *build_time,
154
             const char *build_machine, const char *build_person, const char *build_cflags);
155
  void setup(const char *app_name);
156
157
  const char *
158
  package() const
159
0
  {
160
0
    return PkgStr;
161
0
  }
162
  const char *
163
  application() const
164
0
  {
165
0
    return AppStr;
166
0
  }
167
  const char *
168
  version() const
169
0
  {
170
0
    return VersionStr;
171
0
  }
172
  const char *
173
  build_number() const
174
0
  {
175
0
    return BldNumStr;
176
0
  }
177
  const char *
178
  build_time() const
179
0
  {
180
0
    return BldTimeStr;
181
0
  }
182
  const char *
183
  build_date() const
184
0
  {
185
0
    return BldDateStr;
186
0
  }
187
  const char *
188
  build_machine() const
189
0
  {
190
0
    return BldMachineStr;
191
0
  }
192
  const char *
193
  build_person() const
194
0
  {
195
0
    return BldPersonStr;
196
0
  }
197
  const char *
198
  full_version() const
199
0
  {
200
0
    return FullVersionInfoStr;
201
0
  }
202
203
  static const AppVersionInfo &get_version();
204
  static const AppVersionInfo &setup_version(const char *name);
205
  static void                  print_version();
206
};