2001-03-21 01:42:03 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is nsDiskCacheEntry.cpp, released
|
|
|
|
* May 10, 2001.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2001
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Gordon Sheridan <gordon@netscape.com>
|
|
|
|
* Patrick C. Beard <beard@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
#include "nsDiskCache.h"
|
2001-03-21 01:42:03 +03:00
|
|
|
#include "nsDiskCacheEntry.h"
|
2001-05-19 03:24:09 +04:00
|
|
|
#include "nsDiskCacheBinding.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
#include "nsCache.h"
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2008-01-06 04:07:16 +03:00
|
|
|
#include "nsISerializable.h"
|
|
|
|
#include "nsSerializationHelper.h"
|
2001-03-29 09:54:58 +04:00
|
|
|
|
2001-03-21 01:42:03 +03:00
|
|
|
/******************************************************************************
|
2001-05-19 03:24:09 +04:00
|
|
|
* nsDiskCacheEntry
|
2001-03-21 01:42:03 +03:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
/**
|
|
|
|
* CreateCacheEntry()
|
|
|
|
*
|
|
|
|
* Creates an nsCacheEntry and sets all fields except for the binding.
|
|
|
|
*/
|
|
|
|
nsCacheEntry *
|
|
|
|
nsDiskCacheEntry::CreateCacheEntry(nsCacheDevice * device)
|
|
|
|
{
|
|
|
|
nsCacheEntry * entry = nsnull;
|
2007-01-26 02:09:01 +03:00
|
|
|
nsresult rv = nsCacheEntry::Create(Key(),
|
2001-05-19 03:24:09 +04:00
|
|
|
nsICache::STREAM_BASED,
|
|
|
|
nsICache::STORE_ON_DISK,
|
|
|
|
device,
|
|
|
|
&entry);
|
|
|
|
if (NS_FAILED(rv) || !entry) return nsnull;
|
|
|
|
|
|
|
|
entry->SetFetchCount(mFetchCount);
|
|
|
|
entry->SetLastFetched(mLastFetched);
|
|
|
|
entry->SetLastModified(mLastModified);
|
|
|
|
entry->SetExpirationTime(mExpirationTime);
|
|
|
|
entry->SetCacheDevice(device);
|
|
|
|
// XXX why does nsCacheService have to fill out device in BindEntry()?
|
|
|
|
entry->SetDataSize(mDataSize);
|
|
|
|
|
2007-01-26 02:09:01 +03:00
|
|
|
rv = entry->UnflattenMetaData(MetaData(), mMetaDataSize);
|
2001-05-19 03:24:09 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete entry;
|
|
|
|
return nsnull;
|
|
|
|
}
|
2008-01-06 04:07:16 +03:00
|
|
|
|
|
|
|
// Restore security info, if present
|
|
|
|
const char* info = entry->GetMetaDataElement("security-info");
|
|
|
|
if (info) {
|
|
|
|
nsCOMPtr<nsISupports> infoObj;
|
2012-03-30 13:21:01 +04:00
|
|
|
rv = NS_DeserializeObject(nsDependentCString(info),
|
|
|
|
getter_AddRefs(infoObj));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
delete entry;
|
|
|
|
return nsnull;
|
|
|
|
}
|
2008-01-06 04:07:16 +03:00
|
|
|
entry->SetSecurityInfo(infoObj);
|
|
|
|
}
|
|
|
|
|
2007-12-29 07:22:54 +03:00
|
|
|
return entry;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
/******************************************************************************
|
|
|
|
* nsDiskCacheEntryInfo
|
|
|
|
*****************************************************************************/
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2003-09-08 03:12:15 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(nsDiskCacheEntryInfo, nsICacheEntryInfo)
|
2001-03-21 01:42:03 +03:00
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetClientID(char ** clientID)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(clientID);
|
2007-01-26 02:09:01 +03:00
|
|
|
return ClientIDFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientID);
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
extern const char DISK_CACHE_DEVICE_ID[];
|
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDeviceID(char ** deviceID)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(deviceID);
|
2007-05-15 00:09:20 +04:00
|
|
|
*deviceID = NS_strdup(mDeviceID);
|
2001-05-19 03:24:09 +04:00
|
|
|
return *deviceID ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
|
2005-01-13 06:25:28 +03:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetKey(nsACString &clientKey)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2007-01-26 02:09:01 +03:00
|
|
|
return ClientKeyFromCacheKey(nsDependentCString(mDiskEntry->Key()), clientKey);
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetFetchCount(PRInt32 *aFetchCount)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aFetchCount);
|
|
|
|
*aFetchCount = mDiskEntry->mFetchCount;
|
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastFetched(PRUint32 *aLastFetched)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aLastFetched);
|
|
|
|
*aLastFetched = mDiskEntry->mLastFetched;
|
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetLastModified(PRUint32 *aLastModified)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aLastModified);
|
|
|
|
*aLastModified = mDiskEntry->mLastModified;
|
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetExpirationTime(PRUint32 *aExpirationTime)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aExpirationTime);
|
|
|
|
*aExpirationTime = mDiskEntry->mExpirationTime;
|
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::IsStreamBased(bool *aStreamBased)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aStreamBased);
|
2011-10-17 18:59:28 +04:00
|
|
|
*aStreamBased = true;
|
2001-05-19 03:24:09 +04:00
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|
|
|
|
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_IMETHODIMP nsDiskCacheEntryInfo::GetDataSize(PRUint32 *aDataSize)
|
2001-03-21 01:42:03 +03:00
|
|
|
{
|
2001-05-19 03:24:09 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aDataSize);
|
|
|
|
*aDataSize = mDiskEntry->mDataSize;
|
|
|
|
return NS_OK;
|
2001-03-21 01:42:03 +03:00
|
|
|
}
|