1 /* 2 * Copyright (C) 1996-2021 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_TYPELENGTHVALUEUNPACKER_H 10 #define SQUID_TYPELENGTHVALUEUNPACKER_H 11 12 class StoreMeta; 13 class StoreEntry; 14 15 class StoreMetaUnpacker 16 { 17 18 public: 19 StoreMetaUnpacker (const char *buf, ssize_t bufferLength, int *hdrlen); 20 StoreMeta *createStoreMeta(); 21 bool isBufferZero(); ///< all-zeros buffer, checkBuffer() would throw 22 /// validates buffer sanity and throws if validation fails 23 void checkBuffer(); 24 25 private: 26 static int const MinimumBufferLength; 27 28 void getBufferLength(); 29 void getType(); 30 void getLength(); 31 void getTLV(); 32 bool doOneEntry(); 33 bool moreToProcess() const; 34 35 char const * const buf; 36 ssize_t buflen; 37 int *hdr_len; 38 int position; 39 char type; 40 int length; 41 StoreMeta **tail; 42 }; 43 44 /* 45 * store_swapmeta.c 46 */ 47 char *storeSwapMetaPack(StoreMeta * tlv_list, int *length); 48 StoreMeta *storeSwapMetaBuild(StoreEntry * e); 49 StoreMeta *storeSwapMetaUnpack(const char *buf, int *hdrlen); 50 void storeSwapTLVFree(StoreMeta * n); 51 StoreMeta ** storeSwapTLVAdd(int type, const void *ptr, size_t len, StoreMeta ** tail); 52 53 #endif /* SQUID_TYPELENGTHVALUEUNPACKER_H */ 54 55