SwapMeta.h
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 #ifndef SQUID_SRC_STORE_SWAPMETA_H
10 #define SQUID_SRC_STORE_SWAPMETA_H
11 
12 #include "defines.h"
13 
14 #include <limits>
15 
16 // store swap metadata interfaces shared by input and output code
17 
18 namespace Store {
19 
47 
56 
62 
66 
81 
84 
88 
89  // TODO: Document this type after we start using it; see UnpackHitSwapMeta()
91 };
92 
95 using RawSwapMetaType = char;
96 
101 
107 const size_t SwapMetaFieldValueLengthMax = 64*1024;
108 
109 static_assert(SwapMetaFieldValueLengthMax >= MAX_URL, "MAX_URL will fit in a swap meta field");
110 static_assert(SwapMetaFieldValueLengthMax <= uint64_t(std::numeric_limits<RawSwapMetaLength>::max()), "any swap metadata value size can be stored as RawSwapMetaLength");
111 
113 const char SwapMetaMagic = 0x03;
114 
120 
123 
127 
130 inline constexpr RawSwapMetaType
132 {
133  // This "constant" switch forces developers to update this function when
134  // they add SwapMetaType values [-Wswitch]. It is better than an end_ enum
135  // marker because it does not force us to add that marker to every switch
136  // statement, with an assert(false) or similar "unreachable code" handler.
137  // Optimizing compilers optimize this statement away into a constant.
138  // The non-constant variable is needed for older compilers.
139 
140  // always use the last/maximum enum value here
141  auto top = STORE_META_OBJSIZE;
142  switch (top) {
143  case STORE_META_VOID:
144  case STORE_META_KEY_MD5:
145  case STORE_META_URL:
146  case STORE_META_STD:
148  case STORE_META_STD_LFS:
149  case STORE_META_OBJSIZE:
150  break;
151  }
152  return top;
153 }
154 
157 inline constexpr bool
159 {
160  enum class DeprecatedMetas {
162  STORE_META_KEY_URL = 1,
164  STORE_META_KEY_SHA = 2,
166  STORE_META_HITMETERING = 6,
168  STORE_META_VALID = 7
169  };
170  return
171  type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_KEY_URL) ||
172  type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_KEY_SHA) ||
173  type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_HITMETERING) ||
174  type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_VALID);
175 }
176 
179 inline constexpr bool
181 {
182  enum class ReservedMetas {
184  STORE_META_STOREURL = 11,
186  STORE_META_VARY_ID = 12
187  };
188  return
189  type == static_cast<RawSwapMetaType>(ReservedMetas::STORE_META_STOREURL) ||
190  type == static_cast<RawSwapMetaType>(ReservedMetas::STORE_META_VARY_ID);
191 }
192 
196 inline constexpr bool
198 {
199  switch (type) {
200  case STORE_META_VOID:
201  return false;
202 
203  case STORE_META_KEY_MD5:
204  case STORE_META_URL:
205  case STORE_META_STD:
207  case STORE_META_STD_LFS:
208  case STORE_META_OBJSIZE:
209  return true;
210 
211  default:
212  return false;
213  }
214 }
215 
218 inline constexpr bool
220 {
221  return DeprecatedSwapMetaType(type) || ReservedSwapMetaType(type);
222 }
223 
226 const auto STORE_HDR_METASIZE =
227  4*sizeof(time_t) + sizeof(uint64_t) + 2*sizeof(uint16_t);
228 
232  4*sizeof(time_t) + sizeof(size_t) + 2*sizeof(uint16_t);
233 
238 
239 } // namespace Store
240 
241 #endif /* SQUID_SRC_STORE_SWAPMETA_H */
242 
constexpr RawSwapMetaType RawSwapMetaTypeTop()
Definition: SwapMeta.h:131
constexpr bool IgnoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:219
@ STORE_META_URL
Definition: SwapMeta.h:65
const A & max(A const &lhs, A const &rhs)
@ STORE_META_STD_LFS
Definition: SwapMeta.h:87
const auto STORE_HDR_METASIZE_OLD
Definition: SwapMeta.h:231
#define MAX_URL
Definition: defines.h:76
void CheckSwapMetaSerialization(RawSwapMetaType, RawSwapMetaLength, const void *)
Definition: SwapMeta.cc:13
@ STORE_META_OBJSIZE
Definition: SwapMeta.h:90
constexpr bool DeprecatedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:158
char RawSwapMetaType
Definition: SwapMeta.h:95
constexpr bool ReservedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:180
@ STORE_META_KEY_MD5
Definition: SwapMeta.h:61
const char SwapMetaMagic
the start of the swap meta section
Definition: SwapMeta.h:113
int RawSwapMetaPrefixLength
Definition: SwapMeta.h:119
int RawSwapMetaLength
Definition: SwapMeta.h:100
const size_t SwapMetaFieldValueLengthMax
Definition: SwapMeta.h:107
@ STORE_META_VOID
Definition: SwapMeta.h:55
const RawSwapMetaType RawSwapMetaTypeBottom
Definition: SwapMeta.h:126
SwapMetaType
Definition: SwapMeta.h:52
@ STORE_META_VARY_HEADERS
Stores Vary request headers.
Definition: SwapMeta.h:83
const auto SwapMetaPrefixSize
The size of the initial (and required) portion of any swap metadata.
Definition: SwapMeta.h:122
constexpr bool HonoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:197
@ STORE_META_STD
Definition: SwapMeta.h:80
const auto STORE_HDR_METASIZE
Definition: SwapMeta.h:226
int unsigned int
Definition: stub_fd.cc:19

 

Introduction

Documentation

Support

Miscellaneous