SwapMeta.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2022 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
18namespace Store {
19
47
56
62
66
81
84
88
89 // TODO: Document this type after we start using it; see UnpackHitSwapMeta()
91};
92
95using RawSwapMetaType = char;
96
101
107const size_t SwapMetaFieldValueLengthMax = 64*1024;
108
109static_assert(SwapMetaFieldValueLengthMax >= MAX_URL, "MAX_URL will fit in a swap meta field");
110static_assert(SwapMetaFieldValueLengthMax <= uint64_t(std::numeric_limits<RawSwapMetaLength>::max()), "any swap metadata value size can be stored as RawSwapMetaLength");
111
113const char SwapMetaMagic = 0x03;
114
120
123
127
128// TODO: Use "inline constexpr ..." with C++17.
131inline RawSwapMetaType
133{
134 // This "constant" switch forces developers to update this function when
135 // they add SwapMetaType values [-Wswitch]. It is better than an end_ enum
136 // marker because it does not force us to add that marker to every switch
137 // statement, with an assert(false) or similar "unreachable code" handler.
138 // Optimizing compilers optimize this statement away into a constant.
139 // The non-constant variable is needed for older compilers.
140
141 // always use the last/maximum enum value here
142 auto top = STORE_META_OBJSIZE;
143 switch (top) {
144 case STORE_META_VOID:
146 case STORE_META_URL:
147 case STORE_META_STD:
151 break;
152 }
153 return top;
154}
155
158inline bool
160{
161 enum class DeprecatedMetas {
163 STORE_META_KEY_URL = 1,
165 STORE_META_KEY_SHA = 2,
167 STORE_META_HITMETERING = 6,
169 STORE_META_VALID = 7
170 };
171 return
172 // TODO: simplify with std::underlying_type_t when switching to C++14
173 type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_KEY_URL) ||
174 type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_KEY_SHA) ||
175 type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_HITMETERING) ||
176 type == static_cast<RawSwapMetaType>(DeprecatedMetas::STORE_META_VALID);
177}
178
181inline bool
183{
184 enum class ReservedMetas {
186 STORE_META_STOREURL = 11,
188 STORE_META_VARY_ID = 12
189 };
190 return
191 type == static_cast<RawSwapMetaType>(ReservedMetas::STORE_META_STOREURL) ||
192 type == static_cast<RawSwapMetaType>(ReservedMetas::STORE_META_VARY_ID);
193}
194
198inline bool
200{
201 switch (type) {
202 case STORE_META_VOID:
203 return false;
204
206 case STORE_META_URL:
207 case STORE_META_STD:
211 return true;
212
213 default:
214 return false;
215 }
216}
217
220inline bool
222{
224}
225
229 4*sizeof(time_t) + sizeof(uint64_t) + 2*sizeof(uint16_t);
230
234 4*sizeof(time_t) + sizeof(size_t) + 2*sizeof(uint16_t);
235
240
241} // namespace Store
242
243#endif /* SQUID_SRC_STORE_SWAPMETA_H */
244
A const & max(A const &lhs, A const &rhs)
#define MAX_URL
Definition: defines.h:78
int type
Definition: errorpage.cc:152
const RawSwapMetaType RawSwapMetaTypeBottom
Definition: SwapMeta.h:126
const auto SwapMetaPrefixSize
The size of the initial (and required) portion of any swap metadata.
Definition: SwapMeta.h:122
const size_t SwapMetaFieldValueLengthMax
Definition: SwapMeta.h:107
bool HonoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:199
int RawSwapMetaLength
Definition: SwapMeta.h:100
char RawSwapMetaType
Definition: SwapMeta.h:95
bool ReservedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:182
SwapMetaType
Definition: SwapMeta.h:52
@ STORE_META_URL
Definition: SwapMeta.h:65
@ STORE_META_VARY_HEADERS
Stores Vary request headers.
Definition: SwapMeta.h:83
@ STORE_META_OBJSIZE
Definition: SwapMeta.h:90
@ STORE_META_KEY_MD5
Definition: SwapMeta.h:61
@ STORE_META_STD
Definition: SwapMeta.h:80
@ STORE_META_STD_LFS
Definition: SwapMeta.h:87
@ STORE_META_VOID
Definition: SwapMeta.h:55
void CheckSwapMetaSerialization(RawSwapMetaType, RawSwapMetaLength, const void *)
Definition: SwapMeta.cc:13
const char SwapMetaMagic
the start of the swap meta section
Definition: SwapMeta.h:113
const auto STORE_HDR_METASIZE_OLD
Definition: SwapMeta.h:233
const auto STORE_HDR_METASIZE
Definition: SwapMeta.h:228
int RawSwapMetaPrefixLength
Definition: SwapMeta.h:119
bool DeprecatedSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:159
bool IgnoredSwapMetaType(const RawSwapMetaType type)
Definition: SwapMeta.h:221
RawSwapMetaType RawSwapMetaTypeTop()
Definition: SwapMeta.h:132
int unsigned int
Definition: stub_fd.cc:19

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors