1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
16 * The Original Code is nsMemoryCacheDevice.cpp, released
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 2001
22 * the Initial Developer. All Rights Reserved.
25 * Gordon Sheridan <gordon@netscape.com>
26 * Patrick C. Beard <beard@netscape.com>
28 * Alternatively, the contents of this file may be used under the terms of
29 * either the GNU General Public License Version 2 or later (the "GPL"), or
30 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 * in which case the provisions of the GPL or the LGPL are applicable instead
32 * of those above. If you wish to allow use of your version of this file only
33 * under the terms of either the GPL or the LGPL, and not to allow others to
34 * use your version of this file under the terms of the MPL, indicate your
35 * decision by deleting the provisions above and replace them with the notice
36 * and other provisions required by the GPL or the LGPL. If you do not delete
37 * the provisions above, a recipient may use your version of this file under
38 * the terms of any one of the MPL, the GPL or the LGPL.
40 * ***** END LICENSE BLOCK ***** */
42 #ifndef _nsDiskCacheEntry_h_
43 #define _nsDiskCacheEntry_h_
45 #include "nsDiskCacheMap.h"
47 #include "nsCacheEntry.h"
50 /******************************************************************************
52 *****************************************************************************/
53 struct nsDiskCacheEntry
{
54 PRUint32 mHeaderVersion
; // useful for stand-alone metadata files
55 PRUint32 mMetaLocation
; // for verification
57 PRUint32 mLastFetched
;
58 PRUint32 mLastModified
;
59 PRUint32 mExpirationTime
;
61 PRUint32 mKeySize
; // includes terminating null byte
62 PRUint32 mMetaDataSize
; // includes terminating null byte
63 // followed by key data (mKeySize bytes)
64 // followed by meta data (mMetaDataSize bytes)
66 PRUint32
Size() { return sizeof(nsDiskCacheEntry
) +
67 mKeySize
+ mMetaDataSize
;
70 char* Key() { return reinterpret_cast<char*const>(this) +
71 sizeof(nsDiskCacheEntry
);
75 { return Key() + mKeySize
; }
77 nsCacheEntry
* CreateCacheEntry(nsCacheDevice
* device
);
79 void Swap() // host to network (memory to disk)
81 #if defined(IS_LITTLE_ENDIAN)
82 mHeaderVersion
= htonl(mHeaderVersion
);
83 mMetaLocation
= htonl(mMetaLocation
);
84 mFetchCount
= htonl(mFetchCount
);
85 mLastFetched
= htonl(mLastFetched
);
86 mLastModified
= htonl(mLastModified
);
87 mExpirationTime
= htonl(mExpirationTime
);
88 mDataSize
= htonl(mDataSize
);
89 mKeySize
= htonl(mKeySize
);
90 mMetaDataSize
= htonl(mMetaDataSize
);
94 void Unswap() // network to host (disk to memory)
96 #if defined(IS_LITTLE_ENDIAN)
97 mHeaderVersion
= ntohl(mHeaderVersion
);
98 mMetaLocation
= ntohl(mMetaLocation
);
99 mFetchCount
= ntohl(mFetchCount
);
100 mLastFetched
= ntohl(mLastFetched
);
101 mLastModified
= ntohl(mLastModified
);
102 mExpirationTime
= ntohl(mExpirationTime
);
103 mDataSize
= ntohl(mDataSize
);
104 mKeySize
= ntohl(mKeySize
);
105 mMetaDataSize
= ntohl(mMetaDataSize
);
111 /******************************************************************************
112 * nsDiskCacheEntryInfo
113 *****************************************************************************/
114 class nsDiskCacheEntryInfo
: public nsICacheEntryInfo
{
117 NS_DECL_NSICACHEENTRYINFO
119 nsDiskCacheEntryInfo(const char * deviceID
, nsDiskCacheEntry
* diskEntry
)
120 : mDeviceID(deviceID
)
121 , mDiskEntry(diskEntry
)
125 virtual ~nsDiskCacheEntryInfo() {}
127 const char* Key() { return mDiskEntry
->Key(); }
130 const char * mDeviceID
;
131 nsDiskCacheEntry
* mDiskEntry
;
135 #endif /* _nsDiskCacheEntry_h_ */