Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef _nsDiskCacheEntry_h_ |
michael@0 | 8 | #define _nsDiskCacheEntry_h_ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsDiskCacheMap.h" |
michael@0 | 11 | |
michael@0 | 12 | #include "nsCacheEntry.h" |
michael@0 | 13 | |
michael@0 | 14 | |
michael@0 | 15 | /****************************************************************************** |
michael@0 | 16 | * nsDiskCacheEntry |
michael@0 | 17 | *****************************************************************************/ |
michael@0 | 18 | struct nsDiskCacheEntry { |
michael@0 | 19 | uint32_t mHeaderVersion; // useful for stand-alone metadata files |
michael@0 | 20 | uint32_t mMetaLocation; // for verification |
michael@0 | 21 | int32_t mFetchCount; |
michael@0 | 22 | uint32_t mLastFetched; |
michael@0 | 23 | uint32_t mLastModified; |
michael@0 | 24 | uint32_t mExpirationTime; |
michael@0 | 25 | uint32_t mDataSize; |
michael@0 | 26 | uint32_t mKeySize; // includes terminating null byte |
michael@0 | 27 | uint32_t mMetaDataSize; // includes terminating null byte |
michael@0 | 28 | // followed by key data (mKeySize bytes) |
michael@0 | 29 | // followed by meta data (mMetaDataSize bytes) |
michael@0 | 30 | |
michael@0 | 31 | uint32_t Size() { return sizeof(nsDiskCacheEntry) + |
michael@0 | 32 | mKeySize + mMetaDataSize; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | char* Key() { return reinterpret_cast<char*const>(this) + |
michael@0 | 36 | sizeof(nsDiskCacheEntry); |
michael@0 | 37 | } |
michael@0 | 38 | |
michael@0 | 39 | char* MetaData() |
michael@0 | 40 | { return Key() + mKeySize; } |
michael@0 | 41 | |
michael@0 | 42 | nsCacheEntry * CreateCacheEntry(nsCacheDevice * device); |
michael@0 | 43 | |
michael@0 | 44 | void Swap() // host to network (memory to disk) |
michael@0 | 45 | { |
michael@0 | 46 | #if defined(IS_LITTLE_ENDIAN) |
michael@0 | 47 | mHeaderVersion = htonl(mHeaderVersion); |
michael@0 | 48 | mMetaLocation = htonl(mMetaLocation); |
michael@0 | 49 | mFetchCount = htonl(mFetchCount); |
michael@0 | 50 | mLastFetched = htonl(mLastFetched); |
michael@0 | 51 | mLastModified = htonl(mLastModified); |
michael@0 | 52 | mExpirationTime = htonl(mExpirationTime); |
michael@0 | 53 | mDataSize = htonl(mDataSize); |
michael@0 | 54 | mKeySize = htonl(mKeySize); |
michael@0 | 55 | mMetaDataSize = htonl(mMetaDataSize); |
michael@0 | 56 | #endif |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | void Unswap() // network to host (disk to memory) |
michael@0 | 60 | { |
michael@0 | 61 | #if defined(IS_LITTLE_ENDIAN) |
michael@0 | 62 | mHeaderVersion = ntohl(mHeaderVersion); |
michael@0 | 63 | mMetaLocation = ntohl(mMetaLocation); |
michael@0 | 64 | mFetchCount = ntohl(mFetchCount); |
michael@0 | 65 | mLastFetched = ntohl(mLastFetched); |
michael@0 | 66 | mLastModified = ntohl(mLastModified); |
michael@0 | 67 | mExpirationTime = ntohl(mExpirationTime); |
michael@0 | 68 | mDataSize = ntohl(mDataSize); |
michael@0 | 69 | mKeySize = ntohl(mKeySize); |
michael@0 | 70 | mMetaDataSize = ntohl(mMetaDataSize); |
michael@0 | 71 | #endif |
michael@0 | 72 | } |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | |
michael@0 | 76 | /****************************************************************************** |
michael@0 | 77 | * nsDiskCacheEntryInfo |
michael@0 | 78 | *****************************************************************************/ |
michael@0 | 79 | class nsDiskCacheEntryInfo : public nsICacheEntryInfo { |
michael@0 | 80 | public: |
michael@0 | 81 | NS_DECL_ISUPPORTS |
michael@0 | 82 | NS_DECL_NSICACHEENTRYINFO |
michael@0 | 83 | |
michael@0 | 84 | nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry) |
michael@0 | 85 | : mDeviceID(deviceID) |
michael@0 | 86 | , mDiskEntry(diskEntry) |
michael@0 | 87 | { |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | virtual ~nsDiskCacheEntryInfo() {} |
michael@0 | 91 | |
michael@0 | 92 | const char* Key() { return mDiskEntry->Key(); } |
michael@0 | 93 | |
michael@0 | 94 | private: |
michael@0 | 95 | const char * mDeviceID; |
michael@0 | 96 | nsDiskCacheEntry * mDiskEntry; |
michael@0 | 97 | }; |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | #endif /* _nsDiskCacheEntry_h_ */ |