]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/StoreMetaUnpacker.cc
2 * Copyright (C) 1996-2014 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 Unpacker */
14 #include "StoreMeta.h"
15 #include "StoreMetaUnpacker.h"
17 int const StoreMetaUnpacker::MinimumBufferLength
= sizeof(char) + sizeof(int);
19 /// useful for meta stored in pre-initialized (with zeros) db files
21 StoreMetaUnpacker::isBufferZero()
23 // We could memcmp the entire buffer, but it is probably safe enough
24 // to test a few bytes because if we do not detect a corrupted entry
25 // it is not a big deal. Empty entries are not isBufferSane anyway.
28 return false; // cannot be sure enough
30 for (int i
= 0; i
< depth
; ++i
) {
38 StoreMetaUnpacker::isBufferSane()
40 if (buf
[0] != (char) STORE_META_OK
)
44 * sanity check on 'buflen' value. It should be at least big
45 * enough to hold one type and one length.
49 if (*hdr_len
< MinimumBufferLength
)
52 if (*hdr_len
> buflen
)
59 StoreMetaUnpacker::getBufferLength()
61 memcpy(hdr_len
, &buf
[1], sizeof(int));
64 StoreMetaUnpacker::StoreMetaUnpacker(char const *aBuffer
, ssize_t aLen
, int *anInt
) :
68 position(1 + sizeof(int)),
73 assert(aBuffer
!= NULL
);
77 StoreMetaUnpacker::getType()
84 StoreMetaUnpacker::getLength()
86 memcpy(&length
, &buf
[position
], sizeof(int));
87 position
+= sizeof(int);
91 StoreMetaUnpacker::doOneEntry()
96 if (position
+ length
> *hdr_len
) {
97 debugs(20, DBG_CRITICAL
, "storeSwapMetaUnpack: overflow!");
98 debugs(20, DBG_CRITICAL
, "\ttype=" << type
<< ", length=" << length
<< ", *hdr_len=" << *hdr_len
<< ", offset=" << position
);
102 StoreMeta
*newNode
= StoreMeta::Factory(type
, length
, &buf
[position
]);
105 tail
= StoreMeta::Add (tail
, newNode
);
113 StoreMetaUnpacker::moreToProcess() const
115 return *hdr_len
- position
- MinimumBufferLength
>= 0;
119 StoreMetaUnpacker::createStoreMeta ()
123 assert(hdr_len
!= NULL
);
130 assert (position
== 1 + sizeof(int));
132 while (moreToProcess()) {