]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreMeta.cc
2 * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
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.
9 /* DEBUG: section 20 Storage Manager Swapfile Metadata */
12 #include "base/Range.h"
13 #include "MemObject.h"
15 #include "StoreMeta.h"
16 #include "StoreMetaMD5.h"
17 #include "StoreMetaObjSize.h"
18 #include "StoreMetaSTD.h"
19 #include "StoreMetaSTDLFS.h"
20 #include "StoreMetaURL.h"
21 #include "StoreMetaVary.h"
24 StoreMeta::validType(char type
)
26 /* VOID is reserved, and new types have to be added as classes */
27 if (type
<= STORE_META_VOID
|| type
>= STORE_META_END
+ 10) {
28 debugs(20, DBG_CRITICAL
, "storeSwapMetaUnpack: bad type (" << type
<< ")!");
32 /* Not yet implemented */
33 if (type
>= STORE_META_END
||
34 type
== STORE_META_STOREURL
||
35 type
== STORE_META_VARY_ID
) {
36 debugs(20, 3, "storeSwapMetaUnpack: Not yet implemented (" << type
<< ") in disk metadata");
40 /* Unused in any current squid code */
41 if (type
== STORE_META_KEY_URL
||
42 type
== STORE_META_KEY_SHA
||
43 type
== STORE_META_HITMETERING
||
44 type
== STORE_META_VALID
) {
45 debugs(20, DBG_CRITICAL
, "Obsolete and unused type (" << type
<< ") in disk metadata");
52 const int StoreMeta::MinimumTLVLength
= 0;
53 const int StoreMeta::MaximumTLVLength
= 1 << 16;
56 StoreMeta::validLength(int aLength
) const
58 static const Range
<int> TlvValidLengths
= Range
<int>(StoreMeta::MinimumTLVLength
, StoreMeta::MaximumTLVLength
);
59 if (!TlvValidLengths
.contains(aLength
)) {
60 debugs(20, DBG_CRITICAL
, MYNAME
<< ": insane length (" << aLength
<< ")!");
68 StoreMeta::Factory (char type
, size_t len
, void const *value
)
78 result
= new StoreMetaMD5
;
82 result
= new StoreMetaURL
;
86 result
= new StoreMetaSTD
;
89 case STORE_META_STD_LFS
:
90 result
= new StoreMetaSTDLFS
;
93 case STORE_META_OBJSIZE
:
94 result
= new StoreMetaObjSize
;
97 case STORE_META_VARY_HEADERS
:
98 result
= new StoreMetaVary
;
102 debugs(20, DBG_CRITICAL
, "Attempt to create unknown concrete StoreMeta");
106 if (!result
->validLength(len
)) {
111 result
->length
= len
;
112 result
->value
= xmalloc(len
);
113 memcpy(result
->value
, value
, len
);
118 StoreMeta::FreeList(StoreMeta
**head
)
122 while ((node
= *head
) != NULL
) {
130 StoreMeta::Add(StoreMeta
**tail
, StoreMeta
*aNode
)
132 assert (*tail
== NULL
);
134 return &aNode
->next
; /* return new tail pointer */
138 StoreMeta::checkConsistency(StoreEntry
*) const
146 case STORE_META_VARY_HEADERS
:
153 case STORE_META_STD_LFS
:
156 case STORE_META_OBJSIZE
:
160 debugs(20, DBG_IMPORTANT
, "WARNING: got unused STORE_META type " << getType());
167 StoreMeta::StoreMeta(const StoreMeta
&s
) :
173 StoreMeta
& StoreMeta::operator=(const StoreMeta
&s
)