Compare commits
1 Commits
tags/DISKC
...
src
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
258dc9fead |
6
mozilla/netwerk/cache/public/MANIFEST
vendored
6
mozilla/netwerk/cache/public/MANIFEST
vendored
@@ -1,6 +0,0 @@
|
||||
nsICachedNetData.idl
|
||||
nsINetDataCache.idl
|
||||
nsINetDataCacheManager.idl
|
||||
nsINetDataCacheRecord.idl
|
||||
nsINetDataDiskCache.idl
|
||||
nsIStreamAsFile.idl
|
||||
56
mozilla/netwerk/cache/public/Makefile.in
vendored
56
mozilla/netwerk/cache/public/Makefile.in
vendored
@@ -1,56 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
MODULE = nkcache
|
||||
XPIDL_MODULE = necko_cache
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsICachedNetData.idl \
|
||||
nsINetDataCacheManager.idl \
|
||||
nsINetDataCache.idl \
|
||||
nsINetDataCacheRecord.idl \
|
||||
nsINetDataDiskCache.idl \
|
||||
nsIStreamAsFile.idl \
|
||||
$(NULL)
|
||||
|
||||
|
||||
ifdef MOZ_NEW_CACHE
|
||||
XPIDLSRCS += \
|
||||
nsICache.idl \
|
||||
nsICacheEntryDescriptor.idl \
|
||||
nsICacheListener.idl \
|
||||
nsICacheService.idl \
|
||||
nsICacheSession.idl \
|
||||
nsICacheVisitor.idl \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
51
mozilla/netwerk/cache/public/Makefile.win
vendored
51
mozilla/netwerk/cache/public/Makefile.win
vendored
@@ -1,51 +0,0 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
MODULE = necko
|
||||
XPIDL_MODULE = necko_cache
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
|
||||
EXPORTS = \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsICachedNetData.idl \
|
||||
.\nsINetDataCacheManager.idl \
|
||||
.\nsINetDataCache.idl \
|
||||
.\nsINetDataCacheRecord.idl \
|
||||
.\nsINetDataDiskCache.idl \
|
||||
.\nsIStreamAsFile.idl \
|
||||
!ifdef MOZ_NEW_CACHE
|
||||
.\nsICache.idl \
|
||||
.\nsICacheEntryDescriptor.idl \
|
||||
.\nsICacheListener.idl \
|
||||
.\nsICacheService.idl \
|
||||
.\nsICacheSession.idl \
|
||||
.\nsICacheVisitor.idl \
|
||||
!endif
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
|
||||
158
mozilla/netwerk/cache/public/nsICache.idl
vendored
158
mozilla/netwerk/cache/public/nsICache.idl
vendored
@@ -1,158 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsICache.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
typedef long nsCacheStoragePolicy;
|
||||
typedef long nsCacheAccessMode;
|
||||
|
||||
/**
|
||||
* nsICache is a namespace for various cache constants. It does not represent
|
||||
* an actual object.
|
||||
*/
|
||||
[scriptable, uuid(ec1c0063-197d-44bb-84ba-7525d50fc937)]
|
||||
interface nsICache
|
||||
{
|
||||
/**
|
||||
* Access Modes
|
||||
*
|
||||
*
|
||||
* Mode Requested | Not Cached | Cached
|
||||
* ------------------------------------------------------------------------
|
||||
* READ | KEY_NOT_FOUND | NS_OK
|
||||
* | Mode = NONE | Mode = READ
|
||||
* | No Descriptor | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
* WRITE | NS_OK | NS_OK (Cache service
|
||||
* | Mode = WRITE | Mode = WRITE dooms existing
|
||||
* | Descriptor | Descriptor cache entry)
|
||||
* ------------------------------------------------------------------------
|
||||
* READ_WRITE | NS_OK | NS_OK
|
||||
* (1st req.) | Mode = WRITE | Mode = READ_WRITE
|
||||
* | Descriptor | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
* READ_WRITE | N/A | NS_OK
|
||||
* (Nth req.) | | Mode = READ
|
||||
* | | Descriptor
|
||||
* ------------------------------------------------------------------------
|
||||
*
|
||||
*
|
||||
* Access Requested:
|
||||
*
|
||||
* READ - I only want to READ, if there isn't an entry just fail
|
||||
* WRITE - I have something new I want to write into the cache, make
|
||||
* me a new entry and doom the old one, if any.
|
||||
* READ_WRITE - I want to READ, but I'm willing to update an existing
|
||||
* entry if necessary, or create a new one if none exists.
|
||||
*
|
||||
*
|
||||
* Access Granted:
|
||||
*
|
||||
* NONE - No descriptor is provided. You get zilch. Nada. Nothing.
|
||||
* READ - You can READ from this descriptor.
|
||||
* WRITE - You must WRITE to this descriptor because the cache entry
|
||||
* was just created for you.
|
||||
* READ_WRITE - You can READ the descriptor to determine if it's valid,
|
||||
* you may WRITE if it needs updating.
|
||||
*
|
||||
*
|
||||
* Comments:
|
||||
*
|
||||
* If you think that you might need to modify cached data or meta data,
|
||||
* then you must open a cache entry requesting WRITE access. Only one
|
||||
* cache entry descriptor, per cache entry, will be granted WRITE access.
|
||||
*
|
||||
* Usually, you will request READ_WRITE access in order to first test the
|
||||
* meta data and informational fields to determine if a write (ie. going
|
||||
* to the net) may actually be necessary. If you determine that it is
|
||||
* not, then you would mark the cache entry as valid (using MarkValid) and
|
||||
* then simply read the data from the cache.
|
||||
*
|
||||
* A descriptor granted WRITE access has exclusive access to the cache
|
||||
* entry up to the point at which it marks it as valid. Once the cache
|
||||
* entry has been "validated", other descriptors with READ access may be
|
||||
* opened to the cache entry.
|
||||
*
|
||||
* If you make a request for READ_WRITE access to a cache entry, the cache
|
||||
* service will downgrade your access to READ if there is already a
|
||||
* cache entry descriptor open with WRITE access.
|
||||
*
|
||||
* If you make a request for only WRITE access to a cache entry and another
|
||||
* descriptor with WRITE access is currently open, then the existing cache
|
||||
* entry will be 'doomed', and you will be given a descriptor (with WRITE
|
||||
* access only) to a new cache entry.
|
||||
*
|
||||
*/
|
||||
const nsCacheAccessMode ACCESS_NONE = 0;
|
||||
const nsCacheAccessMode ACCESS_READ = 1;
|
||||
const nsCacheAccessMode ACCESS_WRITE = 2;
|
||||
const nsCacheAccessMode ACCESS_READ_WRITE = 3;
|
||||
|
||||
/**
|
||||
* Storage Policy
|
||||
*
|
||||
* The storage policy of a cache entry determines the device(s) to which
|
||||
* it belongs. See nsICacheSession and nsICacheEntryDescriptor for more
|
||||
* details.
|
||||
*
|
||||
* STORE_ANYWHERE - Allows the cache entry to be stored in any device.
|
||||
* The cache service decides which cache device to use
|
||||
* based on "some resource management calculation."
|
||||
* STORE_IN_MEMORY - Requires the cache entry to reside in non-persistent
|
||||
* storage (ie. typically in system RAM).
|
||||
* STORE_ON_DISK - Requires the cache entry to reside in persistent
|
||||
* storage (ie. typically on a system's hard disk).
|
||||
* STORE_ON_DISK_AS_DISK - Requires the cache entry to reside in persistent
|
||||
* storage, and in a specific file.
|
||||
*/
|
||||
const nsCacheStoragePolicy STORE_ANYWHERE = 0;
|
||||
const nsCacheStoragePolicy STORE_IN_MEMORY = 1;
|
||||
const nsCacheStoragePolicy STORE_ON_DISK = 2;
|
||||
const nsCacheStoragePolicy STORE_ON_DISK_AS_FILE = 3;
|
||||
|
||||
/**
|
||||
* All entries for a cache session are stored as streams of data or
|
||||
* as objects. These constant my be used to specify the type of entries
|
||||
* when calling nsICacheService::CreateSession().
|
||||
*/
|
||||
const long NOT_STREAM_BASED = 0;
|
||||
const long STREAM_BASED = 1;
|
||||
};
|
||||
|
||||
|
||||
%{C++
|
||||
|
||||
/**
|
||||
* Cache specific nsresult error codes
|
||||
*/
|
||||
#define NS_ERROR_CACHE_KEY_NOT_FOUND NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 60)
|
||||
#define NS_ERROR_CACHE_DATA_IS_STREAM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 61)
|
||||
#define NS_ERROR_CACHE_DATA_IS_NOT_STREAM NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 62)
|
||||
#define NS_ERROR_CACHE_WAIT_FOR_VALIDATION NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 63)
|
||||
#define NS_ERROR_CACHE_ENTRY_DOOMED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 64)
|
||||
#define NS_ERROR_CACHE_READ_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 65)
|
||||
#define NS_ERROR_CACHE_WRITE_ACCESS_DENIED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 66)
|
||||
|
||||
%}
|
||||
@@ -1,137 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsICacheEntryDescriptor.idl, released
|
||||
* February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsICacheVisitor.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICacheListener;
|
||||
interface nsITransport;
|
||||
interface nsIFile;
|
||||
interface nsICacheMetaDataVisitor;
|
||||
|
||||
|
||||
[scriptable, uuid(49c1a11d-f5d2-4f09-8262-551e64908ada)]
|
||||
interface nsICacheEntryDescriptor : nsICacheEntryInfo
|
||||
{
|
||||
/**
|
||||
* Set the time at which the cache entry should be considered invalid (in
|
||||
* seconds since the Epoch).
|
||||
*/
|
||||
void setExpirationTime(in PRUint32 expirationTime);
|
||||
|
||||
/**
|
||||
* Set the cache entry data size. This will fail if the cache entry
|
||||
* IS stream based.
|
||||
*/
|
||||
void setDataSize(in unsigned long size);
|
||||
|
||||
/**
|
||||
* Get a transport to the cache data. This will fail if the cache entry
|
||||
* IS NOT stream based.
|
||||
*/
|
||||
readonly attribute nsITransport transport;
|
||||
|
||||
/**
|
||||
* Get/set the cache data element. This will fail if the cache entry
|
||||
* IS stream based. The cache entry holds a strong reference to this
|
||||
* object. The object will be released when the cache entry is destroyed.
|
||||
*/
|
||||
attribute nsISupports cacheElement;
|
||||
|
||||
/**
|
||||
* Get the access granted to this descriptor. See nsICache.idl for the
|
||||
* definitions of the access modes and a thorough description of their
|
||||
* corresponding meanings.
|
||||
*/
|
||||
readonly attribute nsCacheAccessMode accessGranted;
|
||||
|
||||
/**
|
||||
* Get/set the storage policy of the cache entry. See nsICache.idl for
|
||||
* the definitions of the storage policies.
|
||||
*/
|
||||
attribute nsCacheStoragePolicy storagePolicy;
|
||||
|
||||
/**
|
||||
* Get the disk file associated with the cache entry.
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
|
||||
/**
|
||||
* Get/set security info on the cache entry for this descriptor. This fails
|
||||
* if the storage policy is not STORE_IN_MEMORY.
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Doom the cache entry this descriptor references in order to slate it for
|
||||
* removal. Once doomed a cache entry cannot be undoomed.
|
||||
*
|
||||
* A descriptor with WRITE access can doom the cache entry and choose to
|
||||
* fail pending requests. This means that pending requests will not get
|
||||
* a cache descriptor. This is meant as a tool for clients that wish to
|
||||
* instruct pending requests to skip the cache.
|
||||
*/
|
||||
void doom();
|
||||
void doomAndFailPendingRequests(in nsresult status);
|
||||
|
||||
/**
|
||||
* A writer must validate this cache object before any readers are given
|
||||
* a descriptor to the object.
|
||||
*/
|
||||
void markValid();
|
||||
|
||||
/**
|
||||
* Explicitly close the descriptor (optional).
|
||||
*/
|
||||
|
||||
void close();
|
||||
|
||||
/**
|
||||
* Methods for accessing meta data. Meta data is a table of key/value
|
||||
* string pairs. The strings do not have to conform to any particular
|
||||
* charset, but they must be null terminated.
|
||||
*/
|
||||
string getMetaDataElement(in string key);
|
||||
void setMetaDataElement(in string key, in string value);
|
||||
|
||||
/**
|
||||
* Visitor will be called with key/value pair for each meta data element.
|
||||
*/
|
||||
void visitMetaData(in nsICacheMetaDataVisitor visitor);
|
||||
};
|
||||
|
||||
|
||||
|
||||
[scriptable, uuid(22f9a49c-3cf8-4c23-8006-54efb11ac562)]
|
||||
interface nsICacheMetaDataVisitor : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called for each key/value pair in the meta data for a cache entry
|
||||
*/
|
||||
boolean visitMetaDataElement(in string key,
|
||||
in string value);
|
||||
};
|
||||
@@ -1,44 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsICacheListener.idl, released January 19, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
|
||||
interface nsICacheEntryDescriptor;
|
||||
|
||||
[scriptable, uuid(638c3848-778b-4851-8ff3-9400f65b8773)]
|
||||
interface nsICacheListener : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called when the requested access (or appropriate subset) is
|
||||
* acquired. The status parameter equals NS_OK on success.
|
||||
* See nsICacheService.idl for accessGranted values.
|
||||
*/
|
||||
void onCacheEntryAvailable(in nsICacheEntryDescriptor descriptor,
|
||||
in nsCacheAccessMode accessGranted,
|
||||
in nsresult status);
|
||||
};
|
||||
80
mozilla/netwerk/cache/public/nsICacheService.idl
vendored
80
mozilla/netwerk/cache/public/nsICacheService.idl
vendored
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsICacheService.idl, released February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICacheListener;
|
||||
interface nsICacheSession;
|
||||
interface nsICacheVisitor;
|
||||
|
||||
[scriptable, uuid(0ebec4c7-742f-4f27-8e7b-7c8a0cc76348)]
|
||||
interface nsICacheService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Initialize the cache service.
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* Shutdown the cache service.
|
||||
*/
|
||||
void shutdown();
|
||||
|
||||
/**
|
||||
* Create a cache session
|
||||
*
|
||||
* A cache session represents a client's access into the cache. The cache
|
||||
* session is not "owned" by the cache service. Hence, it is possible to
|
||||
* create duplicate cache sessions. Entries created by a cache session
|
||||
* are invisible to other cache sessions, unless the cache sessions are
|
||||
* equivalent.
|
||||
*
|
||||
* @param clientID - Specifies the name of the client using the cache.
|
||||
* @param storagePolicy - Limits the storage policy for all entries
|
||||
* accessed via the returned session. As a result, devices excluded
|
||||
* by the storage policy will not be searched when opening entries
|
||||
* from the returned session.
|
||||
* @param streamBased - Indicates whether or not the data being cached
|
||||
* can be represented as a stream. The storagePolicy must be
|
||||
* consistent with the value of this field. For example, a non-stream-
|
||||
* based cache entry can only have a storage policy of STORE_IN_MEMORY.
|
||||
* @return new cache session.
|
||||
*/
|
||||
nsICacheSession createSession(in string clientID,
|
||||
in nsCacheStoragePolicy storagePolicy,
|
||||
in boolean streamBased);
|
||||
|
||||
/**
|
||||
* Visit entries stored in the cache. Used to implement about:cache.
|
||||
*/
|
||||
void visitEntries(in nsICacheVisitor visitor);
|
||||
|
||||
/**
|
||||
* Evicts all entries in all devices implied by the storage policy.
|
||||
*/
|
||||
void evictEntries(in nsCacheStoragePolicy storagePolicy);
|
||||
};
|
||||
71
mozilla/netwerk/cache/public/nsICacheSession.idl
vendored
71
mozilla/netwerk/cache/public/nsICacheSession.idl
vendored
@@ -1,71 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsICacheSession.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsICache.idl"
|
||||
|
||||
interface nsICacheEntryDescriptor;
|
||||
interface nsICacheListener;
|
||||
|
||||
[scriptable, uuid(b4b419ad-28b7-4d25-9988-20fa98505a19)]
|
||||
interface nsICacheSession : nsISupports
|
||||
{
|
||||
/**
|
||||
* Expired entries will be doomed or evicted if this attribute is set to
|
||||
* true. If false, expired entries will be returned (useful for offline-
|
||||
* mode and clients, such as HTTP, that can update the valid lifetime of
|
||||
* cached content). This attribute defaults to true.
|
||||
*/
|
||||
attribute PRBool doomEntriesIfExpired;
|
||||
|
||||
/**
|
||||
* A cache session can only give out one descriptor with WRITE access
|
||||
* to a given cache entry at a time. Until the client calls MarkValid on
|
||||
* its descriptor, other attempts to open the same cache entry will block.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Synchronous cache access. This returns a unique descriptor each
|
||||
* time it is called, even if the same key is specified. When
|
||||
* called by multiple threads for write access, only one writable
|
||||
* descriptor will be granted.
|
||||
*/
|
||||
nsICacheEntryDescriptor openCacheEntry(in string key,
|
||||
in nsCacheAccessMode accessRequested);
|
||||
|
||||
/**
|
||||
* Asynchronous cache access. Does not block the calling thread.
|
||||
* Instead, the listener will be notified when the descriptor is
|
||||
* available.
|
||||
*/
|
||||
void asyncOpenCacheEntry(in string key,
|
||||
in nsCacheAccessMode accessRequested,
|
||||
in nsICacheListener listener);
|
||||
|
||||
/**
|
||||
* Evict all entries for this session's clientID according to its storagePolicy.
|
||||
*/
|
||||
void evictEntries();
|
||||
};
|
||||
137
mozilla/netwerk/cache/public/nsICacheVisitor.idl
vendored
137
mozilla/netwerk/cache/public/nsICacheVisitor.idl
vendored
@@ -1,137 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsICacheVisitor.idl, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* XXX we should define device and entry info as well (stats, etc) */
|
||||
|
||||
interface nsICacheDeviceInfo;
|
||||
interface nsICacheEntryInfo;
|
||||
|
||||
|
||||
[scriptable, uuid(f8c08c4b-d778-49d1-a59b-866fdc500d95)]
|
||||
interface nsICacheVisitor : nsISupports
|
||||
{
|
||||
/**
|
||||
* Called to provide information about a cache device.
|
||||
*
|
||||
* @param deviceID - specifies the device being visited.
|
||||
* @param deviceInfo - specifies information about this device.
|
||||
*
|
||||
* @return true to start visiting all entries for this device.
|
||||
* @return false to advance to the next device.
|
||||
*/
|
||||
boolean visitDevice(in string deviceID,
|
||||
in nsICacheDeviceInfo deviceInfo);
|
||||
|
||||
/**
|
||||
* Called to provide information about a cache entry.
|
||||
*
|
||||
* @param deviceID - specifies the device being visited.
|
||||
* @param entryInfo - specifies information about this entry.
|
||||
*
|
||||
* @return true to visit the next entry on the current device, or if the
|
||||
* end of the device has been reached, advance to the next device.
|
||||
* @return false to advance to the next device.
|
||||
*/
|
||||
boolean visitEntry(in string deviceID,
|
||||
in nsICacheEntryInfo entryInfo);
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(31d1c294-1dd2-11b2-be3a-c79230dca297)]
|
||||
interface nsICacheDeviceInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get a human readable description of the cache device.
|
||||
*/
|
||||
readonly attribute string description;
|
||||
|
||||
/**
|
||||
* Get a usage report, statistics, miscellaneous data about
|
||||
* the cache device.
|
||||
*/
|
||||
readonly attribute string usageReport;
|
||||
|
||||
/**
|
||||
* Get the number of stored cache entries.
|
||||
*/
|
||||
readonly attribute unsigned long entryCount;
|
||||
|
||||
/**
|
||||
* Get the total size of the stored cache entries.
|
||||
*/
|
||||
readonly attribute unsigned long totalSize;
|
||||
|
||||
/**
|
||||
* Get the upper limit of the size of the data the cache can store.
|
||||
*/
|
||||
readonly attribute unsigned long maximumSize;
|
||||
};
|
||||
|
||||
|
||||
[scriptable, uuid(72c64022-1dd2-11b2-b3a5-b8b859e0a1b2)]
|
||||
interface nsICacheEntryInfo : nsISupports
|
||||
{
|
||||
/**
|
||||
* Get the client id associated with this cache entry.
|
||||
*/
|
||||
readonly attribute string clientID;
|
||||
|
||||
/**
|
||||
* Get the key identifying the cache entry.
|
||||
*/
|
||||
readonly attribute string key;
|
||||
|
||||
/**
|
||||
* Get the number of times the cache entry has been opened.
|
||||
*/
|
||||
readonly attribute long fetchCount;
|
||||
|
||||
/**
|
||||
* Get the last time the cache entry was opened (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 lastFetched;
|
||||
|
||||
/**
|
||||
* Get the last time the cache entry was modified (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 lastModified;
|
||||
|
||||
/**
|
||||
* Get the expiration time of the cache entry (in seconds since the Epoch).
|
||||
*/
|
||||
readonly attribute PRUint32 expirationTime;
|
||||
|
||||
/**
|
||||
* Get the cache entry data size.
|
||||
*/
|
||||
readonly attribute unsigned long dataSize;
|
||||
|
||||
/**
|
||||
* Find out whether or not the cache entry is stream based.
|
||||
*/
|
||||
boolean isStreamBased();
|
||||
};
|
||||
240
mozilla/netwerk/cache/public/nsICachedNetData.idl
vendored
240
mozilla/netwerk/cache/public/nsICachedNetData.idl
vendored
@@ -1,240 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIObserver;
|
||||
interface nsIChannel;
|
||||
interface nsINetDataCache;
|
||||
interface nsINetDataCacheRecord;
|
||||
interface nsILoadGroup;
|
||||
interface nsIStreamListener;
|
||||
|
||||
/**
|
||||
* The nsICachedNetData interface represents a single entry in a database that
|
||||
* caches data retrieved from the network. This interface is implemented by the
|
||||
* cache manager on top of the low-level nsINetDataCacheRecord and
|
||||
* nsINetDataCache interfaces that are implemented by the database.
|
||||
*
|
||||
* Each cache record may contain both content and metadata. The content may
|
||||
* be, for example, GIF image data or HTML, and it is accessed through
|
||||
* nsIChannel's streaming API. The opaque metadata, which may contain HTTP
|
||||
* headers among other things, is stored as a byte array. Each entry in the
|
||||
* cache is indexed by two different keys: a record id number and a key created
|
||||
* by combining the URI with a "secondary key", e.g. HTTP post data.
|
||||
*
|
||||
* @See nsINetDataCacheRecord
|
||||
* @See nsINetDataCache
|
||||
* @See nsINetDataDiskCache
|
||||
* @See nsINetDataCacheManager
|
||||
*/
|
||||
[scriptable, uuid(6aeb2a40-6d43-11d3-90c8-000064657374)]
|
||||
interface nsICachedNetData : nsISupports
|
||||
{
|
||||
/**
|
||||
* String form of the URI provided as an argument to the call to
|
||||
* nsINetDataCacheManager::GetCachedNetData() that created this record.
|
||||
*/
|
||||
readonly attribute string uriSpec;
|
||||
|
||||
/**
|
||||
* Getter for the opaque secondary database key provided as an argument to
|
||||
* the call to nsINetDataCacheManager::GetCachedNetData() that created this
|
||||
* record.
|
||||
*/
|
||||
void getSecondaryKey(out unsigned long length,
|
||||
[retval, size_is(length)] out string secondaryKey);
|
||||
|
||||
/**
|
||||
* This flag may be set by a protocol handler to indicate that it supports
|
||||
* partial fetching of data. In that case, the cache manager is permitted
|
||||
* to truncate the entry's content to accommodate incoming data for other
|
||||
* cache entries rather than deleting it wholesale.
|
||||
*/
|
||||
attribute boolean allowPartial;
|
||||
|
||||
/**
|
||||
* This flag indicates that the write stream supplying content data for the
|
||||
* cache did not complete normally and, therefore, the content may be
|
||||
* truncated.
|
||||
*/
|
||||
readonly attribute boolean partialFlag;
|
||||
|
||||
/**
|
||||
* This flag can be set and cleared by a protocol handler as a form of
|
||||
* self-notification, so as to avoid race conditions in which a protocol
|
||||
* handler issues two identical network requests to fill the same cache
|
||||
* entry. The cache manager itself largely ignores this flag.
|
||||
*/
|
||||
attribute boolean updateInProgress;
|
||||
|
||||
/**
|
||||
* inUse is set if any existing channels are associated with this cache
|
||||
* entry or if the updateInProgess flag is set. This can be used to
|
||||
* prevent writing to a cache entry by a protocol handler if it's being
|
||||
* read or written elsewhere.
|
||||
*/
|
||||
readonly attribute boolean inUse;
|
||||
|
||||
/**
|
||||
* Date/time that the document was last stored on the origin server, as
|
||||
* supplied by the protocol handler. This value is used as input to the
|
||||
* cache replacement policy, i.e. it is not used for validation. If the
|
||||
* protocol can't supply a last-modified time, this attribute should remain
|
||||
* unset. When unset, the value of this attribute is zero.
|
||||
*
|
||||
* FIXME: Should use nsIDateTime interface, once it's created
|
||||
* instead of PRTime, for improved scriptability ?
|
||||
*/
|
||||
attribute PRTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
* Supplied by the protocol handler, the expirationTime attribute specifies
|
||||
* the time until which the document is guaranteed fresh, i.e. the document
|
||||
* does not have to be validated with the server and, therefore, any data
|
||||
* in cache is definitely usable. The value of this attribute serves as a
|
||||
* hint to the cache replacement policy. Only one of either staleTime or
|
||||
* expirationTime may be set for a single cache record. When unset, the
|
||||
* value of this attribute is zero.
|
||||
*/
|
||||
attribute PRTime expirationTime;
|
||||
|
||||
/**
|
||||
* Date/time supplied by the protocol handler, at which point the content
|
||||
* is *likely* to be stale, i.e. the data in the cache may be out-of-date
|
||||
* with respect to the data on the server. This heuristic date does not
|
||||
* necessarily correspond to the HTTP Expires header, as it does not
|
||||
* determine when cached network data must be validated with the origin
|
||||
* server, but only serves as a hint to the cache replacement policy. Only
|
||||
* one of either staleTime or expirationTime may be set for a single cache
|
||||
* record. When unset, the value of this attribute is zero.
|
||||
*/
|
||||
attribute PRTime staleTime;
|
||||
|
||||
/**
|
||||
* Date/time of last access of the data in this cache record, as determined
|
||||
* by the cache manager.
|
||||
*/
|
||||
readonly attribute PRTime lastAccessTime;
|
||||
|
||||
readonly attribute PRTime lastUpdateTime;
|
||||
|
||||
/**
|
||||
* Number of times this record has been accessed since it was first stored.
|
||||
*/
|
||||
readonly attribute PRUint16 numberAccesses;
|
||||
|
||||
/**
|
||||
* Accessor methods for opaque meta-data which can be read and updated
|
||||
* independently of the content data.
|
||||
*
|
||||
* The aTag argument can be used to accommodate multiple clients of the
|
||||
* cache API, each of which wants to store its own private meta-data into
|
||||
* the cache. For example, there could be a "headers" tag that the HTTP
|
||||
* protocol handler uses to store http response headers and a "image size"
|
||||
* tag used to store the image dimensions of a GIF file. The aData
|
||||
* argument refers to an opaque blob of arbitrary bytes.
|
||||
*
|
||||
* IMPORTANT: If aData does not contain byte-oriented data, i.e. it's not a
|
||||
* string, the contents of aData must be byte-swapped by the,
|
||||
* caller, so as to make the cache files endian-independent.
|
||||
*/
|
||||
void getAnnotation(in string aTag,
|
||||
out PRUint32 aLength, [size_is(aLength), retval] out string aData);
|
||||
void setAnnotation(in string aTag,
|
||||
in PRUint32 aLength, [size_is(aLength)] in string aData);
|
||||
|
||||
/**
|
||||
* As a getter, return the number of content bytes stored in the cache,
|
||||
* i.e. via the nsIChannel streaming APIs. This may be less than the
|
||||
* complete content length if a partial cache fill occurred. The cached
|
||||
* content can be truncated by setting the value of this attribute. The
|
||||
* value of the attribute represents a logical, not a physical, length. If
|
||||
* compression has been used, the content may consume less storage than
|
||||
* indicated by this attribute.
|
||||
*
|
||||
* When this attribute is set to zero the associated cache disk file, if
|
||||
* any, should be deleted.
|
||||
*/
|
||||
attribute PRUint32 storedContentLength;
|
||||
|
||||
/**
|
||||
* Length of stored content, which may be less than storage consumed if
|
||||
* compression is used
|
||||
*/
|
||||
readonly attribute PRUint32 logicalLength;
|
||||
|
||||
/**
|
||||
* Opaque security info associated with the cache entry; it can't be serialized
|
||||
* to disk, so it'll only make sense with memory cache
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Notify any observers associated with this cache entry of the deletion
|
||||
* request. If all observers drop their reference to the cache entry,
|
||||
* proceed to delete the underlying cache database record and associated
|
||||
* content storage.
|
||||
*/
|
||||
void delete();
|
||||
|
||||
/**
|
||||
* Flush any changes in this entry's data to the cache database. This
|
||||
* method will automatically be called when the last reference to the cache
|
||||
* is dropped, but it can also be called explicitly for a synchronous
|
||||
* effect.
|
||||
*/
|
||||
void commit();
|
||||
|
||||
/**
|
||||
* Parent container cache for this entry.
|
||||
*/
|
||||
readonly attribute nsINetDataCache cache;
|
||||
|
||||
/**
|
||||
* Create a channel for reading or writing a stream of content into the
|
||||
* entry. It is expected that many of the nsIChannel methods return
|
||||
* NS_NOT_IMPLEMENTED, including:
|
||||
*
|
||||
* + GetURI()
|
||||
* + GetContentType()
|
||||
* + GetContentLength()
|
||||
*
|
||||
* Though nsIChannel provides for both async and synchronous I/O APIs, both
|
||||
* may not be implemented. Only AsyncRead() and OpenOutputStream() is
|
||||
* required.
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup aLoadGroup);
|
||||
|
||||
/**
|
||||
* This method can be used by a caching protocol handler to store data in
|
||||
* the cache by forking an asynchronous read stream so that it is
|
||||
* simultaneously sent to a requester and written into the cache. This
|
||||
* method implicitly sets the updateInProgress flag, if it has not already
|
||||
* been set.
|
||||
*/
|
||||
nsIStreamListener interceptAsyncRead(in nsIStreamListener aOriginalListener,
|
||||
in PRUint32 aStartOffset);
|
||||
};
|
||||
142
mozilla/netwerk/cache/public/nsINetDataCache.idl
vendored
142
mozilla/netwerk/cache/public/nsINetDataCache.idl
vendored
@@ -1,142 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsINetDataCacheRecord;
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
/**
|
||||
* The nsINetDataCache defines the low-level API for a network-data
|
||||
* cache, used to cache the responses to network retrieval commands.
|
||||
* This interface, along with nsINetDataCacheRecord, is implemented by
|
||||
* the memory cache, the file cache and, optionally, by some extension
|
||||
* caches. This interface is essentially a pseudo-private API for the
|
||||
* cache manager. Other clients should never use this interface.
|
||||
*
|
||||
* Each cache entry may contain both content, e.g. GIF image data, and
|
||||
* associated metadata, e.g. HTTP headers. Each entry is indexed by two
|
||||
* different keys: a record id number and a key created by combining the URI
|
||||
* with a "secondary key", e.g. HTTP post data.
|
||||
*
|
||||
* The nsINetDataCache interface is agnostic as to where the data is
|
||||
* stored and whether the storage is volatile or persistent. The
|
||||
* memory cache, any disk caches and any extension caches must all
|
||||
* implement this interface.
|
||||
*
|
||||
*/
|
||||
[scriptable, uuid(ccfc58c0-6dde-11d3-90c8-000064657374)]
|
||||
interface nsINetDataCache : nsISupports
|
||||
{
|
||||
/**
|
||||
* Human-readable description of the cache module, e.g. "Disk Cache"
|
||||
*/
|
||||
readonly attribute wstring description;
|
||||
|
||||
/**
|
||||
* Returns true if cached data is available for the given opaque key,
|
||||
* even if only partial data is stored.
|
||||
*/
|
||||
boolean contains([size_is(length)] in string key, in PRUint32 length);
|
||||
|
||||
/**
|
||||
* Fetch the cache entry record for the given opaque key. If one does not
|
||||
* exist, create a new, empty record.
|
||||
*/
|
||||
nsINetDataCacheRecord getCachedNetData([size_is(length)] in string key,
|
||||
in PRUint32 length);
|
||||
|
||||
/**
|
||||
* Fetch the cache entry record for the given URI using the record ID as a key.
|
||||
*/
|
||||
nsINetDataCacheRecord getCachedNetDataByID(in PRInt32 RecordID);
|
||||
|
||||
/**
|
||||
* False indicates that this cache is entirely bypassed.
|
||||
*/
|
||||
attribute boolean enabled;
|
||||
|
||||
/**
|
||||
* Constants for flags attribute, below
|
||||
*/
|
||||
|
||||
// Used for extension caches, e.g. a CD-ROM cache
|
||||
const long READ_ONLY = 1 << 0;
|
||||
|
||||
// One of these bits must be set
|
||||
const long MEMORY_CACHE = 1 << 1;
|
||||
const long FLAT_FILE_CACHE = 1 << 2;
|
||||
const long FILE_PER_URL_CACHE = 1 << 3;
|
||||
|
||||
/**
|
||||
* See constants defined above.
|
||||
*/
|
||||
readonly attribute PRUint32 flags;
|
||||
|
||||
/**
|
||||
* Total number of URI entries stored in the cache.
|
||||
*/
|
||||
readonly attribute PRUint32 numEntries;
|
||||
|
||||
/**
|
||||
* Maximum number of URI entries that may be stored in the cache.
|
||||
*/
|
||||
readonly attribute PRUint32 maxEntries;
|
||||
|
||||
/**
|
||||
* Enumerate the URI entries stored in the cache.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheEntryIterator();
|
||||
|
||||
/**
|
||||
* Contains a reference to the next cache in search order. For the memory
|
||||
* cache, this attribute always references the disk cache. For the disk
|
||||
* cache, it contains a reference to the first extension cache.
|
||||
*/
|
||||
attribute nsINetDataCache nextCache;
|
||||
|
||||
/**
|
||||
* An estimate of the amount of storage occupied by the cache, in kB.
|
||||
* Actual use may be slightly higher than reported due to cache overhead
|
||||
* and heap fragmentation (in the memory cache) or block quantization (in
|
||||
* the disk cache).
|
||||
*/
|
||||
readonly attribute PRUint32 storageInUse;
|
||||
|
||||
/**
|
||||
* Remove all entries from a writable cache. This could be used, for
|
||||
* example, after a guest ends a browser session. This is equivalent to
|
||||
* setting the cache's Capacity to zero, except that all cache entries,
|
||||
* even those in active use, will be deleted. Also, any global cache
|
||||
* database files will be deleted.
|
||||
*/
|
||||
void removeAll();
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// ContractID prefix for Components that implement this interface
|
||||
#define NS_NETWORK_CACHE_CONTRACTID "@mozilla.org/network/cache;1"
|
||||
#define NS_NETWORK_MEMORY_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=memory-cache"
|
||||
#define NS_NETWORK_FLAT_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=flat-cache"
|
||||
#define NS_NETWORK_FILE_CACHE_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=file-cache"
|
||||
%}
|
||||
@@ -1,169 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsINetDataCache.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsICachedNetData;
|
||||
interface nsINetDataDiskCache;
|
||||
interface nsIURI;
|
||||
|
||||
/**
|
||||
* The network-response cache manager is partly responsible for the caching of
|
||||
* content and associated metadata that has been retrieved via the network.
|
||||
* (The remaining responsibility for caching lies with individual network
|
||||
* protocol handlers.)
|
||||
*
|
||||
* The cache manager supervises the actions of individual cache components,
|
||||
* such as the memory cache, the disk cache and any extension caches, e.g. a
|
||||
* read-only CD-ROM cache.
|
||||
*
|
||||
* @See nsINetDataCache
|
||||
* @See nsICachedNetData
|
||||
*/
|
||||
[scriptable, uuid(71c8ab00-6d5c-11d3-90c8-000064657374)]
|
||||
interface nsINetDataCacheManager : nsISupports
|
||||
{
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, the memory cache is
|
||||
* neither searched nor will any data be stored into it. This might be
|
||||
* appropriate, for example, with images, because they have their own
|
||||
* cache for storing *decoded* images.
|
||||
*/
|
||||
const unsigned long BYPASS_MEMORY_CACHE = 1 << 0;
|
||||
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, the disk cache
|
||||
* is neither searched nor will any be data stored into it.
|
||||
* However, read-only extension caches may be searched. This
|
||||
* might be used to avoid leaving persistent records of secure
|
||||
* data.
|
||||
*/
|
||||
const unsigned long BYPASS_PERSISTENT_CACHE = 1 << 1;
|
||||
|
||||
/**
|
||||
* Flag for the GetCachedNetData() method: If set, any stream
|
||||
* content is stored in the cache as a single disk file. Content
|
||||
* will not be cached in the memory cache nor is it cached in a
|
||||
* flat-file cache database. This is used to implement the jar
|
||||
* protocol handler and to provide the stream-as-file semantics
|
||||
* required by the classic bowser plugin API.
|
||||
*/
|
||||
const unsigned long CACHE_AS_FILE = 1 << 2;
|
||||
|
||||
/**
|
||||
These enum's are used for the ClearCache calls.
|
||||
*/
|
||||
const unsigned long ALL_CACHES = 1;
|
||||
const unsigned long MEM_CACHE = 1<<1;
|
||||
const unsigned long FILE_CACHE = 1<<2;
|
||||
const unsigned long FLAT_CACHE = 1<<3;
|
||||
/**
|
||||
* Fetch the cache entry record for the given URI. If one does not exist,
|
||||
* create a new, empty record. The normal search order for caches is:
|
||||
* + Memory cache
|
||||
* + Disk cache
|
||||
* + File cache (stream-as-file cache)
|
||||
* + All extension caches
|
||||
*
|
||||
* When writing, data is typically stored in both the memory cache and the
|
||||
* disk cache. Both the search order and this write policy can be modified by
|
||||
* setting one or more of the flag argument bits, as defined above.
|
||||
*
|
||||
* The optionally-NULL secondaryKey argument can be used, e.g. for form
|
||||
* post data or for HTTP headers in the case of HTTP.
|
||||
*/
|
||||
nsICachedNetData getCachedNetData(in string uri,
|
||||
[size_is(secondaryKeyLength)] in string secondaryKey,
|
||||
in PRUint32 secondaryKeyLength,
|
||||
in PRUint32 flags);
|
||||
|
||||
/**
|
||||
* Returns true if cached content is available for the given URI, even if
|
||||
* only partial data is stored. The flags argument behaves the same as for
|
||||
* the GetCachedNetData() method, above.
|
||||
*/
|
||||
boolean contains(in string uri,
|
||||
[size_is(secondaryKeyLength)] in string secondaryKey,
|
||||
in PRUint32 secondaryKeyLength,
|
||||
in PRUint32 flags);
|
||||
|
||||
/**
|
||||
* Total number of unexpired URI entries stored in all caches. This number
|
||||
* does not take into account duplicate URIs, e.g. because the memory cache
|
||||
* and the disk cache might each contain an entry for the same URI.
|
||||
*/
|
||||
readonly attribute PRUint32 numEntries;
|
||||
|
||||
/**
|
||||
* Enumerate the unexpired URI entries stored in all caches. Some URIs may
|
||||
* be enumerated more than once, e.g. because the the memory cache and the
|
||||
* disk cache might each contain an entry for the same URI.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheEntryIterator();
|
||||
|
||||
/*
|
||||
* Enumerate all the loaded nsINetDataCache-implementing cache modules.
|
||||
* The first module enumerated will be the memory cache, the second will be
|
||||
* the disk cache, then the file cache, followed by all the extension
|
||||
* caches, in search order.
|
||||
*/
|
||||
nsISimpleEnumerator newCacheModuleIterator();
|
||||
|
||||
/**
|
||||
* Remove all entries from all writable caches. This could be used, for
|
||||
* example, after a guest ends a browser session. This is equivalent to
|
||||
* setting the DiskCacheCapacity to zero, except that all cache entries,
|
||||
* even those in active use, will be deleted. Also, any global cache
|
||||
* database files will be deleted.
|
||||
*/
|
||||
void removeAll();
|
||||
|
||||
/**
|
||||
* Clears the specified cache
|
||||
*/
|
||||
void clear( in PRUint32 aCacheToClear );
|
||||
|
||||
/**
|
||||
* The disk cache is made up of the file cache (for stream-as-file
|
||||
* requests) and a (possibly independent) persistent cache that handles all
|
||||
* other cache requests. This attribute sets/gets the combined capacity of
|
||||
* these caches, measured in KBytes. Setting the capacity lower than the
|
||||
* current amount of space currently in use may cause cache entries to be
|
||||
* evicted from the cache to accomodate the requested capacity.
|
||||
*/
|
||||
attribute PRUint32 diskCacheCapacity;
|
||||
|
||||
/**
|
||||
* This attribute sets/gets the capacity of the memory cache, measured in
|
||||
* KBytes. Setting the capacity lower than the current amount of space
|
||||
* currently in use may cause cache entries to be evicted from the cache to
|
||||
* accomodate the requested capacity.
|
||||
*/
|
||||
attribute PRUint32 memCacheCapacity;
|
||||
};
|
||||
|
||||
%{ C++
|
||||
// ContractID prefix for Components that implement this interface
|
||||
#define NS_NETWORK_CACHE_MANAGER_CONTRACTID NS_NETWORK_CACHE_CONTRACTID "?name=manager"
|
||||
%}
|
||||
@@ -1,131 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsrootidl.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIChannel;
|
||||
interface nsINetDataCache;
|
||||
|
||||
/**
|
||||
* The nsINetDataCacheRecord represents a single entry in a database that
|
||||
* caches data retrieved from the network. On top of this low-level interface
|
||||
* to the raw record data, the cache manager implements a higher-level record
|
||||
* interface, nsICachedNetData. Each instance of nsINetDataCacheRecord is
|
||||
* (internally) associated with a parent database, an instance of the
|
||||
* nsINetDataCache interface. This interface is essentially a pseudo-private
|
||||
* API for the cache manager. Other clients should never use this interface.
|
||||
*
|
||||
* Each cache record may contain both content and metadata. The content may
|
||||
* be, for example, GIF image data or HTML, and it is accessed through
|
||||
* nsIChannel's streaming API. The opaque metadata, which may contain HTTP
|
||||
* headers among other things, is accessed as a contiguous byte array. Each
|
||||
* entry in the cache is indexed by two different keys: a unique record id
|
||||
* number, generated by the cache, and an opaque string. The latter contains
|
||||
* the URI and other secondary key information, e.g. HTTP form post key/value
|
||||
* pairs.
|
||||
*
|
||||
* The nsINetDataCacheRecord interface is agnostic as to where the data is
|
||||
* stored and whether the storage is volatile or persistent. The memory cache,
|
||||
* the disk cache, a flat-file cache and any read-only extension caches must
|
||||
* all implement this interface.
|
||||
*
|
||||
* @See nsICachedNetData
|
||||
* @See nsINetDataCache
|
||||
* @See nsINetDataDiskCache
|
||||
* @See nsINetDataCacheManager
|
||||
*/
|
||||
|
||||
interface nsILoadGroup;
|
||||
|
||||
[scriptable, uuid(fdcdd6a0-7461-11d3-90ca-0040056a906e)]
|
||||
interface nsINetDataCacheRecord : nsISupports
|
||||
{
|
||||
/**
|
||||
* As far as the nsINetDataCacheRecord implementation is concerned, the
|
||||
* cache entry database key is an opaque blob, but it's intended to contain
|
||||
* both the URI and any secondary keys, such as HTTP post data.
|
||||
*/
|
||||
void getKey(out unsigned long length, [size_is(length), retval] out string key);
|
||||
|
||||
/**
|
||||
* A persistent record number assigned by the cache which must be unique
|
||||
* among all entries stored within the same cache. The record ID serves as
|
||||
* an alternate key to the cache record. Providing that they satisfy the
|
||||
* afforementioned uniqueness requirement, record IDs can be assigned any
|
||||
* value by the database except that they may never be zero.
|
||||
*/
|
||||
readonly attribute PRInt32 recordID;
|
||||
|
||||
/**
|
||||
* Opaque data which can be updated for each cache entry independently of
|
||||
* the content data. This data is a combination of protocol-independent
|
||||
* data provided by the cache manager and protocol-specific meta-data,
|
||||
* e.g. HTTP headers.
|
||||
*/
|
||||
void getMetaData(out PRUint32 length, [size_is(length), retval] out string metaData);
|
||||
void setMetaData(in PRUint32 length, [size_is(length)] in string data);
|
||||
|
||||
/**
|
||||
* Number of content bytes stored in the cache, i.e. via the nsIChannel
|
||||
* streaming APIs. This may be less than the complete content length if a
|
||||
* partial cache fill occurred. Additionally, the cached content can be
|
||||
* truncated by reducing the value of this attribute. When this attribute
|
||||
* is set to zero the associated cache disk file, if any, should be
|
||||
* deleted.
|
||||
*/
|
||||
attribute PRUint32 storedContentLength;
|
||||
|
||||
/**
|
||||
* Opaque security info associated with the cache entry; it can't be serialized
|
||||
* to disk, so it'll only make sense with memory cache
|
||||
*/
|
||||
attribute nsISupports securityInfo;
|
||||
|
||||
/**
|
||||
* Delete this cache entry and its associated content.
|
||||
*/
|
||||
void delete();
|
||||
|
||||
/**
|
||||
* Create a channel for reading or writing a stream of content into the
|
||||
* entry. However, many of the nsIChannel methods may return
|
||||
* NS_NOT_IMPLEMENTED, including:
|
||||
*
|
||||
* + GetURI()
|
||||
* + GetContentType()
|
||||
* + GetContentLength()
|
||||
*/
|
||||
nsIChannel newChannel(in nsILoadGroup loadGroup);
|
||||
|
||||
/**
|
||||
* If a cache is implemented such that it stores each URI's content in an
|
||||
* individual disk file, this method will identify the file corresponding
|
||||
* to this record. This may be used to implement the "stream-as-file"
|
||||
* semantics required by some plugins and by the 'jar:' protocol handler.
|
||||
* However, not all cache implementations are *required* to store the data
|
||||
* from each URI in an individual file, so it is acceptable for an
|
||||
* implementation of this method to signal NS_NOT_IMPLEMENTED.
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
};
|
||||
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsINetDataCache.idl"
|
||||
|
||||
interface nsIFile;
|
||||
|
||||
/**
|
||||
* A network-data disk cache is used to persistently cache the responses to
|
||||
* network retrieval commands. Each cache entry may contain both content,
|
||||
* e.g. GIF image data, and associated metadata, e.g. HTTP headers.
|
||||
*/
|
||||
[scriptable, uuid(6408e390-6f13-11d3-90c8-000064657374)]
|
||||
interface nsINetDataDiskCache : nsINetDataCache
|
||||
{
|
||||
/**
|
||||
* This attribute must be set before calling any other methods of this
|
||||
* interface.
|
||||
*/
|
||||
attribute nsIFile diskCacheFolder;
|
||||
};
|
||||
|
||||
106
mozilla/netwerk/cache/public/nsIStreamAsFile.idl
vendored
106
mozilla/netwerk/cache/public/nsIStreamAsFile.idl
vendored
@@ -1,106 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code, released
|
||||
* March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Scott Furman, fur@netscape.com
|
||||
*/
|
||||
#include "nsrootidl.idl"
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIFile;
|
||||
interface nsIStreamAsFileObserver;
|
||||
|
||||
/**
|
||||
* In addition to enhancing effective network response time via caching, the
|
||||
* cache manager serves a second purpose by providing the stream-as-file
|
||||
* service required by traditional browser plugins and the jar: protocol
|
||||
* handler. The interface below provides a means for a client to determine the
|
||||
* filename associated with a stream and to detect modification/deletion of
|
||||
* that file.
|
||||
*/
|
||||
[scriptable, uuid(0eedbbf0-92d9-11d3-90d3-0040056a906e)]
|
||||
interface nsIStreamAsFile : nsISupports
|
||||
{
|
||||
/**
|
||||
* Filename containing stream-as-file
|
||||
*/
|
||||
readonly attribute nsIFile file;
|
||||
|
||||
/**
|
||||
* Add an observer for this cache record. When the cache wants to delete
|
||||
* or truncate a record, so as to make space for another cache entry's
|
||||
* content data, it will call <code>aObserver</code>'s Observe() method,
|
||||
* passing the nsIStreamAsFile instance as the <code>aSubject</code>
|
||||
* argument and an appropriate message. If the observer does not wish to
|
||||
* inhibit deletion/truncation, it should Release() any references it has to the
|
||||
* cache record.
|
||||
*
|
||||
* @See nsIStreamAsFileObserver
|
||||
*/
|
||||
void addObserver(in nsIStreamAsFileObserver aObserver);
|
||||
|
||||
/**
|
||||
* Delete an observer that was added by the AddObserver() method.
|
||||
*/
|
||||
void removeObserver(in nsIStreamAsFileObserver aObserver);
|
||||
};
|
||||
|
||||
/**
|
||||
* This interface can be implemented by a client to receive notifications of
|
||||
* either modification or deletion of a file created by the cache manager using
|
||||
* the stream-as-file semantics.
|
||||
*/
|
||||
[scriptable, uuid(a26e27c0-92da-11d3-90d3-0040056a906e)]
|
||||
interface nsIStreamAsFileObserver : nsISupports
|
||||
{
|
||||
/**
|
||||
* Flag bits for argument to observeStreamAsFile() method.
|
||||
*/
|
||||
const long NOTIFY_AVAILABLE = 1 << 0; // Stream-as-file now available for reading
|
||||
const long NOTIFY_ERROR = 1 << 1; // Error while loading stream / creating file
|
||||
const long REQUEST_DELETION = 1 << 2; // Cache manager wishes to delete/truncate file
|
||||
const long INVALIDATE = 1 << 3; // File is out-of-date
|
||||
|
||||
// Convenience value
|
||||
const long MAKE_UNAVAILABLE = REQUEST_DELETION | INVALIDATE;
|
||||
|
||||
/**
|
||||
* Receive either a notification or a request concerning a file that has
|
||||
* been opened using stream-as-file. The aMessage and aError arguments
|
||||
* have varying values depending on the nature of the notification.
|
||||
* aMessage is set to NOTIFY_AVAILABLE when a complete stream has been read
|
||||
* and stored on disk in a file. At that point, and no sooner, may the
|
||||
* filename attribute of the associated nsIStreamAsFile be accessed via the
|
||||
* associated nsIStreamAsFile interface. If the aMessage argument is
|
||||
* NOTIFY_ERROR, the aError argument contains the relevant error code. If
|
||||
* the aMessage argument is either REQUEST_DELETION or REQUEST_TRUNCATION,
|
||||
* the callee should immediately Release() all references to the
|
||||
* nsIStreamAsFile (and any references to its associated nsICachedNetData
|
||||
* instances), unless it wishes to inhibit the requested file modification.
|
||||
* If the aMessage argument is INVALIDATE, the cache manager is replacing
|
||||
* the file with a more recent version. If a client wants to continue
|
||||
* using the (now out-of-date) file, it must delete it when it has finished,
|
||||
* as the cache manager will effectively relinquished ownership of the
|
||||
* file.
|
||||
*/
|
||||
void observeStreamAsFile(in nsIStreamAsFile aStreamAsFile,
|
||||
in PRUint32 aMessage,
|
||||
in nsresult aError);
|
||||
};
|
||||
70
mozilla/netwerk/cache/src/Makefile.in
vendored
70
mozilla/netwerk/cache/src/Makefile.in
vendored
@@ -1,70 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = nkcache
|
||||
LIBRARY_NAME = nkcache
|
||||
SHORT_LIBNAME = nkcache
|
||||
IS_COMPONENT = 1
|
||||
REQUIRES = xpcom string necko pref
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheService.h \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsANSIFileStreams.cpp \
|
||||
nsCache.cpp \
|
||||
nsCacheEntry.cpp \
|
||||
nsCacheEntryDescriptor.cpp \
|
||||
nsCacheMetaData.cpp \
|
||||
nsCacheModule.cpp \
|
||||
nsCacheService.cpp \
|
||||
nsCacheSession.cpp \
|
||||
nsDiskCacheDevice.cpp \
|
||||
nsDiskCacheEntry.cpp \
|
||||
nsDiskCacheMap.cpp \
|
||||
nsMemoryCacheDevice.cpp \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
EXTRA_LIBS += \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
#EXTRA_LIBS = $(NSPR_LIBS)
|
||||
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
#override NO_SHARED_LIB=1
|
||||
#override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
68
mozilla/netwerk/cache/src/makefile.win
vendored
68
mozilla/netwerk/cache/src/makefile.win
vendored
@@ -1,68 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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/NPL/
|
||||
#
|
||||
# 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 mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
MODULE = nkcache
|
||||
DLLNAME=nkcache
|
||||
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
|
||||
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
|
||||
|
||||
EXPORTS = \
|
||||
nsCacheService.h \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsCache.obj \
|
||||
.\$(OBJDIR)\nsCacheEntry.obj \
|
||||
.\$(OBJDIR)\nsCacheEntryDescriptor.obj \
|
||||
.\$(OBJDIR)\nsCacheMetaData.obj \
|
||||
.\$(OBJDIR)\nsCacheModule.obj \
|
||||
.\$(OBJDIR)\nsCacheService.obj \
|
||||
.\$(OBJDIR)\nsCacheSession.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheDevice.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheEntry.obj \
|
||||
.\$(OBJDIR)\nsDiskCacheMap.obj \
|
||||
.\$(OBJDIR)\nsANSIFileStreams.obj \
|
||||
.\$(OBJDIR)\nsMemoryCacheDevice.obj \
|
||||
$(NULL)
|
||||
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
|
||||
clobber::
|
||||
$(RM) $(DIST)\bin\components\$(DLLNAME).dll
|
||||
$(RM) $(DIST)\lib\$(DLLNAME).lib
|
||||
388
mozilla/netwerk/cache/src/nsANSIFileStreams.cpp
vendored
388
mozilla/netwerk/cache/src/nsANSIFileStreams.cpp
vendored
@@ -1,388 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsANSIFileStreams.cpp, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsANSIFileStreams.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsANSIInputStream, nsIInputStream, nsISeekableStream);
|
||||
|
||||
nsANSIInputStream::nsANSIInputStream() : mFile(nsnull), mSize(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIInputStream::~nsANSIInputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
nsresult nsANSIInputStream::Open(nsILocalFile* file)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = file->OpenANSIFileDesc("rb", &mFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (::fseek(mFile, 0, SEEK_END) != 0) return NS_ERROR_FAILURE;
|
||||
mSize = ::ftell(mFile);
|
||||
::fseek(mFile, 0, SEEK_SET);
|
||||
rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Available(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = (mSize - ::ftell(mFile));
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Read(char * buf, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fread(buf, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::GetObserver(nsIInputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::SetObserver(nsIInputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIInputStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsANSIOutputStream, nsIOutputStream, nsISeekableStream);
|
||||
|
||||
nsANSIOutputStream::nsANSIOutputStream() : mFile(nsnull)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIOutputStream::~nsANSIOutputStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
nsresult nsANSIOutputStream::Open(nsILocalFile* file)
|
||||
{
|
||||
nsresult rv = file->OpenANSIFileDesc("wb", &mFile);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Flush()
|
||||
{
|
||||
if (mFile) {
|
||||
::fflush(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Write(const char *buffer, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fwrite(buffer, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::WriteFrom(nsIInputStream *input, PRUint32 count, PRUint32 *actualCount)
|
||||
{
|
||||
nsresult rv;
|
||||
char buffer[BUFSIZ];
|
||||
PRUint32 totalCount = count;
|
||||
*actualCount = 0;
|
||||
while (totalCount > 0) {
|
||||
count = (totalCount < BUFSIZ ? totalCount : BUFSIZ);
|
||||
rv = input->Read(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) break;
|
||||
rv = Write(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) break;
|
||||
totalCount -= count;
|
||||
*actualCount += count;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
NS_IMETHODIMP nsANSIOutputStream::SetNonBlocking(PRBool aNonBlocking)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::GetObserver(nsIOutputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
NS_IMETHODIMP nsANSIOutputStream::SetObserver(nsIOutputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIOutputStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
///////
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsANSIFileStream, nsIInputStream, nsIOutputStream, nsISeekableStream);
|
||||
|
||||
nsANSIFileStream::nsANSIFileStream() : mFile(nsnull), mSize(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
nsANSIFileStream::~nsANSIFileStream()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
nsresult nsANSIFileStream::Open(nsILocalFile* file)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = file->OpenANSIFileDesc("rb+", &mFile);
|
||||
if (NS_FAILED(rv)) {
|
||||
rv = rv = file->OpenANSIFileDesc("wb+", &mFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
// compute size of file.
|
||||
if (::fseek(mFile, 0, SEEK_END) != 0) return NS_ERROR_FAILURE;
|
||||
mSize = ::ftell(mFile);
|
||||
::fseek(mFile, 0, SEEK_SET);
|
||||
rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Close()
|
||||
{
|
||||
if (mFile) {
|
||||
::fclose(mFile);
|
||||
mFile = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Available(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = (mSize - ::ftell(mFile));
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Read(char * buf, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fread(buf, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::GetNonBlocking(PRBool *aNonBlocking)
|
||||
{
|
||||
*aNonBlocking = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::GetObserver(nsIInputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::SetObserver(nsIInputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Flush()
|
||||
{
|
||||
if (mFile) {
|
||||
::fflush(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Write(const char *buffer, PRUint32 count, PRUint32 *result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::fwrite(buffer, 1, count, mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::WriteFrom(nsIInputStream *input, PRUint32 count, PRUint32 *actualCount)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
PRUint32 totalCount = count;
|
||||
*actualCount = 0;
|
||||
while (totalCount > 0) {
|
||||
count = (totalCount < BUFSIZ ? totalCount : BUFSIZ);
|
||||
nsresult rv = input->Read(buffer, count, &count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = Write(buffer, count, &count);
|
||||
totalCount -= count;
|
||||
*actualCount += count;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::SetNonBlocking(PRBool aNonBlocking)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::GetObserver(nsIOutputStreamObserver * *aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::SetObserver(nsIOutputStreamObserver * aObserver)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Seek(PRInt32 whence, PRInt32 offset)
|
||||
{
|
||||
if (mFile) {
|
||||
::fseek(mFile, offset, whence);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsANSIFileStream::Tell(PRUint32 * result)
|
||||
{
|
||||
if (mFile) {
|
||||
*result = ::ftell(mFile);
|
||||
nsresult rv = (ferror(mFile) ? NS_ERROR_FAILURE : NS_OK);
|
||||
return rv;
|
||||
}
|
||||
return NS_BASE_STREAM_CLOSED;
|
||||
}
|
||||
80
mozilla/netwerk/cache/src/nsANSIFileStreams.h
vendored
80
mozilla/netwerk/cache/src/nsANSIFileStreams.h
vendored
@@ -1,80 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsANSIFileStreams.h, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsANSIFileStreams_h_
|
||||
#define _nsANSIFileStreams_h_
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
class nsANSIInputStream : public nsIInputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
PRUint32 mSize;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIInputStream();
|
||||
virtual ~nsANSIInputStream();
|
||||
nsresult Open(nsILocalFile* file);
|
||||
};
|
||||
|
||||
class nsANSIOutputStream : public nsIOutputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOUTPUTSTREAM
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIOutputStream();
|
||||
virtual ~nsANSIOutputStream();
|
||||
nsresult Open(nsILocalFile* file);
|
||||
};
|
||||
|
||||
class nsANSIFileStream : public nsIInputStream, public nsIOutputStream, public nsISeekableStream {
|
||||
FILE* mFile;
|
||||
PRUint32 mSize;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIINPUTSTREAM
|
||||
|
||||
// NS_DECL_NSIOUTPUTSTREAM
|
||||
// XXX must only declare additional methods introduced by nsIOutputStream.
|
||||
NS_IMETHOD Flush(void);
|
||||
NS_IMETHOD Write(const char *buf, PRUint32 count, PRUint32 *_retval);
|
||||
NS_IMETHOD WriteFrom(nsIInputStream *inStr, PRUint32 count, PRUint32 *_retval);
|
||||
NS_IMETHOD WriteSegments(nsReadSegmentFun reader, void * closure, PRUint32 count, PRUint32 *_retval);
|
||||
NS_IMETHOD SetNonBlocking(PRBool aNonBlocking);
|
||||
NS_IMETHOD GetObserver(nsIOutputStreamObserver * *aObserver);
|
||||
NS_IMETHOD SetObserver(nsIOutputStreamObserver * aObserver);
|
||||
|
||||
NS_DECL_NSISEEKABLESTREAM
|
||||
|
||||
nsANSIFileStream();
|
||||
virtual ~nsANSIFileStream();
|
||||
nsresult Open(nsILocalFile* file);
|
||||
};
|
||||
|
||||
#endif // _nsANSIFileStreams_h_
|
||||
119
mozilla/netwerk/cache/src/nsCache.cpp
vendored
119
mozilla/netwerk/cache/src/nsCache.cpp
vendored
@@ -1,119 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCache.cpp, released March 18, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCache.h"
|
||||
#include "nsReadableUtils.h"
|
||||
|
||||
|
||||
/**
|
||||
* Cache Service Utility Functions
|
||||
*/
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
PRLogModuleInfo * gCacheLog = nsnull;
|
||||
|
||||
void
|
||||
CacheLogInit()
|
||||
{
|
||||
if (gCacheLog) return;
|
||||
gCacheLog = PR_NewLogModule("cache");
|
||||
NS_ASSERTION(gCacheLog, "\n### failed to allocate cache log.\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
PRUint32
|
||||
SecondsFromPRTime(PRTime prTime)
|
||||
{
|
||||
PRInt64 microSecondsPerSecond, intermediateResult;
|
||||
PRUint32 seconds;
|
||||
|
||||
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
|
||||
LL_DIV(intermediateResult, prTime, microSecondsPerSecond);
|
||||
LL_L2UI(seconds, intermediateResult);
|
||||
return seconds;
|
||||
}
|
||||
|
||||
|
||||
PRTime
|
||||
PRTimeFromSeconds(PRUint32 seconds)
|
||||
{
|
||||
PRInt64 microSecondsPerSecond, intermediateResult;
|
||||
PRTime prTime;
|
||||
|
||||
LL_I2L(microSecondsPerSecond, PR_USEC_PER_SEC);
|
||||
LL_UI2L(intermediateResult, seconds);
|
||||
LL_MUL(prTime, intermediateResult, microSecondsPerSecond);
|
||||
return prTime;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
ClientIDFromCacheKey(const nsAReadableCString& key, char ** result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
*result = nsnull;
|
||||
|
||||
nsReadingIterator<char> colon;
|
||||
key.BeginReading(colon);
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key.BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key.EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', colon, end)) {
|
||||
*result = ToNewCString( Substring(start, colon));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
ClientKeyFromCacheKey(const nsAReadableCString& key, char ** result)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
*result = nsnull;
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key.BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key.EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', start, end)) {
|
||||
++start; // advance past clientID ':' delimiter
|
||||
*result = ToNewCString( Substring(start, end));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
63
mozilla/netwerk/cache/src/nsCache.h
vendored
63
mozilla/netwerk/cache/src/nsCache.h
vendored
@@ -1,63 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCache.h, released March 18, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
/**
|
||||
* Cache Service Utility Functions
|
||||
*/
|
||||
|
||||
#ifndef _nsCache_h_
|
||||
#define _nsCache_h_
|
||||
|
||||
#include "nsAReadableString.h"
|
||||
#include "prtime.h"
|
||||
#include "nsError.h"
|
||||
#include "prlog.h"
|
||||
|
||||
// PR_LOG args = "format string", arg, arg, ...
|
||||
#if defined(PR_LOGGING)
|
||||
extern PRLogModuleInfo * gCacheLog;
|
||||
void CacheLogInit();
|
||||
#define CACHE_LOG_INIT() CacheLogInit()
|
||||
#define CACHE_LOG_ALWAYS(args) PR_LOG(gCacheLog, PR_LOG_ALWAYS, args)
|
||||
#define CACHE_LOG_ERROR(args) PR_LOG(gCacheLog, PR_LOG_ERROR, args)
|
||||
#define CACHE_LOG_WARNING(args) PR_LOG(gCacheLog, PR_LOG_WARNING, args)
|
||||
#define CACHE_LOG_DEBUG(args) PR_LOG(gCacheLog, PR_LOG_DEBUG, args)
|
||||
#else
|
||||
#define CACHE_LOG_INIT() {}
|
||||
#define CACHE_LOG_ALWAYS(args) {}
|
||||
#define CACHE_LOG_ERROR(args) {}
|
||||
#define CACHE_LOG_WARNING(args) {}
|
||||
#define CACHE_LOG_DEBUG(args) {}
|
||||
#endif
|
||||
|
||||
|
||||
extern PRUint32 SecondsFromPRTime(PRTime prTime);
|
||||
extern PRTime PRTimeFromSeconds(PRUint32 seconds);
|
||||
|
||||
|
||||
extern nsresult ClientIDFromCacheKey(const nsAReadableCString& key, char ** result);
|
||||
extern nsresult ClientKeyFromCacheKey(const nsAReadableCString& key, char ** result);
|
||||
|
||||
#endif // _nsCache_h
|
||||
72
mozilla/netwerk/cache/src/nsCacheDevice.h
vendored
72
mozilla/netwerk/cache/src/nsCacheDevice.h
vendored
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheDevice.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheDevice_h_
|
||||
#define _nsCacheDevice_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICache.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsCString;
|
||||
class nsCacheEntry;
|
||||
class nsICacheVisitor;
|
||||
class nsITransport;
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheDevice
|
||||
*******************************************************************************/
|
||||
class nsCacheDevice {
|
||||
public:
|
||||
virtual ~nsCacheDevice() {}
|
||||
|
||||
virtual nsresult Init() = 0;
|
||||
virtual nsresult Shutdown() = 0;
|
||||
|
||||
virtual const char * GetDeviceID(void) = 0;
|
||||
virtual nsCacheEntry * FindEntry( nsCString * key ) = 0;
|
||||
|
||||
virtual nsresult DeactivateEntry( nsCacheEntry * entry ) = 0;
|
||||
virtual nsresult BindEntry( nsCacheEntry * entry ) = 0;
|
||||
virtual void DoomEntry( nsCacheEntry * entry ) = 0;
|
||||
|
||||
virtual nsresult GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport **result ) = 0;
|
||||
|
||||
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result ) = 0;
|
||||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize ) = 0;
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor) = 0;
|
||||
|
||||
/**
|
||||
* Device must evict entries associated with clientID. If clientID == nsnull, all
|
||||
* entries must be evicted. Active entries must be doomed, rather than evicted.
|
||||
*/
|
||||
virtual nsresult EvictEntries(const char * clientID) = 0;
|
||||
};
|
||||
|
||||
#endif // _nsCacheDevice_h_
|
||||
579
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
579
mozilla/netwerk/cache/src/nsCacheEntry.cpp
vendored
@@ -1,579 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheEntry.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsCacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsCacheRequest.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCache.h"
|
||||
|
||||
|
||||
nsCacheEntry::nsCacheEntry(nsCString * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy)
|
||||
: mKey(key),
|
||||
mFetchCount(0),
|
||||
mLastFetched(0),
|
||||
mExpirationTime(0),
|
||||
mFlags(0),
|
||||
mDataSize(0),
|
||||
mMetaSize(0),
|
||||
mCacheDevice(nsnull),
|
||||
mData(nsnull),
|
||||
mMetaData(nsnull)
|
||||
{
|
||||
PR_INIT_CLIST(this);
|
||||
PR_INIT_CLIST(&mRequestQ);
|
||||
PR_INIT_CLIST(&mDescriptorQ);
|
||||
|
||||
if (streamBased) MarkStreamBased();
|
||||
SetStoragePolicy(storagePolicy);
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry::~nsCacheEntry()
|
||||
{
|
||||
delete mKey;
|
||||
delete mMetaData;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::Fetched()
|
||||
{
|
||||
mLastFetched = SecondsFromPRTime(PR_Now());
|
||||
++mFetchCount;
|
||||
MarkEntryDirty();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetData(nsISupports **result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
NS_IF_ADDREF(*result = mData);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
nsCacheEntry::TouchData()
|
||||
{
|
||||
mLastModified = SecondsFromPRTime(PR_Now());
|
||||
MarkDataDirty();
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetMetaDataElement( const nsAReadableCString& key,
|
||||
nsAReadableCString ** value)
|
||||
{
|
||||
*value = mMetaData ? mMetaData->GetElement(&key) : nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value)
|
||||
{
|
||||
if (!mMetaData) {
|
||||
mMetaData = nsCacheMetaData::Create();
|
||||
if (!mMetaData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = mMetaData->SetElement(key, value);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
mMetaSize = mMetaData->Size(); // calc new meta data size
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::VisitMetaDataElements( nsICacheMetaDataVisitor * visitor)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(visitor);
|
||||
|
||||
if (mMetaData)
|
||||
mMetaData->VisitElements(visitor);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::FlattenMetaData(char ** data, PRUint32 * size)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(size);
|
||||
|
||||
if (mMetaData)
|
||||
return mMetaData->FlattenMetaData(data, size);
|
||||
|
||||
if (data) *data = nsnull;
|
||||
*size = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::UnflattenMetaData(char * data, PRUint32 size)
|
||||
{
|
||||
delete mMetaData;
|
||||
mMetaData = nsCacheMetaData::Create();
|
||||
if (!mMetaData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = mMetaData->UnflattenMetaData(data, size);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mMetaSize = mMetaData->Size();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::TouchMetaData()
|
||||
{
|
||||
mLastModified = SecondsFromPRTime(PR_Now());
|
||||
MarkMetaDataDirty();
|
||||
}
|
||||
|
||||
#if 0
|
||||
nsresult
|
||||
nsCacheEntry::GetKeyValueArray(nsCacheMetaDataKeyValuePair ** array,
|
||||
PRUint32 * count)
|
||||
{
|
||||
if (!array || !count) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (!mMetaData) {
|
||||
*array = nsnull;
|
||||
*count = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
return mMetaData->GetKeyValueArray(array, count);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::GetSecurityInfo( nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
NS_IF_ADDREF(*result = mSecurityInfo);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* cache entry states
|
||||
* 0 descriptors (new entry)
|
||||
* 0 descriptors (existing, bound entry)
|
||||
* n descriptors (existing, bound entry) valid
|
||||
* n descriptors (existing, bound entry) not valid (wait until valid or doomed)
|
||||
*/
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::RequestAccess(nsCacheRequest * request, nsCacheAccessMode *accessGranted)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!IsInitialized()) {
|
||||
// brand new, unbound entry
|
||||
request->mKey = nsnull; // steal ownership of the key string
|
||||
if (request->IsStreamBased()) MarkStreamBased();
|
||||
MarkInitialized();
|
||||
|
||||
*accessGranted = request->AccessRequested() & nsICache::ACCESS_WRITE;
|
||||
NS_ASSERTION(*accessGranted, "new cache entry for READ-ONLY request");
|
||||
PR_APPEND_LINK(request, &mRequestQ);
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (IsDoomed()) return NS_ERROR_CACHE_ENTRY_DOOMED;
|
||||
|
||||
if (IsStreamData() != request->IsStreamBased()) {
|
||||
*accessGranted = nsICache::ACCESS_NONE;
|
||||
return request->IsStreamBased() ?
|
||||
NS_ERROR_CACHE_DATA_IS_NOT_STREAM : NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
}
|
||||
|
||||
if (PR_CLIST_IS_EMPTY(&mDescriptorQ)) {
|
||||
// 1st descriptor for existing bound entry
|
||||
*accessGranted = request->AccessRequested();
|
||||
if (*accessGranted & nsICache::ACCESS_WRITE) {
|
||||
MarkInvalid();
|
||||
} else {
|
||||
MarkValid();
|
||||
}
|
||||
} else {
|
||||
// nth request for existing, bound entry
|
||||
*accessGranted = request->AccessRequested() & ~nsICache::ACCESS_WRITE;
|
||||
if (!IsValid())
|
||||
rv = NS_ERROR_CACHE_WAIT_FOR_VALIDATION;
|
||||
}
|
||||
PR_APPEND_LINK(request,&mRequestQ);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntry::CreateDescriptor(nsCacheRequest * request,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(request && result);
|
||||
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
new nsCacheEntryDescriptor(this, accessGranted);
|
||||
|
||||
// XXX check request is on q
|
||||
PR_REMOVE_AND_INIT_LINK(request); // remove request regardless of success
|
||||
|
||||
if (descriptor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PR_APPEND_LINK(descriptor, &mDescriptorQ);
|
||||
|
||||
NS_ADDREF(*result = descriptor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCacheEntry::RemoveRequest(nsCacheRequest * request)
|
||||
{
|
||||
// XXX if debug: verify this request belongs to this entry
|
||||
PR_REMOVE_AND_INIT_LINK(request);
|
||||
|
||||
// return true if this entry should stay active
|
||||
return !((PR_CLIST_IS_EMPTY(&mRequestQ)) &&
|
||||
(PR_CLIST_IS_EMPTY(&mDescriptorQ)));
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsCacheEntry::RemoveDescriptor(nsCacheEntryDescriptor * descriptor)
|
||||
{
|
||||
// XXX if debug: verify this descriptor belongs to this entry
|
||||
PR_REMOVE_AND_INIT_LINK(descriptor);
|
||||
|
||||
if (!PR_CLIST_IS_EMPTY(&mDescriptorQ))
|
||||
return PR_TRUE; // stay active if we still have open descriptors
|
||||
|
||||
if (PR_CLIST_IS_EMPTY(&mRequestQ))
|
||||
return PR_FALSE; // no descriptors or requests, we can deactivate
|
||||
|
||||
return PR_TRUE; // find next best request to give a descriptor to
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntry::DetachDescriptors(void)
|
||||
{
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
(nsCacheEntryDescriptor *)PR_LIST_HEAD(&mDescriptorQ);
|
||||
|
||||
while (descriptor != &mDescriptorQ) {
|
||||
nsCacheEntryDescriptor * nextDescriptor =
|
||||
(nsCacheEntryDescriptor *)PR_NEXT_LINK(descriptor);
|
||||
|
||||
descriptor->ClearCacheEntry();
|
||||
PR_REMOVE_AND_INIT_LINK(descriptor);
|
||||
descriptor = nextDescriptor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryInfo - for implementing about:cache
|
||||
*****************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryInfo, nsICacheEntryInfo);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetClientID(char ** clientID)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(clientID);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientIDFromCacheKey(*mCacheEntry->Key(), clientID);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetKey(char ** key)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(key);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*mCacheEntry->Key(), key);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetFetchCount(PRInt32 * fetchCount)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(fetchCount);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*fetchCount = mCacheEntry->FetchCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetLastFetched(PRUint32 * lastFetched)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(lastFetched);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*lastFetched = mCacheEntry->LastFetched();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetLastModified(PRUint32 * lastModified)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(lastModified);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*lastModified = mCacheEntry->LastModified();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetExpirationTime(PRUint32 * expirationTime)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(expirationTime);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*expirationTime = mCacheEntry->ExpirationTime();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::GetDataSize(PRUint32 * dataSize)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(dataSize);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*dataSize = mCacheEntry->DataSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryInfo::IsStreamBased(PRBool * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->IsStreamData();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*****************************************************************************/
|
||||
|
||||
PLDHashTableOps
|
||||
nsCacheEntryHashTable::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
|
||||
nsCacheEntryHashTable::nsCacheEntryHashTable()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntryHashTable::~nsCacheEntryHashTable()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryHashTable::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(nsCacheEntryHashTableEntry), 512);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry *
|
||||
nsCacheEntryHashTable::GetEntry( const nsCString * key)
|
||||
{
|
||||
PLDHashEntryHdr *hashEntry;
|
||||
nsCacheEntry *result = nsnull;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
hashEntry = PL_DHashTableOperate(&table, key, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryHashTable::AddEntry( nsCacheEntry *cacheEntry)
|
||||
{
|
||||
PLDHashEntryHdr *hashEntry;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
if (!cacheEntry) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
hashEntry = PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_ADD);
|
||||
#ifndef DEBUG_dougt
|
||||
NS_ASSERTION(((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry == 0,
|
||||
"### nsCacheEntryHashTable::AddEntry - entry already used");
|
||||
#endif
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = cacheEntry;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::RemoveEntry( nsCacheEntry *cacheEntry)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsCacheEntryHashTable not initialized");
|
||||
NS_ASSERTION(cacheEntry, "### cacheEntry == nsnull");
|
||||
|
||||
#if DEBUG
|
||||
// XXX debug code to make sure we have the entry we're trying to remove
|
||||
nsCacheEntry *check = GetEntry(cacheEntry->mKey);
|
||||
NS_ASSERTION(check == cacheEntry, "### Attempting to remove unknown cache entry!!!");
|
||||
#endif
|
||||
(void) PL_DHashTableOperate(&table, cacheEntry->mKey, PL_DHASH_REMOVE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::VisitEntries( nsCacheEntryHashTable::Visitor *visitor)
|
||||
{
|
||||
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheEntryHashTable::VisitEntry(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hashEntry,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
nsCacheEntryHashTable::Visitor *visitor = (nsCacheEntryHashTable::Visitor*) arg;
|
||||
return (visitor->VisitEntry(cacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
const void * PR_CALLBACK
|
||||
nsCacheEntryHashTable::GetKey( PLDHashTable * /*table*/, PLDHashEntryHdr *hashEntry)
|
||||
{
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
return cacheEntry->mKey;
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
||||
{
|
||||
return PL_DHashStringKey(table,((nsCString *)key)->get());
|
||||
}
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsCacheEntryHashTable::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * hashEntry,
|
||||
const void * key)
|
||||
{
|
||||
NS_ASSERTION(key != nsnull, "### nsCacheEntryHashTable::MatchEntry : null key");
|
||||
nsCacheEntry *cacheEntry = ((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry;
|
||||
|
||||
return nsStr::StrCompare(*cacheEntry->mKey, *(nsCString *)key, -1, PR_FALSE) == 0;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheEntryHashTable::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
((nsCacheEntryHashTableEntry *)to)->cacheEntry =
|
||||
((nsCacheEntryHashTableEntry *)from)->cacheEntry;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheEntryHashTable::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheEntryHashTableEntry *)hashEntry)->cacheEntry = 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsCacheEntryHashTable::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeCacheEntries, nsnull);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheEntryHashTable::FreeCacheEntries(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheEntryHashTableEntry *entry = (nsCacheEntryHashTableEntry *)hdr;
|
||||
delete entry->cacheEntry;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
319
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
319
mozilla/netwerk/cache/src/nsCacheEntry.h
vendored
@@ -1,319 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheEntry.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheEntry_h_
|
||||
#define _nsCacheEntry_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsAReadableString.h"
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheMetaData.h"
|
||||
|
||||
|
||||
class nsCacheDevice;
|
||||
class nsCacheMetaData;
|
||||
class nsCacheRequest;
|
||||
class nsCacheEntryDescriptor;
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntry
|
||||
*******************************************************************************/
|
||||
class nsCacheEntry : public PRCList
|
||||
{
|
||||
public:
|
||||
|
||||
nsCacheEntry(nsCString * key,
|
||||
PRBool streamBased,
|
||||
nsCacheStoragePolicy storagePolicy);
|
||||
~nsCacheEntry();
|
||||
|
||||
|
||||
nsCString * Key() { return mKey; }
|
||||
|
||||
PRInt32 FetchCount() { return mFetchCount;}
|
||||
void SetFetchCount( PRInt32 count) { mFetchCount = count;}
|
||||
void Fetched();
|
||||
|
||||
PRUint32 LastFetched() { return mLastFetched;}
|
||||
void SetLastFetched( PRUint32 lastFetched) { mLastFetched = lastFetched;}
|
||||
|
||||
PRUint32 LastModified() { return mLastModified;}
|
||||
void SetLastModified( PRUint32 lastModified) { mLastModified = lastModified;}
|
||||
|
||||
PRUint32 ExpirationTime() { return mExpirationTime;}
|
||||
void SetExpirationTime( PRUint32 expires) { mExpirationTime = expires;}
|
||||
|
||||
PRUint32 Size() { return mDataSize + mMetaSize; }
|
||||
|
||||
nsCacheDevice * CacheDevice() { return mCacheDevice;}
|
||||
void SetCacheDevice( nsCacheDevice * device) { mCacheDevice = device;}
|
||||
|
||||
|
||||
/**
|
||||
* Data accessors
|
||||
*/
|
||||
nsresult GetData( nsISupports ** result);
|
||||
void SetData( nsISupports * data) { mData = data; }
|
||||
|
||||
PRUint32 DataSize() { return mDataSize;}
|
||||
void SetDataSize( PRUint32 size) { mDataSize = size;}
|
||||
|
||||
void TouchData();
|
||||
|
||||
|
||||
/**
|
||||
* Meta data accessors
|
||||
*/
|
||||
nsresult GetMetaDataElement( const nsAReadableCString& key,
|
||||
nsAReadableCString ** value);
|
||||
nsresult SetMetaDataElement( const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
nsresult VisitMetaDataElements( nsICacheMetaDataVisitor * visitor);
|
||||
|
||||
nsresult FlattenMetaData( char ** data, PRUint32 * size);
|
||||
nsresult UnflattenMetaData( char * data, PRUint32 size);
|
||||
|
||||
PRUint32 MetaDataSize() { return mMetaSize;}
|
||||
|
||||
void TouchMetaData();
|
||||
|
||||
|
||||
/**
|
||||
* Security Info accessors
|
||||
*/
|
||||
nsresult GetSecurityInfo( nsISupports ** result);
|
||||
void SetSecurityInfo( nsISupports * info) { mSecurityInfo = info; }
|
||||
|
||||
|
||||
// XXX enumerate MetaData method
|
||||
|
||||
|
||||
enum CacheEntryFlags {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eDoomedMask = 0x00000100,
|
||||
eEntryDirtyMask = 0x00000200,
|
||||
eDataDirtyMask = 0x00000400,
|
||||
eMetaDataDirtyMask = 0x00000800,
|
||||
eStreamDataMask = 0x00001000,
|
||||
eActiveMask = 0x00002000,
|
||||
eInitializedMask = 0x00004000,
|
||||
eValidMask = 0x00008000,
|
||||
eBindingMask = 0x00010000
|
||||
};
|
||||
|
||||
void MarkBinding() { mFlags |= eBindingMask; }
|
||||
void ClearBinding() { mFlags &= ~eBindingMask; }
|
||||
PRBool IsBinding() { return (mFlags & eBindingMask) != 0; }
|
||||
|
||||
void MarkEntryDirty() { mFlags |= eEntryDirtyMask; }
|
||||
void MarkEntryClean() { mFlags &= ~eEntryDirtyMask; }
|
||||
void MarkDataDirty() { mFlags |= eDataDirtyMask; }
|
||||
void MarkDataClean() { mFlags &= ~eDataDirtyMask; }
|
||||
void MarkMetaDataDirty() { mFlags |= eMetaDataDirtyMask; }
|
||||
void MarkMetaDataClean() { mFlags &= ~eMetaDataDirtyMask; }
|
||||
void MarkStreamData() { mFlags |= eStreamDataMask; }
|
||||
void MarkValid() { mFlags |= eValidMask; }
|
||||
void MarkInvalid() { mFlags &= ~eValidMask; }
|
||||
// void MarkAllowedInMemory() { mFlags |= eAllowedInMemoryMask; }
|
||||
// void MarkAllowedOnDisk() { mFlags |= eAllowedOnDiskMask; }
|
||||
|
||||
PRBool IsDoomed() { return (mFlags & eDoomedMask) != 0; }
|
||||
PRBool IsEntryDirty() { return (mFlags & eEntryDirtyMask) != 0; }
|
||||
PRBool IsDataDirty() { return (mFlags & eDataDirtyMask) != 0; }
|
||||
PRBool IsMetaDataDirty() { return (mFlags & eMetaDataDirtyMask) != 0; }
|
||||
PRBool IsStreamData() { return (mFlags & eStreamDataMask) != 0; }
|
||||
PRBool IsActive() { return (mFlags & eActiveMask) != 0; }
|
||||
PRBool IsInitialized() { return (mFlags & eInitializedMask) != 0; }
|
||||
PRBool IsValid() { return (mFlags & eValidMask) != 0; }
|
||||
PRBool IsInvalid() { return (mFlags & eValidMask) == 0; }
|
||||
PRBool IsInUse() { return !(PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
||||
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
||||
PRBool IsNotInUse() { return (PR_CLIST_IS_EMPTY(&mRequestQ) &&
|
||||
PR_CLIST_IS_EMPTY(&mDescriptorQ)); }
|
||||
|
||||
|
||||
PRBool IsAllowedInMemory()
|
||||
{
|
||||
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
||||
(StoragePolicy() == nsICache::STORE_IN_MEMORY);
|
||||
}
|
||||
|
||||
PRBool IsAllowedOnDisk()
|
||||
{
|
||||
return (StoragePolicy() == nsICache::STORE_ANYWHERE) ||
|
||||
(StoragePolicy() == nsICache::STORE_ON_DISK) ||
|
||||
(StoragePolicy() == nsICache::STORE_ON_DISK_AS_FILE);
|
||||
}
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mFlags & eStoragePolicyMask);
|
||||
}
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mFlags &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mFlags |= policy;
|
||||
}
|
||||
|
||||
|
||||
// methods for nsCacheService
|
||||
nsresult RequestAccess( nsCacheRequest * request, nsCacheAccessMode *accessGranted);
|
||||
nsresult CreateDescriptor( nsCacheRequest * request,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
// nsresult Open(nsCacheRequest *request, nsICacheEntryDescriptor ** result);
|
||||
// nsresult AsyncOpen(nsCacheRequest *request);
|
||||
PRBool RemoveRequest( nsCacheRequest * request);
|
||||
PRBool RemoveDescriptor( nsCacheEntryDescriptor * descriptor);
|
||||
|
||||
private:
|
||||
friend class nsCacheEntryHashTable;
|
||||
friend class nsCacheService;
|
||||
|
||||
void DetachDescriptors(void);
|
||||
|
||||
// internal methods
|
||||
void MarkDoomed() { mFlags |= eDoomedMask; }
|
||||
void MarkStreamBased() { mFlags |= eStreamDataMask; }
|
||||
void MarkInitialized() { mFlags |= eInitializedMask; }
|
||||
void MarkActive() { mFlags |= eActiveMask; }
|
||||
void MarkInactive() { mFlags &= ~eActiveMask; }
|
||||
|
||||
nsCString * mKey; // 4 // XXX ask scc about const'ness
|
||||
PRUint32 mFetchCount; // 4
|
||||
PRUint32 mLastFetched; // 4
|
||||
PRUint32 mLastModified; // 4
|
||||
PRUint32 mLastValidated; // 4
|
||||
PRUint32 mExpirationTime; // 4
|
||||
PRUint32 mFlags; // 4
|
||||
PRUint32 mDataSize; // 4
|
||||
PRUint32 mMetaSize; // 4
|
||||
nsCacheDevice * mCacheDevice; // 4
|
||||
nsCOMPtr<nsISupports> mSecurityInfo; //
|
||||
nsCOMPtr<nsISupports> mData; //
|
||||
nsCacheMetaData * mMetaData; // 4
|
||||
PRCList mRequestQ; // 8
|
||||
PRCList mDescriptorQ; // 8
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryInfo
|
||||
*******************************************************************************/
|
||||
class nsCacheEntryInfo : public nsICacheEntryInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsCacheEntryInfo(nsCacheEntry* entry)
|
||||
: mCacheEntry(entry)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsCacheEntryInfo() {}
|
||||
void DetachEntry() { mCacheEntry = nsnull; }
|
||||
|
||||
private:
|
||||
nsCacheEntry * mCacheEntry;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*******************************************************************************/
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCacheEntry *cacheEntry;
|
||||
} nsCacheEntryHashTableEntry;
|
||||
|
||||
|
||||
class nsCacheEntryHashTable
|
||||
{
|
||||
public:
|
||||
nsCacheEntryHashTable();
|
||||
~nsCacheEntryHashTable();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsCacheEntry *GetEntry( const nsCString * key);
|
||||
nsresult AddEntry( nsCacheEntry *entry);
|
||||
void RemoveEntry( nsCacheEntry *entry);
|
||||
|
||||
// XXX enumerate entries?
|
||||
class Visitor {
|
||||
public:
|
||||
virtual PRBool VisitEntry( nsCacheEntry *entry) = 0;
|
||||
};
|
||||
|
||||
void VisitEntries( Visitor *visitor);
|
||||
|
||||
private:
|
||||
friend class nsCacheService; // XXX redefine interface so this isn't necessary
|
||||
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry( PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry( PLDHashTable *table,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static void PR_CALLBACK Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeCacheEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif // _nsCacheEntry_h_
|
||||
|
||||
654
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
654
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.cpp
vendored
@@ -1,654 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheEntryDescriptor.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsICache.h"
|
||||
#include "nsCache.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsCacheEntryDescriptor.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsReadableUtils.h"
|
||||
#include "nsIOutputStream.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor, nsICacheEntryDescriptor)
|
||||
|
||||
|
||||
nsCacheEntryDescriptor::nsCacheEntryDescriptor(nsCacheEntry * entry,
|
||||
nsCacheAccessMode accessGranted)
|
||||
: mCacheEntry(entry),
|
||||
mAccessGranted(accessGranted)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
PR_INIT_CLIST(this);
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntryDescriptor::~nsCacheEntryDescriptor()
|
||||
{
|
||||
if (mCacheEntry)
|
||||
Close();
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::Create(nsCacheEntry * entry, nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
nsresult rv = nsnull;
|
||||
|
||||
nsCacheEntryDescriptor * descriptor =
|
||||
new nsCacheEntryDescriptor(entry, accessGranted);
|
||||
|
||||
if (descriptor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(descriptor);
|
||||
rv = descriptor->QueryInterface(NS_GET_IID(nsICacheEntryDescriptor), (void**)result);
|
||||
NS_RELEASE(descriptor);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetClientID(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientIDFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetKey(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return ClientKeyFromCacheKey(*(mCacheEntry->Key()), result);
|
||||
|
||||
#if 0
|
||||
nsCString * key;
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*result = nsnull;
|
||||
key = mCacheEntry->Key();
|
||||
|
||||
nsReadingIterator<char> start;
|
||||
key->BeginReading(start);
|
||||
|
||||
nsReadingIterator<char> end;
|
||||
key->EndReading(end);
|
||||
|
||||
if (FindCharInReadable(':', start, end)) {
|
||||
++start; // advance past clientID ':' delimiter
|
||||
*result = ToNewCString( Substring(start, end));
|
||||
if (!*result) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "FindCharInRead failed to find ':'");
|
||||
rv = NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetFetchCount(PRInt32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->FetchCount();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetLastFetched(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->LastFetched();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetLastModified(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->LastModified();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetExpirationTime(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->ExpirationTime();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetExpirationTime(PRUint32 expirationTime)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mCacheEntry->SetExpirationTime(expirationTime);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::IsStreamBased(PRBool *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->IsStreamData(); // XXX which name is better?
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::GetDataSize(PRUint32 *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = mCacheEntry->DataSize();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::RequestDataSizeChange(PRInt32 deltaSize)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OnDataSizeChange(mCacheEntry, deltaSize);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX review for signed/unsigned math errors
|
||||
PRUint32 newDataSize = mCacheEntry->DataSize() + deltaSize;
|
||||
mCacheEntry->SetDataSize(newDataSize);
|
||||
mCacheEntry->TouchData();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetDataSize(PRUint32 dataSize)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// XXX review for signed/unsigned math errors
|
||||
PRInt32 deltaSize = dataSize - mCacheEntry->DataSize();
|
||||
|
||||
// this had better be NS_OK, this call instance is advisory
|
||||
nsresult rv = RequestDataSizeChange(deltaSize);
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "failed SetDataSize() on memory cache object!");
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetTransport(nsITransport ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (!mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_NOT_STREAM;
|
||||
|
||||
NS_ADDREF(*result = &mTransportWrapper);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetCacheElement(nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
|
||||
return mCacheEntry->GetData(result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetCacheElement(nsISupports * cacheElement)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (mCacheEntry->IsStreamData()) return NS_ERROR_CACHE_DATA_IS_STREAM;
|
||||
|
||||
mCacheEntry->SetData(cacheElement);
|
||||
mCacheEntry->TouchData();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetAccessGranted(nsCacheAccessMode *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mAccessGranted;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetStoragePolicy(nsCacheStoragePolicy *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->StoragePolicy();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
// XXX validate policy against session?
|
||||
mCacheEntry->SetStoragePolicy(policy);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetFile(nsIFile ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return nsCacheService::GlobalInstance()->GetFileForEntry(mCacheEntry, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetSecurityInfo(nsISupports ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->GetSecurityInfo(result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetSecurityInfo(nsISupports * securityInfo)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
mCacheEntry->SetSecurityInfo(securityInfo);
|
||||
mCacheEntry->MarkEntryDirty();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::Doom()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return nsCacheService::GlobalInstance()->DoomEntry(mCacheEntry);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::DoomAndFailPendingRequests(nsresult status)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::MarkValid()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->ValidateEntry(mCacheEntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::Close()
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// tell nsCacheService we're going away
|
||||
nsCacheService::GlobalInstance()->CloseDescriptor(this);
|
||||
mCacheEntry = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::GetMetaDataElement(const char *key, char ** result)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!key | !result) return NS_ERROR_NULL_POINTER;
|
||||
nsAReadableCString *value;
|
||||
*result = nsnull;
|
||||
|
||||
// XXX not thread safe
|
||||
nsresult rv = mCacheEntry->GetMetaDataElement(nsLiteralCString(key), &value);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!value) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
*result = ToNewCString(*value);
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::SetMetaDataElement(const char *key, const char *value)
|
||||
{
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
if (!key) return NS_ERROR_NULL_POINTER;
|
||||
// XXX not thread safe
|
||||
// XXX allow null value, for clearing key?
|
||||
nsresult rv = mCacheEntry->SetMetaDataElement(nsLiteralCString(key),
|
||||
nsLiteralCString(value));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
mCacheEntry->TouchMetaData();
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheEntryDescriptor::VisitMetaData(nsICacheMetaDataVisitor * visitor)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(visitor);
|
||||
if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return mCacheEntry->VisitMetaDataElements(visitor);
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheTransportWrapper
|
||||
******************************************************************************/
|
||||
|
||||
// XXX NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor::nsTransportWrapper, nsITransport);
|
||||
NS_IMPL_QUERY_INTERFACE1(nsCacheEntryDescriptor::nsTransportWrapper, nsITransport)
|
||||
|
||||
|
||||
// special AddRef and Release, because we are part of the descriptor
|
||||
#define GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(_this) \
|
||||
((nsCacheEntryDescriptor*)((char*)(_this) - \
|
||||
offsetof(nsCacheEntryDescriptor, mTransportWrapper)))
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AddRef(void)
|
||||
{
|
||||
return GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this)->AddRef();
|
||||
}
|
||||
|
||||
NS_IMETHODIMP_(nsrefcnt) nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::Release(void)
|
||||
{
|
||||
return GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this)->Release();
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::EnsureTransportWithAccess(nsCacheAccessMode mode)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
nsCacheEntryDescriptor * descriptor = GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this);
|
||||
if (!descriptor->mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
if (!descriptor->mAccessGranted & mode) {
|
||||
rv = (mode == nsICache::ACCESS_READ) ?
|
||||
NS_ERROR_CACHE_READ_ACCESS_DENIED : NS_ERROR_CACHE_WRITE_ACCESS_DENIED;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (!mTransport) {
|
||||
rv = nsCacheService::GlobalInstance()->
|
||||
GetTransportForEntry(descriptor->mCacheEntry,
|
||||
descriptor->mAccessGranted,
|
||||
getter_AddRefs(mTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheEntryDescriptor::NewOutputStreamWrapper(nsIOutputStream ** result,
|
||||
nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output)
|
||||
{
|
||||
nsOutputStreamWrapper* cacheOutput =
|
||||
new nsOutputStreamWrapper(descriptor, output);
|
||||
if (!cacheOutput) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsISupports> ref(cacheOutput);
|
||||
nsresult rv = cacheOutput->Init();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_ADDREF(*result = cacheOutput);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::GetSecurityInfo(nsISupports ** securityInfo)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::GetNotificationCallbacks(nsIInterfaceRequestor **result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
// if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::SetNotificationCallbacks(nsIInterfaceRequestor *requestor,
|
||||
PRBool isBackground)
|
||||
{
|
||||
// if (!mCacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::OpenInputStream(PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIInputStream ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->OpenInputStream(offset, count, flags, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::OpenOutputStream(PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIOutputStream ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_WRITE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// XXX allow more than one output stream at a time on a descriptor? Why?
|
||||
|
||||
// Create the underlying output stream using the wrapped transport.
|
||||
nsCOMPtr<nsIOutputStream> output;
|
||||
rv = mTransport->OpenOutputStream(offset, count, flags, getter_AddRefs(output));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Wrap this output stream, with a stream that monitors how much data gets written,
|
||||
// to maintain the cache entry's size, and to inform the cache device. Eventually,
|
||||
// this mechanism will provide a way for the cache device to enforce space limits,
|
||||
// and to drive cache entry eviction.
|
||||
nsCacheEntryDescriptor * descriptor = GET_DESCRIPTOR_FROM_TRANSPORT_WRAPPER(this);
|
||||
return NewOutputStreamWrapper(result, descriptor, output);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AsyncRead(nsIStreamListener * listener,
|
||||
nsISupports * ctxt,
|
||||
PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIRequest ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_READ);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->AsyncRead(listener, ctxt, offset, count, flags, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsTransportWrapper::AsyncWrite(nsIStreamProvider * provider,
|
||||
nsISupports * ctxt,
|
||||
PRUint32 offset,
|
||||
PRUint32 count,
|
||||
PRUint32 flags,
|
||||
nsIRequest ** result)
|
||||
{
|
||||
// we're not planning on implementing this
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
|
||||
#if 0
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
|
||||
nsresult rv = EnsureTransportWithAccess(nsICache::ACCESS_WRITE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return mTransport->AsyncWrite(provider, ctxt, offset, count, flags, result);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheOutputStream - a wrapper for nsIOutputstream to track the amount of
|
||||
* data written to a cache entry.
|
||||
******************************************************************************/
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheEntryDescriptor::nsOutputStreamWrapper, nsIOutputStream);
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::Init()
|
||||
{
|
||||
nsCacheAccessMode mode;
|
||||
nsresult rv = mDescriptor->GetAccessGranted(&mode);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (mode == nsICache::ACCESS_WRITE) {
|
||||
nsCacheEntry* cacheEntry = mDescriptor->CacheEntry();
|
||||
if (!cacheEntry) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
nsCacheDevice* device = cacheEntry->CacheDevice();
|
||||
if (!device) return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
// the entry has been truncated to zero bytes, inform the device.
|
||||
PRInt32 delta = -cacheEntry->DataSize();
|
||||
rv = device->OnDataSizeChange(cacheEntry, delta);
|
||||
cacheEntry->SetDataSize(0);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::Write(const char * buf,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->Write(buf, count, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::WriteFrom(nsIInputStream * inStr,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->WriteFrom(inStr, count, result);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::WriteSegments(nsReadSegmentFun reader,
|
||||
void * closure,
|
||||
PRUint32 count,
|
||||
PRUint32 * result)
|
||||
{
|
||||
nsresult rv = OnWrite(count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
return mOutput->WriteSegments(reader, closure, count, result);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsCacheEntryDescriptor::
|
||||
nsOutputStreamWrapper::OnWrite(PRUint32 count)
|
||||
{
|
||||
// XXX if count > 2^31 error_write_too_big
|
||||
return mDescriptor->RequestDataSizeChange((PRInt32)count);
|
||||
}
|
||||
|
||||
|
||||
167
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.h
vendored
167
mozilla/netwerk/cache/src/nsCacheEntryDescriptor.h
vendored
@@ -1,167 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheEntryDescriptor.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsCacheEntryDescriptor_h_
|
||||
#define _nsCacheEntryDescriptor_h_
|
||||
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsITransport.h"
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryDescriptor
|
||||
*******************************************************************************/
|
||||
class nsCacheEntryDescriptor :
|
||||
public PRCList,
|
||||
public nsICacheEntryDescriptor
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEENTRYDESCRIPTOR
|
||||
NS_DECL_NSICACHEENTRYINFO
|
||||
|
||||
nsCacheEntryDescriptor(nsCacheEntry * entry, nsCacheAccessMode mode);
|
||||
virtual ~nsCacheEntryDescriptor();
|
||||
|
||||
static nsresult Create(nsCacheEntry * entry, nsCacheAccessMode accessGranted,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
|
||||
/**
|
||||
* utility method to attempt changing data size of associated entry
|
||||
*/
|
||||
nsresult RequestDataSizeChange(PRInt32 deltaSize);
|
||||
|
||||
/**
|
||||
* methods callbacks for nsCacheService
|
||||
*/
|
||||
nsCacheEntry * CacheEntry(void) { return mCacheEntry; }
|
||||
void ClearCacheEntry(void) { mCacheEntry = nsnull; }
|
||||
|
||||
private:
|
||||
|
||||
/*************************************************************************
|
||||
* transport wrapper class -
|
||||
*
|
||||
* we want the transport wrapper to have the same lifetime as the
|
||||
* descriptor, but since they each need to reference the other, we have the
|
||||
* descriptor include the transport wrapper as a member, rather than just
|
||||
* pointing to it, which avoids circular AddRefs.
|
||||
*************************************************************************/
|
||||
class nsTransportWrapper : public nsITransport
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSITRANSPORT
|
||||
|
||||
nsTransportWrapper() : mTransport(nsnull) {}
|
||||
virtual ~nsTransportWrapper() {}
|
||||
|
||||
nsresult EnsureTransportWithAccess(nsCacheAccessMode mode);
|
||||
|
||||
nsCOMPtr<nsITransport> mTransport;
|
||||
}; // end of class nsTransportWrapper
|
||||
friend class nsTransportWrapper;
|
||||
|
||||
|
||||
/*************************************************************************
|
||||
* output stream wrapper class -
|
||||
*
|
||||
* The output stream wrapper references the descriptor, but the descriptor
|
||||
* doesn't need any references to the stream wrapper, so we don't need the
|
||||
* same kind of tricks that we're using for the transport wrapper.
|
||||
*************************************************************************/
|
||||
class nsOutputStreamWrapper : public nsIOutputStream {
|
||||
private:
|
||||
nsCacheEntryDescriptor * mDescriptor;
|
||||
nsCOMPtr<nsIOutputStream> mOutput;
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
// NS_DECL_NSIOUTPUTSTREAM
|
||||
NS_IMETHOD Close(void) { return mOutput->Close(); }
|
||||
NS_IMETHOD Flush(void) { return mOutput->Flush(); }
|
||||
|
||||
NS_IMETHOD Write(const char * buf,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD WriteFrom(nsIInputStream * inStr,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD WriteSegments(nsReadSegmentFun reader,
|
||||
void * closure,
|
||||
PRUint32 count,
|
||||
PRUint32 * result);
|
||||
|
||||
NS_IMETHOD GetNonBlocking(PRBool * nonBlocking)
|
||||
{ return mOutput->GetNonBlocking(nonBlocking); }
|
||||
|
||||
NS_IMETHOD SetNonBlocking(PRBool nonBlocking)
|
||||
{ return mOutput->SetNonBlocking(nonBlocking); }
|
||||
|
||||
NS_IMETHOD GetObserver(nsIOutputStreamObserver ** observer)
|
||||
{ return mOutput->GetObserver(observer); }
|
||||
|
||||
NS_IMETHOD SetObserver(nsIOutputStreamObserver * observer)
|
||||
{ return mOutput->SetObserver(observer); }
|
||||
|
||||
nsOutputStreamWrapper(nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output)
|
||||
: mDescriptor(nsnull), mOutput(output)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
NS_ADDREF(mDescriptor = descriptor);
|
||||
}
|
||||
|
||||
virtual ~nsOutputStreamWrapper()
|
||||
{
|
||||
NS_RELEASE(mDescriptor);
|
||||
}
|
||||
|
||||
nsresult Init();
|
||||
|
||||
|
||||
private:
|
||||
nsresult OnWrite(PRUint32 count);
|
||||
}; // end of class nsOutputStreamWrapper
|
||||
friend class nsOutputStreamWrapper;
|
||||
|
||||
|
||||
|
||||
static nsresult NewOutputStreamWrapper(nsIOutputStream ** result,
|
||||
nsCacheEntryDescriptor * descriptor,
|
||||
nsIOutputStream * output);
|
||||
private:
|
||||
/**
|
||||
* nsCacheEntryDescriptor data members
|
||||
*/
|
||||
nsCacheEntry * mCacheEntry; // we are a child of the entry
|
||||
nsCacheAccessMode mAccessGranted;
|
||||
nsTransportWrapper mTransportWrapper;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsCacheEntryDescriptor_h_
|
||||
327
mozilla/netwerk/cache/src/nsCacheMetaData.cpp
vendored
327
mozilla/netwerk/cache/src/nsCacheMetaData.cpp
vendored
@@ -1,327 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheMetaData.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#include "nsCacheMetaData.h"
|
||||
#include "nsString.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
|
||||
|
||||
/*
|
||||
* nsCacheClientHashTable
|
||||
*/
|
||||
|
||||
PLDHashTableOps
|
||||
nsCacheMetaData::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
|
||||
nsCacheMetaData::nsCacheMetaData()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
nsCacheMetaData::~nsCacheMetaData()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(nsCacheMetaDataHashTableEntry), 16);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsCacheMetaData *
|
||||
nsCacheMetaData::Create()
|
||||
{
|
||||
nsCacheMetaData * metaData = new nsCacheMetaData();
|
||||
if (!metaData)
|
||||
return nsnull;
|
||||
|
||||
nsresult rv = metaData->Init();
|
||||
if (NS_FAILED(rv)) {
|
||||
delete metaData;
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
return metaData;
|
||||
}
|
||||
|
||||
|
||||
nsAReadableCString *
|
||||
nsCacheMetaData::GetElement(const nsAReadableCString * key)
|
||||
{
|
||||
PLDHashEntryHdr * hashEntry;
|
||||
nsCString * result = nsnull;
|
||||
|
||||
// XXX need to copy string until we have scc's new flat string abstract class
|
||||
// XXX see nsCacheMetaData::HashKey below (bug 70075)
|
||||
nsCString * tempKey = new nsCString(*key);
|
||||
if (!tempKey) return result;
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
|
||||
hashEntry = PL_DHashTableOperate(&table, tempKey, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = ((nsCacheMetaDataHashTableEntry *)hashEntry)->value;
|
||||
}
|
||||
|
||||
delete tempKey;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::SetElement(const nsAReadableCString& key,
|
||||
const nsAReadableCString& value)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry * metaEntry;
|
||||
nsresult rv = NS_ERROR_OUT_OF_MEMORY; // presume the worst
|
||||
|
||||
NS_ASSERTION(initialized, "nsCacheMetaDataHashTable not initialized");
|
||||
|
||||
// XXX need to copy string until we have scc's new flat string abstract class
|
||||
// XXX see nsCacheMetaData::HashKey below (bug 70075)
|
||||
nsCString * tempKey = new nsCString(key);
|
||||
if (!tempKey) return rv;
|
||||
|
||||
// XXX should empty value remove the key?
|
||||
|
||||
metaEntry = (nsCacheMetaDataHashTableEntry *)
|
||||
PL_DHashTableOperate(&table, tempKey, PL_DHASH_ADD);
|
||||
if (!metaEntry) goto error_exit;
|
||||
|
||||
|
||||
if (metaEntry->key == nsnull) {
|
||||
metaEntry->key = new nsCString(key);
|
||||
if (metaEntry->key == nsnull) {
|
||||
goto error_exit;
|
||||
}
|
||||
}
|
||||
if (metaEntry->value != nsnull)
|
||||
delete metaEntry->value; // clear the old value
|
||||
|
||||
metaEntry->value = new nsCString(value);
|
||||
if (metaEntry->value == nsnull) {
|
||||
// XXX remove key?
|
||||
goto error_exit;
|
||||
}
|
||||
|
||||
rv = NS_OK;
|
||||
error_exit:
|
||||
delete tempKey;
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
PRUint32
|
||||
nsCacheMetaData::Size(void)
|
||||
{
|
||||
PRUint32 size = 0;
|
||||
(void) PL_DHashTableEnumerate(&table, CalculateSize, &size);
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::FlattenMetaData(char ** data, PRUint32 * size)
|
||||
{
|
||||
*size = 0;
|
||||
|
||||
if (PL_DHashTableEnumerate(&table, CalculateSize, size) != 0 && data) {
|
||||
*data = new char[*size];
|
||||
if (*data == nsnull) return NS_ERROR_OUT_OF_MEMORY;
|
||||
char* state = *data;
|
||||
PL_DHashTableEnumerate(&table, AccumulateElement, &state);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::UnflattenMetaData(char * data, PRUint32 size)
|
||||
{
|
||||
nsresult rv = NS_ERROR_UNEXPECTED;
|
||||
char* limit = data + size;
|
||||
while (data < limit) {
|
||||
const char* name = data;
|
||||
PRUint32 nameSize = nsCRT::strlen(name);
|
||||
data += 1 + nameSize;
|
||||
if (data < limit) {
|
||||
const char* value = data;
|
||||
PRUint32 valueSize = nsCRT::strlen(value);
|
||||
data += 1 + valueSize;
|
||||
rv = SetElement(nsLocalCString(name, nameSize),
|
||||
nsLocalCString(value, valueSize));
|
||||
if (NS_FAILED(rv)) break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsCacheMetaData::VisitElements(nsICacheMetaDataVisitor * visitor)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(&table, VisitElement, visitor);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
|
||||
const void * PR_CALLBACK
|
||||
nsCacheMetaData::GetKey( PLDHashTable * /* table */, PLDHashEntryHdr *hashEntry)
|
||||
{
|
||||
return ((nsCacheMetaDataHashTableEntry *)hashEntry)->key;
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsCacheMetaData::HashKey( PLDHashTable * table, const void *key)
|
||||
{
|
||||
// XXX need scc's new flat string abstract class here (bug 70075)
|
||||
return PL_DHashStringKey(table, ((nsCString *)key)->get());
|
||||
}
|
||||
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsCacheMetaData::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * hashEntry,
|
||||
const void * key)
|
||||
{
|
||||
NS_ASSERTION(key != nsnull, "### nsCacheMetaDataHashTable::MatchEntry : null key");
|
||||
nsCString * entryKey = ((nsCacheMetaDataHashTableEntry *)hashEntry)->key;
|
||||
NS_ASSERTION(entryKey, "### hashEntry->key == nsnull");
|
||||
|
||||
return entryKey->Equals(*NS_STATIC_CAST(const nsAReadableCString*,key));
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to)
|
||||
{
|
||||
((nsCacheMetaDataHashTableEntry *)to)->key =
|
||||
((nsCacheMetaDataHashTableEntry *)from)->key;
|
||||
((nsCacheMetaDataHashTableEntry *)to)->value =
|
||||
((nsCacheMetaDataHashTableEntry *)from)->value;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * hashEntry)
|
||||
{
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->key = 0;
|
||||
((nsCacheMetaDataHashTableEntry *)hashEntry)->value = 0;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsCacheMetaData::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeElement, nsnull);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hash table enumeration callback functions
|
||||
*/
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::CalculateSize(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry* hashEntry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
*(PRUint32*)arg += (2 + hashEntry->key->Length() + hashEntry->value->Length());
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::AccumulateElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
char** bufferPtr = (char**) arg;
|
||||
nsCacheMetaDataHashTableEntry* hashEntry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
PRUint32 size = 1 + hashEntry->key->Length();
|
||||
nsCRT::memcpy(*bufferPtr, hashEntry->key->get(), size);
|
||||
*bufferPtr += size;
|
||||
size = 1 + hashEntry->value->Length();
|
||||
nsCRT::memcpy(*bufferPtr, hashEntry->value->get(), size);
|
||||
*bufferPtr += size;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::FreeElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
delete entry->key;
|
||||
delete entry->value;
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsCacheMetaData::VisitElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg)
|
||||
{
|
||||
nsCacheMetaDataHashTableEntry *entry = (nsCacheMetaDataHashTableEntry *)hdr;
|
||||
nsICacheMetaDataVisitor *visitor = (nsICacheMetaDataVisitor *)arg;
|
||||
const char * key = entry->key ? entry->key->get() : nsnull;
|
||||
const char * value = entry->value ? entry->value->get() : nsnull;
|
||||
|
||||
PRBool keepGoing;
|
||||
nsresult rv = visitor->VisitMetaDataElement(key, value, &keepGoing);
|
||||
|
||||
return NS_SUCCEEDED(rv) && keepGoing ? PL_DHASH_NEXT : PL_DHASH_STOP;
|
||||
}
|
||||
119
mozilla/netwerk/cache/src/nsCacheMetaData.h
vendored
119
mozilla/netwerk/cache/src/nsCacheMetaData.h
vendored
@@ -1,119 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheMetaData.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheMetaData_h_
|
||||
#define _nsCacheMetaData_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
#include "nscore.h"
|
||||
// #include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
// #include "nsAReadableString.h"
|
||||
|
||||
class nsICacheMetaDataVisitor;
|
||||
|
||||
typedef struct {
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataKeyValuePair;
|
||||
|
||||
|
||||
typedef struct {
|
||||
PLDHashNumber keyHash;
|
||||
nsCString * key;
|
||||
nsCString * value;
|
||||
} nsCacheMetaDataHashTableEntry;
|
||||
|
||||
|
||||
class nsCacheMetaData {
|
||||
public:
|
||||
nsCacheMetaData();
|
||||
~nsCacheMetaData();
|
||||
|
||||
static
|
||||
nsCacheMetaData * Create(void);
|
||||
|
||||
nsresult Init(void);
|
||||
|
||||
nsAReadableCString * GetElement(const nsAReadableCString * key);
|
||||
|
||||
nsresult SetElement(const nsAReadableCString& key,
|
||||
const nsAReadableCString& value);
|
||||
|
||||
PRUint32 Size(void);
|
||||
|
||||
nsresult FlattenMetaData(char ** data, PRUint32 * size);
|
||||
|
||||
nsresult UnflattenMetaData(char * data, PRUint32 size);
|
||||
|
||||
nsresult VisitElements(nsICacheMetaDataVisitor * visitor);
|
||||
|
||||
private:
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey( PLDHashTable *table, const void *key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry( PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry( PLDHashTable *table,
|
||||
const PLDHashEntryHdr *from,
|
||||
PLDHashEntryHdr *to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry( PLDHashTable *table, PLDHashEntryHdr *entry);
|
||||
|
||||
static void PR_CALLBACK Finalize( PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK CalculateSize(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK AccumulateElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitElement(PLDHashTable *table,
|
||||
PLDHashEntryHdr *hdr,
|
||||
PRUint32 number,
|
||||
void *arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif // _nsCacheMetaData_h
|
||||
41
mozilla/netwerk/cache/src/nsCacheModule.cpp
vendored
41
mozilla/netwerk/cache/src/nsCacheModule.cpp
vendored
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheModule.cpp, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsNetCID.h"
|
||||
|
||||
// nsCacheService
|
||||
//
|
||||
|
||||
static nsModuleComponentInfo gResComponents[] = {
|
||||
{
|
||||
NS_CACHESERVICE_CLASSNAME,
|
||||
NS_CACHESERVICE_CID,
|
||||
NS_CACHESERVICE_CONTRACTID,
|
||||
nsCacheService::Create
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(cacheservice, gResComponents)
|
||||
171
mozilla/netwerk/cache/src/nsCacheRequest.h
vendored
171
mozilla/netwerk/cache/src/nsCacheRequest.h
vendored
@@ -1,171 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheRequest.h, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 22-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheRequest_h_
|
||||
#define _nsCacheRequest_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsICache.h"
|
||||
#include "nsICacheListener.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsCacheSession.h"
|
||||
|
||||
|
||||
class nsCacheRequest : public PRCList
|
||||
{
|
||||
private:
|
||||
friend class nsCacheService;
|
||||
friend class nsCacheEntry;
|
||||
|
||||
nsCacheRequest( nsCString * key,
|
||||
nsICacheListener * listener,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsCacheSession * session)
|
||||
: mKey(key),
|
||||
mInfo(0),
|
||||
mListener(listener),
|
||||
mEventQ(nsnull),
|
||||
mLock(nsnull),
|
||||
mCondVar(nsnull)
|
||||
{
|
||||
PR_INIT_CLIST(this);
|
||||
SetAccessRequested(accessRequested);
|
||||
SetStoragePolicy(session->StoragePolicy());
|
||||
if (session->IsStreamBased()) MarkStreamBased();
|
||||
if (session->WillDoomEntriesIfExpired()) MarkDoomEntriesIfExpired();
|
||||
MarkWaitingForValidation();
|
||||
}
|
||||
|
||||
~nsCacheRequest()
|
||||
{
|
||||
delete mKey;
|
||||
if (mLock) PR_DestroyLock(mLock);
|
||||
if (mCondVar) PR_DestroyCondVar(mCondVar);
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(this), "request still on a list");
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Accessors
|
||||
*/
|
||||
enum CacheRequestInfo {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eStreamBasedMask = 0x00000100,
|
||||
eDoomEntriesIfExpiredMask = 0x00001000,
|
||||
eWaitingForValidationMask = 0x00010000,
|
||||
eAccessRequestedMask = 0xFF000000
|
||||
};
|
||||
|
||||
void SetAccessRequested(nsCacheAccessMode mode)
|
||||
{
|
||||
NS_ASSERTION(mode <= 0xFF, "too many bits in nsCacheAccessMode");
|
||||
mInfo &= ~eAccessRequestedMask;
|
||||
mInfo |= mode << 24;
|
||||
}
|
||||
|
||||
nsCacheAccessMode AccessRequested()
|
||||
{
|
||||
return (nsCacheAccessMode)((mInfo >> 24) & 0xFF);
|
||||
}
|
||||
|
||||
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
||||
PRBool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
||||
|
||||
|
||||
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
||||
PRBool WillDoomEntriesIfExpired() { return (mInfo & eDoomEntriesIfExpiredMask); }
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mInfo |= policy; // or in new bits
|
||||
}
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mInfo & 0xFF);
|
||||
}
|
||||
|
||||
void MarkWaitingForValidation() { mInfo |= eWaitingForValidationMask; }
|
||||
void DoneWaitingForValidation() { mInfo &= ~eWaitingForValidationMask; }
|
||||
PRBool WaitingForValidation()
|
||||
{
|
||||
return (mInfo & eWaitingForValidationMask) != 0;
|
||||
}
|
||||
|
||||
nsresult
|
||||
WaitForValidation(void)
|
||||
{
|
||||
if (!WaitingForValidation()) { // flag already cleared
|
||||
MarkWaitingForValidation(); // set up for next time
|
||||
return NS_OK; // early exit;
|
||||
}
|
||||
|
||||
if (!mLock) {
|
||||
mLock = PR_NewLock();
|
||||
if (!mLock) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ASSERTION(!mCondVar,"we have mCondVar, but didn't have mLock?");
|
||||
mCondVar = PR_NewCondVar(mLock);
|
||||
if (!mCondVar) {
|
||||
PR_DestroyLock(mLock);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
PRStatus status;
|
||||
PR_Lock(mLock);
|
||||
while (WaitingForValidation() && (status == PR_SUCCESS) ) {
|
||||
status = PR_WaitCondVar(mCondVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
MarkWaitingForValidation(); // set up for next time
|
||||
PR_Unlock(mLock);
|
||||
|
||||
NS_ASSERTION(status == PR_SUCCESS, "PR_WaitCondVar() returned PR_FAILURE?");
|
||||
if (status == PR_FAILURE)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void WakeUp(void) {
|
||||
DoneWaitingForValidation();
|
||||
if (mLock) {
|
||||
PR_Lock(mLock);
|
||||
PR_NotifyCondVar(mCondVar);
|
||||
PR_Unlock(mLock);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Data members
|
||||
*/
|
||||
nsCString * mKey;
|
||||
PRUint32 mInfo;
|
||||
nsCOMPtr<nsICacheListener> mListener;
|
||||
nsCOMPtr<nsIEventQueue> mEventQ;
|
||||
PRLock * mLock;
|
||||
PRCondVar * mCondVar;
|
||||
};
|
||||
|
||||
#endif // _nsCacheRequest_h_
|
||||
1074
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
1074
mozilla/netwerk/cache/src/nsCacheService.cpp
vendored
File diff suppressed because it is too large
Load Diff
184
mozilla/netwerk/cache/src/nsCacheService.h
vendored
184
mozilla/netwerk/cache/src/nsCacheService.h
vendored
@@ -1,184 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheService.h, released February 10, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsCacheService_h_
|
||||
#define _nsCacheService_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsCacheSession.h"
|
||||
#include "nsCacheDevice.h"
|
||||
#include "nsCacheEntry.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsCacheRequest;
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheService
|
||||
******************************************************************************/
|
||||
|
||||
class nsCacheService : public nsICacheService, public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHESERVICE
|
||||
NS_DECL_NSIOBSERVER
|
||||
|
||||
nsCacheService();
|
||||
virtual ~nsCacheService();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* outer, const nsIID& iid, void* *result);
|
||||
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheSession
|
||||
*/
|
||||
nsresult OpenCacheEntry(nsCacheSession * session,
|
||||
const char * key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener * listener,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
/**
|
||||
* Methods called by nsCacheEntryDescriptor
|
||||
*/
|
||||
|
||||
nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
nsresult ValidateEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult GetTransportForEntry(nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** result);
|
||||
|
||||
void CloseDescriptor(nsCacheEntryDescriptor * descriptor);
|
||||
|
||||
nsresult GetFileForEntry(nsCacheEntry * entry,
|
||||
nsIFile ** result);
|
||||
|
||||
/**
|
||||
* Methods called by any cache classes
|
||||
*/
|
||||
|
||||
static
|
||||
nsCacheService * GlobalInstance(void) { return gService; };
|
||||
|
||||
nsresult DoomEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult DoomEntry_Locked(nsCacheEntry * entry);
|
||||
|
||||
/**
|
||||
* Methods called by nsCachePrefObserver
|
||||
*/
|
||||
void SetCacheDevicesEnabled(PRBool disk, PRBool memory);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Internal Methods
|
||||
*/
|
||||
|
||||
nsresult CreateDiskDevice();
|
||||
nsresult CreateMemoryDevice();
|
||||
|
||||
nsresult CreateRequest(nsCacheSession * session,
|
||||
const char * clientKey,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener * listener,
|
||||
nsCacheRequest ** request);
|
||||
|
||||
nsresult NotifyListener(nsCacheRequest * request,
|
||||
nsICacheEntryDescriptor * descriptor,
|
||||
nsCacheAccessMode accessGranted,
|
||||
nsresult error);
|
||||
|
||||
nsresult ActivateEntry(nsCacheRequest * request, nsCacheEntry ** entry);
|
||||
|
||||
nsCacheDevice * EnsureEntryHasDevice(nsCacheEntry * entry);
|
||||
|
||||
nsCacheEntry * SearchCacheDevices(nsCString * key, nsCacheStoragePolicy policy);
|
||||
|
||||
void DeactivateEntry(nsCacheEntry * entry);
|
||||
|
||||
nsresult ProcessRequest(nsCacheRequest * request,
|
||||
nsICacheEntryDescriptor ** result);
|
||||
|
||||
nsresult ProcessPendingRequests(nsCacheEntry * entry);
|
||||
|
||||
void ClearPendingRequests(nsCacheEntry * entry);
|
||||
void ClearDoomList(void);
|
||||
void ClearActiveEntries(void);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK DeactivateAndClearEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
#if defined(PR_LOGGING)
|
||||
void LogCacheStatistics();
|
||||
#endif
|
||||
/**
|
||||
* Data Members
|
||||
*/
|
||||
|
||||
enum {
|
||||
cacheServiceActiveMask = 1
|
||||
};
|
||||
|
||||
static nsCacheService * gService; // there can be only one...
|
||||
|
||||
PRLock* mCacheServiceLock;
|
||||
|
||||
PRBool mEnableMemoryDevice;
|
||||
PRBool mEnableDiskDevice;
|
||||
|
||||
nsCacheDevice * mMemoryDevice;
|
||||
nsCacheDevice * mDiskDevice;
|
||||
|
||||
// nsCacheClientHashTable mClientIDs;
|
||||
nsCacheEntryHashTable mActiveEntries;
|
||||
PRCList mDoomedEntries;
|
||||
|
||||
// stats
|
||||
|
||||
PRUint32 mTotalEntries;
|
||||
PRUint32 mCacheHits;
|
||||
PRUint32 mCacheMisses;
|
||||
PRUint32 mMaxKeyLength;
|
||||
PRUint32 mMaxDataSize;
|
||||
PRUint32 mMaxMetaSize;
|
||||
|
||||
// Unexpected error totals
|
||||
PRUint32 mDeactivateFailures;
|
||||
PRUint32 mDeactivatedUnboundEntries;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsCacheService_h_
|
||||
101
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
101
mozilla/netwerk/cache/src/nsCacheSession.cpp
vendored
@@ -1,101 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheSession.h, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsCacheSession.h"
|
||||
#include "nsCacheService.h"
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsCacheSession, nsICacheSession)
|
||||
|
||||
nsCacheSession::nsCacheSession(const char * clientID,
|
||||
nsCacheStoragePolicy storagePolicy,
|
||||
PRBool streamBased)
|
||||
: mClientID(clientID),
|
||||
mInfo(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
SetStoragePolicy(storagePolicy);
|
||||
|
||||
if (streamBased) MarkStreamBased();
|
||||
else SetStoragePolicy(nsICache::STORE_IN_MEMORY);
|
||||
}
|
||||
|
||||
nsCacheSession::~nsCacheSession()
|
||||
{
|
||||
/* destructor code */
|
||||
// notify service we are going away?
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::GetDoomEntriesIfExpired(PRBool *result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = WillDoomEntriesIfExpired();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::SetDoomEntriesIfExpired(PRBool doomEntriesIfExpired)
|
||||
{
|
||||
if (doomEntriesIfExpired) MarkDoomEntriesIfExpired();
|
||||
else ClearDoomEntriesIfExpired();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsCacheSession::OpenCacheEntry(const char * key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheEntryDescriptor ** result)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OpenCacheEntry(this,
|
||||
key,
|
||||
accessRequested,
|
||||
nsnull, // no listener
|
||||
result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::AsyncOpenCacheEntry(const char *key,
|
||||
nsCacheAccessMode accessRequested,
|
||||
nsICacheListener *listener)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsCacheService::GlobalInstance()->OpenCacheEntry(this,
|
||||
key,
|
||||
accessRequested,
|
||||
listener,
|
||||
nsnull); // no result
|
||||
|
||||
if (rv == NS_ERROR_CACHE_WAIT_FOR_VALIDATION) rv = NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsCacheSession::EvictEntries()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
76
mozilla/netwerk/cache/src/nsCacheSession.h
vendored
76
mozilla/netwerk/cache/src/nsCacheSession.h
vendored
@@ -1,76 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheSession.h, released February 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsCacheSession_h_
|
||||
#define _nsCacheSession_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsError.h"
|
||||
#include "nsICacheSession.h"
|
||||
#include "nsString.h"
|
||||
|
||||
class nsCacheSession : public nsICacheSession
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHESESSION
|
||||
|
||||
nsCacheSession(const char * clientID, nsCacheStoragePolicy storagePolicy, PRBool streamBased);
|
||||
virtual ~nsCacheSession();
|
||||
|
||||
nsCString * ClientID() { return &mClientID; }
|
||||
|
||||
enum SessionInfo {
|
||||
eStoragePolicyMask = 0x000000FF,
|
||||
eStreamBasedMask = 0x00000100,
|
||||
eDoomEntriesIfExpiredMask = 0x00001000
|
||||
};
|
||||
|
||||
void MarkStreamBased() { mInfo |= eStreamBasedMask; }
|
||||
void ClearStreamBased() { mInfo &= ~eStreamBasedMask; }
|
||||
PRBool IsStreamBased() { return (mInfo & eStreamBasedMask) != 0; }
|
||||
|
||||
void MarkDoomEntriesIfExpired() { mInfo |= eDoomEntriesIfExpiredMask; }
|
||||
void ClearDoomEntriesIfExpired() { mInfo &= ~eDoomEntriesIfExpiredMask; }
|
||||
PRBool WillDoomEntriesIfExpired() { return (mInfo & eDoomEntriesIfExpiredMask); }
|
||||
|
||||
nsCacheStoragePolicy StoragePolicy()
|
||||
{
|
||||
return (nsCacheStoragePolicy)(mInfo & eStoragePolicyMask);
|
||||
}
|
||||
|
||||
void SetStoragePolicy(nsCacheStoragePolicy policy)
|
||||
{
|
||||
NS_ASSERTION(policy <= 0xFF, "too many bits in nsCacheStoragePolicy");
|
||||
mInfo &= ~eStoragePolicyMask; // clear storage policy bits
|
||||
mInfo |= policy;
|
||||
}
|
||||
|
||||
private:
|
||||
nsCString mClientID;
|
||||
PRUint32 mInfo;
|
||||
};
|
||||
|
||||
#endif // _nsCacheSession_h_
|
||||
199
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
199
mozilla/netwerk/cache/src/nsDiskCache.h
vendored
@@ -1,199 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsCacheDevice.h, released March 9, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick Beard <beard@netscape.com>
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _nsDiskCache_h_
|
||||
#define _nsDiskCache_h_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prnetdb.h"
|
||||
#include "nsDebug.h"
|
||||
|
||||
class nsDiskCacheRecord {
|
||||
enum {
|
||||
eEvictionRankMask = 0xFF000000,
|
||||
eLocationSelectorMask = 0x00C00000,
|
||||
|
||||
eExtraBlocksMask = 0x00300000,
|
||||
eBlockNumberMask = 0x000FFFFF,
|
||||
|
||||
eFileReservedMask = 0x003F0000,
|
||||
eFileGenerationMask = 0x0000FFFF
|
||||
};
|
||||
|
||||
public:
|
||||
nsDiskCacheRecord()
|
||||
: mHashNumber(0), mEvictionRank(0), mLocation(0), mUnused(0)
|
||||
{
|
||||
}
|
||||
|
||||
PRUint32 HashNumber() const
|
||||
{
|
||||
return mHashNumber;
|
||||
}
|
||||
|
||||
void SetHashNumber(PRUint32 hashNumber)
|
||||
{
|
||||
mHashNumber = hashNumber;
|
||||
}
|
||||
|
||||
PRUint32 EvictionRank() const
|
||||
{
|
||||
return mEvictionRank;
|
||||
}
|
||||
|
||||
void SetEvictionRank(PRUint32 rank)
|
||||
{
|
||||
mEvictionRank = rank;
|
||||
}
|
||||
|
||||
PRUint32 LocationSelector() const
|
||||
{
|
||||
return (PRUint32)(mLocation & eLocationSelectorMask) >> 22;
|
||||
}
|
||||
|
||||
void SetLocationSelector(PRUint32 selector)
|
||||
{
|
||||
mLocation &= ~eLocationSelectorMask; // clear location selector bits
|
||||
mLocation |= (selector & eLocationSelectorMask) << 22;
|
||||
}
|
||||
|
||||
PRUint32 BlockCount() const
|
||||
{
|
||||
return (PRUint32)((mLocation & eExtraBlocksMask) >> 20) + 1;
|
||||
}
|
||||
|
||||
void SetBlockCount(PRUint32 count)
|
||||
{
|
||||
NS_ASSERTION( (count>=1) && (count<=4),"invalid block count");
|
||||
count = --count;
|
||||
mLocation &= ~eExtraBlocksMask; // clear extra blocks bits
|
||||
mLocation |= (count & eExtraBlocksMask) << 20;
|
||||
}
|
||||
|
||||
PRUint32 BlockNumber() const
|
||||
{
|
||||
return (mLocation & eBlockNumberMask);
|
||||
}
|
||||
|
||||
void SetBlockNumber(PRUint32 blockNumber)
|
||||
{
|
||||
mLocation &= ~eBlockNumberMask; // clear block number bits
|
||||
mLocation |= blockNumber & eBlockNumberMask;
|
||||
}
|
||||
|
||||
PRUint16 FileGeneration() const
|
||||
{
|
||||
return (mLocation & eFileGenerationMask);
|
||||
}
|
||||
|
||||
void SetFileGeneration(PRUint16 generation)
|
||||
{
|
||||
mLocation &= ~eFileGenerationMask; // clear file generation bits
|
||||
mLocation |= generation & eFileGenerationMask;
|
||||
}
|
||||
|
||||
void Swap()
|
||||
{
|
||||
mHashNumber = ::PR_htonl(mHashNumber);
|
||||
mEvictionRank = ::PR_htonl(mEvictionRank);
|
||||
mLocation = ::PR_htonl(mLocation);
|
||||
mUnused = ::PR_htonl(mUnused);
|
||||
}
|
||||
|
||||
void Unswap()
|
||||
{
|
||||
mHashNumber = ::PR_ntohl(mHashNumber);
|
||||
mEvictionRank = ::PR_ntohl(mEvictionRank);
|
||||
mLocation = ::PR_ntohl(mLocation);
|
||||
mUnused = ::PR_ntohl(mUnused);
|
||||
}
|
||||
|
||||
private:
|
||||
PRUint32 mHashNumber;
|
||||
PRUint32 mEvictionRank;
|
||||
PRUint32 mLocation;
|
||||
PRUint32 mUnused;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
Cache Extent Table
|
||||
|
||||
|
||||
1111 1111 0000 0000 0000 0000 0000 0000 : eEvictionRankMask
|
||||
0000 0000 1100 0000 0000 0000 0000 0000 : eLocationSelectorMask (0-3)
|
||||
0000 0000 0011 0000 0000 0000 0000 0000 : number of extra contiguous blocks 1-4
|
||||
0000 0000 0000 1111 1111 1111 1111 1111 : block# 0-1,048,575
|
||||
|
||||
0000 0000 0011 1111 0000 0000 0000 0000 : eFileReservedMask
|
||||
0000 0000 0000 0000 1111 1111 1111 1111 : eFileGenerationMask
|
||||
|
||||
0 file
|
||||
1 256 bytes
|
||||
2 1024
|
||||
3 4096
|
||||
|
||||
|
||||
log2 of seconds = 5 bits
|
||||
|
||||
log2 minutes hours days years
|
||||
00000 1
|
||||
00001 2
|
||||
00010 4
|
||||
00011 8
|
||||
00100 16
|
||||
00101 32
|
||||
00110 64 1
|
||||
00111 128 2
|
||||
01000 256 4
|
||||
01001 512 8.5
|
||||
01010 1024 17
|
||||
01011 2048 34
|
||||
01100 68
|
||||
01101 136
|
||||
01110 273 11
|
||||
01111 22
|
||||
10000 45.5
|
||||
10001 91
|
||||
10010 182
|
||||
10011 364 1
|
||||
10100 2
|
||||
10101 3
|
||||
10110 4
|
||||
10111
|
||||
11000
|
||||
11001
|
||||
11010
|
||||
11011
|
||||
11100
|
||||
11101
|
||||
11110
|
||||
11111
|
||||
|
||||
*/
|
||||
|
||||
|
||||
#endif // _nsDiskCache_h_
|
||||
1712
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
1712
mozilla/netwerk/cache/src/nsDiskCacheDevice.cpp
vendored
File diff suppressed because it is too large
Load Diff
121
mozilla/netwerk/cache/src/nsDiskCacheDevice.h
vendored
121
mozilla/netwerk/cache/src/nsDiskCacheDevice.h
vendored
@@ -1,121 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsDiskCacheDevice.h, released February 20, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheDevice_h_
|
||||
#define _nsDiskCacheDevice_h_
|
||||
|
||||
#include "nsCacheDevice.h"
|
||||
#include "nsDiskCacheEntry.h"
|
||||
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIObserver.h"
|
||||
|
||||
class nsDiskCacheEntry;
|
||||
class nsDiskCacheMap;
|
||||
class nsDiskCacheRecord;
|
||||
|
||||
class nsISupportsArray;
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
class nsANSIFileStream;
|
||||
|
||||
class nsDiskCacheDevice : public nsCacheDevice {
|
||||
public:
|
||||
nsDiskCacheDevice();
|
||||
virtual ~nsDiskCacheDevice();
|
||||
|
||||
static nsresult Create(nsCacheDevice **result);
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
virtual const char * GetDeviceID(void);
|
||||
virtual nsCacheEntry * FindEntry(nsCString * key);
|
||||
virtual nsresult DeactivateEntry(nsCacheEntry * entry);
|
||||
virtual nsresult BindEntry(nsCacheEntry * entry);
|
||||
virtual void DoomEntry( nsCacheEntry * entry );
|
||||
|
||||
virtual nsresult GetTransportForEntry(nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** result);
|
||||
|
||||
virtual nsresult GetFileForEntry(nsCacheEntry * entry,
|
||||
nsIFile ** result);
|
||||
|
||||
virtual nsresult OnDataSizeChange(nsCacheEntry * entry, PRInt32 deltaSize);
|
||||
|
||||
virtual nsresult Visit(nsICacheVisitor * visitor);
|
||||
|
||||
virtual nsresult EvictEntries(const char * clientID);
|
||||
|
||||
/* private: */
|
||||
void setPrefsObserver(nsIObserver* observer);
|
||||
void getPrefsObserver(nsIObserver ** result);
|
||||
void setCacheDirectory(nsILocalFile* directory);
|
||||
void setCacheCapacity(PRUint32 capacity);
|
||||
PRUint32 getCacheCapacity();
|
||||
PRUint32 getCacheSize();
|
||||
PRUint32 getEntryCount();
|
||||
|
||||
nsresult getFileForHashNumber(PLDHashNumber hashNumber, PRBool meta, PRUint32 generation, nsIFile ** result);
|
||||
nsresult getFileForKey(const char* key, PRBool meta, PRUint32 generation, nsIFile ** result);
|
||||
nsresult getFileForDiskCacheEntry(nsDiskCacheEntry * diskEntry, PRBool meta, nsIFile ** result);
|
||||
|
||||
static nsresult getTransportForFile(nsIFile* file, nsCacheAccessMode mode, nsITransport ** result);
|
||||
static nsresult openInputStream(nsIFile* file, nsIInputStream ** result);
|
||||
static nsresult openOutputStream(nsIFile* file, nsIOutputStream ** result);
|
||||
|
||||
nsresult visitEntries(nsICacheVisitor * visitory);
|
||||
|
||||
nsresult readDiskCacheEntry(const char * key, nsDiskCacheEntry ** diskEntry);
|
||||
|
||||
nsresult updateDiskCacheEntries();
|
||||
nsresult updateDiskCacheEntry(nsDiskCacheEntry * diskEntry);
|
||||
nsresult deleteDiskCacheEntry(nsDiskCacheEntry * diskEntry);
|
||||
|
||||
nsresult scavengeDiskCacheEntries(nsDiskCacheEntry * diskEntry);
|
||||
|
||||
nsresult scanDiskCacheEntries(nsISupportsArray ** result);
|
||||
nsresult evictDiskCacheEntries();
|
||||
|
||||
nsresult clobberDiskCache();
|
||||
|
||||
nsresult openCacheMap();
|
||||
nsresult readCacheMap();
|
||||
nsresult writeCacheMap();
|
||||
|
||||
nsresult updateCacheMap(nsDiskCacheEntry * diskEntry);
|
||||
nsresult evictDiskCacheRecord(nsDiskCacheRecord * record);
|
||||
|
||||
private:
|
||||
PRBool mInitialized;
|
||||
nsCOMPtr<nsIObserver> mPrefsObserver;
|
||||
nsCOMPtr<nsILocalFile> mCacheDirectory;
|
||||
nsDiskCacheEntryHashTable mBoundEntries;
|
||||
PRUint32 mCacheCapacity;
|
||||
nsDiskCacheMap* mCacheMap;
|
||||
nsANSIFileStream* mCacheStream;
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheDevice_h_
|
||||
213
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
213
mozilla/netwerk/cache/src/nsDiskCacheEntry.cpp
vendored
@@ -1,213 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
#include "nsDiskCacheEntry.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS0(nsDiskCacheEntry);
|
||||
|
||||
PLDHashNumber
|
||||
nsDiskCacheEntry::Hash(const char* key)
|
||||
{
|
||||
PLDHashNumber h = 0;
|
||||
for (const PRUint8* s = (PRUint8*) key; *s != '\0'; ++s)
|
||||
h = (h >> (PL_DHASH_BITS - 4)) ^ (h << 4) ^ *s;
|
||||
return (h == 0 ? ULONG_MAX : h);
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* nsCacheEntryHashTable
|
||||
*****************************************************************************/
|
||||
|
||||
PLDHashTableOps nsDiskCacheEntryHashTable::ops =
|
||||
{
|
||||
PL_DHashAllocTable,
|
||||
PL_DHashFreeTable,
|
||||
GetKey,
|
||||
HashKey,
|
||||
MatchEntry,
|
||||
MoveEntry,
|
||||
ClearEntry,
|
||||
Finalize
|
||||
};
|
||||
|
||||
nsDiskCacheEntryHashTable::nsDiskCacheEntryHashTable()
|
||||
: initialized(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheEntryHashTable::~nsDiskCacheEntryHashTable()
|
||||
{
|
||||
if (initialized)
|
||||
PL_DHashTableFinish(&table);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheEntryHashTable::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
initialized = PL_DHashTableInit(&table, &ops, nsnull,
|
||||
sizeof(HashTableEntry), 512);
|
||||
|
||||
if (!initialized) rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheEntry *
|
||||
nsDiskCacheEntryHashTable::GetEntry(const char * key)
|
||||
{
|
||||
return GetEntry(nsDiskCacheEntry::Hash(key));
|
||||
}
|
||||
|
||||
|
||||
nsDiskCacheEntry *
|
||||
nsDiskCacheEntryHashTable::GetEntry(PLDHashNumber key)
|
||||
{
|
||||
nsDiskCacheEntry * result = nsnull;
|
||||
NS_ASSERTION(initialized, "nsDiskCacheEntryHashTable not initialized");
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry*) PL_DHashTableOperate(&table, (void*) key, PL_DHASH_LOOKUP);
|
||||
if (PL_DHASH_ENTRY_IS_BUSY(hashEntry)) {
|
||||
result = hashEntry->mDiskCacheEntry;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsDiskCacheEntryHashTable::AddEntry(nsDiskCacheEntry * entry)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(entry);
|
||||
NS_ASSERTION(initialized, "nsDiskCacheEntryHashTable not initialized");
|
||||
|
||||
HashTableEntry * hashEntry;
|
||||
hashEntry = (HashTableEntry *) PL_DHashTableOperate(&table,
|
||||
(void*) entry->getHashNumber(),
|
||||
PL_DHASH_ADD);
|
||||
if (!hashEntry) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(hashEntry->mDiskCacheEntry = entry);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDiskCacheEntryHashTable::RemoveEntry(nsDiskCacheEntry * entry)
|
||||
{
|
||||
NS_ASSERTION(initialized, "nsDiskCacheEntryHashTable not initialized");
|
||||
NS_ASSERTION(entry, "### cacheEntry == nsnull");
|
||||
|
||||
(void) PL_DHashTableOperate(&table, (void*) entry->getHashNumber(), PL_DHASH_REMOVE);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsDiskCacheEntryHashTable::VisitEntries(Visitor *visitor)
|
||||
{
|
||||
PL_DHashTableEnumerate(&table, VisitEntry, visitor);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * header,
|
||||
PRUint32 number,
|
||||
void * arg)
|
||||
{
|
||||
HashTableEntry* hashEntry = (HashTableEntry *) header;
|
||||
Visitor *visitor = (Visitor*) arg;
|
||||
return (visitor->VisitEntry(hashEntry->mDiskCacheEntry) ? PL_DHASH_NEXT : PL_DHASH_STOP);
|
||||
}
|
||||
|
||||
/**
|
||||
* hash table operation callback functions
|
||||
*/
|
||||
const void * PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::GetKey(PLDHashTable * /*table*/, PLDHashEntryHdr * header)
|
||||
{
|
||||
HashTableEntry * hashEntry = (HashTableEntry *) header;
|
||||
return (void*) hashEntry->mDiskCacheEntry->getHashNumber();
|
||||
}
|
||||
|
||||
|
||||
PLDHashNumber PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::HashKey( PLDHashTable *table, const void *key)
|
||||
{
|
||||
return (PLDHashNumber) key;
|
||||
}
|
||||
|
||||
PRBool PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::MatchEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * header,
|
||||
const void * key)
|
||||
{
|
||||
HashTableEntry * hashEntry = (HashTableEntry *) header;
|
||||
return (hashEntry->mDiskCacheEntry->getHashNumber() == (PLDHashNumber) key);
|
||||
}
|
||||
|
||||
void PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::MoveEntry(PLDHashTable * /* table */,
|
||||
const PLDHashEntryHdr * fromHeader,
|
||||
PLDHashEntryHdr * toHeader)
|
||||
{
|
||||
HashTableEntry * fromEntry = (HashTableEntry *) fromHeader;
|
||||
HashTableEntry * toEntry = (HashTableEntry *) toHeader;
|
||||
toEntry->keyHash = fromEntry->keyHash;
|
||||
toEntry->mDiskCacheEntry = fromEntry->mDiskCacheEntry;
|
||||
fromEntry->mDiskCacheEntry = nsnull;
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::ClearEntry(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * header)
|
||||
{
|
||||
HashTableEntry* hashEntry = (HashTableEntry *) header;
|
||||
hashEntry->keyHash = 0;
|
||||
NS_IF_RELEASE(hashEntry->mDiskCacheEntry);
|
||||
}
|
||||
|
||||
|
||||
void PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::Finalize(PLDHashTable * table)
|
||||
{
|
||||
(void) PL_DHashTableEnumerate(table, FreeCacheEntries, nsnull);
|
||||
}
|
||||
|
||||
|
||||
PLDHashOperator PR_CALLBACK
|
||||
nsDiskCacheEntryHashTable::FreeCacheEntries(PLDHashTable * /* table */,
|
||||
PLDHashEntryHdr * header,
|
||||
PRUint32 number,
|
||||
void * arg)
|
||||
{
|
||||
HashTableEntry *entry = (HashTableEntry *) header;
|
||||
NS_IF_RELEASE(entry->mDiskCacheEntry);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
164
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
164
mozilla/netwerk/cache/src/nsDiskCacheEntry.h
vendored
@@ -1,164 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheEntry_h_
|
||||
#define _nsDiskCacheEntry_h_
|
||||
|
||||
#include "nspr.h"
|
||||
#include "pldhash.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
#include "nsITransport.h"
|
||||
#endif
|
||||
|
||||
class nsDiskCacheEntry : public nsISupports, public PRCList {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsDiskCacheEntry(nsCacheEntry* entry)
|
||||
: mCacheEntry(entry),
|
||||
mGeneration(0)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
PR_INIT_CLIST(this);
|
||||
mHashNumber = Hash(entry->Key()->get());
|
||||
}
|
||||
|
||||
virtual ~nsDiskCacheEntry()
|
||||
{
|
||||
PR_REMOVE_LINK(this);
|
||||
}
|
||||
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
/**
|
||||
* Maps a cache access mode to a cached nsITransport for that access
|
||||
* mode. We keep these cached to avoid repeated trips to the
|
||||
* file transport service.
|
||||
*/
|
||||
nsCOMPtr<nsITransport>& getTransport(nsCacheAccessMode mode)
|
||||
{
|
||||
return mTransports[mode - 1];
|
||||
}
|
||||
#endif
|
||||
|
||||
nsCacheEntry* getCacheEntry()
|
||||
{
|
||||
return mCacheEntry;
|
||||
}
|
||||
|
||||
PRUint32 getGeneration()
|
||||
{
|
||||
return mGeneration;
|
||||
}
|
||||
|
||||
void setGeneration(PRUint32 generation)
|
||||
{
|
||||
mGeneration = generation;
|
||||
}
|
||||
|
||||
PLDHashNumber getHashNumber()
|
||||
{
|
||||
return mHashNumber;
|
||||
}
|
||||
|
||||
nsrefcnt getRefCount()
|
||||
{
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
static PLDHashNumber Hash(const char* key);
|
||||
|
||||
private:
|
||||
#ifdef MOZ_NEW_CACHE_REUSE_TRANSPORTS
|
||||
nsCOMPtr<nsITransport> mTransports[3];
|
||||
#endif
|
||||
nsCacheEntry* mCacheEntry;
|
||||
PRUint32 mGeneration;
|
||||
PLDHashNumber mHashNumber;
|
||||
};
|
||||
|
||||
class nsDiskCacheEntryHashTable {
|
||||
public:
|
||||
nsDiskCacheEntryHashTable();
|
||||
~nsDiskCacheEntryHashTable();
|
||||
|
||||
nsresult Init();
|
||||
|
||||
nsDiskCacheEntry * GetEntry(const char * key);
|
||||
nsDiskCacheEntry * GetEntry(PLDHashNumber key);
|
||||
nsresult AddEntry(nsDiskCacheEntry * entry);
|
||||
void RemoveEntry(nsDiskCacheEntry * entry);
|
||||
|
||||
class Visitor {
|
||||
public:
|
||||
virtual PRBool VisitEntry(nsDiskCacheEntry * entry) = 0;
|
||||
};
|
||||
|
||||
void VisitEntries(Visitor * visitor);
|
||||
|
||||
private:
|
||||
struct HashTableEntry : PLDHashEntryHdr {
|
||||
nsDiskCacheEntry * mDiskCacheEntry; // STRONG ref?
|
||||
};
|
||||
|
||||
// PLDHashTable operation callbacks
|
||||
static const void * PR_CALLBACK GetKey(PLDHashTable * table,
|
||||
PLDHashEntryHdr * entry);
|
||||
|
||||
static PLDHashNumber PR_CALLBACK HashKey(PLDHashTable * table,
|
||||
const void * key);
|
||||
|
||||
static PRBool PR_CALLBACK MatchEntry(PLDHashTable * table,
|
||||
const PLDHashEntryHdr * entry,
|
||||
const void * key);
|
||||
|
||||
static void PR_CALLBACK MoveEntry(PLDHashTable * table,
|
||||
const PLDHashEntryHdr * from,
|
||||
PLDHashEntryHdr * to);
|
||||
|
||||
static void PR_CALLBACK ClearEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * entry);
|
||||
|
||||
static void PR_CALLBACK Finalize(PLDHashTable *table);
|
||||
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK FreeCacheEntries(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
static
|
||||
PLDHashOperator PR_CALLBACK VisitEntry(PLDHashTable * table,
|
||||
PLDHashEntryHdr * hdr,
|
||||
PRUint32 number,
|
||||
void * arg);
|
||||
|
||||
// member variables
|
||||
static PLDHashTableOps ops;
|
||||
PLDHashTable table;
|
||||
PRBool initialized;
|
||||
};
|
||||
|
||||
#endif /* _nsDiskCacheEntry_h_ */
|
||||
263
mozilla/netwerk/cache/src/nsDiskCacheMap.cpp
vendored
263
mozilla/netwerk/cache/src/nsDiskCacheMap.cpp
vendored
@@ -1,263 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsDiskCacheMap.cpp, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsDiskCacheMap.h"
|
||||
#include "nsIFileStreams.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
nsDiskCacheMap::nsDiskCacheMap()
|
||||
{
|
||||
}
|
||||
|
||||
nsDiskCacheMap::~nsDiskCacheMap()
|
||||
{
|
||||
}
|
||||
|
||||
void nsDiskCacheMap::Reset()
|
||||
{
|
||||
mHeader.mDataSize = 0;
|
||||
mHeader.mEntryCount = 0;
|
||||
mHeader.mIsDirty = PR_TRUE;
|
||||
|
||||
for (PRUint32 b = 0; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
::memset(&bucket, 0, sizeof(nsDiskCacheBucket));
|
||||
}
|
||||
}
|
||||
|
||||
nsDiskCacheRecord* nsDiskCacheMap::GetRecord(PRUint32 hashNumber)
|
||||
{
|
||||
nsDiskCacheBucket& bucket = mBuckets[GetBucketIndex(hashNumber)];
|
||||
nsDiskCacheRecord* oldestRecord = &bucket.mRecords[0];
|
||||
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0 || record->HashNumber() == hashNumber)
|
||||
return record;
|
||||
if (record->EvictionRank() < oldestRecord->EvictionRank())
|
||||
oldestRecord = record;
|
||||
}
|
||||
// if we don't find an empty record, return the oldest record for eviction.
|
||||
return oldestRecord;
|
||||
}
|
||||
|
||||
|
||||
void nsDiskCacheMap::DeleteRecord(nsDiskCacheRecord* deletedRecord)
|
||||
{
|
||||
PRUint32 hashNumber = deletedRecord->HashNumber();
|
||||
nsDiskCacheBucket& bucket = mBuckets[GetBucketIndex(hashNumber)];
|
||||
NS_ASSERTION(deletedRecord >= &bucket.mRecords[0] &&
|
||||
deletedRecord < &bucket.mRecords[kRecordsPerBucket],
|
||||
"invalid record to delete.");
|
||||
nsDiskCacheRecord* limit = &bucket.mRecords[kRecordsPerBucket];
|
||||
nsDiskCacheRecord* lastRecord = nsnull;
|
||||
// XXX use binary search to find the end, much quicker.
|
||||
// find the last record, to fill in the deleted record.
|
||||
for (nsDiskCacheRecord* record = deletedRecord + 1; record < limit; ++record) {
|
||||
if (record->HashNumber() == 0) {
|
||||
lastRecord = record - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// copy the last record, to the newly deleted record.
|
||||
if (lastRecord && deletedRecord != lastRecord) {
|
||||
*deletedRecord = *lastRecord;
|
||||
deletedRecord = lastRecord;
|
||||
}
|
||||
// mark record as free.
|
||||
deletedRecord->SetHashNumber(0);
|
||||
// reduce the number of entries.
|
||||
mHeader.mEntryCount--;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsDiskCacheMap::Read(nsIInputStream* input)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
|
||||
// seek to beginning of the file.
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(input, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// read the header.
|
||||
nsDiskCacheHeader header;
|
||||
rv = input->Read((char*)&header, sizeof(header), &count);
|
||||
if (count != sizeof(header)) return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
header.Unswap();
|
||||
|
||||
// validate the version.
|
||||
if (header.mVersion != nsDiskCacheHeader::kCurrentVersion) return NS_ERROR_FAILURE;
|
||||
mHeader = header;
|
||||
|
||||
// seek to beginning of first bucket.
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, sizeof(nsDiskCacheBucket));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// read the buckets.
|
||||
rv = input->Read((char*)&mBuckets, sizeof(mBuckets), &count);
|
||||
if (count != sizeof(mBuckets)) return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// unswap all of the active records.
|
||||
for (int b = 0; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Unswap();
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsDiskCacheMap::Write(nsIOutputStream* output)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
|
||||
// seek to beginning of the file.
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(output, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// write the header.
|
||||
nsDiskCacheHeader header = mHeader;
|
||||
header.Swap();
|
||||
rv = output->Write((char*)&header, sizeof(header), &count);
|
||||
if (count != sizeof(header)) return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// pad the rest of the header to sizeof(nsDiskCacheBucket).
|
||||
char padding[sizeof(nsDiskCacheBucket) - sizeof(nsDiskCacheHeader)];
|
||||
::memset(padding, 0, sizeof(padding));
|
||||
rv = output->Write(padding, sizeof(padding), &count);
|
||||
if (count != sizeof(padding)) return NS_ERROR_FAILURE;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// swap all of the active records.
|
||||
{
|
||||
for (int b = 0; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Swap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// write the buckets.
|
||||
rv = output->Write((char*)&mBuckets, sizeof(mBuckets), &count);
|
||||
output->Flush();
|
||||
|
||||
// unswap all of the active records.
|
||||
{
|
||||
for (int b = 0; b < kBucketsPerTable; ++b) {
|
||||
nsDiskCacheBucket& bucket = mBuckets[b];
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Unswap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (count != sizeof(mBuckets)) return NS_ERROR_FAILURE;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsDiskCacheMap::WriteBucket(nsIOutputStream* output, PRUint32 index)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// can only do this if the stream is seekable.
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(output, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// seek to the offset of this bucket, (index + 1) to skip the header.
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, (index + 1) * sizeof(nsDiskCacheBucket));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsDiskCacheBucket& bucket = mBuckets[index];
|
||||
|
||||
// swap all of the active records.
|
||||
{
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Swap();
|
||||
}
|
||||
}
|
||||
|
||||
PRUint32 count;
|
||||
rv = output->Write((char*)&bucket, sizeof(nsDiskCacheBucket), &count);
|
||||
output->Flush();
|
||||
|
||||
// unswap all of the active records.
|
||||
{
|
||||
for (int r = 0; r < kRecordsPerBucket; ++r) {
|
||||
nsDiskCacheRecord* record = &bucket.mRecords[r];
|
||||
if (record->HashNumber() == 0)
|
||||
break;
|
||||
record->Unswap();
|
||||
}
|
||||
}
|
||||
|
||||
NS_ASSERTION(count == sizeof(nsDiskCacheBucket), "nsDiskCacheMap::WriteBucket failed");
|
||||
if (count != sizeof(nsDiskCacheBucket)) return NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsDiskCacheMap::WriteHeader(nsIOutputStream* output)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
|
||||
// can only do this if the stream is seekable.
|
||||
nsCOMPtr<nsISeekableStream> seekable = do_QueryInterface(output, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// write the header.
|
||||
nsDiskCacheHeader header = mHeader;
|
||||
header.Swap();
|
||||
rv = output->Write((char*)&header, sizeof(header), &count);
|
||||
output->Flush();
|
||||
if (count != sizeof(header)) return NS_ERROR_FAILURE;
|
||||
|
||||
return rv;
|
||||
}
|
||||
117
mozilla/netwerk/cache/src/nsDiskCacheMap.h
vendored
117
mozilla/netwerk/cache/src/nsDiskCacheMap.h
vendored
@@ -1,117 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsDiskCacheMap.h, released March 23, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _nsDiskCacheMap_h_
|
||||
|
||||
#include "nsDiskCache.h"
|
||||
#include "nsError.h"
|
||||
|
||||
class nsIInputStream;
|
||||
class nsIOutputStream;
|
||||
|
||||
struct nsDiskCacheHeader {
|
||||
enum { kCurrentVersion = 0x00010002 };
|
||||
|
||||
PRUint32 mVersion; // cache version.
|
||||
PRUint32 mDataSize; // size of cache in bytes.
|
||||
PRUint32 mEntryCount; // number of entries stored in cache.
|
||||
PRUint32 mIsDirty; // dirty flag.
|
||||
// XXX need a bitmap?
|
||||
|
||||
nsDiskCacheHeader()
|
||||
: mVersion(kCurrentVersion), mDataSize(0),
|
||||
mEntryCount(0), mIsDirty(PR_TRUE)
|
||||
{
|
||||
}
|
||||
|
||||
void Swap()
|
||||
{
|
||||
mVersion = ::PR_htonl(mVersion);
|
||||
mDataSize = ::PR_htonl(mDataSize);
|
||||
mEntryCount = ::PR_htonl(mEntryCount);
|
||||
mIsDirty = ::PR_htonl(mIsDirty);
|
||||
}
|
||||
|
||||
void Unswap()
|
||||
{
|
||||
mVersion = ::PR_ntohl(mVersion);
|
||||
mDataSize = ::PR_ntohl(mDataSize);
|
||||
mEntryCount = ::PR_ntohl(mEntryCount);
|
||||
mIsDirty = ::PR_ntohl(mIsDirty);
|
||||
}
|
||||
};
|
||||
|
||||
// XXX initial capacity, enough for 8192 distinct entries.
|
||||
class nsDiskCacheMap {
|
||||
public:
|
||||
nsDiskCacheMap();
|
||||
~nsDiskCacheMap();
|
||||
|
||||
void Reset();
|
||||
|
||||
PRUint32& DataSize() { return mHeader.mDataSize; }
|
||||
PRUint32& EntryCount() { return mHeader.mEntryCount; }
|
||||
PRUint32& IsDirty() { return mHeader.mIsDirty; }
|
||||
|
||||
nsDiskCacheRecord* GetRecord(PRUint32 hashNumber);
|
||||
void DeleteRecord(nsDiskCacheRecord* record);
|
||||
|
||||
enum {
|
||||
kRecordsPerBucket = 256,
|
||||
kBucketsPerTable = (1 << 5) // must be a power of 2!
|
||||
};
|
||||
|
||||
nsDiskCacheRecord* GetBucket(PRUint32 index)
|
||||
{
|
||||
return mBuckets[index].mRecords;
|
||||
}
|
||||
|
||||
PRUint32 GetBucketIndex(PRUint32 hashNumber)
|
||||
{
|
||||
return (hashNumber & (kBucketsPerTable - 1));
|
||||
}
|
||||
|
||||
PRUint32 GetBucketIndex(nsDiskCacheRecord* record)
|
||||
{
|
||||
return GetBucketIndex(record->HashNumber());
|
||||
}
|
||||
|
||||
nsresult Read(nsIInputStream* input);
|
||||
nsresult Write(nsIOutputStream* output);
|
||||
|
||||
nsresult ReadBucket(nsIInputStream* input, PRUint32 index);
|
||||
nsresult WriteBucket(nsIOutputStream* output, PRUint32 index);
|
||||
|
||||
nsresult ReadHeader(nsIInputStream* input);
|
||||
nsresult WriteHeader(nsIOutputStream* output);
|
||||
|
||||
private:
|
||||
struct nsDiskCacheBucket {
|
||||
nsDiskCacheRecord mRecords[kRecordsPerBucket];
|
||||
};
|
||||
|
||||
nsDiskCacheHeader mHeader;
|
||||
nsDiskCacheBucket mBuckets[kBucketsPerTable];
|
||||
};
|
||||
|
||||
#endif // _nsDiskCacheMap_h_
|
||||
442
mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp
vendored
442
mozilla/netwerk/cache/src/nsMemoryCacheDevice.cpp
vendored
@@ -1,442 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsMemoryCacheDevice.cpp, released February 22, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, <gordon@netscape.com>
|
||||
* Patrick C. Beard <beard@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsMemoryCacheDevice.h"
|
||||
#include "nsCacheService.h"
|
||||
#include "nsICacheService.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsICacheVisitor.h"
|
||||
#include "nsITransport.h"
|
||||
#include "signal.h"
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kStorageTransportCID, NS_STORAGETRANSPORT_CID);
|
||||
|
||||
const char *gMemoryDeviceID = "memory";
|
||||
const char *gMemoryCacheSizePref = "browser.cache.memory_cache_size";
|
||||
|
||||
|
||||
nsMemoryCacheDevice::nsMemoryCacheDevice()
|
||||
: mHardLimit(0),
|
||||
mSoftLimit(0),
|
||||
mTotalSize(0),
|
||||
mInactiveSize(0),
|
||||
mEntryCount(0),
|
||||
mMaxEntryCount(0)
|
||||
{
|
||||
PR_INIT_CLIST(&mEvictionList);
|
||||
}
|
||||
|
||||
nsMemoryCacheDevice::~nsMemoryCacheDevice()
|
||||
{
|
||||
#if DEBUG
|
||||
printf("### starting ~nsMemoryCacheDevice()\n");
|
||||
#endif
|
||||
// XXX dealloc all memory
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
prefs->UnregisterCallback(gMemoryCacheSizePref, MemoryCacheSizeChanged, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int PR_CALLBACK
|
||||
nsMemoryCacheDevice::MemoryCacheSizeChanged(const char * pref, void * closure)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 softLimit = 0;
|
||||
nsMemoryCacheDevice * device = (nsMemoryCacheDevice *)closure;
|
||||
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = prefs->GetIntPref(gMemoryCacheSizePref, (PRInt32 *)&softLimit);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
softLimit *= 1024; // convert k into bytes
|
||||
PRUint32 hardLimit = softLimit + 1024*1024*2; // XXX find better limit than +2Meg
|
||||
device->AdjustMemoryLimits(softLimit, hardLimit);
|
||||
|
||||
return 0; // XXX what are we supposed to return?
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Init()
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
rv = mMemCacheEntries.Init();
|
||||
|
||||
// set some default memory limits, in case prefs aren't available
|
||||
mSoftLimit = 1024 * 1024 * 3;
|
||||
mHardLimit = mSoftLimit + 1024 *1024 * 2;
|
||||
|
||||
// read user prefs for memory cache limits
|
||||
NS_WITH_SERVICE(nsIPref, prefs, NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
|
||||
rv = prefs->RegisterCallback(gMemoryCacheSizePref, MemoryCacheSizeChanged, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// Initialize the pref
|
||||
MemoryCacheSizeChanged(gMemoryCacheSizePref, this);
|
||||
}
|
||||
|
||||
// Register as a memory pressure observer
|
||||
NS_WITH_SERVICE(nsIObserverService,
|
||||
observerService,
|
||||
NS_OBSERVERSERVICE_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// XXX rv = observerServcie->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC);
|
||||
}
|
||||
// Ignore failure of memory pressure registration
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Shutdown()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
const char *
|
||||
nsMemoryCacheDevice::GetDeviceID()
|
||||
{
|
||||
return gMemoryDeviceID;
|
||||
}
|
||||
|
||||
|
||||
nsCacheEntry *
|
||||
nsMemoryCacheDevice::FindEntry(nsCString * key)
|
||||
{
|
||||
nsCacheEntry * entry = mMemCacheEntries.GetEntry(key);
|
||||
if (!entry) return nsnull;
|
||||
|
||||
// move entry to the tail of the eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
PR_APPEND_LINK(entry, &mEvictionList);
|
||||
|
||||
mInactiveSize -= entry->Size();
|
||||
|
||||
return entry;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::DeactivateEntry(nsCacheEntry * entry)
|
||||
{
|
||||
if (entry->IsDoomed()) {
|
||||
#if debug
|
||||
// XXX verify we've removed it from mMemCacheEntries & eviction list
|
||||
#endif
|
||||
// update statistics
|
||||
mTotalSize -= entry->Size();
|
||||
--mEntryCount;
|
||||
|
||||
delete entry;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCacheEntry * ourEntry = mMemCacheEntries.GetEntry(entry->Key());
|
||||
NS_ASSERTION(ourEntry, "DeactivateEntry called for an entry we don't have!");
|
||||
NS_ASSERTION(entry == ourEntry, "entry doesn't match ourEntry");
|
||||
if (ourEntry != entry)
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
|
||||
mInactiveSize += entry->Size();
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::BindEntry(nsCacheEntry * entry)
|
||||
{
|
||||
NS_ASSERTION(PR_CLIST_IS_EMPTY(entry),"entry is already on a list!");
|
||||
|
||||
if (!entry->IsDoomed()) {
|
||||
// append entry to the eviction list
|
||||
PR_APPEND_LINK(entry, &mEvictionList);
|
||||
|
||||
// add entry to hashtable of mem cache entries
|
||||
nsresult rv = mMemCacheEntries.AddEntry(entry);
|
||||
if (NS_FAILED(rv)) {
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
||||
// add size of entry to memory totals
|
||||
++mEntryCount;
|
||||
if (mMaxEntryCount < mEntryCount) mMaxEntryCount = mEntryCount;
|
||||
|
||||
mTotalSize += entry->Size();
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::DoomEntry(nsCacheEntry * entry)
|
||||
{
|
||||
// XXX debug code to verify we have entry
|
||||
mMemCacheEntries.RemoveEntry(entry);
|
||||
|
||||
// remove entry from our eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport ** transport )
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(entry);
|
||||
NS_ENSURE_ARG_POINTER(transport);
|
||||
|
||||
nsCOMPtr<nsISupports> data;
|
||||
|
||||
nsresult rv = entry->GetData(getter_AddRefs(data));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (data)
|
||||
return CallQueryInterface(data, transport);
|
||||
else {
|
||||
// create a new transport for this entry
|
||||
rv = nsComponentManager::CreateInstance(kStorageTransportCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsITransport),
|
||||
(void **) transport);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
entry->SetData(*transport);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result )
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize)
|
||||
{
|
||||
if (entry->IsStreamData()) {
|
||||
// we have the right to refuse or pre-evict
|
||||
}
|
||||
|
||||
// adjust our totals
|
||||
mTotalSize += deltaSize;
|
||||
|
||||
EvictEntriesIfNecessary();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::AdjustMemoryLimits(PRUint32 softLimit, PRUint32 hardLimit)
|
||||
{
|
||||
mSoftLimit = softLimit;
|
||||
mHardLimit = hardLimit;
|
||||
EvictEntriesIfNecessary();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::EvictEntry(nsCacheEntry * entry)
|
||||
{
|
||||
// remove entry from our hashtable
|
||||
mMemCacheEntries.RemoveEntry(entry);
|
||||
|
||||
// remove entry from the eviction list
|
||||
PR_REMOVE_AND_INIT_LINK(entry);
|
||||
|
||||
// update statistics
|
||||
PRUint32 memoryRecovered = entry->Size();
|
||||
mTotalSize -= memoryRecovered;
|
||||
mInactiveSize -= memoryRecovered;
|
||||
--mEntryCount;
|
||||
|
||||
delete entry;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
nsMemoryCacheDevice::EvictEntriesIfNecessary(void)
|
||||
{
|
||||
nsCacheEntry * entry, * next;
|
||||
|
||||
if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit))
|
||||
return;
|
||||
|
||||
// XXX implement more sophisticated eviction ordering
|
||||
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList);
|
||||
while (entry != &mEvictionList) {
|
||||
if (entry->IsInUse()) {
|
||||
entry = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
continue;
|
||||
}
|
||||
|
||||
next = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
EvictEntry(entry);
|
||||
entry = next;
|
||||
|
||||
if ((mTotalSize < mHardLimit) && (mInactiveSize < mSoftLimit))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::Visit(nsICacheVisitor * visitor)
|
||||
{
|
||||
nsMemoryCacheDeviceInfo * deviceInfo = new nsMemoryCacheDeviceInfo(this);
|
||||
nsCOMPtr<nsICacheDeviceInfo> deviceRef(deviceInfo);
|
||||
if (!deviceInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRBool keepGoing;
|
||||
nsresult rv = visitor->VisitDevice(gMemoryDeviceID, deviceInfo, &keepGoing);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!keepGoing)
|
||||
return NS_OK;
|
||||
|
||||
nsCacheEntry * entry;
|
||||
nsCOMPtr<nsICacheEntryInfo> entryRef;
|
||||
|
||||
entry = (nsCacheEntry *)PR_LIST_HEAD(&mEvictionList);
|
||||
while (entry != &mEvictionList) {
|
||||
nsCacheEntryInfo * entryInfo = new nsCacheEntryInfo(entry);
|
||||
if (!entryInfo) return NS_ERROR_OUT_OF_MEMORY;
|
||||
entryRef = entryInfo;
|
||||
|
||||
rv = visitor->VisitEntry(gMemoryDeviceID, entryInfo, &keepGoing);
|
||||
entryInfo->DetachEntry();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!keepGoing) break;
|
||||
|
||||
entry = (nsCacheEntry *)PR_NEXT_LINK(entry);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMemoryCacheDevice::EvictEntries(const char * clientID)
|
||||
{
|
||||
nsCacheEntry * entry;
|
||||
PRUint32 prefixLength = nsCRT::strlen(clientID);
|
||||
|
||||
PRCList * elem = PR_LIST_HEAD(&mEvictionList);
|
||||
while (elem != &mEvictionList) {
|
||||
entry = (nsCacheEntry *)elem;
|
||||
elem = PR_NEXT_LINK(elem);
|
||||
|
||||
const char * key = entry->Key()->get();
|
||||
if (clientID && nsCRT::strncmp(clientID, key, prefixLength) != 0)
|
||||
continue;
|
||||
|
||||
if (entry->IsInUse()) {
|
||||
nsresult rv = nsCacheService::GlobalInstance()->DoomEntry_Locked(entry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
} else {
|
||||
EvictEntry(entry);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDeviceInfo - for implementing about:cache
|
||||
*****************************************************************************/
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsMemoryCacheDeviceInfo, nsICacheDeviceInfo);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetDescription(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = nsCRT::strdup("Memory cache device");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetUsageReport(char ** result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = nsCRT::strdup("Memory cache usage report:");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetEntryCount(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
// XXX compare calculated count vs. mEntryCount
|
||||
*result = mDevice->mEntryCount;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetTotalSize(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mDevice->mTotalSize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMemoryCacheDeviceInfo::GetMaximumSize(PRUint32 * result)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(result);
|
||||
*result = mDevice->mHardLimit;
|
||||
return NS_OK;
|
||||
}
|
||||
111
mozilla/netwerk/cache/src/nsMemoryCacheDevice.h
vendored
111
mozilla/netwerk/cache/src/nsMemoryCacheDevice.h
vendored
@@ -1,111 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsMemoryCacheDevice.h, released February 20, 2001.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 2001 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Gordon Sheridan, 20-February-2001
|
||||
*/
|
||||
|
||||
#ifndef _nsMemoryCacheDevice_h_
|
||||
#define _nsMemoryCacheDevice_h_
|
||||
|
||||
#include "nsCacheDevice.h"
|
||||
#include "pldhash.h"
|
||||
#include "nsCacheEntry.h"
|
||||
|
||||
|
||||
class nsMemoryCacheDeviceInfo;
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDevice
|
||||
******************************************************************************/
|
||||
class nsMemoryCacheDevice : public nsCacheDevice
|
||||
{
|
||||
public:
|
||||
nsMemoryCacheDevice();
|
||||
virtual ~nsMemoryCacheDevice();
|
||||
|
||||
virtual nsresult Init();
|
||||
virtual nsresult Shutdown();
|
||||
|
||||
virtual const char * GetDeviceID(void);
|
||||
|
||||
virtual nsresult BindEntry( nsCacheEntry * entry );
|
||||
virtual nsCacheEntry * FindEntry( nsCString * key );
|
||||
virtual void DoomEntry( nsCacheEntry * entry );
|
||||
virtual nsresult DeactivateEntry( nsCacheEntry * entry );
|
||||
|
||||
virtual nsresult GetTransportForEntry( nsCacheEntry * entry,
|
||||
nsCacheAccessMode mode,
|
||||
nsITransport **transport );
|
||||
|
||||
virtual nsresult GetFileForEntry( nsCacheEntry * entry,
|
||||
nsIFile ** result );
|
||||
|
||||
virtual nsresult OnDataSizeChange( nsCacheEntry * entry, PRInt32 deltaSize );
|
||||
|
||||
virtual nsresult Visit( nsICacheVisitor * visitor );
|
||||
|
||||
virtual nsresult EvictEntries(const char * clientID);
|
||||
|
||||
static int PR_CALLBACK MemoryCacheSizeChanged(const char * pref, void * closure);
|
||||
|
||||
private:
|
||||
friend class nsMemoryCacheDeviceInfo;
|
||||
void AdjustMemoryLimits( PRUint32 softLimit, PRUint32 hardLimit);
|
||||
void EvictEntry( nsCacheEntry * entry );
|
||||
void EvictEntriesIfNecessary();
|
||||
|
||||
nsCacheEntryHashTable mMemCacheEntries;
|
||||
PRCList mEvictionList;
|
||||
|
||||
PRUint32 mHardLimit;
|
||||
PRUint32 mSoftLimit;
|
||||
|
||||
PRUint32 mTotalSize;
|
||||
PRUint32 mInactiveSize;
|
||||
|
||||
PRUint32 mEntryCount;
|
||||
|
||||
PRUint32 mMaxEntryCount;
|
||||
// XXX what other stats do we want to keep?
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* nsMemoryCacheDeviceInfo - used to call nsIVisitor for about:cache
|
||||
******************************************************************************/
|
||||
class nsMemoryCacheDeviceInfo : public nsICacheDeviceInfo {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSICACHEDEVICEINFO
|
||||
|
||||
nsMemoryCacheDeviceInfo(nsMemoryCacheDevice* device)
|
||||
: mDevice(device)
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
}
|
||||
|
||||
virtual ~nsMemoryCacheDeviceInfo() {}
|
||||
|
||||
private:
|
||||
nsMemoryCacheDevice* mDevice;
|
||||
};
|
||||
|
||||
|
||||
#endif // _nsMemoryCacheDevice_h_
|
||||
231
mozilla/netwerk/cache/src/win32.order
vendored
231
mozilla/netwerk/cache/src/win32.order
vendored
@@ -1,231 +0,0 @@
|
||||
?AddRef@nsCacheEntryDescriptor@@UAGKXZ ; 35743
|
||||
?HashKey@nsCacheEntryHashTable@@CAIPAUPLDHashTable@@PBX@Z ; 29743
|
||||
?Release@nsCacheEntryDescriptor@@UAGKXZ ; 21199
|
||||
??_EnsCString@@UAEPAXI@Z ; 19905
|
||||
?AddRef@nsCacheSession@@UAGKXZ ; 17435
|
||||
?GetEntry@nsCacheEntryHashTable@@QAEPAVnsCacheEntry@@PBVnsCString@@@Z ; 17433
|
||||
?SecondsFromPRTime@@YAI_J@Z ; 14263
|
||||
?CalculateSize@nsCacheMetaData@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 14243
|
||||
?Release@nsCacheEntryInfo@@UAGKXZ ; 10964
|
||||
?GetLastModified@nsDiskCacheEntryInfo@@UAGIPAI@Z ; 9800
|
||||
?Release@nsANSIOutputStream@@UAGKXZ ; 9758
|
||||
?MatchEntry@nsCacheEntryHashTable@@CAHPAUPLDHashTable@@PBUPLDHashEntryHdr@@PBX@Z ; 9663
|
||||
?QueryInterface@nsCacheEntryInfo@@UAGIABUnsID@@PAPAX@Z ; 8638
|
||||
??Rdo_QueryElementAt@@UBEIABUnsID@@PAPAX@Z ; 8638
|
||||
?assign_assuming_AddRef@nsCOMPtr_base@@IAEXPAVnsISupports@@@Z ; 8259
|
||||
??0nsDiskCacheRecord@@QAE@XZ ; 8192
|
||||
?EnsureEntryHasDevice@nsCacheService@@AAEPAVnsCacheDevice@@PAVnsCacheEntry@@@Z ; 7918
|
||||
?MoveEntry@nsCacheEntryHashTable@@CAXPAUPLDHashTable@@PBUPLDHashEntryHdr@@PAU3@@Z ; 7653
|
||||
?GetKey@nsCacheEntryHashTable@@CAPBXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 7653
|
||||
?Close@nsANSIOutputStream@@UAGIXZ ; 7092
|
||||
?Write@nsANSIOutputStream@@UAGIPBDIPAI@Z ; 7067
|
||||
?AccumulateElements@nsCacheMetaData@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 7063
|
||||
?Release@nsDiskCacheDeviceInfo@@UAGKXZ ; 6471
|
||||
?CreateRequest@nsCacheService@@AAEIPAVnsCacheSession@@PBDHPAVnsICacheListener@@PAPAVnsCacheRequest@@@Z ; 6468
|
||||
?ActivateEntry@nsCacheService@@AAEIPAVnsCacheRequest@@PAPAVnsCacheEntry@@@Z ; 6468
|
||||
?ProcessRequest@nsCacheService@@AAEIPAVnsCacheRequest@@PAPAVnsICacheEntryDescriptor@@@Z ; 6468
|
||||
??1nsCacheRequest@@AAE@XZ ; 6468
|
||||
?OpenCacheEntry@nsCacheService@@QAEIPAVnsCacheSession@@PBDHPAVnsICacheListener@@PAPAVnsICacheEntryDescriptor@@@Z ; 6468
|
||||
??0nsCacheRequest@@AAE@PAVnsCString@@PAVnsICacheListener@@HPAVnsCacheSession@@@Z ; 6468
|
||||
?Hash@nsDiskCacheEntry@@SAIPBD@Z ; 6166
|
||||
?HashKey@nsDiskCacheEntryHashTable@@CAIPAUPLDHashTable@@PBX@Z ; 6037
|
||||
?EvictEntriesIfNecessary@nsMemoryCacheDevice@@AAEXXZ ; 5780
|
||||
?TouchData@nsCacheEntry@@QAEXXZ ; 5503
|
||||
?OpenCacheEntry@nsCacheSession@@UAGIPBDHPAPAVnsICacheEntryDescriptor@@@Z ; 5165
|
||||
?RequestAccess@nsCacheEntry@@QAEIPAVnsCacheRequest@@PAH@Z ; 5099
|
||||
?Fetched@nsCacheEntry@@QAEXXZ ; 5094
|
||||
??0nsTransportWrapper@nsCacheEntryDescriptor@@QAE@XZ ; 5092
|
||||
?CreateDescriptor@nsCacheEntry@@QAEIPAVnsCacheRequest@@HPAPAVnsICacheEntryDescriptor@@@Z ; 5092
|
||||
??0nsCacheEntryDescriptor@@QAE@PAVnsCacheEntry@@H@Z ; 5092
|
||||
?RemoveDescriptor@nsCacheEntry@@QAEHPAVnsCacheEntryDescriptor@@@Z ; 5090
|
||||
?CloseDescriptor@nsCacheService@@QAEXPAVnsCacheEntryDescriptor@@@Z ; 5090
|
||||
?Close@nsCacheEntryDescriptor@@UAGIXZ ; 5090
|
||||
??_GnsCacheEntryDescriptor@@UAEPAXI@Z ; 5090
|
||||
??1nsCacheEntryDescriptor@@UAE@XZ ; 5090
|
||||
?SearchCacheDevices@nsCacheService@@AAEPAVnsCacheEntry@@PAVnsCString@@H@Z ; 4993
|
||||
?AddEntry@nsCacheEntryHashTable@@QAEIPAVnsCacheEntry@@@Z ; 4993
|
||||
?FindEntry@nsMemoryCacheDevice@@UAEPAVnsCacheEntry@@PAVnsCString@@@Z ; 4993
|
||||
?ClearEntry@nsCacheEntryHashTable@@CAXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 4993
|
||||
?RemoveEntry@nsCacheEntryHashTable@@QAEXPAVnsCacheEntry@@@Z ; 4921
|
||||
?GetData@nsCacheEntry@@QAEIPAPAVnsISupports@@@Z ; 4811
|
||||
?Release@nsDiskCacheEntry@@UAGKXZ ; 4784
|
||||
?RequestDataSizeChange@nsCacheEntryDescriptor@@QAEIH@Z ; 4127
|
||||
?OnDataSizeChange@nsCacheService@@QAEIPAVnsCacheEntry@@H@Z ; 4127
|
||||
?SetElement@nsCacheMetaData@@QAEIABVnsACString@@0@Z ; 3682
|
||||
?ClearEntry@nsCacheMetaData@@CAXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 3681
|
||||
?FreeElements@nsCacheMetaData@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 3681
|
||||
?GetEntry@nsDiskCacheEntryHashTable@@QAEPAVnsDiskCacheEntry@@PBD@Z ; 3651
|
||||
?GetRecord@nsDiskCacheMap@@QAEPAVnsDiskCacheRecord@@I@Z ; 3650
|
||||
?Size@nsCacheMetaData@@QAEIXZ ; 3628
|
||||
?DeactivateEntry@nsCacheService@@AAEXPAVnsCacheEntry@@@Z ; 3619
|
||||
?TouchMetaData@nsCacheEntry@@QAEXXZ ; 3601
|
||||
?SetMetaDataElement@nsCacheEntryDescriptor@@UAGIPBD0@Z ; 3601
|
||||
?SetMetaDataElement@nsCacheEntry@@QAEIABVnsACString@@0@Z ; 3601
|
||||
?getFileForHashNumber@nsDiskCacheDevice@@QAEIIHIPAPAVnsIFile@@@Z ; 3587
|
||||
?Read@nsANSIInputStream@@UAGIPADIPAI@Z ; 3570
|
||||
?getFileForDiskCacheEntry@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@HPAPAVnsIFile@@@Z ; 3560
|
||||
?Unswap@MetaDataHeader@@QAEXXZ ; 3545
|
||||
??1MetaDataFile@@QAE@XZ ; 3545
|
||||
?OnDataSizeChange@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@H@Z ; 3210
|
||||
?ProcessPendingRequests@nsCacheService@@AAEIPAVnsCacheEntry@@@Z ; 2800
|
||||
??0nsCacheEntry@@QAE@PAVnsCString@@HH@Z ; 2673
|
||||
??1nsCacheEntry@@QAE@XZ ; 2673
|
||||
?MarkValid@nsCacheEntryDescriptor@@UAGIXZ ; 2592
|
||||
?ValidateEntry@nsCacheService@@QAEIPAVnsCacheEntry@@@Z ; 2592
|
||||
?GetCacheElement@nsCacheEntryDescriptor@@UAGIPAPAVnsISupports@@@Z ; 2413
|
||||
?MatchEntry@nsDiskCacheEntryHashTable@@CAHPAUPLDHashTable@@PBUPLDHashEntryHdr@@PBX@Z ; 2383
|
||||
?Release@nsANSIInputStream@@UAGKXZ ; 2380
|
||||
?AddRef@nsANSIInputStream@@UAGKXZ ; 2380
|
||||
?MatchEntry@nsCacheMetaData@@CAHPAUPLDHashTable@@PBUPLDHashEntryHdr@@PBX@Z ; 2365
|
||||
?GetMetaDataElement@nsCacheEntry@@QAEIABVnsACString@@PAPBV2@@Z ; 2365
|
||||
?GetElement@nsCacheMetaData@@QAEPBVnsACString@@PBV2@@Z ; 2365
|
||||
?GetMetaDataElement@nsCacheEntryDescriptor@@UAGIPBDPAPAD@Z ; 2365
|
||||
?openOutputStream@nsDiskCacheDevice@@SAIPAVnsIFile@@PAPAVnsIOutputStream@@@Z ; 2356
|
||||
?updateDiskCacheEntry@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@@Z ; 2356
|
||||
??0nsANSIOutputStream@@QAE@PAU_iobuf@@@Z ; 2356
|
||||
??_EnsANSIOutputStream@@UAEPAXI@Z ; 2356
|
||||
??1nsANSIOutputStream@@UAE@XZ ; 2356
|
||||
?Swap@MetaDataHeader@@QAEXXZ ; 2355
|
||||
?FlattenMetaData@nsCacheMetaData@@QAEIPAPADPAI@Z ; 2355
|
||||
?Init@MetaDataFile@@QAEIPAVnsCacheEntry@@@Z ; 2355
|
||||
?updateCacheMap@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@@Z ; 2355
|
||||
??0MetaDataHeader@@QAE@PAVnsCacheEntry@@@Z ; 2355
|
||||
?Write@MetaDataFile@@QAEIPAVnsIOutputStream@@@Z ; 2355
|
||||
?FlattenMetaData@nsCacheEntry@@QAEIPAPADPAI@Z ; 2355
|
||||
?DeactivateEntry@nsMemoryCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 2322
|
||||
?SetExpirationTime@nsCacheEntryDescriptor@@UAGII@Z ; 2259
|
||||
?QueryInterface@nsCacheEntryDescriptor@@UAGIABUnsID@@PAPAX@Z ; 2186
|
||||
?GetDataSize@nsCacheEntryDescriptor@@UAGIPAI@Z ; 2107
|
||||
?OnDataSizeChange@nsMemoryCacheDevice@@UAEIPAVnsCacheEntry@@H@Z ; 2082
|
||||
?SetDataSize@nsCacheEntryDescriptor@@UAGII@Z ; 2082
|
||||
?Write@nsOutputStreamWrapper@nsCacheEntryDescriptor@@UAGIPBDIPAI@Z ; 2045
|
||||
?OnWrite@nsOutputStreamWrapper@nsCacheEntryDescriptor@@AAEII@Z ; 2045
|
||||
?GetNonBlocking@nsOutputStreamWrapper@nsCacheEntryDescriptor@@UAGIPAH@Z ; 1550
|
||||
?SetCacheElement@nsCacheEntryDescriptor@@UAGIPAVnsISupports@@@Z ; 1376
|
||||
?BindEntry@nsMemoryCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 1376
|
||||
?AsyncOpenCacheEntry@nsCacheSession@@UAGIPBDHPAVnsICacheListener@@@Z ; 1303
|
||||
?NotifyListener@nsCacheService@@AAEIPAVnsCacheRequest@@PAVnsICacheEntryDescriptor@@HI@Z ; 1303
|
||||
??0nsCacheMetaData@@QAE@XZ ; 1298
|
||||
??1nsCacheMetaData@@QAE@XZ ; 1298
|
||||
?FindEntry@nsDiskCacheDevice@@UAEPAVnsCacheEntry@@PAVnsCString@@@Z ; 1295
|
||||
?Init@nsCacheMetaData@@QAEIXZ ; 1295
|
||||
?Finalize@nsCacheMetaData@@CAXPAUPLDHashTable@@@Z ; 1295
|
||||
?Create@nsCacheMetaData@@SAPAV1@XZ ; 1295
|
||||
?getTransportForFile@nsDiskCacheDevice@@SAIPAVnsIFile@@HPAPAVnsITransport@@@Z ; 1199
|
||||
?GetTransportForEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@HPAPAVnsITransport@@@Z ; 1198
|
||||
?AddRef@nsTransportWrapper@nsCacheEntryDescriptor@@UAGKXZ ; 1198
|
||||
?EnsureTransportWithAccess@nsTransportWrapper@nsCacheEntryDescriptor@@QAEIH@Z ; 1198
|
||||
?GetTransport@nsCacheEntryDescriptor@@UAGIPAPAVnsITransport@@@Z ; 1198
|
||||
?GetTransportForEntry@nsCacheService@@QAEIPAVnsCacheEntry@@HPAPAVnsITransport@@@Z ; 1198
|
||||
?Release@nsTransportWrapper@nsCacheEntryDescriptor@@UAGKXZ ; 1198
|
||||
?GetSecurityInfo@nsCacheEntryDescriptor@@UAGIPAPAVnsISupports@@@Z ; 1195
|
||||
?GetSecurityInfo@nsCacheEntry@@QAEIPAPAVnsISupports@@@Z ; 1195
|
||||
??1nsDiskCacheEntry@@UAE@XZ ; 1193
|
||||
??0nsDiskCacheEntry@@QAE@PAVnsCacheEntry@@@Z ; 1193
|
||||
??_EnsDiskCacheEntry@@UAEPAXI@Z ; 1193
|
||||
?DeactivateEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 1193
|
||||
?AddEntry@nsDiskCacheEntryHashTable@@QAEIPAVnsDiskCacheEntry@@@Z ; 1193
|
||||
?ClearEntry@nsDiskCacheEntryHashTable@@CAXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 1193
|
||||
?RemoveEntry@nsDiskCacheEntryHashTable@@QAEXPAVnsDiskCacheEntry@@@Z ; 1193
|
||||
?openInputStream@nsDiskCacheDevice@@SAIPAVnsIFile@@PAPAVnsIInputStream@@@Z ; 1191
|
||||
??1nsANSIInputStream@@UAE@XZ ; 1190
|
||||
?Read@MetaDataFile@@QAEIPAVnsIInputStream@@@Z ; 1190
|
||||
??0nsANSIInputStream@@QAE@PAU_iobuf@@@Z ; 1190
|
||||
??_EnsANSIInputStream@@UAEPAXI@Z ; 1190
|
||||
??0MetaDataHeader@@QAE@XZ ; 1190
|
||||
?OpenOutputStream@nsTransportWrapper@nsCacheEntryDescriptor@@UAGIIIIPAPAVnsIOutputStream@@@Z ; 1166
|
||||
?BindEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@@Z ; 1166
|
||||
?IsAllowedOnDisk@nsCacheEntry@@QAEHXZ ; 1166
|
||||
??1nsOutputStreamWrapper@nsCacheEntryDescriptor@@UAE@XZ ; 1165
|
||||
?NewOutputStreamWrapper@nsCacheEntryDescriptor@@CAIPAPAVnsIOutputStream@@PAV1@PAV2@@Z ; 1165
|
||||
?GetAccessGranted@nsCacheEntryDescriptor@@UAGIPAH@Z ; 1165
|
||||
??0nsOutputStreamWrapper@nsCacheEntryDescriptor@@QAE@PAV1@PAVnsIOutputStream@@@Z ; 1165
|
||||
?Init@nsOutputStreamWrapper@nsCacheEntryDescriptor@@QAEIXZ ; 1165
|
||||
??_GnsOutputStreamWrapper@nsCacheEntryDescriptor@@UAEPAXI@Z ; 1165
|
||||
??0MetaDataFile@@QAE@XZ ; 1163
|
||||
?GetDataSize@nsDiskCacheEntryInfo@@UAGIPAI@Z ; 1163
|
||||
??_GnsDiskCacheEntryInfo@@UAEPAXI@Z ; 1163
|
||||
?Swap@nsDiskCacheRecord@@QAEXXZ ; 1123
|
||||
?Unswap@nsDiskCacheRecord@@QAEXXZ ; 1123
|
||||
?GetExpirationTime@nsCacheEntryDescriptor@@UAGIPAI@Z ; 1118
|
||||
?GetKey@nsDiskCacheEntryHashTable@@CAPBXPAUPLDHashTable@@PAUPLDHashEntryHdr@@@Z ; 395
|
||||
?MoveEntry@nsDiskCacheEntryHashTable@@CAXPAUPLDHashTable@@PBUPLDHashEntryHdr@@PAU3@@Z ; 395
|
||||
?DoomEntry_Locked@nsCacheService@@QAEIPAVnsCacheEntry@@@Z ; 106
|
||||
?DoomEntry@nsCacheService@@QAEIPAVnsCacheEntry@@@Z ; 104
|
||||
?Doom@nsCacheEntryDescriptor@@UAGIXZ ; 104
|
||||
?FreeCacheEntries@nsCacheEntryHashTable@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 72
|
||||
?AsyncRead@nsTransportWrapper@nsCacheEntryDescriptor@@UAGIPAVnsIStreamListener@@PAVnsISupports@@IIIPAPAVnsIRequest@@@Z ; 32
|
||||
??_H@YGXPAXIHP6EX0@Z@Z ; 32
|
||||
?getFileForKey@nsDiskCacheDevice@@QAEIPBDHIPAPAVnsIFile@@@Z ; 27
|
||||
?UnflattenMetaData@nsCacheMetaData@@QAEIPADI@Z ; 27
|
||||
?UnflattenMetaData@nsCacheEntry@@QAEIPADI@Z ; 27
|
||||
?readDiskCacheEntry@nsDiskCacheDevice@@QAEIPBDPAPAVnsDiskCacheEntry@@@Z ; 27
|
||||
?GetLastModified@nsCacheEntryDescriptor@@UAGIPAI@Z ; 25
|
||||
?AddRef@nsDiskCacheObserver@@UAGKXZ ; 12
|
||||
?Release@nsDiskCacheObserver@@UAGKXZ ; 12
|
||||
?AddRef@nsCacheService@@UAGKXZ ; 9
|
||||
?Release@nsCacheService@@UAGKXZ ; 9
|
||||
?QueryInterface@nsDiskCacheObserver@@UAGIABUnsID@@PAPAX@Z ; 6
|
||||
?QueryInterface@nsCacheService@@UAGIABUnsID@@PAPAX@Z ; 6
|
||||
?do_GetService@@YA?BVnsGetServiceByContractID@@PBDPAI@Z ; 5
|
||||
?DeleteRecord@nsDiskCacheMap@@QAEXI@Z ; 3
|
||||
??0nsCacheSession@@QAE@PBDHH@Z ; 3
|
||||
??1nsCacheSession@@UAE@XZ ; 3
|
||||
??_EnsCacheSession@@UAEPAXI@Z ; 3
|
||||
?deleteDiskCacheEntry@nsDiskCacheDevice@@QAEIPAVnsDiskCacheEntry@@@Z ; 3
|
||||
?DoomEntry@nsDiskCacheDevice@@UAEXPAVnsCacheEntry@@@Z ; 3
|
||||
?CreateSession@nsCacheService@@UAGIPBDHHPAPAVnsICacheSession@@@Z ; 3
|
||||
?setPrefsObserver@nsDiskCacheDevice@@QAEXPAVnsIObserver@@@Z ; 2
|
||||
?VisitEntries@nsDiskCacheEntryHashTable@@QAEXPAVVisitor@1@@Z ; 2
|
||||
?DetachDescriptors@nsCacheEntry@@AAEXXZ ; 2
|
||||
?ClearPendingRequests@nsCacheService@@AAEXPAVnsCacheEntry@@@Z ; 2
|
||||
?SetDoomEntriesIfExpired@nsCacheSession@@UAGIH@Z ; 2
|
||||
?Finalize@nsCacheEntryHashTable@@CAXPAUPLDHashTable@@@Z ; 2
|
||||
?DeactivateAndClearEntry@nsCacheService@@CA?AW4PLDHashOperator@@PAUPLDHashTable@@PAUPLDHashEntryHdr@@IPAX@Z ; 2
|
||||
?Init@nsCacheEntryHashTable@@QAEIXZ ; 2
|
||||
?updateDiskCacheEntries@nsDiskCacheDevice@@QAEIXZ ; 2
|
||||
?scanDiskCacheEntries@nsDiskCacheDevice@@QAEIPAPAVnsISupportsArray@@@Z ; 2
|
||||
?AdjustMemoryLimits@nsMemoryCacheDevice@@AAEXII@Z ; 1
|
||||
_NSGetModule ; 1
|
||||
?Finalize@nsDiskCacheEntryHashTable@@CAXPAUPLDHashTable@@@Z ; 1
|
||||
??0nsMemoryCacheDevice@@QAE@XZ ; 1
|
||||
?evictDiskCacheEntries@nsDiskCacheDevice@@QAEIXZ ; 1
|
||||
??0nsDiskCacheMap@@QAE@XZ ; 1
|
||||
?ClearActiveEntries@nsCacheService@@AAEXXZ ; 1
|
||||
?setCacheCapacity@nsDiskCacheDevice@@QAEXI@Z ; 1
|
||||
?Init@nsDiskCacheEntryHashTable@@QAEIXZ ; 1
|
||||
?DoomEntry@nsMemoryCacheDevice@@UAEXPAVnsCacheEntry@@@Z ; 1
|
||||
?getPrefsObserver@nsDiskCacheDevice@@QAEXPAPAVnsIObserver@@@Z ; 1
|
||||
??_EnsMemoryCacheDevice@@UAEPAXI@Z ; 1
|
||||
?setCacheDirectory@nsDiskCacheDevice@@QAEXPAVnsILocalFile@@@Z ; 1
|
||||
?Shutdown@nsCacheService@@UAGIXZ ; 1
|
||||
??_GnsCacheService@@UAEPAXI@Z ; 1
|
||||
?ClearDoomList@nsCacheService@@AAEXXZ ; 1
|
||||
?QueryInterface@nsANSIOutputStream@@UAGIABUnsID@@PAPAX@Z ; 1
|
||||
?Init@nsCacheService@@UAGIXZ ; 1
|
||||
??0nsDiskCacheDevice@@QAE@XZ ; 1
|
||||
?Swap@nsDiskCacheHeader@@QAEXXZ ; 1
|
||||
?GetFileForEntry@nsCacheService@@QAEIPAVnsCacheEntry@@PAPAVnsIFile@@@Z ; 1
|
||||
??_GnsDiskCacheDevice@@UAEPAXI@Z ; 1
|
||||
??1nsCacheService@@UAE@XZ ; 1
|
||||
?GetFileForEntry@nsDiskCacheDevice@@UAEIPAVnsCacheEntry@@PAPAVnsIFile@@@Z ; 1
|
||||
?Init@nsMemoryCacheDevice@@UAEIXZ ; 1
|
||||
?GetFile@nsCacheEntryDescriptor@@UAGIPAPAVnsIFile@@@Z ; 1
|
||||
?Seek@nsANSIOutputStream@@UAGIHH@Z ; 1
|
||||
?MemoryCacheSizeChanged@nsMemoryCacheDevice@@SAHPBDPAX@Z ; 1
|
||||
?SetStoragePolicy@nsCacheEntryDescriptor@@UAGIH@Z ; 1
|
||||
??0nsCacheService@@QAE@XZ ; 1
|
||||
?Observe@nsCacheService@@UAGIPAVnsISupports@@PBG1@Z ; 1
|
||||
?writeCacheMap@nsDiskCacheDevice@@QAEIXZ ; 1
|
||||
?Init@nsDiskCacheDevice@@UAEIXZ ; 1
|
||||
?Create@nsCacheService@@SGIPAVnsISupports@@ABUnsID@@PAPAX@Z ; 1
|
||||
?NS_GetSpecialDirectory@@YAIPBDPAPAVnsIFile@@@Z ; 1
|
||||
??1nsDiskCacheDevice@@UAE@XZ ; 1
|
||||
?readCacheMap@nsDiskCacheDevice@@QAEIXZ ; 1
|
||||
??1nsDiskCacheMap@@QAE@XZ ; 1
|
||||
??_EnsDiskCacheObserver@@UAEPAXI@Z ; 1
|
||||
?Unswap@nsDiskCacheHeader@@QAEXXZ ; 1
|
||||
?CreateDiskDevice@nsCacheService@@AAEIXZ ; 1
|
||||
??1nsMemoryCacheDevice@@UAE@XZ ; 1
|
||||
?Shutdown@nsDiskCacheDevice@@UAEIXZ ; 1
|
||||
?Write@nsDiskCacheMap@@QAEIPAVnsIOutputStream@@@Z ; 1
|
||||
39
mozilla/xpinstall/Makefile.in
Normal file
39
mozilla/xpinstall/Makefile.in
Normal file
@@ -0,0 +1,39 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (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/NPL/
|
||||
#
|
||||
# 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 Mozilla Communicator client code,
|
||||
# released March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# Contributors:
|
||||
# Daniel Veditz <dveditz@netscape.com>
|
||||
# Douglas Turner <dougt@netscape.com>
|
||||
|
||||
|
||||
DEPTH = ..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
|
||||
BIN
mozilla/xpinstall/macbuild/xpinstall.mcp
Normal file
BIN
mozilla/xpinstall/macbuild/xpinstall.mcp
Normal file
Binary file not shown.
BIN
mozilla/xpinstall/macbuild/xpinstallIDL.mcp
Normal file
BIN
mozilla/xpinstall/macbuild/xpinstallIDL.mcp
Normal file
Binary file not shown.
30
mozilla/xpinstall/makefile.win
Normal file
30
mozilla/xpinstall/makefile.win
Normal file
@@ -0,0 +1,30 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (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/NPL/
|
||||
#
|
||||
# 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 Mozilla Communicator client code,
|
||||
# released March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# Contributors:
|
||||
# Daniel Veditz <dveditz@netscape.com>
|
||||
# Douglas Turner <dougt@netscape.com>
|
||||
|
||||
|
||||
DEPTH=..
|
||||
|
||||
DIRS= public res src
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
33
mozilla/xpinstall/notifier/SoftwareUpdate-Source-1.rdf
Normal file
33
mozilla/xpinstall/notifier/SoftwareUpdate-Source-1.rdf
Normal file
@@ -0,0 +1,33 @@
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:NC="http://home.netscape.com/NC-rdf#">
|
||||
|
||||
<RDF:Bag ID="NC:SoftwareUpdateRoot">
|
||||
<RDF:li>
|
||||
<RDF:Bag ID="NC:NewSoftwareToday" NC:title="New Software">
|
||||
|
||||
<RDF:li>
|
||||
<RDF:Description ID="AimUpdate344">
|
||||
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
|
||||
<NC:title>AOL AIM</NC:title>
|
||||
<NC:description>An Instant Message Client</NC:description>
|
||||
<NC:version>3.4.1.12</NC:version>
|
||||
<NC:registryKey>/AOL/AIM/</NC:registryKey>
|
||||
<NC:url>http://home.netscape.com/index.html</NC:url>
|
||||
</RDF:Description>
|
||||
</RDF:li>
|
||||
|
||||
<RDF:li>
|
||||
<RDF:Description ID="PGPPlugin345">
|
||||
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
|
||||
<NC:title>PGP Plugin For Mozilla</NC:title>
|
||||
<NC:description>A high grade encryption plugin</NC:description>
|
||||
<NC:version>1.1.2.0</NC:version>
|
||||
<NC:registryKey>/PGP/ROCKS/</NC:registryKey>
|
||||
<NC:url>http://home.netscape.com/index.html</NC:url>
|
||||
</RDF:Description>
|
||||
</RDF:li>
|
||||
|
||||
</RDF:Bag>
|
||||
</RDF:li>
|
||||
</RDF:Bag>
|
||||
</RDF:RDF>
|
||||
57
mozilla/xpinstall/notifier/SoftwareUpdate.css
Normal file
57
mozilla/xpinstall/notifier/SoftwareUpdate.css
Normal file
@@ -0,0 +1,57 @@
|
||||
window {
|
||||
display: block;
|
||||
}
|
||||
|
||||
tree {
|
||||
display: table;
|
||||
background-color: #FFFFFF;
|
||||
border: none;
|
||||
border-spacing: 0px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
treecol {
|
||||
display: table-column;
|
||||
width: 200px;
|
||||
}
|
||||
|
||||
treeitem {
|
||||
display: table-row;
|
||||
}
|
||||
|
||||
treehead {
|
||||
display: table-header-group;
|
||||
}
|
||||
|
||||
treebody {
|
||||
display: table-row-group;
|
||||
}
|
||||
|
||||
treecell {
|
||||
display: table-cell;
|
||||
font-family: Verdana, Sans-Serif;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
treecell[selectedcell] {
|
||||
background-color: yellow;
|
||||
}
|
||||
|
||||
|
||||
treehead treeitem treecell {
|
||||
background-color: #c0c0c0;
|
||||
border: outset 1px;
|
||||
border-color: white #707070 #707070 white;
|
||||
padding-left: 4px;
|
||||
}
|
||||
|
||||
treeitem[type="http://home.netscape.com/NC-rdf#SoftwarePackage"] > treecell > titledbutton {
|
||||
list-style-image: url("resource:/res/rdf/SoftwareUpdatePackage.gif");
|
||||
}
|
||||
|
||||
treeitem[type="http://home.netscape.com/NC-rdf#Folder"] > treecell > titledbutton {
|
||||
list-style-image: url("resource:/res/rdf/bookmark-folder-closed.gif");
|
||||
|
||||
treeitem[type="http://home.netscape.com/NC-rdf#Folder"][open="true"] > treecell > titledbutton {
|
||||
list-style-image: url("resource:/res/rdf/bookmark-folder-open.gif");
|
||||
}
|
||||
123
mozilla/xpinstall/notifier/SoftwareUpdate.js
Normal file
123
mozilla/xpinstall/notifier/SoftwareUpdate.js
Normal file
@@ -0,0 +1,123 @@
|
||||
// the rdf service
|
||||
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
|
||||
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
|
||||
|
||||
function getAttr(registry,service,attr_name)
|
||||
{
|
||||
var attr = registry.GetTarget(service,
|
||||
RDF.GetResource('http://home.netscape.com/NC-rdf#' + attr_name),
|
||||
true);
|
||||
if (attr)
|
||||
attr = attr.QueryInterface(Components.interfaces.nsIRDFLiteral);
|
||||
|
||||
if (attr)
|
||||
attr = attr.Value;
|
||||
|
||||
return attr;
|
||||
}
|
||||
|
||||
function Init()
|
||||
{
|
||||
// this is the main rdf file.
|
||||
|
||||
var mainRegistry = RDF.GetDataSource('resource://res/rdf/SoftwareUpdates.rdf');
|
||||
|
||||
var mainContainer = Components.classes['component://netscape/rdf/container'].createInstance();
|
||||
mainContainer = mainContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
|
||||
mainContainer.Init(mainRegistry, RDF.GetResource('NC:SoftwareUpdateDataSources'));
|
||||
|
||||
// Now enumerate all of the softwareupdate datasources.
|
||||
var mainEnumerator = mainContainer.GetElements();
|
||||
while (mainEnumerator.HasMoreElements())
|
||||
{
|
||||
var aDistributor = mainEnumerator.GetNext();
|
||||
aDistributor = aDistributor.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
|
||||
var distributorContainer = Components.classes['component://netscape/rdf/container'].createInstance();
|
||||
distributorContainer = distributorContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
|
||||
|
||||
var distributorRegistry = RDF.GetDataSource(aDistributor.Value);
|
||||
var distributorResource = RDF.GetResource('NC:SoftwareUpdateRoot');
|
||||
|
||||
distributorContainer.Init(distributorRegistry, distributorResource);
|
||||
|
||||
// Now enumerate all of the distributorContainer's packages.
|
||||
|
||||
var distributorEnumerator = distributorContainer.GetElements();
|
||||
|
||||
while (distributorEnumerator.HasMoreElements())
|
||||
{
|
||||
var aPackage = distributorEnumerator.GetNext();
|
||||
aPackage = aPackage.QueryInterface(Components.interfaces.nsIRDFResource);
|
||||
|
||||
// remove any that we do not want.
|
||||
|
||||
if (getAttr(distributorRegistry, aPackage, 'title') == "AOL AIM")
|
||||
{
|
||||
//distributorContainer.RemoveElement(aPackage, true);
|
||||
}
|
||||
}
|
||||
var tree = document.getElementById('tree');
|
||||
|
||||
// Add it to the tree control's composite datasource.
|
||||
tree.database.AddDataSource(distributorRegistry);
|
||||
|
||||
}
|
||||
|
||||
// Install all of the stylesheets in the softwareupdate Registry into the
|
||||
// panel.
|
||||
|
||||
// TODO
|
||||
|
||||
// XXX hack to force the tree to rebuild
|
||||
var treebody = document.getElementById('NC:SoftwareUpdateRoot');
|
||||
treebody.setAttribute('id', 'NC:SoftwareUpdateRoot');
|
||||
}
|
||||
|
||||
|
||||
function OpenURL(event, node)
|
||||
{
|
||||
if (node.getAttribute('type') == "http://home.netscape.com/NC-rdf#SoftwarePackage")
|
||||
{
|
||||
url = node.getAttribute('url');
|
||||
|
||||
/*window.open(url,'bookmarks');*/
|
||||
|
||||
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
|
||||
if (!toolkitCore)
|
||||
{
|
||||
toolkitCore = new ToolkitCore();
|
||||
if (toolkitCore)
|
||||
{
|
||||
toolkitCore.Init("ToolkitCore");
|
||||
}
|
||||
}
|
||||
|
||||
if (toolkitCore)
|
||||
{
|
||||
toolkitCore.ShowWindow(url,window);
|
||||
}
|
||||
|
||||
dump("OpenURL(" + url + ")\n");
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// To get around "window.onload" not working in viewer.
|
||||
function Boot()
|
||||
{
|
||||
var tree = document.getElementById('tree');
|
||||
if (tree == null) {
|
||||
setTimeout(Boot, 0);
|
||||
}
|
||||
else {
|
||||
Init();
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout('Boot()', 0);
|
||||
|
||||
30
mozilla/xpinstall/notifier/SoftwareUpdate.xul
Normal file
30
mozilla/xpinstall/notifier/SoftwareUpdate.xul
Normal file
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="resource:/res/rdf/sidebar.css" type="text/css"?>
|
||||
<?xml-stylesheet href="resource:/res/rdf/SoftwareUpdate.css" type="text/css"?>
|
||||
<window
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<html:script src="SoftwareUpdate.js"/>
|
||||
|
||||
<tree id="tree"
|
||||
flex="100%"
|
||||
datasources="rdf:softwareupdates"
|
||||
ondblclick="return OpenURL(event, event.target.parentNode);">
|
||||
|
||||
<treecol rdf:resource="http://home.netscape.com/NC-rdf#title" />
|
||||
<treecol rdf:resource="http://home.netscape.com/NC-rdf#description" />
|
||||
<treecol rdf:resource="http://home.netscape.com/NC-rdf#version" />
|
||||
|
||||
<treehead>
|
||||
<treeitem>
|
||||
<treecell>Title</treecell>
|
||||
<treecell>Description</treecell>
|
||||
<treecell>Version</treecell>
|
||||
</treeitem>
|
||||
</treehead>
|
||||
|
||||
<treebody id="NC:SoftwareUpdateRoot" rdf:containment="http://home.netscape.com/NC-rdf#child" />
|
||||
</tree>
|
||||
</window>
|
||||
BIN
mozilla/xpinstall/notifier/SoftwareUpdatePackage.gif
Normal file
BIN
mozilla/xpinstall/notifier/SoftwareUpdatePackage.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 201 B |
7
mozilla/xpinstall/notifier/SoftwareUpdates.rdf
Normal file
7
mozilla/xpinstall/notifier/SoftwareUpdates.rdf
Normal file
@@ -0,0 +1,7 @@
|
||||
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:NC="http://home.netscape.com/softwareupdate-schema#">
|
||||
|
||||
<RDF:Bag ID="NC:SoftwareUpdateDataSources">
|
||||
<RDF:li resource="resource:/res/rdf/SoftwareUpdate-Source-1.rdf" />
|
||||
</RDF:Bag>
|
||||
</RDF:RDF>
|
||||
6
mozilla/xpinstall/public/MANIFEST
Normal file
6
mozilla/xpinstall/public/MANIFEST
Normal file
@@ -0,0 +1,6 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
nsISoftwareUpdate.h
|
||||
nsSoftwareUpdateIIDs.h
|
||||
47
mozilla/xpinstall/public/Makefile.in
Normal file
47
mozilla/xpinstall/public/Makefile.in
Normal file
@@ -0,0 +1,47 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (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/NPL/
|
||||
#
|
||||
# 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 Mozilla Communicator client code,
|
||||
# released March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# Contributors:
|
||||
# Daniel Veditz <dveditz@netscape.com>
|
||||
# Douglas Turner <dougt@netscape.com>
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xpinstall
|
||||
|
||||
XPIDLSRCS = nsIXPInstallProgress.idl
|
||||
|
||||
EXPORTS = \
|
||||
nsIDOMInstallTriggerGlobal.h \
|
||||
nsIDOMInstallVersion.h \
|
||||
nsSoftwareUpdateIIDs.h \
|
||||
nsISoftwareUpdate.h \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
113
mozilla/xpinstall/public/idl/Install.idl
Normal file
113
mozilla/xpinstall/public/idl/Install.idl
Normal file
@@ -0,0 +1,113 @@
|
||||
interface Install
|
||||
{
|
||||
/* IID: { 0x18c2f988, 0xb09f, 0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
|
||||
|
||||
const int BAD_PACKAGE_NAME = -200;
|
||||
const int UNEXPECTED_ERROR = -201;
|
||||
const int ACCESS_DENIED = -202;
|
||||
const int TOO_MANY_CERTIFICATES = -203; /* Installer file must have 1 certificate */
|
||||
const int NO_INSTALLER_CERTIFICATE = -204; /* Installer file must have a certificate */
|
||||
const int NO_CERTIFICATE = -205; /* Extracted file is not signed */
|
||||
const int NO_MATCHING_CERTIFICATE = -206; /* Extracted file does not match installer certificate */
|
||||
const int UNKNOWN_JAR_FILE = -207; /* JAR file has not been opened */
|
||||
const int INVALID_ARGUMENTS = -208; /* Bad arguments to a function */
|
||||
const int ILLEGAL_RELATIVE_PATH = -209; /* Illegal relative path */
|
||||
const int USER_CANCELLED = -210; /* User cancelled */
|
||||
const int INSTALL_NOT_STARTED = -211;
|
||||
const int SILENT_MODE_DENIED = -212;
|
||||
const int NO_SUCH_COMPONENT = -213; /* no such component in the registry. */
|
||||
const int FILE_DOES_NOT_EXIST = -214; /* File cannot be deleted as it does not exist */
|
||||
const int FILE_READ_ONLY = -215; /* File cannot be deleted as it is read only. */
|
||||
const int FILE_IS_DIRECTORY = -216; /* File cannot be deleted as it is a directory */
|
||||
const int NETWORK_FILE_IS_IN_USE = -217; /* File on the network is in-use */
|
||||
const int APPLE_SINGLE_ERR = -218; /* error in AppleSingle unpacking */
|
||||
const int INVALID_PATH_ERR = -219; /* GetFolder() did not like the folderID */
|
||||
const int PATCH_BAD_DIFF = -220; /* error in GDIFF patch */
|
||||
const int PATCH_BAD_CHECKSUM_TARGET = -221; /* source file doesn't checksum */
|
||||
const int PATCH_BAD_CHECKSUM_RESULT = -222; /* final patched file fails checksum */
|
||||
const int UNINSTALL_FAILED = -223; /* error while uninstalling a package */
|
||||
const int GESTALT_UNKNOWN_ERR = -5550;
|
||||
const int GESTALT_INVALID_ARGUMENT = -5551;
|
||||
|
||||
const int SUCCESS = 0;
|
||||
const int REBOOT_NEEDED = 999;
|
||||
|
||||
/* install types */
|
||||
const int LIMITED_INSTALL = 0;
|
||||
const int FULL_INSTALL = 1;
|
||||
const int NO_STATUS_DLG = 2;
|
||||
const int NO_FINALIZE_DLG = 4;
|
||||
|
||||
// these should not be public...
|
||||
/* message IDs*/
|
||||
const int SU_INSTALL_FILE_UNEXPECTED_MSG_ID = 0;
|
||||
const int SU_DETAILS_REPLACE_FILE_MSG_ID = 1;
|
||||
const int SU_DETAILS_INSTALL_FILE_MSG_ID = 2;
|
||||
//////////////////////////
|
||||
|
||||
readonly attribute wstring UserPackageName;
|
||||
readonly attribute wstring RegPackageName;
|
||||
|
||||
void Install();
|
||||
|
||||
void AbortInstall();
|
||||
|
||||
long AddDirectory( in wstring regName,
|
||||
in wstring version,
|
||||
in wstring jarSource,
|
||||
in InstallFolder folder,
|
||||
in wstring subdir,
|
||||
in boolean forceMode );
|
||||
|
||||
|
||||
long AddSubcomponent( in wstring regName,
|
||||
in wstring version,
|
||||
in wstring jarSource,
|
||||
in InstallFolder folder,
|
||||
in wstring targetName,
|
||||
in boolean forceMode );
|
||||
|
||||
long DeleteComponent( in wstring registryName);
|
||||
|
||||
long DeleteFile( in InstallFolder folder,
|
||||
in wstring relativeFileName );
|
||||
|
||||
long DiskSpaceAvailable( in InstallFolder folder );
|
||||
|
||||
long Execute(in wstring jarSource, in wstring args);
|
||||
|
||||
long FinalizeInstall();
|
||||
|
||||
long Gestalt (in wstring selector);
|
||||
|
||||
InstallFolder GetComponentFolder( in wstring regName,
|
||||
in wstring subdirectory);
|
||||
|
||||
InstallFolder GetFolder(in wstring targetFolder,
|
||||
in wstring subdirectory);
|
||||
|
||||
long GetLastError();
|
||||
|
||||
long GetWinProfile(in InstallFolder folder, in wstring file);
|
||||
|
||||
long GetWinRegistry();
|
||||
|
||||
long Patch( in wstring regName,
|
||||
in wstring version,
|
||||
in wstring jarSource,
|
||||
in InstallFolder folder,
|
||||
in wstring targetName );
|
||||
|
||||
void ResetError();
|
||||
|
||||
void SetPackageFolder( in InstallFolder folder );
|
||||
|
||||
long StartInstall( in wstring userPackageName,
|
||||
in wstring packageName,
|
||||
in wstring version,
|
||||
in long flags );
|
||||
|
||||
long Uninstall( in wstring packageName);
|
||||
|
||||
};
|
||||
24
mozilla/xpinstall/public/idl/InstallTrigger.idl
Normal file
24
mozilla/xpinstall/public/idl/InstallTrigger.idl
Normal file
@@ -0,0 +1,24 @@
|
||||
interface InstallTriggerGlobal
|
||||
{
|
||||
/* IID: { 0x18c2f987, 0xb09f, 0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
|
||||
|
||||
const int MAJOR_DIFF = 4;
|
||||
const int MINOR_DIFF = 3;
|
||||
const int REL_DIFF = 2;
|
||||
const int BLD_DIFF = 1;
|
||||
const int EQUAL = 0;
|
||||
|
||||
boolean UpdateEnabled ();
|
||||
|
||||
long StartSoftwareUpdate(in wstring URL);
|
||||
|
||||
long ConditionalSoftwareUpdate( in wstring URL,
|
||||
in wstring regName,
|
||||
in long diffLevel,
|
||||
in wstring version,
|
||||
in long mode);
|
||||
|
||||
long CompareVersion( in wstring regName, in wstring version );
|
||||
|
||||
};
|
||||
34
mozilla/xpinstall/public/idl/InstallVersion.idl
Normal file
34
mozilla/xpinstall/public/idl/InstallVersion.idl
Normal file
@@ -0,0 +1,34 @@
|
||||
interface InstallVersion
|
||||
{
|
||||
/* IID: { 0x18c2f986, 0xb09f, 0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
|
||||
|
||||
const int EQUAL = 0;
|
||||
const int BLD_DIFF = 1;
|
||||
const int BLD_DIFF_MINUS = -1;
|
||||
const int REL_DIFF = 2;
|
||||
const int REL_DIFF_MINUS = -2;
|
||||
const int MINOR_DIFF = 3;
|
||||
const int MINOR_DIFF_MINUS = -3;
|
||||
const int MAJOR_DIFF = 4;
|
||||
const int MAJOR_DIFF_MINUS = -4;
|
||||
|
||||
attribute int major;
|
||||
attribute int minor;
|
||||
attribute int release;
|
||||
attribute int build;
|
||||
|
||||
void InstallVersion();
|
||||
|
||||
void init(in wstring versionString);
|
||||
/*
|
||||
void init(in int major, in int minor, in int release, in int build);
|
||||
*/
|
||||
wstring toString();
|
||||
|
||||
/* int compareTo(in wstring version);
|
||||
int compareTo(in int major, in int minor, in int release, in int build);
|
||||
*/
|
||||
int compareTo(in InstallVersion versionObject);
|
||||
|
||||
};
|
||||
36
mozilla/xpinstall/public/makefile.win
Normal file
36
mozilla/xpinstall/public/makefile.win
Normal file
@@ -0,0 +1,36 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (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/NPL/
|
||||
#
|
||||
# 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 Mozilla Communicator client code,
|
||||
# released March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# Contributors:
|
||||
# Daniel Veditz <dveditz@netscape.com>
|
||||
# Douglas Turner <dougt@netscape.com>
|
||||
|
||||
MODULE=xpinstall
|
||||
DEPTH=..\..
|
||||
|
||||
EXPORTS= nsIDOMInstallTriggerGlobal.h \
|
||||
nsIDOMInstallVersion.h \
|
||||
nsSoftwareUpdateIIDs.h \
|
||||
nsISoftwareUpdate.h
|
||||
|
||||
XPIDLSRCS = .\nsIXPInstallProgress.idl
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
1
mozilla/xpinstall/public/nsIDOMInstall.h
Normal file
1
mozilla/xpinstall/public/nsIDOMInstall.h
Normal file
@@ -0,0 +1 @@
|
||||
#error
|
||||
96
mozilla/xpinstall/public/nsIDOMInstallTriggerGlobal.h
Normal file
96
mozilla/xpinstall/public/nsIDOMInstallTriggerGlobal.h
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#ifndef nsIDOMInstallTriggerGlobal_h__
|
||||
#define nsIDOMInstallTriggerGlobal_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
|
||||
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
|
||||
{ 0x18c2f987, 0xb09f, 0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
|
||||
|
||||
class nsIDOMInstallTriggerGlobal : public nsISupports {
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLTRIGGERGLOBAL_IID; return iid; }
|
||||
enum {
|
||||
MAJOR_DIFF = 4,
|
||||
MINOR_DIFF = 3,
|
||||
REL_DIFF = 2,
|
||||
BLD_DIFF = 1,
|
||||
EQUAL = 0
|
||||
};
|
||||
|
||||
NS_IMETHOD UpdateEnabled(PRBool* aReturn)=0;
|
||||
|
||||
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)=0;
|
||||
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
|
||||
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMINSTALLTRIGGERGLOBAL \
|
||||
NS_IMETHOD UpdateEnabled(PRBool* aReturn); \
|
||||
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); \
|
||||
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn); \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMINSTALLTRIGGERGLOBAL(_to) \
|
||||
NS_IMETHOD UpdateEnabled(PRBool* aReturn) { return _to##UpdateEnabled(aReturn); } \
|
||||
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aFlags, aReturn); } \
|
||||
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aReturn); } \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, nsIDOMInstallVersion* aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
|
||||
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aMajor, aMinor, aRelease, aBuild, aReturn); } \
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
|
||||
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
|
||||
|
||||
|
||||
extern nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype);
|
||||
|
||||
extern "C" NS_DOM nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
|
||||
|
||||
#endif // nsIDOMInstallTriggerGlobal_h__
|
||||
107
mozilla/xpinstall/public/nsIDOMInstallVersion.h
Normal file
107
mozilla/xpinstall/public/nsIDOMInstallVersion.h
Normal file
@@ -0,0 +1,107 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#ifndef nsIDOMInstallVersion_h__
|
||||
#define nsIDOMInstallVersion_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIScriptContext.h"
|
||||
|
||||
class nsIDOMInstallVersion;
|
||||
|
||||
#define NS_IDOMINSTALLVERSION_IID \
|
||||
{ 0x18c2f986, 0xb09f, 0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
|
||||
|
||||
class nsIDOMInstallVersion : public nsISupports {
|
||||
public:
|
||||
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLVERSION_IID; return iid; }
|
||||
enum {
|
||||
EQUAL = 0,
|
||||
BLD_DIFF = 1,
|
||||
BLD_DIFF_MINUS = -1,
|
||||
REL_DIFF = 2,
|
||||
REL_DIFF_MINUS = -2,
|
||||
MINOR_DIFF = 3,
|
||||
MINOR_DIFF_MINUS = -3,
|
||||
MAJOR_DIFF = 4,
|
||||
MAJOR_DIFF_MINUS = -4
|
||||
};
|
||||
|
||||
NS_IMETHOD GetMajor(PRInt32* aMajor)=0;
|
||||
NS_IMETHOD SetMajor(PRInt32 aMajor)=0;
|
||||
|
||||
NS_IMETHOD GetMinor(PRInt32* aMinor)=0;
|
||||
NS_IMETHOD SetMinor(PRInt32 aMinor)=0;
|
||||
|
||||
NS_IMETHOD GetRelease(PRInt32* aRelease)=0;
|
||||
NS_IMETHOD SetRelease(PRInt32 aRelease)=0;
|
||||
|
||||
NS_IMETHOD GetBuild(PRInt32* aBuild)=0;
|
||||
NS_IMETHOD SetBuild(PRInt32 aBuild)=0;
|
||||
|
||||
NS_IMETHOD Init(const nsString& aVersionString)=0;
|
||||
|
||||
NS_IMETHOD ToString(nsString& aReturn)=0;
|
||||
|
||||
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn)=0;
|
||||
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
|
||||
};
|
||||
|
||||
|
||||
#define NS_DECL_IDOMINSTALLVERSION \
|
||||
NS_IMETHOD GetMajor(PRInt32* aMajor); \
|
||||
NS_IMETHOD SetMajor(PRInt32 aMajor); \
|
||||
NS_IMETHOD GetMinor(PRInt32* aMinor); \
|
||||
NS_IMETHOD SetMinor(PRInt32 aMinor); \
|
||||
NS_IMETHOD GetRelease(PRInt32* aRelease); \
|
||||
NS_IMETHOD SetRelease(PRInt32 aRelease); \
|
||||
NS_IMETHOD GetBuild(PRInt32* aBuild); \
|
||||
NS_IMETHOD SetBuild(PRInt32 aBuild); \
|
||||
NS_IMETHOD Init(const nsString& aVersionString); \
|
||||
NS_IMETHOD ToString(nsString& aReturn); \
|
||||
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn); \
|
||||
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); \
|
||||
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
|
||||
|
||||
|
||||
|
||||
#define NS_FORWARD_IDOMINSTALLVERSION(_to) \
|
||||
NS_IMETHOD GetMajor(PRInt32* aMajor) { return _to##GetMajor(aMajor); } \
|
||||
NS_IMETHOD SetMajor(PRInt32 aMajor) { return _to##SetMajor(aMajor); } \
|
||||
NS_IMETHOD GetMinor(PRInt32* aMinor) { return _to##GetMinor(aMinor); } \
|
||||
NS_IMETHOD SetMinor(PRInt32 aMinor) { return _to##SetMinor(aMinor); } \
|
||||
NS_IMETHOD GetRelease(PRInt32* aRelease) { return _to##GetRelease(aRelease); } \
|
||||
NS_IMETHOD SetRelease(PRInt32 aRelease) { return _to##SetRelease(aRelease); } \
|
||||
NS_IMETHOD GetBuild(PRInt32* aBuild) { return _to##GetBuild(aBuild); } \
|
||||
NS_IMETHOD SetBuild(PRInt32 aBuild) { return _to##SetBuild(aBuild); } \
|
||||
NS_IMETHOD Init(const nsString& aVersionString) { return _to##Init(aVersionString); } \
|
||||
NS_IMETHOD ToString(nsString& aReturn) { return _to##ToString(aReturn); } \
|
||||
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn) { return _to##CompareTo(aVersionObject, aReturn); } \
|
||||
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn) { return _to##CompareTo(aString, aReturn); } \
|
||||
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn); } \
|
||||
|
||||
|
||||
extern nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype);
|
||||
|
||||
extern "C" NS_DOM nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
|
||||
|
||||
#endif // nsIDOMInstallVersion_h__
|
||||
85
mozilla/xpinstall/public/nsISoftwareUpdate.h
Normal file
85
mozilla/xpinstall/public/nsISoftwareUpdate.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef nsISoftwareUpdate_h__
|
||||
#define nsISoftwareUpdate_h__
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsIXPInstallProgress.h"
|
||||
|
||||
#define NS_IXPINSTALLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/xpinstall"
|
||||
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
|
||||
|
||||
|
||||
#define NS_ISOFTWAREUPDATE_IID \
|
||||
{ 0x18c2f992, \
|
||||
0xb09f, \
|
||||
0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}\
|
||||
}
|
||||
|
||||
|
||||
class nsISoftwareUpdate : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID)
|
||||
|
||||
NS_IMETHOD InstallJar(const nsString& fromURL,
|
||||
const nsString& localFile,
|
||||
long flags) = 0;
|
||||
|
||||
NS_IMETHOD RegisterNotifier(nsIXPInstallProgress *notifier) = 0;
|
||||
|
||||
NS_IMETHOD InstallPending(void) = 0;
|
||||
|
||||
/* FIX: these should be in a private interface */
|
||||
NS_IMETHOD InstallJarCallBack() = 0;
|
||||
NS_IMETHOD GetTopLevelNotifier(nsIXPInstallProgress **notifier) = 0;
|
||||
};
|
||||
|
||||
|
||||
class nsSoftwareUpdateFactory : public nsIFactory
|
||||
{
|
||||
public:
|
||||
|
||||
nsSoftwareUpdateFactory();
|
||||
virtual ~nsSoftwareUpdateFactory();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
REFNSIID aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // nsISoftwareUpdate_h__
|
||||
|
||||
30
mozilla/xpinstall/public/nsIXPInstallProgress.idl
Normal file
30
mozilla/xpinstall/public/nsIXPInstallProgress.idl
Normal file
@@ -0,0 +1,30 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[uuid(eea90d40-b059-11d2-915e-c12b696c9333)]
|
||||
interface nsIXPInstallProgress : nsISupports
|
||||
{
|
||||
void BeforeJavascriptEvaluation();
|
||||
void AfterJavascriptEvaluation();
|
||||
void InstallStarted([const] in string UIPackageName);
|
||||
void ItemScheduled([const] in string message );
|
||||
void InstallFinalization([const] in string message, in long itemNum, in long totNum );
|
||||
void InstallAborted();
|
||||
};
|
||||
93
mozilla/xpinstall/public/nsIXPInstallProgressNotifier.h
Normal file
93
mozilla/xpinstall/public/nsIXPInstallProgressNotifier.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsIXPInstallProgressNotifier_h__
|
||||
#define nsIXPInstallProgressNotifier_h__
|
||||
|
||||
|
||||
class nsIXPInstallProgressNotifier
|
||||
{
|
||||
public:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name : BeforeJavascriptEvaluation
|
||||
// Description : This will be called when prior to the install script being evaluate
|
||||
// Return type : void
|
||||
// Argument : void
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void BeforeJavascriptEvaluation(void) = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name : AfterJavascriptEvaluation
|
||||
// Description : This will be called after the install script has being evaluated
|
||||
// Return type : void
|
||||
// Argument : void
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void AfterJavascriptEvaluation(void) = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name : InstallStarted
|
||||
// Description : This will be called when StartInstall has been called
|
||||
// Return type : void
|
||||
// Argument : char* UIPackageName - User Package Name
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void InstallStarted(const char* UIPackageName) = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name : ItemScheduled
|
||||
// Description : This will be called when items are being scheduled
|
||||
// Return type : Any value returned other than zero, will be treated as an error and the script will be aborted
|
||||
// Argument : The message that should be displayed to the user
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual long ItemScheduled( const char* message ) = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name : InstallFinalization
|
||||
// Description : This will be called when the installation is in its Finalize stage
|
||||
// Return type : void
|
||||
// Argument : char* message - The message that should be displayed to the user
|
||||
// Argument : long itemNum - This is the current item number
|
||||
// Argument : long totNum - This is the total number of items
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void InstallFinalization( const char* message, long itemNum, long totNum ) = 0;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Function name : InstallAborted
|
||||
// Description : This will be called when the install is aborted
|
||||
// Return type : void
|
||||
// Argument : void
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
virtual void InstallAborted(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
64
mozilla/xpinstall/public/nsSoftwareUpdateIIDs.h
Normal file
64
mozilla/xpinstall/public/nsSoftwareUpdateIIDs.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef nsSoftwareUpdateIIDs_h___
|
||||
#define nsSoftwareUpdateIIDs_h___
|
||||
|
||||
#define NS_SoftwareUpdate_CID \
|
||||
{ /* 18c2f989-b09f-11d2-bcde-00805f0e1353 */ \
|
||||
0x18c2f989, \
|
||||
0xb09f, \
|
||||
0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
}
|
||||
|
||||
#define NS_SoftwareUpdateInstall_CID \
|
||||
{ /* 18c2f98b-b09f-11d2-bcde-00805f0e1353 */ \
|
||||
0x18c2f98b, \
|
||||
0xb09f, \
|
||||
0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
}
|
||||
|
||||
#define NS_SoftwareUpdateInstallTrigger_CID \
|
||||
{ /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \
|
||||
0x18c2f98d, \
|
||||
0xb09f, \
|
||||
0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
}
|
||||
|
||||
#define NS_SoftwareUpdateInstallVersion_CID \
|
||||
{ /* 18c2f98f-b09f-11d2-bcde-00805f0e1353 */ \
|
||||
0x18c2f98f, \
|
||||
0xb09f, \
|
||||
0x11d2, \
|
||||
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif /* nsSoftwareUpdateIIDs_h___ */
|
||||
|
||||
3
mozilla/xpinstall/res/MANIFEST
Normal file
3
mozilla/xpinstall/res/MANIFEST
Normal file
@@ -0,0 +1,3 @@
|
||||
progress.xul
|
||||
progress.css
|
||||
progress.html
|
||||
34
mozilla/xpinstall/res/Makefile.in
Normal file
34
mozilla/xpinstall/res/Makefile.in
Normal file
@@ -0,0 +1,34 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
include $(topsrcdir)/config/config.mk
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
EXPORT_RESOURCE_XPINSTALL = \
|
||||
$(srcdir)/progress.xul \
|
||||
$(srcdir)/progress.html \
|
||||
$(srcdir)/progress.css \
|
||||
$(NULL)
|
||||
|
||||
install::
|
||||
$(INSTALL) $(EXPORT_RESOURCE_XPINSTALL) $(DIST)/bin/res/xpinstall
|
||||
31
mozilla/xpinstall/res/makefile.win
Normal file
31
mozilla/xpinstall/res/makefile.win
Normal file
@@ -0,0 +1,31 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (the "NPL"); you may not use this file except in
|
||||
# compliance with the NPL. You may obtain a copy of the NPL at
|
||||
# http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
# for the specific language governing rights and limitations under the
|
||||
# NPL.
|
||||
#
|
||||
# The Initial Developer of this code under the NPL is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) progress.xul $(DIST)\bin\res\xpinstall
|
||||
$(MAKE_INSTALL) progress.css $(DIST)\bin\res\xpinstall
|
||||
$(MAKE_INSTALL) progress.html $(DIST)\bin\res\xpinstall
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\res\xpinstall\progress.xul
|
||||
rm -f $(DIST)\res\xpinstall\progress.css
|
||||
rm -f $(DIST)\res\xpinstall\progress.html
|
||||
3
mozilla/xpinstall/res/progress.css
Normal file
3
mozilla/xpinstall/res/progress.css
Normal file
@@ -0,0 +1,3 @@
|
||||
TD {
|
||||
font: 10pt sans-serif;
|
||||
}
|
||||
16
mozilla/xpinstall/res/progress.html
Normal file
16
mozilla/xpinstall/res/progress.html
Normal file
@@ -0,0 +1,16 @@
|
||||
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
|
||||
<html>
|
||||
<body bgcolor="#C0C0C0" style="overflow:visible; margin: 0px; color-background: rgb(192,192,192);">
|
||||
<center>
|
||||
<table BORDER COLS=5 WIDTH="99%" style="color-background:rgb(192,192,192);">
|
||||
<tr>
|
||||
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);"> </td>
|
||||
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);"> </td>
|
||||
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);"> </td>
|
||||
<td WIDTH="10%" NOWRAP style="border: 1px inset rgb(192,192,192);"> </td>
|
||||
<td WIDTH="81%" NOWRAP style="border: 1px inset rgb(192,192,192);"> </td>
|
||||
</tr>
|
||||
</table>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
||||
67
mozilla/xpinstall/res/progress.xul
Normal file
67
mozilla/xpinstall/res/progress.xul
Normal file
@@ -0,0 +1,67 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="../samples/xul.css" type="text/css"?>
|
||||
<?xml-stylesheet href="progress.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE window
|
||||
[
|
||||
<!ENTITY downloadWindow.title "XPInstall Progress">
|
||||
<!ENTITY status "Status:">
|
||||
<!ENTITY cancelButtonTitle "Cancel">
|
||||
]
|
||||
>
|
||||
|
||||
<window xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
title="XPInstall Progress"
|
||||
width="425"
|
||||
height="225">
|
||||
|
||||
<data>
|
||||
<broadcaster id="data.canceled" type="string" value="false"/>
|
||||
</data>
|
||||
|
||||
|
||||
<html:script>
|
||||
|
||||
function cancelInstall()
|
||||
{
|
||||
var cancelData = document.getElementById("data.canceled");
|
||||
cancelData.setAttribute( "value", "true");
|
||||
}
|
||||
|
||||
</html:script>
|
||||
|
||||
<html:center>
|
||||
<html:table style="width:100%;">
|
||||
|
||||
<html:tr>
|
||||
<html:td align="center">
|
||||
<html:input id="dialog.uiPackageName" readonly="" style="background-color:lightgray;width:300px;"/>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
|
||||
<html:tr>
|
||||
<html:td nowrap="" style="border: 1px rgb(192,192,192);" align="center">
|
||||
<html:input id="dialog.currentAction" readonly="" style="background-color:lightgray;width:450px;"/>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
|
||||
|
||||
<html:tr>
|
||||
<html:td align="center" width="15%" nowrap="" style="border: 1px rgb(192,192,192);">
|
||||
<progressmeter id="dialog.progress" mode="undetermined" style="width:300px;height:16px;">
|
||||
</progressmeter>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
|
||||
<html:tr>
|
||||
<html:td align="center" width="3%" nowrap="" style="border: 1px rgb(192,192,192);">
|
||||
<html:button onclick="cancelInstall()" height="12">
|
||||
&cancelButtonTitle;
|
||||
</html:button>
|
||||
</html:td>
|
||||
</html:tr>
|
||||
</html:table>
|
||||
|
||||
</html:center>
|
||||
</window>
|
||||
61
mozilla/xpinstall/src/Makefile.in
Normal file
61
mozilla/xpinstall/src/Makefile.in
Normal file
@@ -0,0 +1,61 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (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/NPL/
|
||||
#
|
||||
# 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 Mozilla Communicator client code,
|
||||
# released March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# Contributors:
|
||||
# Daniel Veditz <dveditz@netscape.com>
|
||||
# Douglas Turner <dougt@netscape.com>
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
VPATH = @srcdir@
|
||||
srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = xpinstall
|
||||
LIBRARY_NAME = xpinstall
|
||||
IS_COMPONENT = 1
|
||||
REQUIRES = dom js netlib raptor xpcom
|
||||
|
||||
CPPSRCS = \
|
||||
nsSoftwareUpdate.cpp \
|
||||
nsInstall.cpp \
|
||||
nsInstallDelete.cpp \
|
||||
nsInstallExecute.cpp \
|
||||
nsInstallFile.cpp \
|
||||
nsInstallFolder.cpp \
|
||||
nsInstallPatch.cpp \
|
||||
nsInstallUninstall.cpp \
|
||||
nsInstallTrigger.cpp \
|
||||
nsInstallResources.cpp \
|
||||
nsJSInstall.cpp \
|
||||
nsJSInstallTriggerGlobal.cpp\
|
||||
nsSoftwareUpdateRun.cpp \
|
||||
nsSoftwareUpdateStream.cpp \
|
||||
nsTopProgressNotifier.cpp \
|
||||
nsLoggingProgressNotifier \
|
||||
ScheduledTasks.cpp \
|
||||
nsInstallFileOpItem.cpp \
|
||||
$(NULL)
|
||||
|
||||
INCLUDES += -I$(srcdir)/../public
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
1854
mozilla/xpinstall/src/PatchableAppleSingle.cpp
Normal file
1854
mozilla/xpinstall/src/PatchableAppleSingle.cpp
Normal file
File diff suppressed because it is too large
Load Diff
233
mozilla/xpinstall/src/PatchableAppleSingle.h
Normal file
233
mozilla/xpinstall/src/PatchableAppleSingle.h
Normal file
@@ -0,0 +1,233 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
|
||||
/*
|
||||
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
|
||||
* Version 1.0 (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/NPL/
|
||||
|
||||
*
|
||||
|
||||
* 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 Mozilla Communicator client code,
|
||||
|
||||
* released March 31, 1998.
|
||||
|
||||
*
|
||||
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
|
||||
* Corporation. Portions created by Netscape are
|
||||
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
|
||||
* Reserved.
|
||||
|
||||
*
|
||||
|
||||
* Contributors:
|
||||
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef SU_PAS_H
|
||||
|
||||
#define SU_PAS_H
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <Errors.h>
|
||||
|
||||
#include <Types.h>
|
||||
|
||||
#include <Files.h>
|
||||
|
||||
#include <Script.h>
|
||||
|
||||
#include <Resources.h>
|
||||
|
||||
|
||||
|
||||
typedef struct PASHeader /* header portion of Patchable AppleSingle */
|
||||
|
||||
{
|
||||
|
||||
UInt32 magicNum; /* internal file type tag = 0x00244200*/
|
||||
|
||||
UInt32 versionNum; /* format version: 1 = 0x00010000 */
|
||||
|
||||
UInt8 filler[16]; /* filler */
|
||||
|
||||
UInt16 numEntries; /* number of entries which follow */
|
||||
|
||||
} PASHeader ;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct PASEntry /* one Patchable AppleSingle entry descriptor */
|
||||
|
||||
{
|
||||
|
||||
UInt32 entryID; /* entry type: see list, 0 invalid */
|
||||
|
||||
UInt32 entryOffset; /* offset, in bytes, from beginning */
|
||||
|
||||
/* of file to this entry's data */
|
||||
|
||||
UInt32 entryLength; /* length of data in octets */
|
||||
|
||||
|
||||
|
||||
} PASEntry;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct PASMiscInfo
|
||||
|
||||
{
|
||||
|
||||
short fileHasResFork;
|
||||
|
||||
short fileResAttrs;
|
||||
|
||||
OSType fileType;
|
||||
|
||||
OSType fileCreator;
|
||||
|
||||
UInt32 fileFlags;
|
||||
|
||||
|
||||
|
||||
} PASMiscInfo;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct PASResFork
|
||||
|
||||
{
|
||||
|
||||
short NumberOfTypes;
|
||||
|
||||
|
||||
|
||||
} PASResFork;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
typedef struct PASResource
|
||||
|
||||
{
|
||||
|
||||
short attr;
|
||||
|
||||
short attrID;
|
||||
|
||||
OSType attrType;
|
||||
|
||||
Str255 attrName;
|
||||
|
||||
unsigned long length;
|
||||
|
||||
|
||||
|
||||
} PASResource;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#if PRAGMA_ALIGN_SUPPORTED
|
||||
|
||||
#pragma options align=reset
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define kCreator 'MOSS'
|
||||
|
||||
#define kType 'PASf'
|
||||
|
||||
#define PAS_BUFFER_SIZE (1024*512)
|
||||
|
||||
|
||||
|
||||
#define PAS_MAGIC_NUM (0x00244200)
|
||||
|
||||
#define PAS_VERSION (0x00010000)
|
||||
|
||||
|
||||
|
||||
enum
|
||||
|
||||
{
|
||||
|
||||
ePas_Data = 1,
|
||||
|
||||
ePas_Misc,
|
||||
|
||||
ePas_Resource
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
extern "C" {
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* Prototypes */
|
||||
|
||||
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec);
|
||||
|
||||
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif /* SU_PAS_H */
|
||||
380
mozilla/xpinstall/src/ScheduledTasks.cpp
Normal file
380
mozilla/xpinstall/src/ScheduledTasks.cpp
Normal file
@@ -0,0 +1,380 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "NSReg.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsInstall.h" // for error codes
|
||||
#include "prmem.h"
|
||||
#include "ScheduledTasks.h"
|
||||
|
||||
#ifdef _WINDOWS
|
||||
#include <sys/stat.h>
|
||||
#include <windows.h>
|
||||
|
||||
BOOL WIN32_IsMoveFileExBroken()
|
||||
{
|
||||
/* the NT option MOVEFILE_DELAY_UNTIL_REBOOT is broken on
|
||||
* Windows NT 3.51 Service Pack 4 and NT 4.0 before Service Pack 2
|
||||
*/
|
||||
BOOL broken = FALSE;
|
||||
OSVERSIONINFO osinfo;
|
||||
|
||||
// they *all* appear broken--better to have one way that works.
|
||||
return TRUE;
|
||||
|
||||
osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
||||
if (GetVersionEx(&osinfo) && osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
|
||||
{
|
||||
if ( osinfo.dwMajorVersion == 3 && osinfo.dwMinorVersion == 51 )
|
||||
{
|
||||
if ( 0 == stricmp(osinfo.szCSDVersion,"Service Pack 4"))
|
||||
{
|
||||
broken = TRUE;
|
||||
}
|
||||
}
|
||||
else if ( osinfo.dwMajorVersion == 4 )
|
||||
{
|
||||
if (osinfo.szCSDVersion[0] == '\0' ||
|
||||
(0 == stricmp(osinfo.szCSDVersion,"Service Pack 1")))
|
||||
{
|
||||
broken = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return broken;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 DoWindowsReplaceExistingFileStuff(const char* currentName, const char* finalName)
|
||||
{
|
||||
PRInt32 err = 0;
|
||||
|
||||
char* final = strdup(finalName);
|
||||
char* current = strdup(currentName);
|
||||
|
||||
/* couldn't delete, probably in use. Schedule for later */
|
||||
DWORD dwVersion, dwWindowsMajorVersion;
|
||||
|
||||
/* Get OS version info */
|
||||
dwVersion = GetVersion();
|
||||
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
|
||||
|
||||
/* Get build numbers for Windows NT or Win32s */
|
||||
|
||||
if (dwVersion < 0x80000000) // Windows NT
|
||||
{
|
||||
/* On Windows NT */
|
||||
if ( WIN32_IsMoveFileExBroken() )
|
||||
{
|
||||
/* the MOVEFILE_DELAY_UNTIL_REBOOT option doesn't work on
|
||||
* NT 3.51 SP4 or on NT 4.0 until SP2
|
||||
*/
|
||||
struct stat statbuf;
|
||||
PRBool nameFound = PR_FALSE;
|
||||
char tmpname[_MAX_PATH];
|
||||
|
||||
strncpy( tmpname, finalName, _MAX_PATH );
|
||||
int len = strlen(tmpname);
|
||||
while (!nameFound && len < _MAX_PATH )
|
||||
{
|
||||
tmpname[len-1] = '~';
|
||||
tmpname[len] = '\0';
|
||||
if ( stat(tmpname, &statbuf) != 0 )
|
||||
nameFound = TRUE;
|
||||
else
|
||||
len++;
|
||||
}
|
||||
|
||||
if ( nameFound )
|
||||
{
|
||||
if ( MoveFile( finalName, tmpname ) )
|
||||
{
|
||||
if ( MoveFile( currentName, finalName ) )
|
||||
{
|
||||
DeleteFileNowOrSchedule(nsFileSpec(tmpname));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* 2nd move failed, put old file back */
|
||||
MoveFile( tmpname, finalName );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* non-executable in use; schedule for later */
|
||||
return -1; // let the start registry stuff do our work!
|
||||
}
|
||||
}
|
||||
}
|
||||
else if ( MoveFileEx(currentName, finalName, MOVEFILE_DELAY_UNTIL_REBOOT) )
|
||||
{
|
||||
err = 0;
|
||||
}
|
||||
}
|
||||
else // Windows 95 or Win16
|
||||
{
|
||||
/*
|
||||
* Place an entry in the WININIT.INI file in the Windows directory
|
||||
* to delete finalName and rename currentName to be finalName at reboot
|
||||
*/
|
||||
|
||||
int strlen;
|
||||
char Src[_MAX_PATH]; // 8.3 name
|
||||
char Dest[_MAX_PATH]; // 8.3 name
|
||||
|
||||
strlen = GetShortPathName( (LPCTSTR)currentName, (LPTSTR)Src, (DWORD)sizeof(Src) );
|
||||
if ( strlen > 0 )
|
||||
{
|
||||
free(current);
|
||||
current = strdup(Src);
|
||||
}
|
||||
|
||||
strlen = GetShortPathName( (LPCTSTR) finalName, (LPTSTR) Dest, (DWORD) sizeof(Dest));
|
||||
if ( strlen > 0 )
|
||||
{
|
||||
free(final);
|
||||
final = strdup(Dest);
|
||||
}
|
||||
|
||||
/* NOTE: use OEM filenames! Even though it looks like a Windows
|
||||
* .INI file, WININIT.INI is processed under DOS
|
||||
*/
|
||||
|
||||
AnsiToOem( final, final );
|
||||
AnsiToOem( current, current );
|
||||
|
||||
if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) )
|
||||
err = 0;
|
||||
}
|
||||
|
||||
free(final);
|
||||
free(current);
|
||||
|
||||
return err;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename)
|
||||
{
|
||||
|
||||
REGERR result = 0;
|
||||
|
||||
filename.Delete(false);
|
||||
|
||||
if (filename.Exists())
|
||||
{
|
||||
RKEY newkey;
|
||||
HREG reg;
|
||||
if ( REGERR_OK == NR_RegOpen("", ®) )
|
||||
{
|
||||
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) )
|
||||
{
|
||||
// FIX should be using nsPersistentFileDescriptor!!!
|
||||
|
||||
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)filename.GetNativePathCString(), REGTYPE_ENTRY_FILE, nsnull, 0);
|
||||
if (result == REGERR_OK)
|
||||
result = nsInstall::REBOOT_NEEDED;
|
||||
}
|
||||
|
||||
NR_RegClose(reg);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
/* tmp file is the bad one that we want to replace with target. */
|
||||
|
||||
REGERR ReplaceFileNowOrSchedule(nsFileSpec& replacementFile, nsFileSpec& doomedFile )
|
||||
{
|
||||
REGERR result = 0;
|
||||
|
||||
if(replacementFile == doomedFile)
|
||||
{
|
||||
/* do not have to do anything */
|
||||
return result;
|
||||
}
|
||||
|
||||
doomedFile.Delete(false);
|
||||
|
||||
if (! doomedFile.Exists() )
|
||||
{
|
||||
// Now that we have move the existing file, we can move the mExtracedFile into place.
|
||||
nsFileSpec parentofFinalFile;
|
||||
|
||||
doomedFile.GetParent(parentofFinalFile);
|
||||
result = replacementFile.Move(parentofFinalFile);
|
||||
if ( NS_SUCCEEDED(result) )
|
||||
{
|
||||
char* leafName = doomedFile.GetLeafName();
|
||||
replacementFile.Rename(leafName);
|
||||
nsCRT::free(leafName);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef _WINDOWS
|
||||
if (DoWindowsReplaceExistingFileStuff(replacementFile.GetNativePathCString(), doomedFile.GetNativePathCString()) == 0)
|
||||
return 0;
|
||||
#endif
|
||||
|
||||
RKEY newkey;
|
||||
HREG reg;
|
||||
|
||||
if ( REGERR_OK == NR_RegOpen("", ®) )
|
||||
{
|
||||
result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
|
||||
if ( result == REGERR_OK )
|
||||
{
|
||||
char* replacementFileName = (char*)(const char*)replacementFile.GetNativePathCString();
|
||||
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)doomedFile.GetNativePathCString(), REGTYPE_ENTRY_FILE, replacementFileName, strlen(replacementFileName));
|
||||
if (result == REGERR_OK)
|
||||
result = nsInstall::REBOOT_NEEDED;
|
||||
}
|
||||
|
||||
NR_RegClose(reg);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void DeleteScheduledFiles(void);
|
||||
void ReplaceScheduledFiles(void);
|
||||
|
||||
extern "C" void PerformScheduledTasks(void *data)
|
||||
{
|
||||
DeleteScheduledFiles();
|
||||
ReplaceScheduledFiles();
|
||||
}
|
||||
|
||||
|
||||
void DeleteScheduledFiles(void)
|
||||
{
|
||||
HREG reg;
|
||||
|
||||
if (REGERR_OK == NR_RegOpen("", ®))
|
||||
{
|
||||
RKEY key;
|
||||
REGENUM state;
|
||||
|
||||
/* perform scheduled file deletions and replacements (PC only) */
|
||||
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY,&key))
|
||||
{
|
||||
char buf[MAXREGNAMELEN];
|
||||
|
||||
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, buf, sizeof(buf), NULL ))
|
||||
{
|
||||
nsFileSpec doomedFile(buf);
|
||||
|
||||
doomedFile.Delete(PR_FALSE);
|
||||
|
||||
if (! doomedFile.Exists())
|
||||
{
|
||||
NR_RegDeleteEntry( reg, key, buf );
|
||||
}
|
||||
}
|
||||
|
||||
/* delete list node if empty */
|
||||
if (REGERR_NOMORE == NR_RegEnumEntries( reg, key, &state, buf, sizeof(buf), NULL ))
|
||||
{
|
||||
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
NR_RegClose(reg);
|
||||
}
|
||||
}
|
||||
|
||||
void ReplaceScheduledFiles(void)
|
||||
{
|
||||
HREG reg;
|
||||
|
||||
if (REGERR_OK == NR_RegOpen("", ®))
|
||||
{
|
||||
RKEY key;
|
||||
REGENUM state;
|
||||
|
||||
/* replace files if any listed */
|
||||
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &key))
|
||||
{
|
||||
char tmpfile[MAXREGNAMELEN];
|
||||
char target[MAXREGNAMELEN];
|
||||
|
||||
state = 0;
|
||||
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
|
||||
{
|
||||
|
||||
nsFileSpec replaceFile(tmpfile);
|
||||
|
||||
if (! replaceFile.Exists() )
|
||||
{
|
||||
NR_RegDeleteEntry( reg, key, tmpfile );
|
||||
}
|
||||
else if ( REGERR_OK != NR_RegGetEntryString( reg, key, tmpfile, target, sizeof(target) ) )
|
||||
{
|
||||
/* can't read target filename, corruption? */
|
||||
NR_RegDeleteEntry( reg, key, tmpfile );
|
||||
}
|
||||
else
|
||||
{
|
||||
nsFileSpec targetFile(target);
|
||||
|
||||
targetFile.Delete(PR_FALSE);
|
||||
|
||||
if (!targetFile.Exists())
|
||||
{
|
||||
nsFileSpec parentofTarget;
|
||||
targetFile.GetParent(parentofTarget);
|
||||
|
||||
nsresult result = replaceFile.Move(parentofTarget);
|
||||
if ( NS_SUCCEEDED(result) )
|
||||
{
|
||||
char* leafName = targetFile.GetLeafName();
|
||||
replaceFile.Rename(leafName);
|
||||
nsCRT::free(leafName);
|
||||
|
||||
NR_RegDeleteEntry( reg, key, tmpfile );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
/* delete list node if empty */
|
||||
if (REGERR_NOMORE == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
|
||||
{
|
||||
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
NR_RegClose(reg);
|
||||
}
|
||||
}
|
||||
42
mozilla/xpinstall/src/ScheduledTasks.h
Normal file
42
mozilla/xpinstall/src/ScheduledTasks.h
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SCHEDULEDTASKS_H__
|
||||
#define __SCHEDULEDTASKS_H__
|
||||
|
||||
|
||||
#include "NSReg.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
|
||||
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename);
|
||||
REGERR ReplaceFileNowOrSchedule(nsFileSpec& tmpfile, nsFileSpec& target );
|
||||
|
||||
|
||||
extern "C" void PerformScheduledTasks(void *data);
|
||||
|
||||
|
||||
#endif
|
||||
135
mozilla/xpinstall/src/gdiff.h
Normal file
135
mozilla/xpinstall/src/gdiff.h
Normal file
@@ -0,0 +1,135 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
/*--------------------------------------------------------------
|
||||
* GDIFF.H
|
||||
*
|
||||
* Constants used in processing the GDIFF format
|
||||
*--------------------------------------------------------------*/
|
||||
|
||||
|
||||
#include "prio.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#define GDIFF_MAGIC "\xD1\xFF\xD1\xFF"
|
||||
#define GDIFF_MAGIC_LEN 4
|
||||
#define GDIFF_VER 5
|
||||
#define GDIFF_EOF "\0"
|
||||
|
||||
#define GDIFF_VER_POS 4
|
||||
#define GDIFF_CS_POS 5
|
||||
#define GDIFF_CSLEN_POS 6
|
||||
|
||||
#define GDIFF_HEADERSIZE 7
|
||||
#define GDIFF_APPDATALEN 4
|
||||
|
||||
#define GDIFF_CS_NONE 0
|
||||
#define GDIFF_CS_MD5 1
|
||||
#define GDIFF_CS_SHA 2
|
||||
#define GDIFF_CS_CRC32 32
|
||||
|
||||
#define CRC32_LEN 4
|
||||
|
||||
/*--------------------------------------
|
||||
* GDIFF opcodes
|
||||
*------------------------------------*/
|
||||
#define ENDDIFF 0
|
||||
#define ADD8MAX 246
|
||||
#define ADD16 247
|
||||
#define ADD32 248
|
||||
#define COPY16BYTE 249
|
||||
#define COPY16SHORT 250
|
||||
#define COPY16LONG 251
|
||||
#define COPY32BYTE 252
|
||||
#define COPY32SHORT 253
|
||||
#define COPY32LONG 254
|
||||
#define COPY64 255
|
||||
|
||||
/* instruction sizes */
|
||||
#define ADD16SIZE 2
|
||||
#define ADD32SIZE 4
|
||||
#define COPY16BYTESIZE 3
|
||||
#define COPY16SHORTSIZE 4
|
||||
#define COPY16LONGSIZE 6
|
||||
#define COPY32BYTESIZE 5
|
||||
#define COPY32SHORTSIZE 6
|
||||
#define COPY32LONGSIZE 8
|
||||
#define COPY64SIZE 12
|
||||
|
||||
|
||||
/*--------------------------------------
|
||||
* error codes
|
||||
*------------------------------------*/
|
||||
#define GDIFF_OK 0
|
||||
#define GDIFF_ERR_UNKNOWN -1
|
||||
#define GDIFF_ERR_ARGS -2
|
||||
#define GDIFF_ERR_ACCESS -3
|
||||
#define GDIFF_ERR_MEM -4
|
||||
#define GDIFF_ERR_HEADER -5
|
||||
#define GDIFF_ERR_BADDIFF -6
|
||||
#define GDIFF_ERR_OPCODE -7
|
||||
#define GDIFF_ERR_OLDFILE -8
|
||||
#define GDIFF_ERR_CHKSUMTYPE -9
|
||||
#define GDIFF_ERR_CHECKSUM -10
|
||||
#define GDIFF_ERR_CHECKSUM_TARGET -11
|
||||
#define GDIFF_ERR_CHECKSUM_RESULT -12
|
||||
|
||||
|
||||
/*--------------------------------------
|
||||
* types
|
||||
*------------------------------------*/
|
||||
#ifndef AIX
|
||||
#ifdef OSF1
|
||||
#include <sys/types.h>
|
||||
#else
|
||||
typedef unsigned char uchar;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
typedef struct _diffdata {
|
||||
PRFileDesc* fSrc;
|
||||
PRFileDesc* fOut;
|
||||
PRFileDesc* fDiff;
|
||||
uint8 checksumType;
|
||||
uint8 checksumLength;
|
||||
uchar* oldChecksum;
|
||||
uchar* newChecksum;
|
||||
PRBool bMacAppleSingle;
|
||||
PRBool bWin32BoundImage;
|
||||
uchar* databuf;
|
||||
uint32 bufsize;
|
||||
} DIFFDATA;
|
||||
|
||||
typedef DIFFDATA* pDIFFDATA;
|
||||
|
||||
|
||||
/*--------------------------------------
|
||||
* miscellaneous
|
||||
*------------------------------------*/
|
||||
|
||||
#define APPFLAG_W32BOUND "autoinstall:Win32PE"
|
||||
#define APPFLAG_APPLESINGLE "autoinstall:AppleSingle"
|
||||
|
||||
#ifndef TRUE
|
||||
#define TRUE 1
|
||||
#endif
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
|
||||
|
||||
111
mozilla/xpinstall/src/makefile.win
Normal file
111
mozilla/xpinstall/src/makefile.win
Normal file
@@ -0,0 +1,111 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public License
|
||||
# Version 1.0 (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/NPL/
|
||||
#
|
||||
# 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 Mozilla Communicator client code,
|
||||
# released March 31, 1998.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
#
|
||||
# Contributors:
|
||||
# Daniel Veditz <dveditz@netscape.com>
|
||||
# Douglas Turner <dougt@netscape.com>
|
||||
|
||||
|
||||
DEPTH=..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
MODULE=xpinstall
|
||||
|
||||
DLL=.\$(OBJDIR)\$(MODULE).dll
|
||||
|
||||
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
LINCS= \
|
||||
-I$(PUBLIC)\xpinstall \
|
||||
-I$(PUBLIC)\jar \
|
||||
-I$(PUBLIC)\libreg \
|
||||
-I$(PUBLIC)\netlib \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
-I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\rdf \
|
||||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\dom \
|
||||
-I$(PUBLIC)\raptor \
|
||||
-I$(PUBLIC)\nspr2 \
|
||||
-I$(PUBLIC)\zlib \
|
||||
-I$(PUBLIC)\xpfe\components \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(DIST)\lib\jar50.lib \
|
||||
$(DIST)\lib\libreg32.lib \
|
||||
$(DIST)\lib\netlib.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\js3250.lib \
|
||||
$(DIST)\lib\jsdombase_s.lib \
|
||||
$(DIST)\lib\jsdomevents_s.lib \
|
||||
$(DIST)\lib\zlib.lib \
|
||||
$(DIST)\lib\plc3.lib \
|
||||
$(LIBNSPR) \
|
||||
$(NULL)
|
||||
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsInstall.obj \
|
||||
.\$(OBJDIR)\nsInstallTrigger.obj \
|
||||
.\$(OBJDIR)\nsInstallVersion.obj \
|
||||
.\$(OBJDIR)\nsInstallFolder.obj \
|
||||
.\$(OBJDIR)\nsJSInstall.obj \
|
||||
.\$(OBJDIR)\nsJSInstallTriggerGlobal.obj \
|
||||
.\$(OBJDIR)\nsJSInstallVersion.obj \
|
||||
.\$(OBJDIR)\nsSoftwareUpdate.obj \
|
||||
.\$(OBJDIR)\nsSoftwareUpdateRun.obj \
|
||||
.\$(OBJDIR)\nsSoftwareUpdateStream.obj \
|
||||
.\$(OBJDIR)\nsInstallFile.obj \
|
||||
.\$(OBJDIR)\nsInstallDelete.obj \
|
||||
.\$(OBJDIR)\nsInstallExecute.obj \
|
||||
.\$(OBJDIR)\nsInstallPatch.obj \
|
||||
.\$(OBJDIR)\nsInstallUninstall.obj \
|
||||
.\$(OBJDIR)\nsInstallResources.obj \
|
||||
.\$(OBJDIR)\nsTopProgressNotifier.obj \
|
||||
.\$(OBJDIR)\nsLoggingProgressNotifier.obj\
|
||||
.\$(OBJDIR)\ScheduledTasks.obj \
|
||||
.\$(OBJDIR)\nsWinReg.obj \
|
||||
.\$(OBJDIR)\nsJSWinReg.obj \
|
||||
.\$(OBJDIR)\nsWinRegItem.obj \
|
||||
.\$(OBJDIR)\nsWinRegValue.obj \
|
||||
.\$(OBJDIR)\nsWinProfile.obj \
|
||||
.\$(OBJDIR)\nsJSWinProfile.obj \
|
||||
.\$(OBJDIR)\nsWinProfileItem.obj \
|
||||
.\$(OBJDIR)\nsInstallProgressDialog.obj \
|
||||
.\$(OBJDIR)\nsInstallFileOpItem.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(MODULE).lib
|
||||
rm -f $(DIST)\bin\components\$(MODULE).dll
|
||||
|
||||
1692
mozilla/xpinstall/src/nsInstall.cpp
Normal file
1692
mozilla/xpinstall/src/nsInstall.cpp
Normal file
File diff suppressed because it is too large
Load Diff
265
mozilla/xpinstall/src/nsInstall.h
Normal file
265
mozilla/xpinstall/src/nsInstall.h
Normal file
@@ -0,0 +1,265 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NS_INSTALL_H__
|
||||
#define __NS_INSTALL_H__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
|
||||
#include "plevent.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsVector.h"
|
||||
#include "nsHashtable.h"
|
||||
|
||||
#include "nsSoftwareUpdate.h"
|
||||
|
||||
#include "nsInstallObject.h"
|
||||
#include "nsInstallVersion.h"
|
||||
|
||||
#include "nsIXPInstallProgress.h"
|
||||
|
||||
|
||||
class nsInstallInfo
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallInfo(const nsString& fromURL, const nsString& localFile, long flags);
|
||||
|
||||
nsInstallInfo(nsVector* fromURL, nsVector* localFiles, long flags);
|
||||
|
||||
virtual ~nsInstallInfo();
|
||||
|
||||
nsString& GetFromURL(PRUint32 index = 0);
|
||||
|
||||
nsString& GetLocalFile(PRUint32 index = 0);
|
||||
|
||||
void GetArguments(nsString& args, PRUint32 index = 0);
|
||||
|
||||
long GetFlags();
|
||||
|
||||
PRBool IsMultipleTrigger();
|
||||
|
||||
static void DeleteVector(nsVector* vector);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
PRBool mMultipleTrigger;
|
||||
nsresult mError;
|
||||
|
||||
long mFlags;
|
||||
nsVector *mFromURLs;
|
||||
nsVector *mLocalFiles;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class nsInstall
|
||||
{
|
||||
friend class nsWinReg;
|
||||
friend class nsWinProfile;
|
||||
|
||||
public:
|
||||
|
||||
enum
|
||||
{
|
||||
BAD_PACKAGE_NAME = -200,
|
||||
UNEXPECTED_ERROR = -201,
|
||||
ACCESS_DENIED = -202,
|
||||
TOO_MANY_CERTIFICATES = -203,
|
||||
NO_INSTALLER_CERTIFICATE = -204,
|
||||
NO_CERTIFICATE = -205,
|
||||
NO_MATCHING_CERTIFICATE = -206,
|
||||
UNKNOWN_JAR_FILE = -207,
|
||||
INVALID_ARGUMENTS = -208,
|
||||
ILLEGAL_RELATIVE_PATH = -209,
|
||||
USER_CANCELLED = -210,
|
||||
INSTALL_NOT_STARTED = -211,
|
||||
SILENT_MODE_DENIED = -212,
|
||||
NO_SUCH_COMPONENT = -213,
|
||||
FILE_DOES_NOT_EXIST = -214,
|
||||
FILE_READ_ONLY = -215,
|
||||
FILE_IS_DIRECTORY = -216,
|
||||
NETWORK_FILE_IS_IN_USE = -217,
|
||||
APPLE_SINGLE_ERR = -218,
|
||||
INVALID_PATH_ERR = -219,
|
||||
PATCH_BAD_DIFF = -220,
|
||||
PATCH_BAD_CHECKSUM_TARGET = -221,
|
||||
PATCH_BAD_CHECKSUM_RESULT = -222,
|
||||
UNINSTALL_FAILED = -223,
|
||||
GESTALT_UNKNOWN_ERR = -5550,
|
||||
GESTALT_INVALID_ARGUMENT = -5551,
|
||||
|
||||
SUCCESS = 0,
|
||||
REBOOT_NEEDED = 999,
|
||||
|
||||
LIMITED_INSTALL = 0,
|
||||
FULL_INSTALL = 1,
|
||||
NO_STATUS_DLG = 2,
|
||||
NO_FINALIZE_DLG = 4,
|
||||
|
||||
INSTALL_FILE_UNEXPECTED_MSG_ID = 0,
|
||||
DETAILS_REPLACE_FILE_MSG_ID = 1,
|
||||
DETAILS_INSTALL_FILE_MSG_ID = 2
|
||||
};
|
||||
|
||||
|
||||
nsInstall();
|
||||
virtual ~nsInstall();
|
||||
|
||||
PRInt32 SetScriptObject(void* aScriptObject);
|
||||
|
||||
PRInt32 SaveWinRegPrototype(void* aScriptObject);
|
||||
PRInt32 SaveWinProfilePrototype(void* aScriptObject);
|
||||
|
||||
JSObject* RetrieveWinRegPrototype(void);
|
||||
JSObject* RetrieveWinProfilePrototype(void);
|
||||
|
||||
PRInt32 GetUserPackageName(nsString& aUserPackageName);
|
||||
PRInt32 GetRegPackageName(nsString& aRegPackageName);
|
||||
|
||||
PRInt32 AbortInstall();
|
||||
|
||||
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn);
|
||||
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
|
||||
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
|
||||
PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn);
|
||||
|
||||
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn);
|
||||
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
|
||||
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
|
||||
PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn);
|
||||
|
||||
PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn);
|
||||
PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn);
|
||||
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn);
|
||||
PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn);
|
||||
PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn);
|
||||
PRInt32 FinalizeInstall(PRInt32* aReturn);
|
||||
PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn);
|
||||
PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder);
|
||||
PRInt32 GetComponentFolder(const nsString& aComponentName, nsString** aFolder);
|
||||
PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsString** aFolder);
|
||||
PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder);
|
||||
PRInt32 GetLastError(PRInt32* aReturn);
|
||||
PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn);
|
||||
PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn);
|
||||
PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
|
||||
PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
|
||||
PRInt32 ResetError();
|
||||
PRInt32 SetPackageFolder(const nsString& aFolder);
|
||||
PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn);
|
||||
PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn);
|
||||
|
||||
PRInt32 FileOpDirCreate(nsFileSpec& aTarget, PRInt32* aReturn);
|
||||
PRInt32 FileOpDirGetParent(nsFileSpec& aTarget, nsFileSpec* aReturn);
|
||||
PRInt32 FileOpDirRemove(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
|
||||
PRInt32 FileOpDirRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileCopy(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileDelete(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileExists(nsFileSpec& aTarget, PRBool* aReturn);
|
||||
PRInt32 FileOpFileExecute(nsFileSpec& aTarget, nsString& aParams, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileGetNativeVersion(nsFileSpec& aTarget, nsString* aReturn);
|
||||
PRInt32 FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint32* aReturn);
|
||||
PRInt32 FileOpFileGetModDate(nsFileSpec& aTarget, nsFileSpec::TimeStamp* aReturn);
|
||||
PRInt32 FileOpFileGetSize(nsFileSpec& aTarget, PRUint32* aReturn);
|
||||
PRInt32 FileOpFileIsDirectory(nsFileSpec& aTarget, PRBool* aReturn);
|
||||
PRInt32 FileOpFileIsFile(nsFileSpec& aTarget, PRBool* aReturn);
|
||||
PRInt32 FileOpFileModDateChanged(nsFileSpec& aTarget, nsFileSpec::TimeStamp& aOldStamp, PRBool* aReturn);
|
||||
PRInt32 FileOpFileMove(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileWinShortcutCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileMacAliasCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
|
||||
PRInt32 FileOpFileUnixLinkCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
|
||||
|
||||
PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName);
|
||||
void AddPatch(nsHashKey *aKey, nsFileSpec* fileName);
|
||||
void GetPatch(nsHashKey *aKey, nsFileSpec* fileName);
|
||||
|
||||
void GetJarFileLocation(nsString& aFile);
|
||||
void SetJarFileLocation(const nsString& aFile);
|
||||
|
||||
void GetInstallArguments(nsString& args);
|
||||
void SetInstallArguments(const nsString& args);
|
||||
|
||||
|
||||
private:
|
||||
JSObject* mScriptObject;
|
||||
|
||||
JSObject* mWinRegObject;
|
||||
JSObject* mWinProfileObject;
|
||||
|
||||
nsString mJarFileLocation;
|
||||
void* mJarFileData;
|
||||
|
||||
nsString mInstallArguments;
|
||||
|
||||
PRBool mUserCancelled;
|
||||
|
||||
PRBool mUninstallPackage;
|
||||
PRBool mRegisterPackage;
|
||||
|
||||
nsString mRegistryPackageName; /* Name of the package we are installing */
|
||||
nsString mUIName; /* User-readable package name */
|
||||
|
||||
nsInstallVersion* mVersionInfo; /* Component version info */
|
||||
|
||||
nsVector* mInstalledFiles;
|
||||
nsHashtable* mPatchList;
|
||||
|
||||
nsIXPInstallProgress *mNotifier;
|
||||
|
||||
PRInt32 mLastError;
|
||||
|
||||
void ParseFlags(int flags);
|
||||
PRInt32 SanityCheck(void);
|
||||
void GetTime(nsString &aString);
|
||||
|
||||
|
||||
PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName );
|
||||
PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName );
|
||||
|
||||
void CurrentUserNode(nsString& userRegNode);
|
||||
PRBool BadRegName(const nsString& regName);
|
||||
PRInt32 SaveError(PRInt32 errcode);
|
||||
|
||||
void CleanUp();
|
||||
|
||||
PRInt32 OpenJARFile(void);
|
||||
void CloseJARFile(void);
|
||||
PRInt32 ExtractDirEntries(const nsString& directory, nsVector *paths);
|
||||
|
||||
PRInt32 ScheduleForInstall(nsInstallObject* ob);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
235
mozilla/xpinstall/src/nsInstallDelete.cpp
Normal file
235
mozilla/xpinstall/src/nsInstallDelete.cpp
Normal file
@@ -0,0 +1,235 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "VerReg.h"
|
||||
#include "ScheduledTasks.h"
|
||||
#include "nsInstallDelete.h"
|
||||
#include "nsInstallResources.h"
|
||||
|
||||
#include "nsInstall.h"
|
||||
#include "nsIDOMInstallVersion.h"
|
||||
|
||||
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
|
||||
const nsString& folderSpec,
|
||||
const nsString& inPartialPath,
|
||||
PRInt32 *error)
|
||||
|
||||
: nsInstallObject(inInstall)
|
||||
{
|
||||
if ((folderSpec == "null") || (inInstall == NULL))
|
||||
{
|
||||
*error = nsInstall::INVALID_ARGUMENTS;
|
||||
return;
|
||||
}
|
||||
|
||||
mDeleteStatus = DELETE_FILE;
|
||||
mFinalFile = nsnull;
|
||||
mRegistryName = "";
|
||||
|
||||
|
||||
mFinalFile = new nsFileSpec(folderSpec);
|
||||
*mFinalFile += inPartialPath;
|
||||
|
||||
*error = ProcessInstallDelete();
|
||||
}
|
||||
|
||||
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
|
||||
const nsString& inComponentName,
|
||||
PRInt32 *error)
|
||||
|
||||
: nsInstallObject(inInstall)
|
||||
{
|
||||
if (inInstall == NULL)
|
||||
{
|
||||
*error = nsInstall::INVALID_ARGUMENTS;
|
||||
return;
|
||||
}
|
||||
|
||||
mDeleteStatus = DELETE_COMPONENT;
|
||||
mFinalFile = nsnull;
|
||||
mRegistryName = inComponentName;
|
||||
|
||||
*error = ProcessInstallDelete();
|
||||
}
|
||||
|
||||
|
||||
nsInstallDelete::~nsInstallDelete()
|
||||
{
|
||||
if (mFinalFile == nsnull)
|
||||
delete mFinalFile;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsInstallDelete::Prepare()
|
||||
{
|
||||
// no set-up necessary
|
||||
return nsInstall::SUCCESS;
|
||||
}
|
||||
|
||||
PRInt32 nsInstallDelete::Complete()
|
||||
{
|
||||
PRInt32 err = nsInstall::SUCCESS;
|
||||
|
||||
if (mInstall == NULL)
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
|
||||
if (mDeleteStatus == DELETE_COMPONENT)
|
||||
{
|
||||
char* temp = mRegistryName.ToNewCString();
|
||||
err = VR_Remove(temp);
|
||||
delete [] temp;
|
||||
}
|
||||
|
||||
if ((mDeleteStatus == DELETE_FILE) || (err == REGERR_OK))
|
||||
{
|
||||
err = NativeComplete();
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nsInstall::UNEXPECTED_ERROR;
|
||||
}
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void nsInstallDelete::Abort()
|
||||
{
|
||||
}
|
||||
|
||||
char* nsInstallDelete::toString()
|
||||
{
|
||||
char* buffer = new char[1024];
|
||||
|
||||
if (mDeleteStatus == DELETE_COMPONENT)
|
||||
{
|
||||
sprintf( buffer, nsInstallResources::GetDeleteComponentString(), nsAutoCString(mRegistryName));
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mFinalFile)
|
||||
sprintf( buffer, nsInstallResources::GetDeleteFileString(), mFinalFile->GetCString());
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsInstallDelete::CanUninstall()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsInstallDelete::RegisterPackageNode()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsInstallDelete::ProcessInstallDelete()
|
||||
{
|
||||
PRInt32 err;
|
||||
|
||||
char* tempCString = nsnull;
|
||||
|
||||
if (mDeleteStatus == DELETE_COMPONENT)
|
||||
{
|
||||
/* Check if the component is in the registry */
|
||||
tempCString = mRegistryName.ToNewCString();
|
||||
|
||||
err = VR_InRegistry( tempCString );
|
||||
|
||||
if (err != REGERR_OK)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
else
|
||||
{
|
||||
char* tempRegistryString;
|
||||
|
||||
tempRegistryString = (char*)PR_Calloc(MAXREGPATHLEN, sizeof(char));
|
||||
|
||||
err = VR_GetPath( tempCString , MAXREGPATHLEN, tempRegistryString);
|
||||
|
||||
if (err == REGERR_OK)
|
||||
{
|
||||
if (mFinalFile)
|
||||
delete mFinalFile;
|
||||
|
||||
mFinalFile = new nsFileSpec(tempRegistryString);
|
||||
}
|
||||
|
||||
PR_FREEIF(tempRegistryString);
|
||||
}
|
||||
}
|
||||
|
||||
if(tempCString)
|
||||
delete [] tempCString;
|
||||
|
||||
if (mFinalFile->Exists())
|
||||
{
|
||||
if (mFinalFile->IsFile())
|
||||
{
|
||||
err = nsInstall::SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nsInstall::FILE_IS_DIRECTORY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nsInstall::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRInt32 nsInstallDelete::NativeComplete()
|
||||
{
|
||||
if (mFinalFile->Exists())
|
||||
{
|
||||
if (mFinalFile->IsFile())
|
||||
{
|
||||
return DeleteFileNowOrSchedule(*mFinalFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
return nsInstall::FILE_IS_DIRECTORY;
|
||||
}
|
||||
}
|
||||
|
||||
return nsInstall::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
78
mozilla/xpinstall/src/nsInstallDelete.h
Normal file
78
mozilla/xpinstall/src/nsInstallDelete.h
Normal file
@@ -0,0 +1,78 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsInstallDelete_h__
|
||||
#define nsInstallDelete_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsInstallObject.h"
|
||||
|
||||
#include "nsInstall.h"
|
||||
|
||||
#define DELETE_COMPONENT 1
|
||||
#define DELETE_FILE 2
|
||||
|
||||
class nsInstallDelete : public nsInstallObject
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallDelete( nsInstall* inInstall,
|
||||
const nsString& folderSpec,
|
||||
const nsString& inPartialPath,
|
||||
PRInt32 *error);
|
||||
|
||||
nsInstallDelete( nsInstall* inInstall,
|
||||
const nsString& ,
|
||||
PRInt32 *error);
|
||||
|
||||
virtual ~nsInstallDelete();
|
||||
|
||||
PRInt32 Prepare();
|
||||
PRInt32 Complete();
|
||||
void Abort();
|
||||
char* toString();
|
||||
|
||||
PRBool CanUninstall();
|
||||
PRBool RegisterPackageNode();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/* Private Fields */
|
||||
|
||||
nsFileSpec* mFinalFile;
|
||||
|
||||
nsString mRegistryName;
|
||||
PRInt32 mDeleteStatus;
|
||||
|
||||
PRInt32 ProcessInstallDelete();
|
||||
PRInt32 NativeComplete();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsInstallDelete_h__ */
|
||||
136
mozilla/xpinstall/src/nsInstallExecute.cpp
Normal file
136
mozilla/xpinstall/src/nsInstallExecute.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
#include "VerReg.h"
|
||||
#include "nsInstallExecute.h"
|
||||
#include "nsInstallResources.h"
|
||||
#include "ScheduledTasks.h"
|
||||
|
||||
#include "nsInstall.h"
|
||||
#include "nsIDOMInstallVersion.h"
|
||||
|
||||
nsInstallExecute:: nsInstallExecute( nsInstall* inInstall,
|
||||
const nsString& inJarLocation,
|
||||
const nsString& inArgs,
|
||||
PRInt32 *error)
|
||||
|
||||
: nsInstallObject(inInstall)
|
||||
{
|
||||
if ((inInstall == nsnull) || (inJarLocation == "null"))
|
||||
{
|
||||
*error = nsInstall::INVALID_ARGUMENTS;
|
||||
return;
|
||||
}
|
||||
|
||||
mJarLocation = inJarLocation;
|
||||
mArgs = inArgs;
|
||||
mExecutableFile = nsnull;
|
||||
|
||||
}
|
||||
|
||||
|
||||
nsInstallExecute::~nsInstallExecute()
|
||||
{
|
||||
if (mExecutableFile)
|
||||
delete mExecutableFile;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRInt32 nsInstallExecute::Prepare()
|
||||
{
|
||||
if (mInstall == NULL || mJarLocation == "null")
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
|
||||
return mInstall->ExtractFileFromJar(mJarLocation, nsnull, &mExecutableFile);
|
||||
}
|
||||
|
||||
PRInt32 nsInstallExecute::Complete()
|
||||
{
|
||||
if (mExecutableFile == nsnull)
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
|
||||
nsFileSpec app( *mExecutableFile);
|
||||
|
||||
if (!app.Exists())
|
||||
{
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
PRInt32 result = app.Execute( mArgs );
|
||||
|
||||
DeleteFileNowOrSchedule( app );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void nsInstallExecute::Abort()
|
||||
{
|
||||
/* Get the names */
|
||||
if (mExecutableFile == nsnull)
|
||||
return;
|
||||
|
||||
DeleteFileNowOrSchedule(*mExecutableFile);
|
||||
}
|
||||
|
||||
char* nsInstallExecute::toString()
|
||||
{
|
||||
char* buffer = new char[1024];
|
||||
|
||||
// if the FileSpec is NULL, just us the in jar file name.
|
||||
|
||||
if (mExecutableFile == nsnull)
|
||||
{
|
||||
char *tempString = mJarLocation.ToNewCString();
|
||||
sprintf( buffer, nsInstallResources::GetExecuteString(), tempString);
|
||||
delete [] tempString;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString());
|
||||
}
|
||||
return buffer;
|
||||
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsInstallExecute::CanUninstall()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsInstallExecute::RegisterPackageNode()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
73
mozilla/xpinstall/src/nsInstallExecute.h
Normal file
73
mozilla/xpinstall/src/nsInstallExecute.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsInstallExecute_h__
|
||||
#define nsInstallExecute_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsInstallObject.h"
|
||||
|
||||
#include "nsInstall.h"
|
||||
#include "nsIDOMInstallVersion.h"
|
||||
|
||||
|
||||
class nsInstallExecute : public nsInstallObject
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallExecute( nsInstall* inInstall,
|
||||
const nsString& inJarLocation,
|
||||
const nsString& inArgs,
|
||||
PRInt32 *error);
|
||||
|
||||
|
||||
virtual ~nsInstallExecute();
|
||||
|
||||
PRInt32 Prepare();
|
||||
PRInt32 Complete();
|
||||
void Abort();
|
||||
char* toString();
|
||||
|
||||
PRBool CanUninstall();
|
||||
PRBool RegisterPackageNode();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
nsString mJarLocation; // Location in the JAR
|
||||
nsString mArgs; // command line arguments
|
||||
|
||||
nsFileSpec *mExecutableFile; // temporary file location
|
||||
|
||||
|
||||
PRInt32 NativeComplete(void);
|
||||
void NativeAbort(void);
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsInstallExecute_h__ */
|
||||
366
mozilla/xpinstall/src/nsInstallFile.cpp
Normal file
366
mozilla/xpinstall/src/nsInstallFile.cpp
Normal file
@@ -0,0 +1,366 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsInstallFile.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "VerReg.h"
|
||||
#include "ScheduledTasks.h"
|
||||
#include "nsInstall.h"
|
||||
#include "nsIDOMInstallVersion.h"
|
||||
#include "nsInstallResources.h"
|
||||
|
||||
/* Public Methods */
|
||||
|
||||
/* Constructor
|
||||
inInstall - softUpdate object we belong to
|
||||
inComponentName - full path of the registry component
|
||||
inVInfo - full version info
|
||||
inJarLocation - location inside the JAR file
|
||||
inFinalFileSpec - final location on disk
|
||||
*/
|
||||
|
||||
|
||||
nsInstallFile::nsInstallFile(nsInstall* inInstall,
|
||||
const nsString& inComponentName,
|
||||
const nsString& inVInfo,
|
||||
const nsString& inJarLocation,
|
||||
const nsString& folderSpec,
|
||||
const nsString& inPartialPath,
|
||||
PRBool forceInstall,
|
||||
PRInt32 *error)
|
||||
: nsInstallObject(inInstall)
|
||||
{
|
||||
mVersionRegistryName = nsnull;
|
||||
mJarLocation = nsnull;
|
||||
mExtracedFile = nsnull;
|
||||
mFinalFile = nsnull;
|
||||
mVersionInfo = nsnull;
|
||||
|
||||
mUpgradeFile = PR_FALSE;
|
||||
|
||||
if ((folderSpec == "null") || (inInstall == NULL))
|
||||
{
|
||||
*error = nsInstall::INVALID_ARGUMENTS;
|
||||
return;
|
||||
}
|
||||
|
||||
/* Check for existence of the newer version */
|
||||
|
||||
PRBool versionNewer = PR_FALSE; // Is this a newer version
|
||||
char* qualifiedRegNameString = inComponentName.ToNewCString();
|
||||
|
||||
if ( (forceInstall == PR_FALSE ) && (inVInfo != "") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) )
|
||||
{
|
||||
nsInstallVersion *newVersion = new nsInstallVersion();
|
||||
newVersion->Init(inVInfo);
|
||||
|
||||
VERSION versionStruct;
|
||||
|
||||
VR_GetVersion( qualifiedRegNameString, &versionStruct );
|
||||
|
||||
nsInstallVersion* oldVersion = new nsInstallVersion();
|
||||
|
||||
oldVersion->Init(versionStruct.major,
|
||||
versionStruct.minor,
|
||||
versionStruct.release,
|
||||
versionStruct.build);
|
||||
|
||||
PRInt32 areTheyEqual;
|
||||
newVersion->CompareTo(oldVersion, &areTheyEqual);
|
||||
|
||||
delete oldVersion;
|
||||
delete newVersion;
|
||||
|
||||
if (areTheyEqual == nsIDOMInstallVersion::MAJOR_DIFF_MINUS ||
|
||||
areTheyEqual == nsIDOMInstallVersion::MINOR_DIFF_MINUS ||
|
||||
areTheyEqual == nsIDOMInstallVersion::REL_DIFF_MINUS ||
|
||||
areTheyEqual == nsIDOMInstallVersion::BLD_DIFF_MINUS )
|
||||
{
|
||||
// the file to be installed is OLDER than what is on disk. Return error
|
||||
delete qualifiedRegNameString;
|
||||
*error = areTheyEqual;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
delete qualifiedRegNameString;
|
||||
|
||||
|
||||
mFinalFile = new nsFileSpec(folderSpec);
|
||||
*mFinalFile += inPartialPath;
|
||||
|
||||
mReplaceFile = mFinalFile->Exists();
|
||||
|
||||
if (mReplaceFile == PR_FALSE)
|
||||
{
|
||||
nsFileSpec parent;
|
||||
mFinalFile->GetParent(parent);
|
||||
nsFileSpec makeDirs(parent.GetCString(), PR_TRUE);
|
||||
}
|
||||
|
||||
mForceInstall = forceInstall;
|
||||
|
||||
mVersionRegistryName = new nsString(inComponentName);
|
||||
mJarLocation = new nsString(inJarLocation);
|
||||
mVersionInfo = new nsString(inVInfo);
|
||||
|
||||
nsString regPackageName;
|
||||
mInstall->GetRegPackageName(regPackageName);
|
||||
|
||||
// determine Child status
|
||||
if ( regPackageName == "" )
|
||||
{
|
||||
// in the "current communicator package" absolute pathnames (start
|
||||
// with slash) indicate shared files -- all others are children
|
||||
mChildFile = ( mVersionRegistryName->CharAt(0) != '/' );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
// there is no "starts with" api in nsString. LAME!
|
||||
nsString startsWith;
|
||||
mVersionRegistryName->Left(startsWith, regPackageName.Length());
|
||||
|
||||
if (startsWith.Equals(regPackageName))
|
||||
{
|
||||
mChildFile = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
mChildFile = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsInstallFile::~nsInstallFile()
|
||||
{
|
||||
if (mVersionRegistryName)
|
||||
delete mVersionRegistryName;
|
||||
|
||||
if (mJarLocation)
|
||||
delete mJarLocation;
|
||||
|
||||
if (mExtracedFile)
|
||||
delete mExtracedFile;
|
||||
|
||||
if (mFinalFile)
|
||||
delete mFinalFile;
|
||||
|
||||
if (mVersionInfo)
|
||||
delete mVersionInfo;
|
||||
}
|
||||
|
||||
/* Prepare
|
||||
* Extracts file out of the JAR archive
|
||||
*/
|
||||
PRInt32 nsInstallFile::Prepare()
|
||||
{
|
||||
if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
|
||||
return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, &mExtracedFile);
|
||||
}
|
||||
|
||||
/* Complete
|
||||
* Completes the install:
|
||||
* - move the downloaded file to the final location
|
||||
* - updates the registry
|
||||
*/
|
||||
PRInt32 nsInstallFile::Complete()
|
||||
{
|
||||
PRInt32 err;
|
||||
|
||||
if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull )
|
||||
{
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
err = CompleteFileMove();
|
||||
|
||||
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
|
||||
{
|
||||
err = RegisterInVersionRegistry();
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
void nsInstallFile::Abort()
|
||||
{
|
||||
if (mExtracedFile != nsnull)
|
||||
mExtracedFile->Delete(PR_FALSE);
|
||||
}
|
||||
|
||||
char* nsInstallFile::toString()
|
||||
{
|
||||
char* buffer = new char[1024];
|
||||
|
||||
if (mFinalFile == nsnull)
|
||||
{
|
||||
sprintf( buffer, nsInstallResources::GetInstallFileString(), nsnull);
|
||||
}
|
||||
else if (mReplaceFile)
|
||||
{
|
||||
// we are replacing this file.
|
||||
|
||||
sprintf( buffer, nsInstallResources::GetReplaceFileString(), mFinalFile->GetCString());
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf( buffer, nsInstallResources::GetInstallFileString(), mFinalFile->GetCString());
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsInstallFile::CompleteFileMove()
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
if (mExtracedFile == nsnull)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( *mExtracedFile == *mFinalFile )
|
||||
{
|
||||
/* No need to rename, they are the same */
|
||||
result = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = ReplaceFileNowOrSchedule(*mExtracedFile, *mFinalFile );
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFile::RegisterInVersionRegistry()
|
||||
{
|
||||
int refCount;
|
||||
nsString regPackageName;
|
||||
mInstall->GetRegPackageName(regPackageName);
|
||||
|
||||
|
||||
// Register file and log for Uninstall
|
||||
|
||||
if (!mChildFile)
|
||||
{
|
||||
int found;
|
||||
if (regPackageName != "")
|
||||
{
|
||||
found = VR_UninstallFileExistsInList( (char*)(const char*)nsAutoCString(regPackageName) ,
|
||||
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
|
||||
}
|
||||
else
|
||||
{
|
||||
found = VR_UninstallFileExistsInList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
|
||||
}
|
||||
|
||||
if (found != REGERR_OK)
|
||||
mUpgradeFile = PR_FALSE;
|
||||
else
|
||||
mUpgradeFile = PR_TRUE;
|
||||
}
|
||||
else if (REGERR_OK == VR_InRegistry( (char*)(const char*)nsAutoCString(*mVersionRegistryName)))
|
||||
{
|
||||
mUpgradeFile = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
mUpgradeFile = PR_FALSE;
|
||||
}
|
||||
|
||||
if ( REGERR_OK != VR_GetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), &refCount ))
|
||||
{
|
||||
refCount = 0;
|
||||
}
|
||||
|
||||
VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName),
|
||||
(char*)(const char*)mFinalFile->GetNativePathCString(), // DO NOT CHANGE THIS.
|
||||
(char*)(const char*)nsAutoCString(*mVersionInfo),
|
||||
PR_FALSE );
|
||||
|
||||
if (mUpgradeFile)
|
||||
{
|
||||
if (refCount == 0)
|
||||
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
|
||||
else
|
||||
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount ); //FIX?? what should the ref count be/
|
||||
}
|
||||
else
|
||||
{
|
||||
if (refCount != 0)
|
||||
{
|
||||
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount + 1 );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mReplaceFile)
|
||||
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 );
|
||||
else
|
||||
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
|
||||
}
|
||||
}
|
||||
|
||||
if ( !mChildFile && !mUpgradeFile )
|
||||
{
|
||||
if (regPackageName != "")
|
||||
{
|
||||
VR_UninstallAddFileToList( (char*)(const char*)nsAutoCString(regPackageName),
|
||||
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
|
||||
}
|
||||
else
|
||||
{
|
||||
VR_UninstallAddFileToList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
|
||||
}
|
||||
}
|
||||
|
||||
return nsInstall::SUCCESS;
|
||||
}
|
||||
|
||||
/* CanUninstall
|
||||
* InstallFile() installs files which can be uninstalled,
|
||||
* hence this function returns true.
|
||||
*/
|
||||
PRBool
|
||||
nsInstallFile::CanUninstall()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* RegisterPackageNode
|
||||
* InstallFile() installs files which need to be registered,
|
||||
* hence this function returns true.
|
||||
*/
|
||||
PRBool
|
||||
nsInstallFile::RegisterPackageNode()
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
93
mozilla/xpinstall/src/nsInstallFile.h
Normal file
93
mozilla/xpinstall/src/nsInstallFile.h
Normal file
@@ -0,0 +1,93 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsInstallFile_h__
|
||||
#define nsInstallFile_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsInstallObject.h"
|
||||
|
||||
#include "nsInstall.h"
|
||||
#include "nsInstallVersion.h"
|
||||
|
||||
class nsInstallFile : public nsInstallObject
|
||||
{
|
||||
public:
|
||||
|
||||
/*************************************************************
|
||||
* Public Methods
|
||||
*
|
||||
* Constructor
|
||||
* inSoftUpdate - softUpdate object we belong to
|
||||
* inComponentName - full path of the registry component
|
||||
* inVInfo - full version info
|
||||
* inJarLocation - location inside the JAR file
|
||||
* inFinalFileSpec - final location on disk
|
||||
*************************************************************/
|
||||
nsInstallFile( nsInstall* inInstall,
|
||||
const nsString& inVRName,
|
||||
const nsString& inVInfo,
|
||||
const nsString& inJarLocation,
|
||||
const nsString& folderSpec,
|
||||
const nsString& inPartialPath,
|
||||
PRBool forceInstall,
|
||||
PRInt32 *error);
|
||||
|
||||
virtual ~nsInstallFile();
|
||||
|
||||
PRInt32 Prepare();
|
||||
PRInt32 Complete();
|
||||
void Abort();
|
||||
char* toString();
|
||||
|
||||
PRBool CanUninstall();
|
||||
PRBool RegisterPackageNode();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
/* Private Fields */
|
||||
nsString* mVersionInfo; /* Version info for this file*/
|
||||
|
||||
nsString* mJarLocation; /* Location in the JAR */
|
||||
nsFileSpec* mExtracedFile; /* temporary file location */
|
||||
nsFileSpec* mFinalFile; /* final file destination */
|
||||
|
||||
nsString* mVersionRegistryName; /* full version path */
|
||||
|
||||
PRBool mForceInstall; /* whether install is forced */
|
||||
PRBool mReplaceFile; /* whether file exists */
|
||||
PRBool mChildFile; /* whether file is a child */
|
||||
PRBool mUpgradeFile; /* whether file is an upgrade */
|
||||
|
||||
|
||||
PRInt32 CompleteFileMove();
|
||||
PRInt32 RegisterInVersionRegistry();
|
||||
};
|
||||
|
||||
#endif /* nsInstallFile_h__ */
|
||||
38
mozilla/xpinstall/src/nsInstallFileOpEnums.h
Normal file
38
mozilla/xpinstall/src/nsInstallFileOpEnums.h
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsInstallFileOpEnums_h__
|
||||
#define nsInstallFileOpEnums_h__
|
||||
|
||||
typedef enum nsInstallFileOpEnums {
|
||||
NS_FOP_DIR_CREATE = 0,
|
||||
NS_FOP_DIR_REMOVE = 1,
|
||||
NS_FOP_DIR_RENAME = 2,
|
||||
NS_FOP_FILE_COPY = 3,
|
||||
NS_FOP_FILE_DELETE = 4,
|
||||
NS_FOP_FILE_EXECUTE = 5,
|
||||
NS_FOP_FILE_MOVE = 6,
|
||||
NS_FOP_FILE_RENAME = 7,
|
||||
NS_FOP_WIN_SHORTCUT_CREATE = 8,
|
||||
NS_FOP_MAC_ALIAS_CREATE = 9,
|
||||
NS_FOP_UNIX_LINK_CREATE = 10,
|
||||
NS_FOP_FILE_SET_STAT = 11
|
||||
|
||||
} nsInstallFileOpEnums;
|
||||
|
||||
#endif /* nsInstallFileOpEnums_h__ */
|
||||
316
mozilla/xpinstall/src/nsInstallFileOpItem.cpp
Normal file
316
mozilla/xpinstall/src/nsInstallFileOpItem.cpp
Normal file
@@ -0,0 +1,316 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsInstall.h"
|
||||
#include "nsInstallFileOpEnums.h"
|
||||
#include "nsInstallFileOpItem.h"
|
||||
|
||||
/* Public Methods */
|
||||
|
||||
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aTarget,
|
||||
PRInt32 aFlags,
|
||||
PRInt32* aReturn)
|
||||
:nsInstallObject(aInstallObj)
|
||||
{
|
||||
mIObj = aInstallObj;
|
||||
mCommand = aCommand;
|
||||
mFlags = aFlags;
|
||||
mSrc = nsnull;
|
||||
mParams = nsnull;
|
||||
mTarget = new nsFileSpec(aTarget);
|
||||
|
||||
*aReturn = NS_OK;
|
||||
}
|
||||
|
||||
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aSrc,
|
||||
nsFileSpec& aTarget,
|
||||
PRInt32* aReturn)
|
||||
:nsInstallObject(aInstallObj)
|
||||
{
|
||||
mIObj = aInstallObj;
|
||||
mCommand = aCommand;
|
||||
mFlags = 0;
|
||||
mSrc = new nsFileSpec(aSrc);
|
||||
mParams = nsnull;
|
||||
mTarget = new nsFileSpec(aTarget);
|
||||
|
||||
*aReturn = NS_OK;
|
||||
}
|
||||
|
||||
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aTarget,
|
||||
PRInt32* aReturn)
|
||||
:nsInstallObject(aInstallObj)
|
||||
{
|
||||
mIObj = aInstallObj;
|
||||
mCommand = aCommand;
|
||||
mFlags = 0;
|
||||
mSrc = nsnull;
|
||||
mParams = nsnull;
|
||||
mTarget = new nsFileSpec(aTarget);
|
||||
|
||||
*aReturn = NS_OK;
|
||||
}
|
||||
|
||||
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aTarget,
|
||||
nsString& aParams,
|
||||
PRInt32* aReturn)
|
||||
:nsInstallObject(aInstallObj)
|
||||
{
|
||||
mIObj = aInstallObj;
|
||||
mCommand = aCommand;
|
||||
mFlags = 0;
|
||||
mSrc = nsnull;
|
||||
mParams = new nsString(aParams);
|
||||
mTarget = new nsFileSpec(aTarget);
|
||||
|
||||
*aReturn = NS_OK;
|
||||
}
|
||||
|
||||
nsInstallFileOpItem::~nsInstallFileOpItem()
|
||||
{
|
||||
if(mSrc)
|
||||
delete mSrc;
|
||||
if(mTarget)
|
||||
delete mTarget;
|
||||
}
|
||||
|
||||
PRInt32 nsInstallFileOpItem::Complete()
|
||||
{
|
||||
PRInt32 aReturn = NS_OK;
|
||||
|
||||
switch(mCommand)
|
||||
{
|
||||
case NS_FOP_DIR_CREATE:
|
||||
NativeFileOpDirCreate(mTarget);
|
||||
break;
|
||||
case NS_FOP_DIR_REMOVE:
|
||||
NativeFileOpDirRemove(mTarget, mFlags);
|
||||
break;
|
||||
case NS_FOP_DIR_RENAME:
|
||||
NativeFileOpDirRename(mSrc, mTarget);
|
||||
break;
|
||||
case NS_FOP_FILE_COPY:
|
||||
NativeFileOpFileCopy(mSrc, mTarget);
|
||||
break;
|
||||
case NS_FOP_FILE_DELETE:
|
||||
NativeFileOpFileDelete(mTarget, mFlags);
|
||||
break;
|
||||
case NS_FOP_FILE_EXECUTE:
|
||||
NativeFileOpFileExecute(mTarget, mParams);
|
||||
break;
|
||||
case NS_FOP_FILE_MOVE:
|
||||
NativeFileOpFileMove(mSrc, mTarget);
|
||||
break;
|
||||
case NS_FOP_FILE_RENAME:
|
||||
NativeFileOpFileRename(mSrc, mTarget);
|
||||
break;
|
||||
case NS_FOP_WIN_SHORTCUT_CREATE:
|
||||
NativeFileOpWinShortcutCreate();
|
||||
break;
|
||||
case NS_FOP_MAC_ALIAS_CREATE:
|
||||
NativeFileOpMacAliasCreate();
|
||||
break;
|
||||
case NS_FOP_UNIX_LINK_CREATE:
|
||||
NativeFileOpUnixLinkCreate();
|
||||
break;
|
||||
}
|
||||
return aReturn;
|
||||
}
|
||||
|
||||
float nsInstallFileOpItem::GetInstallOrder()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
char* nsInstallFileOpItem::toString()
|
||||
{
|
||||
nsString result;
|
||||
char* resultCString;
|
||||
|
||||
switch(mCommand)
|
||||
{
|
||||
case NS_FOP_FILE_COPY:
|
||||
result = "Copy file: ";
|
||||
result.Append(mSrc->GetNativePathCString());
|
||||
result.Append(" to ");
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
case NS_FOP_FILE_DELETE:
|
||||
result = "Delete file: ";
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
case NS_FOP_FILE_MOVE:
|
||||
result = "Move file: ";
|
||||
result.Append(mSrc->GetNativePathCString());
|
||||
result.Append(" to ");
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
case NS_FOP_FILE_RENAME:
|
||||
result = "Rename file: ";
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
case NS_FOP_DIR_CREATE:
|
||||
result = "Create Folder: ";
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
case NS_FOP_DIR_REMOVE:
|
||||
result = "Remove Folder: ";
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
case NS_FOP_WIN_SHORTCUT_CREATE:
|
||||
break;
|
||||
case NS_FOP_MAC_ALIAS_CREATE:
|
||||
break;
|
||||
case NS_FOP_UNIX_LINK_CREATE:
|
||||
break;
|
||||
case NS_FOP_FILE_SET_STAT:
|
||||
result = "Set file stat: ";
|
||||
result.Append(mTarget->GetNativePathCString());
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
default:
|
||||
result = "Unkown file operation command!";
|
||||
resultCString = result.ToNewCString();
|
||||
break;
|
||||
}
|
||||
return resultCString;
|
||||
}
|
||||
|
||||
PRInt32 nsInstallFileOpItem::Prepare()
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void nsInstallFileOpItem::Abort()
|
||||
{
|
||||
}
|
||||
|
||||
/* Private Methods */
|
||||
|
||||
/* CanUninstall
|
||||
* InstallFileOpItem() does not install any files which can be uninstalled,
|
||||
* hence this function returns false.
|
||||
*/
|
||||
PRBool
|
||||
nsInstallFileOpItem::CanUninstall()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* RegisterPackageNode
|
||||
* InstallFileOpItem() does notinstall files which need to be registered,
|
||||
* hence this function returns false.
|
||||
*/
|
||||
PRBool
|
||||
nsInstallFileOpItem::RegisterPackageNode()
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
//
|
||||
// File operation functions begin here
|
||||
//
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpDirCreate(nsFileSpec* aTarget)
|
||||
{
|
||||
aTarget->CreateDirectory();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags)
|
||||
{
|
||||
aTarget->Delete(aFlags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
|
||||
{
|
||||
aSrc->Rename(*aTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget)
|
||||
{
|
||||
aSrc->Copy(*aTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags)
|
||||
{
|
||||
aTarget->Delete(aFlags);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams)
|
||||
{
|
||||
aTarget->Execute(*aParams);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget)
|
||||
{
|
||||
aSrc->Move(*aTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
|
||||
{
|
||||
aSrc->Rename(*aTarget);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpWinShortcutCreate()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpMacAliasCreate()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PRInt32
|
||||
nsInstallFileOpItem::NativeFileOpUnixLinkCreate()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
111
mozilla/xpinstall/src/nsInstallFileOpItem.h
Normal file
111
mozilla/xpinstall/src/nsInstallFileOpItem.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsInstallFileOpItem_h__
|
||||
#define nsInstallFileOpItem_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsSoftwareUpdate.h"
|
||||
#include "nsInstallObject.h"
|
||||
#include "nsInstall.h"
|
||||
|
||||
class nsInstallFileOpItem : public nsInstallObject
|
||||
{
|
||||
public:
|
||||
/* Public Fields */
|
||||
|
||||
/* Public Methods */
|
||||
// used by:
|
||||
// FileOpFileDelete()
|
||||
nsInstallFileOpItem(nsInstall* installObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aTarget,
|
||||
PRInt32 aFlags,
|
||||
PRInt32* aReturn);
|
||||
|
||||
// used by:
|
||||
// FileOpDirRemove()
|
||||
// FileOpDirRename()
|
||||
// FileOpFileCopy()
|
||||
// FileOpFileMove()
|
||||
// FileOpFileRename()
|
||||
nsInstallFileOpItem(nsInstall* installObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aSrc,
|
||||
nsFileSpec& aTarget,
|
||||
PRInt32* aReturn);
|
||||
|
||||
// used by:
|
||||
// FileOpDirCreate()
|
||||
nsInstallFileOpItem(nsInstall* aInstallObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aTarget,
|
||||
PRInt32* aReturn);
|
||||
|
||||
// used by:
|
||||
// FileOpFileExecute()
|
||||
nsInstallFileOpItem(nsInstall* aInstallObj,
|
||||
PRInt32 aCommand,
|
||||
nsFileSpec& aTarget,
|
||||
nsString& aParams,
|
||||
PRInt32* aReturn);
|
||||
|
||||
~nsInstallFileOpItem();
|
||||
|
||||
PRInt32 Prepare(void);
|
||||
PRInt32 Complete();
|
||||
char* toString();
|
||||
void Abort();
|
||||
float GetInstallOrder();
|
||||
|
||||
/* should these be protected? */
|
||||
PRBool CanUninstall();
|
||||
PRBool RegisterPackageNode();
|
||||
|
||||
private:
|
||||
|
||||
/* Private Fields */
|
||||
|
||||
nsInstall* mIObj; // initiating Install object
|
||||
nsFileSpec* mSrc;
|
||||
nsFileSpec* mTarget;
|
||||
nsString* mParams;
|
||||
long mFStat;
|
||||
PRInt32 mFlags;
|
||||
PRInt32 mCommand;
|
||||
|
||||
/* Private Methods */
|
||||
|
||||
PRInt32 NativeFileOpDirCreate(nsFileSpec* aTarget);
|
||||
PRInt32 NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags);
|
||||
PRInt32 NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
|
||||
PRInt32 NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget);
|
||||
PRInt32 NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags);
|
||||
PRInt32 NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams);
|
||||
PRInt32 NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget);
|
||||
PRInt32 NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
|
||||
PRInt32 NativeFileOpWinShortcutCreate();
|
||||
PRInt32 NativeFileOpMacAliasCreate();
|
||||
PRInt32 NativeFileOpUnixLinkCreate();
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsInstallFileOpItem_h__ */
|
||||
|
||||
336
mozilla/xpinstall/src/nsInstallFolder.cpp
Normal file
336
mozilla/xpinstall/src/nsInstallFolder.cpp
Normal file
@@ -0,0 +1,336 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsInstall.h"
|
||||
#include "nsInstallFolder.h"
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prtypes.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
#include "nsFileLocations.h"
|
||||
#include "nsIFileLocator.h"
|
||||
|
||||
struct DirectoryTable
|
||||
{
|
||||
char * directoryName; /* The formal directory name */
|
||||
PRInt32 folderEnum; /* Directory ID */
|
||||
};
|
||||
|
||||
struct DirectoryTable DirectoryTable[] =
|
||||
{
|
||||
{"Plugins", 100 },
|
||||
{"Program", 101 },
|
||||
{"Communicator", 102 },
|
||||
{"User Pick", 103 },
|
||||
{"Temporary", 104 },
|
||||
{"Installed", 105 },
|
||||
{"Current User", 106 },
|
||||
{"Preferences", 107 },
|
||||
{"OS Drive", 108 },
|
||||
{"file:///", 109 },
|
||||
|
||||
{"Components", 110 },
|
||||
{"Chrome", 111 },
|
||||
|
||||
{"Win System", 200 },
|
||||
{"Windows", 201 },
|
||||
|
||||
{"Mac System", 300 },
|
||||
{"Mac Desktop", 301 },
|
||||
{"Mac Trash", 302 },
|
||||
{"Mac Startup", 303 },
|
||||
{"Mac Shutdown", 304 },
|
||||
{"Mac Apple Menu", 305 },
|
||||
{"Mac Control Panel", 306 },
|
||||
{"Mac Extension", 307 },
|
||||
{"Mac Fonts", 308 },
|
||||
{"Mac Preferences", 309 },
|
||||
{"Mac Documents", 310 },
|
||||
|
||||
{"Unix Local", 400 },
|
||||
{"Unix Lib", 401 },
|
||||
|
||||
{"", -1 }
|
||||
};
|
||||
|
||||
|
||||
|
||||
nsInstallFolder::nsInstallFolder(const nsString& aFolderID)
|
||||
{
|
||||
mFileSpec = nsnull;
|
||||
SetDirectoryPath( aFolderID, "");
|
||||
}
|
||||
|
||||
nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath)
|
||||
{
|
||||
mFileSpec = nsnull;
|
||||
|
||||
/*
|
||||
aFolderID can be either a Folder enum in which case we merely pass it to SetDirectoryPath, or
|
||||
it can be a Directory. If it is the later, it must already exist and of course be a directory
|
||||
not a file.
|
||||
*/
|
||||
|
||||
nsFileSpec dirCheck(aFolderID);
|
||||
if ( (dirCheck.Error() == NS_OK) && (dirCheck.IsDirectory()) && (dirCheck.Exists()))
|
||||
{
|
||||
nsString tempString = aFolderID;
|
||||
tempString += aRelativePath;
|
||||
mFileSpec = new nsFileSpec(tempString);
|
||||
|
||||
// make sure that the directory is created.
|
||||
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetDirectoryPath( aFolderID, aRelativePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsInstallFolder::~nsInstallFolder()
|
||||
{
|
||||
if (mFileSpec != nsnull)
|
||||
delete mFileSpec;
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath)
|
||||
{
|
||||
aDirectoryPath = "";
|
||||
|
||||
if (mFileSpec != nsnull)
|
||||
{
|
||||
// We want the a NATIVE path.
|
||||
aDirectoryPath.SetString(mFileSpec->GetCString());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath)
|
||||
{
|
||||
if ( aFolderID.EqualsIgnoreCase("User Pick") )
|
||||
{
|
||||
PickDefaultDirectory();
|
||||
return;
|
||||
}
|
||||
else if ( aFolderID.EqualsIgnoreCase("Installed") )
|
||||
{
|
||||
mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path.
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
PRInt32 folderDirSpecID = MapNameToEnum(aFolderID);
|
||||
|
||||
switch (folderDirSpecID)
|
||||
{
|
||||
case 100: /////////////////////////////////////////////////////////// Plugins
|
||||
SetAppShellDirectory(nsSpecialFileSpec::App_PluginsDirectory );
|
||||
break;
|
||||
|
||||
case 101: /////////////////////////////////////////////////////////// Program
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
|
||||
break;
|
||||
|
||||
case 102: /////////////////////////////////////////////////////////// Communicator
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
|
||||
break;
|
||||
|
||||
case 103: /////////////////////////////////////////////////////////// User Pick
|
||||
// we should never be here.
|
||||
mFileSpec = nsnull;
|
||||
break;
|
||||
|
||||
case 104: /////////////////////////////////////////////////////////// Temporary
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_TemporaryDirectory ));
|
||||
break;
|
||||
|
||||
case 105: /////////////////////////////////////////////////////////// Installed
|
||||
// we should never be here.
|
||||
mFileSpec = nsnull;
|
||||
break;
|
||||
|
||||
case 106: /////////////////////////////////////////////////////////// Current User
|
||||
SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 );
|
||||
break;
|
||||
|
||||
case 107: /////////////////////////////////////////////////////////// Preferences
|
||||
SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 );
|
||||
break;
|
||||
|
||||
case 108: /////////////////////////////////////////////////////////// OS Drive
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_DriveDirectory ));
|
||||
break;
|
||||
|
||||
case 109: /////////////////////////////////////////////////////////// File URL
|
||||
{
|
||||
nsString tempFileURLString = aFolderID;
|
||||
tempFileURLString += aRelativePath;
|
||||
mFileSpec = new nsFileSpec( nsFileURL(tempFileURLString) );
|
||||
}
|
||||
break;
|
||||
|
||||
case 110: /////////////////////////////////////////////////////////// Components
|
||||
SetAppShellDirectory(nsSpecialFileSpec::App_ComponentsDirectory );
|
||||
break;
|
||||
|
||||
case 111: /////////////////////////////////////////////////////////// Chrome
|
||||
SetAppShellDirectory(nsSpecialFileSpec::App_ChromeDirectory );
|
||||
break;
|
||||
|
||||
case 200: /////////////////////////////////////////////////////////// Win System
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_SystemDirectory ));
|
||||
break;
|
||||
|
||||
case 201: /////////////////////////////////////////////////////////// Windows
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_WindowsDirectory ));
|
||||
break;
|
||||
|
||||
case 300: /////////////////////////////////////////////////////////// Mac System
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_SystemDirectory ));
|
||||
break;
|
||||
|
||||
case 301: /////////////////////////////////////////////////////////// Mac Desktop
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DesktopDirectory ));
|
||||
break;
|
||||
|
||||
case 302: /////////////////////////////////////////////////////////// Mac Trash
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_TrashDirectory ));
|
||||
break;
|
||||
|
||||
case 303: /////////////////////////////////////////////////////////// Mac Startup
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
|
||||
break;
|
||||
|
||||
case 304: /////////////////////////////////////////////////////////// Mac Shutdown
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
|
||||
break;
|
||||
|
||||
case 305: /////////////////////////////////////////////////////////// Mac Apple Menu
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_AppleMenuDirectory ));
|
||||
break;
|
||||
|
||||
case 306: /////////////////////////////////////////////////////////// Mac Control Panel
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ControlPanelDirectory ));
|
||||
break;
|
||||
|
||||
case 307: /////////////////////////////////////////////////////////// Mac Extension
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ExtensionDirectory ));
|
||||
break;
|
||||
|
||||
case 308: /////////////////////////////////////////////////////////// Mac Fonts
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_FontsDirectory ));
|
||||
break;
|
||||
|
||||
case 309: /////////////////////////////////////////////////////////// Mac Preferences
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_PreferencesDirectory ));
|
||||
break;
|
||||
|
||||
case 310: /////////////////////////////////////////////////////////// Mac Documents
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DocumentsDirectory ));
|
||||
break;
|
||||
|
||||
case 400: /////////////////////////////////////////////////////////// Unix Local
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LocalDirectory ));
|
||||
break;
|
||||
|
||||
case 401: /////////////////////////////////////////////////////////// Unix Lib
|
||||
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LibDirectory ));
|
||||
break;
|
||||
|
||||
|
||||
case -1:
|
||||
default:
|
||||
mFileSpec = nsnull;
|
||||
return;
|
||||
}
|
||||
#ifndef XP_MAC
|
||||
if (aRelativePath.Length() > 0)
|
||||
{
|
||||
nsString tempPath(aRelativePath);
|
||||
|
||||
if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\')
|
||||
tempPath += '/';
|
||||
|
||||
*mFileSpec += tempPath;
|
||||
}
|
||||
#endif
|
||||
// make sure that the directory is created.
|
||||
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
void nsInstallFolder::PickDefaultDirectory()
|
||||
{
|
||||
//FIX: Need to put up a dialog here and set mFileSpec
|
||||
return;
|
||||
}
|
||||
|
||||
/* MapNameToEnum
|
||||
* maps name from the directory table to its enum */
|
||||
PRInt32
|
||||
nsInstallFolder::MapNameToEnum(const nsString& name)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if ( name == "null")
|
||||
return -1;
|
||||
|
||||
while ( DirectoryTable[i].directoryName[0] != 0 )
|
||||
{
|
||||
if ( name.EqualsIgnoreCase(DirectoryTable[i].directoryName) )
|
||||
return DirectoryTable[i].folderEnum;
|
||||
i++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kFileLocatorIID, NS_IFILELOCATOR_IID);
|
||||
static NS_DEFINE_IID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
|
||||
void
|
||||
nsInstallFolder::SetAppShellDirectory(PRUint32 value)
|
||||
{
|
||||
nsIFileLocator * appShellLocator;
|
||||
|
||||
nsresult rv = nsComponentManager::CreateInstance(kFileLocatorCID,
|
||||
nsnull,
|
||||
kFileLocatorIID,
|
||||
(void**) &appShellLocator);
|
||||
|
||||
if ( NS_SUCCEEDED(rv) )
|
||||
{
|
||||
mFileSpec = new nsFileSpec();
|
||||
appShellLocator->GetFileLocation(value, mFileSpec);
|
||||
NS_RELEASE(appShellLocator);
|
||||
}
|
||||
}
|
||||
58
mozilla/xpinstall/src/nsInstallFolder.h
Normal file
58
mozilla/xpinstall/src/nsInstallFolder.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NS_INSTALLFOLDER_H__
|
||||
#define __NS_INSTALLFOLDER_H__
|
||||
|
||||
#include "nscore.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#include "nsString.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
|
||||
class nsInstallFolder
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallFolder(const nsString& aFolderID);
|
||||
nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath);
|
||||
virtual ~nsInstallFolder();
|
||||
|
||||
void GetDirectoryPath(nsString& aDirectoryPath);
|
||||
|
||||
private:
|
||||
|
||||
nsFileSpec* mFileSpec;
|
||||
|
||||
void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath);
|
||||
void PickDefaultDirectory();
|
||||
PRInt32 MapNameToEnum(const nsString& name);
|
||||
void SetAppShellDirectory(PRUint32 value);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
52
mozilla/xpinstall/src/nsInstallObject.h
Normal file
52
mozilla/xpinstall/src/nsInstallObject.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsInstallObject_h__
|
||||
#define nsInstallObject_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
|
||||
class nsInstall;
|
||||
|
||||
class nsInstallObject
|
||||
{
|
||||
public:
|
||||
/* Public Methods */
|
||||
nsInstallObject(nsInstall* inInstall) {mInstall = inInstall; }
|
||||
|
||||
/* Override with your set-up action */
|
||||
virtual PRInt32 Prepare() = 0;
|
||||
|
||||
/* Override with your Completion action */
|
||||
virtual PRInt32 Complete() = 0;
|
||||
|
||||
/* Override with an explanatory string for the progress dialog */
|
||||
virtual char* toString() = 0;
|
||||
|
||||
/* Override with your clean-up function */
|
||||
virtual void Abort() = 0;
|
||||
|
||||
/* should these be protected? */
|
||||
virtual PRBool CanUninstall() = 0;
|
||||
virtual PRBool RegisterPackageNode() = 0;
|
||||
|
||||
protected:
|
||||
nsInstall* mInstall;
|
||||
};
|
||||
|
||||
#endif /* nsInstallObject_h__ */
|
||||
986
mozilla/xpinstall/src/nsInstallPatch.cpp
Normal file
986
mozilla/xpinstall/src/nsInstallPatch.cpp
Normal file
@@ -0,0 +1,986 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
#include "prmem.h"
|
||||
#include "nsInstall.h"
|
||||
#include "nsInstallPatch.h"
|
||||
#include "nsInstallResources.h"
|
||||
#include "nsIDOMInstallVersion.h"
|
||||
#include "zlib.h"
|
||||
|
||||
#include "gdiff.h"
|
||||
|
||||
#include "VerReg.h"
|
||||
#include "ScheduledTasks.h"
|
||||
#include "plstr.h"
|
||||
#include "xp_file.h" /* for XP_PlatformFileToURL */
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
#include "PatchableAppleSingle.h"
|
||||
#endif
|
||||
|
||||
#define BUFSIZE 32768
|
||||
#define OPSIZE 1
|
||||
#define MAXCMDSIZE 12
|
||||
#define SRCFILE 0
|
||||
#define OUTFILE 1
|
||||
|
||||
#define getshort(s) (uint16)( ((uchar)*(s) << 8) + ((uchar)*((s)+1)) )
|
||||
|
||||
#define getlong(s) \
|
||||
(uint32)( ((uchar)*(s) << 24) + ((uchar)*((s)+1) << 16 ) + \
|
||||
((uchar)*((s)+2) << 8) + ((uchar)*((s)+3)) )
|
||||
|
||||
|
||||
|
||||
static int32 gdiff_parseHeader( pDIFFDATA dd );
|
||||
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
|
||||
static int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum );
|
||||
static int32 gdiff_ApplyPatch( pDIFFDATA dd );
|
||||
static int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length );
|
||||
static int32 gdiff_add( pDIFFDATA dd, uint32 count );
|
||||
static int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count );
|
||||
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
|
||||
|
||||
|
||||
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
|
||||
const nsString& inVRName,
|
||||
const nsString& inVInfo,
|
||||
const nsString& inJarLocation,
|
||||
PRInt32 *error)
|
||||
|
||||
: nsInstallObject(inInstall)
|
||||
{
|
||||
char tempTargetFile[MAXREGPATHLEN];
|
||||
char* tempVersionString = inVRName.ToNewCString();
|
||||
|
||||
PRInt32 err = VR_GetPath(tempVersionString, MAXREGPATHLEN, tempTargetFile );
|
||||
|
||||
delete [] tempVersionString;
|
||||
|
||||
if (err != REGERR_OK)
|
||||
{
|
||||
*error = nsInstall::NO_SUCH_COMPONENT;
|
||||
return;
|
||||
}
|
||||
nsString folderSpec(tempTargetFile);
|
||||
|
||||
mPatchFile = nsnull;
|
||||
mTargetFile = nsnull;
|
||||
mPatchedFile = nsnull;
|
||||
mRegistryName = new nsString(inVRName);
|
||||
mJarLocation = new nsString(inJarLocation);
|
||||
mTargetFile = new nsFileSpec(folderSpec);
|
||||
|
||||
mVersionInfo = new nsInstallVersion();
|
||||
|
||||
mVersionInfo->Init(inVInfo);
|
||||
|
||||
}
|
||||
|
||||
|
||||
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
|
||||
const nsString& inVRName,
|
||||
const nsString& inVInfo,
|
||||
const nsString& inJarLocation,
|
||||
const nsString& folderSpec,
|
||||
const nsString& inPartialPath,
|
||||
PRInt32 *error)
|
||||
|
||||
: nsInstallObject(inInstall)
|
||||
{
|
||||
if ((inInstall == nsnull) || (inVRName == "null") || (inJarLocation == "null"))
|
||||
{
|
||||
*error = nsInstall::INVALID_ARGUMENTS;
|
||||
return;
|
||||
}
|
||||
|
||||
mPatchFile = nsnull;
|
||||
mTargetFile = nsnull;
|
||||
mPatchedFile = nsnull;
|
||||
mRegistryName = new nsString(inVRName);
|
||||
mJarLocation = new nsString(inJarLocation);
|
||||
mVersionInfo = new nsInstallVersion();
|
||||
|
||||
mVersionInfo->Init(inVInfo);
|
||||
|
||||
mTargetFile = new nsFileSpec(folderSpec);
|
||||
if(inPartialPath != "null")
|
||||
*mTargetFile += inPartialPath;
|
||||
}
|
||||
|
||||
nsInstallPatch::~nsInstallPatch()
|
||||
{
|
||||
if (mVersionInfo)
|
||||
delete mVersionInfo;
|
||||
|
||||
if (mTargetFile)
|
||||
delete mTargetFile;
|
||||
|
||||
if (mJarLocation)
|
||||
delete mJarLocation;
|
||||
|
||||
if (mRegistryName)
|
||||
delete mRegistryName;
|
||||
|
||||
if (mPatchedFile)
|
||||
delete mPatchedFile;
|
||||
|
||||
if (mPatchFile)
|
||||
delete mPatchFile;
|
||||
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsInstallPatch::Prepare()
|
||||
{
|
||||
PRInt32 err;
|
||||
PRBool deleteOldSrc;
|
||||
|
||||
if (mTargetFile == nsnull)
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
|
||||
if (mTargetFile->Exists())
|
||||
{
|
||||
if (mTargetFile->IsFile())
|
||||
{
|
||||
err = nsInstall::SUCCESS;
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nsInstall::FILE_IS_DIRECTORY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nsInstall::FILE_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
if (err != nsInstall::SUCCESS)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, &mPatchFile);
|
||||
|
||||
|
||||
nsFileSpec *fileName = nsnull;
|
||||
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
|
||||
|
||||
mInstall->GetPatch(&ikey, fileName);
|
||||
|
||||
if (fileName != nsnull)
|
||||
{
|
||||
deleteOldSrc = PR_TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = mTargetFile;
|
||||
deleteOldSrc = PR_FALSE;
|
||||
}
|
||||
|
||||
err = NativePatch( *fileName, // the file to patch
|
||||
*mPatchFile, // the patch that was extracted from the jarfile
|
||||
&mPatchedFile); // the new patched file
|
||||
|
||||
if (err != nsInstall::SUCCESS)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
|
||||
PR_ASSERT(mPatchedFile != nsnull);
|
||||
mInstall->AddPatch(&ikey, mPatchedFile );
|
||||
|
||||
if ( deleteOldSrc )
|
||||
{
|
||||
DeleteFileNowOrSchedule(*fileName );
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
PRInt32 nsInstallPatch::Complete()
|
||||
{
|
||||
if ((mInstall == nsnull) || (mVersionInfo == nsnull) || (mPatchedFile == nsnull) || (mTargetFile == nsnull))
|
||||
{
|
||||
return nsInstall::INVALID_ARGUMENTS;
|
||||
}
|
||||
|
||||
PRInt32 err = nsInstall::SUCCESS;
|
||||
|
||||
nsFileSpec *fileName = nsnull;
|
||||
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
|
||||
|
||||
mInstall->GetPatch(&ikey, fileName);
|
||||
|
||||
if (fileName != nsnull && (*fileName == *mPatchedFile) )
|
||||
{
|
||||
// the patch has not been superceded--do final replacement
|
||||
err = ReplaceFileNowOrSchedule( *mTargetFile, *mPatchedFile);
|
||||
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
|
||||
{
|
||||
nsString tempVersionString;
|
||||
mVersionInfo->ToString(tempVersionString);
|
||||
|
||||
char* tempRegName = mRegistryName->ToNewCString();
|
||||
char* tempVersion = tempVersionString.ToNewCString();
|
||||
|
||||
err = VR_Install( tempRegName,
|
||||
(char*) (const char *) nsNSPRPath(*mTargetFile),
|
||||
tempVersion,
|
||||
PR_FALSE );
|
||||
|
||||
delete [] tempRegName;
|
||||
delete [] tempVersion;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
err = nsInstall::UNEXPECTED_ERROR;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// nothing -- old intermediate patched file was
|
||||
// deleted by a superceding patch
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
void nsInstallPatch::Abort()
|
||||
{
|
||||
nsFileSpec *fileName = nsnull;
|
||||
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
|
||||
|
||||
mInstall->GetPatch(&ikey, fileName);
|
||||
|
||||
if (fileName != nsnull && (*fileName == *mPatchedFile) )
|
||||
{
|
||||
DeleteFileNowOrSchedule( *mPatchedFile );
|
||||
}
|
||||
}
|
||||
|
||||
char* nsInstallPatch::toString()
|
||||
{
|
||||
char* buffer = new char[1024];
|
||||
|
||||
// FIX! sprintf( buffer, nsInstallResources::GetPatchFileString(), mPatchedFile->GetCString());
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsInstallPatch::CanUninstall()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsInstallPatch::RegisterPackageNode()
|
||||
{
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
PRInt32
|
||||
nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchFile, nsFileSpec **newFile)
|
||||
{
|
||||
|
||||
DIFFDATA *dd;
|
||||
PRInt32 status = GDIFF_ERR_MEM;
|
||||
char *tmpurl = NULL;
|
||||
char *realfile = PL_strdup(nsNSPRPath(sourceFile)); // needs to be sourceFile!!!
|
||||
nsFileSpec outFileSpec = sourceFile;
|
||||
|
||||
dd = (DIFFDATA *)PR_Calloc( 1, sizeof(DIFFDATA));
|
||||
if (dd != NULL)
|
||||
{
|
||||
dd->databuf = (uchar*)PR_Malloc(BUFSIZE);
|
||||
if (dd->databuf == NULL)
|
||||
{
|
||||
status = GDIFF_ERR_MEM;
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
||||
dd->bufsize = BUFSIZE;
|
||||
|
||||
// validate patch header & check for special instructions
|
||||
dd->fDiff = PR_Open (nsNSPRPath(patchFile), PR_RDONLY, 0666);
|
||||
|
||||
|
||||
if (dd->fDiff != NULL)
|
||||
{
|
||||
status = gdiff_parseHeader(dd);
|
||||
} else {
|
||||
status = GDIFF_ERR_ACCESS;
|
||||
}
|
||||
|
||||
#ifdef dono
|
||||
#ifdef WIN32
|
||||
|
||||
/* unbind Win32 images */
|
||||
if ( dd->bWin32BoundImage && status == GDIFF_OK ) {
|
||||
tmpurl = WH_TempName( xpURL, NULL );
|
||||
if ( tmpurl != NULL ) {
|
||||
if (su_unbind( srcfile, srctype, tmpurl, xpURL ))
|
||||
{
|
||||
PL_strfree(realfile);
|
||||
realfile = tmpurl;
|
||||
realtype = xpURL;
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
status = GDIFF_ERR_MEM;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef XP_MAC
|
||||
|
||||
if ( dd->bMacAppleSingle && status == GDIFF_OK )
|
||||
{
|
||||
// create a tmp file, so that we can AppleSingle the src file
|
||||
nsSpecialSystemDirectory tempMacFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
|
||||
nsString srcName = sourceFile.GetLeafName();
|
||||
tempMacFile.SetLeafName(srcName);
|
||||
tempMacFile.MakeUnique();
|
||||
|
||||
// Encode!
|
||||
// Encode src file, and put into temp file
|
||||
FSSpec sourceSpec = sourceFile.GetFSSpec();
|
||||
FSSpec tempSpec = tempMacFile.GetFSSpec();
|
||||
|
||||
status = PAS_EncodeFile(&sourceSpec, &tempSpec);
|
||||
|
||||
if (status == noErr)
|
||||
{
|
||||
// set
|
||||
PL_strfree(realfile);
|
||||
realfile = PL_strdup(nsNSPRPath(tempMacFile));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if (status != NS_OK)
|
||||
goto cleanup;
|
||||
|
||||
// make a unique file at the same location of our source file (FILENAME-ptch.EXT)
|
||||
nsString patchFileName = "-ptch";
|
||||
nsString newFileName = sourceFile.GetLeafName();
|
||||
|
||||
PRInt32 index;
|
||||
if ((index = newFileName.RFind(".")) > 0)
|
||||
{
|
||||
nsString extention;
|
||||
nsString fileName;
|
||||
newFileName.Right(extention, (newFileName.Length() - index) );
|
||||
newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index)));
|
||||
newFileName = fileName + patchFileName + extention;
|
||||
|
||||
} else {
|
||||
newFileName += patchFileName;
|
||||
}
|
||||
|
||||
|
||||
outFileSpec.SetLeafName(newFileName); //????
|
||||
outFileSpec.MakeUnique();
|
||||
|
||||
char *outFile = PL_strdup(nsNSPRPath(outFileSpec));
|
||||
|
||||
// apply patch to the source file
|
||||
dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666);
|
||||
dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666);
|
||||
|
||||
if (dd->fSrc != NULL && dd->fOut != NULL)
|
||||
{
|
||||
status = gdiff_validateFile (dd, SRCFILE);
|
||||
|
||||
// specify why diff failed
|
||||
if (status == GDIFF_ERR_CHECKSUM)
|
||||
status = GDIFF_ERR_CHECKSUM_TARGET;
|
||||
|
||||
if (status == GDIFF_OK)
|
||||
status = gdiff_ApplyPatch(dd);
|
||||
|
||||
if (status == GDIFF_OK)
|
||||
status = gdiff_validateFile (dd, OUTFILE);
|
||||
|
||||
if (status == GDIFF_ERR_CHECKSUM)
|
||||
status = GDIFF_ERR_CHECKSUM_RESULT;
|
||||
|
||||
if (status == GDIFF_OK)
|
||||
{
|
||||
*newFile = &outFileSpec;
|
||||
if ( outFile != nsnull)
|
||||
PL_strfree( outFile );
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
status = GDIFF_ERR_ACCESS;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef XP_MAC
|
||||
if ( dd->bMacAppleSingle && status == GDIFF_OK )
|
||||
{
|
||||
// create another file, so that we can decode somewhere
|
||||
nsFileSpec anotherName = outFileSpec;
|
||||
anotherName.MakeUnique();
|
||||
|
||||
// Close the out file so that we can read it
|
||||
PR_Close( dd->fOut );
|
||||
dd->fOut = NULL;
|
||||
|
||||
|
||||
FSSpec outSpec = outFileSpec.GetFSSpec();
|
||||
FSSpec anotherSpec = anotherName.GetFSSpec();
|
||||
|
||||
|
||||
status = PAS_DecodeFile(&outSpec, &anotherSpec);
|
||||
if (status != noErr)
|
||||
{
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
nsFileSpec parent;
|
||||
|
||||
outFileSpec.GetParent(parent);
|
||||
|
||||
outFileSpec.Delete(PR_FALSE);
|
||||
anotherName.Copy(parent);
|
||||
|
||||
*newFile = &anotherName;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
cleanup:
|
||||
if ( dd != NULL )
|
||||
{
|
||||
if ( dd->fSrc != nsnull )
|
||||
PR_Close( dd->fSrc );
|
||||
|
||||
|
||||
if ( dd->fDiff != nsnull )
|
||||
PR_Close( dd->fDiff );
|
||||
|
||||
if ( dd->fOut != nsnull )
|
||||
{
|
||||
PR_Close( dd->fOut );
|
||||
}
|
||||
|
||||
if ( status != GDIFF_OK )
|
||||
//XP_FileRemove( outfile, outtype );
|
||||
newFile = NULL;
|
||||
|
||||
PR_FREEIF( dd->databuf );
|
||||
PR_FREEIF( dd->oldChecksum );
|
||||
PR_FREEIF( dd->newChecksum );
|
||||
PR_DELETE(dd);
|
||||
}
|
||||
|
||||
if ( tmpurl != NULL ) {
|
||||
//XP_FileRemove( tmpurl, xpURL );
|
||||
tmpurl = NULL;
|
||||
PR_DELETE( tmpurl );
|
||||
}
|
||||
|
||||
/* lets map any GDIFF error to nice SU errors */
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case GDIFF_OK:
|
||||
break;
|
||||
case GDIFF_ERR_HEADER:
|
||||
case GDIFF_ERR_BADDIFF:
|
||||
case GDIFF_ERR_OPCODE:
|
||||
case GDIFF_ERR_CHKSUMTYPE:
|
||||
status = nsInstall::PATCH_BAD_DIFF;
|
||||
break;
|
||||
case GDIFF_ERR_CHECKSUM_TARGET:
|
||||
status = nsInstall::PATCH_BAD_CHECKSUM_TARGET;
|
||||
break;
|
||||
case GDIFF_ERR_CHECKSUM_RESULT:
|
||||
status = nsInstall::PATCH_BAD_CHECKSUM_RESULT;
|
||||
break;
|
||||
case GDIFF_ERR_OLDFILE:
|
||||
case GDIFF_ERR_ACCESS:
|
||||
case GDIFF_ERR_MEM:
|
||||
case GDIFF_ERR_UNKNOWN:
|
||||
default:
|
||||
status = nsInstall::UNEXPECTED_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
return status;
|
||||
|
||||
// return -1; //old return value
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
nsInstallPatch::HashFilePath(const nsFilePath& aPath)
|
||||
{
|
||||
PRUint32 rv = 0;
|
||||
|
||||
char* cPath = PL_strdup(nsNSPRPath(aPath));
|
||||
|
||||
if(cPath != nsnull)
|
||||
{
|
||||
char ch;
|
||||
char* filePath = PL_strdup(cPath);
|
||||
PRUint32 cnt=0;
|
||||
|
||||
while ((ch = *filePath++) != 0)
|
||||
{
|
||||
// FYI: rv = rv*37 + ch
|
||||
rv = ((rv << 5) + (rv << 2) + rv) + ch;
|
||||
cnt++;
|
||||
}
|
||||
|
||||
for (PRUint32 i=0; i<=cnt; i++)
|
||||
*filePath--;
|
||||
PL_strfree(filePath);
|
||||
}
|
||||
|
||||
PL_strfree(cPath);
|
||||
|
||||
return (void*)rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_parseHeader()
|
||||
*
|
||||
* reads and validates the GDIFF header info
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_parseHeader( pDIFFDATA dd )
|
||||
{
|
||||
int32 err = GDIFF_OK;
|
||||
uint8 cslen;
|
||||
uint8 oldcslen;
|
||||
uint8 newcslen;
|
||||
uint32 nRead;
|
||||
uchar header[GDIFF_HEADERSIZE];
|
||||
|
||||
/* Read the fixed-size part of the header */
|
||||
|
||||
nRead = PR_Read (dd->fDiff, header, GDIFF_HEADERSIZE);
|
||||
if ( nRead != GDIFF_HEADERSIZE ||
|
||||
memcmp( header, GDIFF_MAGIC, GDIFF_MAGIC_LEN ) != 0 ||
|
||||
header[GDIFF_VER_POS] != GDIFF_VER )
|
||||
{
|
||||
err = GDIFF_ERR_HEADER;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* get the checksum information */
|
||||
|
||||
dd->checksumType = header[GDIFF_CS_POS];
|
||||
cslen = header[GDIFF_CSLEN_POS];
|
||||
|
||||
if ( cslen > 0 )
|
||||
{
|
||||
oldcslen = cslen / 2;
|
||||
newcslen = cslen - oldcslen;
|
||||
PR_ASSERT( newcslen == oldcslen );
|
||||
|
||||
dd->checksumLength = oldcslen;
|
||||
dd->oldChecksum = (uchar*)PR_MALLOC(oldcslen);
|
||||
dd->newChecksum = (uchar*)PR_MALLOC(newcslen);
|
||||
|
||||
if ( dd->oldChecksum != NULL && dd->newChecksum != NULL )
|
||||
{
|
||||
nRead = PR_Read (dd->fDiff, dd->oldChecksum, oldcslen);
|
||||
if ( nRead == oldcslen )
|
||||
{
|
||||
nRead = PR_Read (dd->fDiff, dd->newChecksum, newcslen);
|
||||
if ( nRead != newcslen ) {
|
||||
err = GDIFF_ERR_HEADER;
|
||||
}
|
||||
}
|
||||
else {
|
||||
err = GDIFF_ERR_HEADER;
|
||||
}
|
||||
}
|
||||
else {
|
||||
err = GDIFF_ERR_MEM;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* get application data, if any */
|
||||
|
||||
if ( err == GDIFF_OK )
|
||||
{
|
||||
uint32 appdataSize;
|
||||
uchar *buf;
|
||||
uchar lenbuf[GDIFF_APPDATALEN];
|
||||
|
||||
nRead = PR_Read(dd->fDiff, lenbuf, GDIFF_APPDATALEN);
|
||||
if ( nRead == GDIFF_APPDATALEN )
|
||||
{
|
||||
appdataSize = getlong(lenbuf);
|
||||
|
||||
if ( appdataSize > 0 )
|
||||
{
|
||||
buf = (uchar *)PR_MALLOC( appdataSize );
|
||||
|
||||
if ( buf != NULL )
|
||||
{
|
||||
nRead = PR_Read (dd->fDiff, buf, appdataSize);
|
||||
if ( nRead == appdataSize )
|
||||
{
|
||||
if ( 0 == memcmp( buf, APPFLAG_W32BOUND, appdataSize ) )
|
||||
dd->bWin32BoundImage = TRUE;
|
||||
|
||||
if ( 0 == memcmp( buf, APPFLAG_APPLESINGLE, appdataSize ) )
|
||||
dd->bMacAppleSingle = TRUE;
|
||||
}
|
||||
else {
|
||||
err = GDIFF_ERR_HEADER;
|
||||
}
|
||||
|
||||
PR_DELETE( buf );
|
||||
}
|
||||
else {
|
||||
err = GDIFF_ERR_MEM;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
err = GDIFF_ERR_HEADER;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_validateFile()
|
||||
*
|
||||
* computes the checksum of the file and compares it to
|
||||
* the value stored in the GDIFF header
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_validateFile( pDIFFDATA dd, int file )
|
||||
{
|
||||
int32 result;
|
||||
PRFileDesc* fh;
|
||||
uchar* chksum;
|
||||
|
||||
/* which file are we dealing with? */
|
||||
if ( file == SRCFILE ) {
|
||||
fh = dd->fSrc;
|
||||
chksum = dd->oldChecksum;
|
||||
}
|
||||
else { /* OUTFILE */
|
||||
fh = dd->fOut;
|
||||
chksum = dd->newChecksum;
|
||||
}
|
||||
|
||||
/* make sure file's at beginning */
|
||||
PR_Seek( fh, 0, PR_SEEK_SET );
|
||||
|
||||
/* calculate appropriate checksum */
|
||||
switch (dd->checksumType)
|
||||
{
|
||||
case GDIFF_CS_NONE:
|
||||
result = GDIFF_OK;
|
||||
break;
|
||||
|
||||
|
||||
case GDIFF_CS_CRC32:
|
||||
if ( dd->checksumLength == CRC32_LEN )
|
||||
result = gdiff_valCRC32( dd, fh, getlong(chksum) );
|
||||
else
|
||||
result = GDIFF_ERR_HEADER;
|
||||
break;
|
||||
|
||||
|
||||
case GDIFF_CS_MD5:
|
||||
|
||||
|
||||
case GDIFF_CS_SHA:
|
||||
|
||||
|
||||
default:
|
||||
/* unsupported checksum type */
|
||||
result = GDIFF_ERR_CHKSUMTYPE;
|
||||
break;
|
||||
}
|
||||
|
||||
/* reset file position to beginning and return status */
|
||||
PR_Seek( fh, 0, PR_SEEK_SET );
|
||||
return (result);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_valCRC32()
|
||||
*
|
||||
* computes the checksum of the file and compares it to
|
||||
* the passed in checksum. Assumes file is positioned at
|
||||
* beginning.
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum )
|
||||
{
|
||||
uint32 crc;
|
||||
uint32 nRead;
|
||||
|
||||
crc = crc32(0L, Z_NULL, 0);
|
||||
|
||||
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
|
||||
while ( nRead > 0 )
|
||||
{
|
||||
crc = crc32( crc, dd->databuf, nRead );
|
||||
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
|
||||
}
|
||||
|
||||
if ( crc == chksum )
|
||||
return GDIFF_OK;
|
||||
else
|
||||
return GDIFF_ERR_CHECKSUM;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_ApplyPatch()
|
||||
*
|
||||
* Combines patch data with source file to produce the
|
||||
* new target file. Assumes all three files have been
|
||||
* opened, GDIFF header read, and all other setup complete
|
||||
*
|
||||
* The GDIFF patch is processed sequentially which random
|
||||
* access is neccessary for the source file.
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_ApplyPatch( pDIFFDATA dd )
|
||||
{
|
||||
int32 err;
|
||||
XP_Bool done;
|
||||
uint32 position;
|
||||
uint32 count;
|
||||
uchar opcode;
|
||||
uchar cmdbuf[MAXCMDSIZE];
|
||||
|
||||
done = FALSE;
|
||||
while ( !done ) {
|
||||
err = gdiff_getdiff( dd, &opcode, OPSIZE );
|
||||
if ( err != GDIFF_OK )
|
||||
break;
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case ENDDIFF:
|
||||
done = TRUE;
|
||||
break;
|
||||
|
||||
case ADD16:
|
||||
err = gdiff_getdiff( dd, cmdbuf, ADD16SIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
err = gdiff_add( dd, getshort( cmdbuf ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case ADD32:
|
||||
err = gdiff_getdiff( dd, cmdbuf, ADD32SIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
err = gdiff_add( dd, getlong( cmdbuf ) );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY16BYTE:
|
||||
err = gdiff_getdiff( dd, cmdbuf, COPY16BYTESIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
position = getshort( cmdbuf );
|
||||
count = *(cmdbuf + sizeof(short));
|
||||
err = gdiff_copy( dd, position, count );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY16SHORT:
|
||||
err = gdiff_getdiff( dd, cmdbuf, COPY16SHORTSIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
position = getshort( cmdbuf );
|
||||
count = getshort(cmdbuf + sizeof(short));
|
||||
err = gdiff_copy( dd, position, count );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY16LONG:
|
||||
err = gdiff_getdiff( dd, cmdbuf, COPY16LONGSIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
position = getshort( cmdbuf );
|
||||
count = getlong(cmdbuf + sizeof(short));
|
||||
err = gdiff_copy( dd, position, count );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY32BYTE:
|
||||
err = gdiff_getdiff( dd, cmdbuf, COPY32BYTESIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
position = getlong( cmdbuf );
|
||||
count = *(cmdbuf + sizeof(long));
|
||||
err = gdiff_copy( dd, position, count );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY32SHORT:
|
||||
err = gdiff_getdiff( dd, cmdbuf, COPY32SHORTSIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
position = getlong( cmdbuf );
|
||||
count = getshort(cmdbuf + sizeof(long));
|
||||
err = gdiff_copy( dd, position, count );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY32LONG:
|
||||
err = gdiff_getdiff( dd, cmdbuf, COPY32LONGSIZE );
|
||||
if ( err == GDIFF_OK ) {
|
||||
position = getlong( cmdbuf );
|
||||
count = getlong(cmdbuf + sizeof(long));
|
||||
err = gdiff_copy( dd, position, count );
|
||||
}
|
||||
break;
|
||||
|
||||
case COPY64:
|
||||
/* we don't support 64-bit file positioning yet */
|
||||
err = GDIFF_ERR_OPCODE;
|
||||
break;
|
||||
|
||||
default:
|
||||
err = gdiff_add( dd, opcode );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( err != GDIFF_OK )
|
||||
done = TRUE;
|
||||
}
|
||||
|
||||
/* return status */
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_getdiff()
|
||||
*
|
||||
* reads the next "length" bytes of the diff into "buffer"
|
||||
*
|
||||
* XXX: need a diff buffer to optimize reads!
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length )
|
||||
{
|
||||
uint32 bytesRead;
|
||||
|
||||
bytesRead = PR_Read (dd->fDiff, buffer, length);
|
||||
if ( bytesRead != length )
|
||||
return GDIFF_ERR_BADDIFF;
|
||||
|
||||
return GDIFF_OK;
|
||||
}
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_add()
|
||||
*
|
||||
* append "count" bytes from diff file to new file
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_add( pDIFFDATA dd, uint32 count )
|
||||
{
|
||||
int32 err = GDIFF_OK;
|
||||
uint32 nRead;
|
||||
uint32 chunksize;
|
||||
|
||||
while ( count > 0 ) {
|
||||
chunksize = ( count > dd->bufsize) ? dd->bufsize : count;
|
||||
nRead = PR_Read (dd->fDiff, dd->databuf, chunksize);
|
||||
if ( nRead != chunksize ) {
|
||||
err = GDIFF_ERR_BADDIFF;
|
||||
break;
|
||||
}
|
||||
|
||||
PR_Write (dd->fOut, dd->databuf, chunksize);
|
||||
|
||||
count -= chunksize;
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------------
|
||||
* gdiff_copy()
|
||||
*
|
||||
* copy "count" bytes from "position" in source file
|
||||
*---------------------------------------------------------
|
||||
*/
|
||||
static
|
||||
int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count )
|
||||
{
|
||||
int32 err = GDIFF_OK;
|
||||
uint32 nRead;
|
||||
uint32 chunksize;
|
||||
|
||||
PR_Seek (dd->fSrc, position, PR_SEEK_SET);
|
||||
|
||||
while ( count > 0 ) {
|
||||
chunksize = (count > dd->bufsize) ? dd->bufsize : count;
|
||||
|
||||
nRead = PR_Read (dd->fSrc, dd->databuf, chunksize);
|
||||
if ( nRead != chunksize ) {
|
||||
err = GDIFF_ERR_OLDFILE;
|
||||
break;
|
||||
}
|
||||
|
||||
PR_Write (dd->fOut, dd->databuf, chunksize);
|
||||
|
||||
count -= chunksize;
|
||||
}
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
79
mozilla/xpinstall/src/nsInstallPatch.h
Normal file
79
mozilla/xpinstall/src/nsInstallPatch.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsInstallPatch_h__
|
||||
#define nsInstallPatch_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsInstallObject.h"
|
||||
|
||||
#include "nsInstall.h"
|
||||
#include "nsInstallFolder.h"
|
||||
#include "nsInstallVersion.h"
|
||||
|
||||
|
||||
class nsInstallPatch : public nsInstallObject
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallPatch( nsInstall* inInstall,
|
||||
const nsString& inVRName,
|
||||
const nsString& inVInfo,
|
||||
const nsString& inJarLocation,
|
||||
const nsString& folderSpec,
|
||||
const nsString& inPartialPath,
|
||||
PRInt32 *error);
|
||||
|
||||
nsInstallPatch( nsInstall* inInstall,
|
||||
const nsString& inVRName,
|
||||
const nsString& inVInfo,
|
||||
const nsString& inJarLocation,
|
||||
PRInt32 *error);
|
||||
|
||||
virtual ~nsInstallPatch();
|
||||
|
||||
PRInt32 Prepare();
|
||||
PRInt32 Complete();
|
||||
void Abort();
|
||||
char* toString();
|
||||
|
||||
PRBool CanUninstall();
|
||||
PRBool RegisterPackageNode();
|
||||
|
||||
|
||||
private:
|
||||
|
||||
|
||||
nsInstallVersion *mVersionInfo;
|
||||
|
||||
nsFileSpec *mTargetFile;
|
||||
nsFileSpec *mPatchFile;
|
||||
nsFileSpec *mPatchedFile;
|
||||
|
||||
nsString *mJarLocation;
|
||||
nsString *mRegistryName;
|
||||
|
||||
|
||||
|
||||
PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile);
|
||||
void* HashFilePath(const nsFilePath& aPath);
|
||||
};
|
||||
|
||||
#endif /* nsInstallPatch_h__ */
|
||||
343
mozilla/xpinstall/src/nsInstallProgressDialog.cpp
Normal file
343
mozilla/xpinstall/src/nsInstallProgressDialog.cpp
Normal file
@@ -0,0 +1,343 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#include "nsIXPInstallProgress.h"
|
||||
#include "nsInstallProgressDialog.h"
|
||||
|
||||
#include "nsIAppShellComponentImpl.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsINameSpaceManager.h"
|
||||
#include "nsIContentViewer.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsINetService.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
|
||||
static NS_DEFINE_IID( kNetServiceCID, NS_NETSERVICE_CID );
|
||||
|
||||
// Utility to set element attribute.
|
||||
static nsresult setAttribute( nsIDOMXULDocument *doc,
|
||||
const char *id,
|
||||
const char *name,
|
||||
const nsString &value ) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if ( doc ) {
|
||||
// Find specified element.
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
|
||||
if ( elem ) {
|
||||
// Set the text attribute.
|
||||
rv = elem->SetAttribute( name, value );
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
} else {
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// Utility to get element attribute.
|
||||
static nsresult getAttribute( nsIDOMXULDocument *doc,
|
||||
const char *id,
|
||||
const char *name,
|
||||
nsString &value ) {
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if ( doc ) {
|
||||
// Find specified element.
|
||||
nsCOMPtr<nsIDOMElement> elem;
|
||||
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
|
||||
if ( elem ) {
|
||||
// Set the text attribute.
|
||||
rv = elem->GetAttribute( name, value );
|
||||
if ( NS_SUCCEEDED( rv ) ) {
|
||||
} else {
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
} else {
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
} else {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsInstallProgressDialog::nsInstallProgressDialog()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mWindow = nsnull;
|
||||
mDocument = nsnull;
|
||||
|
||||
}
|
||||
|
||||
nsInstallProgressDialog::~nsInstallProgressDialog()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ADDREF( nsInstallProgressDialog );
|
||||
NS_IMPL_RELEASE( nsInstallProgressDialog );
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
||||
{
|
||||
if (aInstancePtr == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aInstancePtr = NULL;
|
||||
|
||||
if (aIID.Equals(nsIXPInstallProgress::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsInstallProgressDialog*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsIXULWindowCallbacks::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIXULWindowCallbacks*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*) (nsISupports*)((nsIXPInstallProgress*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::BeforeJavascriptEvaluation()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Get app shell service.
|
||||
nsIAppShellService *appShell;
|
||||
rv = nsServiceManager::GetService( kAppShellServiceCID,
|
||||
nsIAppShellService::GetIID(),
|
||||
(nsISupports**)&appShell );
|
||||
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
// Open "progress" dialog.
|
||||
nsIURL *url;
|
||||
rv = NS_NewURL( &url, "resource:/res/xpinstall/progress.xul" );
|
||||
|
||||
if ( NS_SUCCEEDED(rv) )
|
||||
{
|
||||
|
||||
nsIWebShellWindow *newWindow;
|
||||
|
||||
rv = appShell->CreateTopLevelWindow( nsnull,
|
||||
url,
|
||||
PR_TRUE,
|
||||
newWindow,
|
||||
nsnull,
|
||||
this, // callbacks??
|
||||
0,
|
||||
0 );
|
||||
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
mWindow = newWindow;
|
||||
NS_RELEASE( newWindow );
|
||||
|
||||
if (mWindow != nsnull)
|
||||
mWindow->Show(PR_TRUE);
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_PRINTF( PR_STDOUT, "Error creating progress dialog, rv=0x%X\n", (int)rv );
|
||||
}
|
||||
NS_RELEASE( url );
|
||||
}
|
||||
|
||||
nsServiceManager::ReleaseService( kAppShellServiceCID, appShell );
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_PRINTF( PR_STDOUT, "Unable to get app shell service, rv=0x%X\n", (int)rv );
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::AfterJavascriptEvaluation()
|
||||
{
|
||||
if (mWindow)
|
||||
{
|
||||
mWindow->Close();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::InstallStarted(const char *UIPackageName)
|
||||
{
|
||||
setAttribute( mDocument, "dialog.uiPackageName", "value", nsString(UIPackageName) );
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::ItemScheduled(const char *message)
|
||||
{
|
||||
PRInt32 maxChars = 40;
|
||||
|
||||
nsString theMessage(message);
|
||||
PRInt32 len = theMessage.Length();
|
||||
if (len > maxChars)
|
||||
{
|
||||
PRInt32 offset = (len/2) - ((len - maxChars)/2);
|
||||
PRInt32 count = (len - maxChars);
|
||||
theMessage.Cut(offset, count);
|
||||
theMessage.Insert(nsString("..."), offset);
|
||||
}
|
||||
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
|
||||
|
||||
nsString aValue;
|
||||
getAttribute( mDocument, "data.canceled", "value", aValue );
|
||||
|
||||
if (aValue.EqualsIgnoreCase("true"))
|
||||
return -1;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum)
|
||||
{
|
||||
|
||||
PRInt32 maxChars = 40;
|
||||
|
||||
nsString theMessage(message);
|
||||
PRInt32 len = theMessage.Length();
|
||||
if (len > maxChars)
|
||||
{
|
||||
PRInt32 offset = (len/2) - ((len - maxChars)/2);
|
||||
PRInt32 count = (len - maxChars);
|
||||
theMessage.Cut(offset, count);
|
||||
theMessage.Insert(nsString("..."), offset);
|
||||
}
|
||||
|
||||
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
char buf[16];
|
||||
|
||||
PR_snprintf( buf, sizeof buf, "%lu", totNum );
|
||||
setAttribute( mDocument, "dialog.progress", "max", buf );
|
||||
|
||||
if (totNum != 0)
|
||||
{
|
||||
PR_snprintf( buf, sizeof buf, "%lu", ((totNum-itemNum)/totNum) );
|
||||
}
|
||||
else
|
||||
{
|
||||
PR_snprintf( buf, sizeof buf, "%lu", 0 );
|
||||
}
|
||||
setAttribute( mDocument, "dialog.progress", "value", buf );
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::InstallAborted()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Do startup stuff from C++ side.
|
||||
NS_IMETHODIMP
|
||||
nsInstallProgressDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Get content viewer from the web shell.
|
||||
nsCOMPtr<nsIContentViewer> contentViewer;
|
||||
rv = aWebShell ? aWebShell->GetContentViewer(getter_AddRefs(contentViewer))
|
||||
: NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ( contentViewer ) {
|
||||
// Up-cast to a document viewer.
|
||||
nsCOMPtr<nsIDocumentViewer> docViewer( do_QueryInterface( contentViewer, &rv ) );
|
||||
if ( docViewer ) {
|
||||
// Get the document from the doc viewer.
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
rv = docViewer->GetDocument(*getter_AddRefs(document));
|
||||
if ( document ) {
|
||||
// Upcast to XUL document.
|
||||
mDocument = do_QueryInterface( document, &rv );
|
||||
if ( ! mDocument )
|
||||
{
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDOMXULDocument failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetDocument failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDocumentViewer failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetContentViewer failed, rv=0x%X\n",
|
||||
__FILE__, (int)__LINE__, (int)rv );
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
67
mozilla/xpinstall/src/nsInstallProgressDialog.h
Normal file
67
mozilla/xpinstall/src/nsInstallProgressDialog.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
#ifndef __nsInstallProgressDialog_h__
|
||||
#define __nsInstallProgressDialog_h__
|
||||
|
||||
#include "nsIXPInstallProgress.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsIWebShell.h"
|
||||
#include "nsIWebShellWindow.h"
|
||||
#include "nsIXULWindowCallbacks.h"
|
||||
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
|
||||
|
||||
class nsInstallProgressDialog : public nsIXPInstallProgress, public nsIXULWindowCallbacks
|
||||
{
|
||||
public:
|
||||
|
||||
nsInstallProgressDialog();
|
||||
virtual ~nsInstallProgressDialog();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
|
||||
NS_IMETHOD BeforeJavascriptEvaluation();
|
||||
NS_IMETHOD AfterJavascriptEvaluation();
|
||||
NS_IMETHOD InstallStarted(const char *UIPackageName);
|
||||
NS_IMETHOD ItemScheduled(const char *message);
|
||||
NS_IMETHOD InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum);
|
||||
NS_IMETHOD InstallAborted();
|
||||
|
||||
// Declare implementations of nsIXULWindowCallbacks interface functions.
|
||||
NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell);
|
||||
NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; }
|
||||
|
||||
private:
|
||||
|
||||
nsCOMPtr<nsIDOMXULDocument> mDocument;
|
||||
nsCOMPtr<nsIWebShellWindow> mWindow;
|
||||
};
|
||||
#endif
|
||||
67
mozilla/xpinstall/src/nsInstallResources.cpp
Normal file
67
mozilla/xpinstall/src/nsInstallResources.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsInstallResources.h"
|
||||
|
||||
char* nsInstallResources::GetInstallFileString(void)
|
||||
{
|
||||
return "Installing: %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetReplaceFileString(void)
|
||||
{
|
||||
return "Replacing %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetDeleteFileString(void)
|
||||
{
|
||||
return "Deleting file: %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetDeleteComponentString(void)
|
||||
{
|
||||
return "Deleting component: %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetExecuteString(void)
|
||||
{
|
||||
return "Executing: %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetExecuteWithArgsString(void)
|
||||
{
|
||||
return "Executing: %s with argument: %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetPatchFileString(void)
|
||||
{
|
||||
return "Patching: %s";
|
||||
}
|
||||
|
||||
char* nsInstallResources::GetUninstallString(void)
|
||||
{
|
||||
return "Uninstalling: %s";
|
||||
}
|
||||
|
||||
45
mozilla/xpinstall/src/nsInstallResources.h
Normal file
45
mozilla/xpinstall/src/nsInstallResources.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (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/NPL/
|
||||
*
|
||||
* 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 Mozilla Communicator client code,
|
||||
* released March 31, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Douglas Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NS_INSTALLRESOURCES_H__
|
||||
#define __NS_INSTALLRESOURCES_H__
|
||||
|
||||
class nsInstallResources
|
||||
{
|
||||
public:
|
||||
|
||||
static char* GetInstallFileString(void);
|
||||
static char* GetReplaceFileString(void);
|
||||
static char* GetDeleteFileString(void);
|
||||
static char* GetDeleteComponentString(void);
|
||||
static char* GetExecuteString(void);
|
||||
static char* GetExecuteWithArgsString(void);
|
||||
static char* GetPatchFileString(void);
|
||||
static char* GetUninstallString(void);
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user