]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreMeta.cc
2 * Copyright (C) 1996-2015 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 "MemObject.h"
14 #include "StoreMeta.h"
15 #include "StoreMetaMD5.h"
16 #include "StoreMetaObjSize.h"
17 #include "StoreMetaSTD.h"
18 #include "StoreMetaSTDLFS.h"
19 #include "StoreMetaURL.h"
20 #include "StoreMetaVary.h"
23 StoreMeta::validType(char type
)
25 /* VOID is reserved, and new types have to be added as classes */
26 if (type
<= STORE_META_VOID
|| type
>= STORE_META_END
+ 10) {
27 debugs(20, DBG_CRITICAL
, "storeSwapMetaUnpack: bad type (" << type
<< ")!");
31 /* Not yet implemented */
32 if (type
>= STORE_META_END
||
33 type
== STORE_META_STOREURL
||
34 type
== STORE_META_VARY_ID
) {
35 debugs(20, 3, "storeSwapMetaUnpack: Not yet implemented (" << type
<< ") in disk metadata");
39 /* Unused in any current squid code */
40 if (type
== STORE_META_KEY_URL
||
41 type
== STORE_META_KEY_SHA
||
42 type
== STORE_META_HITMETERING
||
43 type
== STORE_META_VALID
) {
44 debugs(20, DBG_CRITICAL
, "Obsolete and unused type (" << type
<< ") in disk metadata");
55 IntRange (int minimum
, int maximum
) : _min (minimum
), _max (maximum
) {
63 bool includes (int anInt
) const {
64 if (anInt
< _min
|| anInt
> _max
)
75 const int StoreMeta::MinimumTLVLength
= 0;
76 const int StoreMeta::MaximumTLVLength
= 1 << 16;
79 StoreMeta::validLength(int aLength
) const
81 if (!IntRange (MinimumTLVLength
, MaximumTLVLength
).includes(aLength
)) {
82 debugs(20, DBG_CRITICAL
, "storeSwapMetaUnpack: insane length (" << aLength
<< ")!");
90 StoreMeta::Factory (char type
, size_t len
, void const *value
)
100 result
= new StoreMetaMD5
;
104 result
= new StoreMetaURL
;
108 result
= new StoreMetaSTD
;
111 case STORE_META_STD_LFS
:
112 result
= new StoreMetaSTDLFS
;
115 case STORE_META_OBJSIZE
:
116 result
= new StoreMetaObjSize
;
119 case STORE_META_VARY_HEADERS
:
120 result
= new StoreMetaVary
;
124 debugs(20, DBG_CRITICAL
, "Attempt to create unknown concrete StoreMeta");
128 if (!result
->validLength(len
)) {
133 result
->length
= len
;
134 result
->value
= xmalloc(len
);
135 memcpy(result
->value
, value
, len
);
140 StoreMeta::FreeList(StoreMeta
**head
)
144 while ((node
= *head
) != NULL
) {
152 StoreMeta::Add(StoreMeta
**tail
, StoreMeta
*aNode
)
154 assert (*tail
== NULL
);
156 return &aNode
->next
; /* return new tail pointer */
160 StoreMeta::checkConsistency(StoreEntry
*) const
168 case STORE_META_VARY_HEADERS
:
175 case STORE_META_STD_LFS
:
178 case STORE_META_OBJSIZE
:
182 debugs(20, DBG_IMPORTANT
, "WARNING: got unused STORE_META type " << getType());