1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 : *
3 : * ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
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/
10 : *
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
14 : * License.
15 : *
16 : * The Original Code is nsMemoryCacheDevice.cpp, released
17 : * February 22, 2001.
18 : *
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.
23 : *
24 : * Contributor(s):
25 : * Gordon Sheridan <gordon@netscape.com>
26 : * Patrick C. Beard <beard@netscape.com>
27 : *
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.
39 : *
40 : * ***** END LICENSE BLOCK ***** */
41 :
42 : #ifndef _nsDiskCacheEntry_h_
43 : #define _nsDiskCacheEntry_h_
44 :
45 : #include "nsDiskCacheMap.h"
46 :
47 : #include "nsCacheEntry.h"
48 :
49 :
50 : /******************************************************************************
51 : * nsDiskCacheEntry
52 : *****************************************************************************/
53 : struct nsDiskCacheEntry {
54 : PRUint32 mHeaderVersion; // useful for stand-alone metadata files
55 : PRUint32 mMetaLocation; // for verification
56 : PRInt32 mFetchCount;
57 : PRUint32 mLastFetched;
58 : PRUint32 mLastModified;
59 : PRUint32 mExpirationTime;
60 : PRUint32 mDataSize;
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)
65 :
66 279 : PRUint32 Size() { return sizeof(nsDiskCacheEntry) +
67 279 : mKeySize + mMetaDataSize;
68 : }
69 :
70 2157 : char* Key() { return reinterpret_cast<char*const>(this) +
71 2157 : sizeof(nsDiskCacheEntry);
72 : }
73 :
74 939 : char* MetaData()
75 939 : { return Key() + mKeySize; }
76 :
77 : nsCacheEntry * CreateCacheEntry(nsCacheDevice * device);
78 :
79 660 : void Swap() // host to network (memory to disk)
80 : {
81 : #if defined(IS_LITTLE_ENDIAN)
82 660 : mHeaderVersion = htonl(mHeaderVersion);
83 660 : mMetaLocation = htonl(mMetaLocation);
84 660 : mFetchCount = htonl(mFetchCount);
85 660 : mLastFetched = htonl(mLastFetched);
86 660 : mLastModified = htonl(mLastModified);
87 660 : mExpirationTime = htonl(mExpirationTime);
88 660 : mDataSize = htonl(mDataSize);
89 660 : mKeySize = htonl(mKeySize);
90 660 : mMetaDataSize = htonl(mMetaDataSize);
91 : #endif
92 660 : }
93 :
94 279 : void Unswap() // network to host (disk to memory)
95 : {
96 : #if defined(IS_LITTLE_ENDIAN)
97 279 : mHeaderVersion = ntohl(mHeaderVersion);
98 279 : mMetaLocation = ntohl(mMetaLocation);
99 279 : mFetchCount = ntohl(mFetchCount);
100 279 : mLastFetched = ntohl(mLastFetched);
101 279 : mLastModified = ntohl(mLastModified);
102 279 : mExpirationTime = ntohl(mExpirationTime);
103 279 : mDataSize = ntohl(mDataSize);
104 279 : mKeySize = ntohl(mKeySize);
105 279 : mMetaDataSize = ntohl(mMetaDataSize);
106 : #endif
107 279 : }
108 : };
109 :
110 :
111 : /******************************************************************************
112 : * nsDiskCacheEntryInfo
113 : *****************************************************************************/
114 : class nsDiskCacheEntryInfo : public nsICacheEntryInfo {
115 : public:
116 : NS_DECL_ISUPPORTS
117 : NS_DECL_NSICACHEENTRYINFO
118 :
119 0 : nsDiskCacheEntryInfo(const char * deviceID, nsDiskCacheEntry * diskEntry)
120 : : mDeviceID(deviceID)
121 0 : , mDiskEntry(diskEntry)
122 : {
123 0 : }
124 :
125 0 : virtual ~nsDiskCacheEntryInfo() {}
126 :
127 : const char* Key() { return mDiskEntry->Key(); }
128 :
129 : private:
130 : const char * mDeviceID;
131 : nsDiskCacheEntry * mDiskEntry;
132 : };
133 :
134 :
135 : #endif /* _nsDiskCacheEntry_h_ */
|