зеркало из https://github.com/mozilla/gecko-dev.git
Libjar cleanup. Added Close method. Bug#18273. r=mstoltz,gayatrib,dveditz
This commit is contained in:
Родитель
925f33ebbc
Коммит
4a274d01f1
|
@ -44,8 +44,7 @@ EXPORTS = zipfile.h \
|
||||||
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
|
||||||
|
|
||||||
XPIDLSRCS = \
|
XPIDLSRCS = \
|
||||||
nsIZip.idl \
|
nsIZipReader.idl \
|
||||||
nsIJAR.idl \
|
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,7 @@ DLLNAME=jar$(VERSION_NUMBER)
|
||||||
DLL=$(OBJDIR)\$(DLLNAME).dll
|
DLL=$(OBJDIR)\$(DLLNAME).dll
|
||||||
MAPFILE=$(DLLNAME).map
|
MAPFILE=$(DLLNAME).map
|
||||||
|
|
||||||
XPIDLSRCS=.\nsIZip.idl \
|
XPIDLSRCS=.\nsIZipReader.idl \
|
||||||
.\nsIJAR.idl \
|
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
||||||
EXPORTS=zipfile.h
|
EXPORTS=zipfile.h
|
||||||
|
|
|
@ -61,7 +61,6 @@ interface nsIJAR : nsIZip
|
||||||
/* This interface will be filled with other "JAR"-related functions. */
|
/* This interface will be filled with other "JAR"-related functions. */
|
||||||
/* The term "JAR" is in reference to security as opposed to "Zip"
|
/* The term "JAR" is in reference to security as opposed to "Zip"
|
||||||
* which is a non-secure archive format. */
|
* which is a non-secure archive format. */
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
[uuid(70993CAD-2922-11d3-A431-0060B0EB5963)]
|
[uuid(70993CAD-2922-11d3-A431-0060B0EB5963)]
|
||||||
|
|
|
@ -36,53 +36,132 @@
|
||||||
#include "nsRepository.h"
|
#include "nsRepository.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
|
|
||||||
#include "nsIZip.h"
|
|
||||||
#include "nsJAR.h"
|
#include "nsJAR.h"
|
||||||
#include "nsJARInputStream.h"
|
#include "nsJARInputStream.h"
|
||||||
|
//#include "nsIFile.h"
|
||||||
|
|
||||||
|
#ifndef __gen_nsIFile_h__
|
||||||
|
#define NS_ERROR_FILE_UNRECONGNIZED_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 1)
|
||||||
|
#define NS_ERROR_FILE_UNRESOLVABLE_SYMLINK NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 2)
|
||||||
|
#define NS_ERROR_FILE_EXECUTION_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 3)
|
||||||
|
#define NS_ERROR_FILE_UNKNOWN_TYPE NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 4)
|
||||||
|
#define NS_ERROR_FILE_DESTINATION_NOT_DIR NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 5)
|
||||||
|
#define NS_ERROR_FILE_TARGET_DOES_NOT_EXIST NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 6)
|
||||||
|
#define NS_ERROR_FILE_COPY_OR_MOVE_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 7)
|
||||||
|
#define NS_ERROR_FILE_ALREADY_EXISTS NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 8)
|
||||||
|
#define NS_ERROR_FILE_INVALID_PATH NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 9)
|
||||||
|
#define NS_ERROR_FILE_DISK_FULL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 10)
|
||||||
|
#define NS_ERROR_FILE_CORRUPTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_FILES, 11)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
ziperr2nsresult(PRInt32 ziperr)
|
||||||
|
{
|
||||||
|
switch (ziperr) {
|
||||||
|
case ZIP_OK: return NS_OK;
|
||||||
|
case ZIP_ERR_MEMORY: return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
case ZIP_ERR_DISK: return NS_ERROR_FILE_DISK_FULL;
|
||||||
|
case ZIP_ERR_CORRUPT: return NS_ERROR_FILE_CORRUPTED;
|
||||||
|
case ZIP_ERR_PARAM: return NS_ERROR_ILLEGAL_VALUE;
|
||||||
|
case ZIP_ERR_FNF: return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
||||||
|
case ZIP_ERR_UNSUPPORTED: return NS_ERROR_NOT_IMPLEMENTED;
|
||||||
|
default: return NS_ERROR_FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static PRInt32
|
||||||
|
nsresult2ziperr(nsresult rv)
|
||||||
|
{
|
||||||
|
switch (rv) {
|
||||||
|
case NS_OK: return ZIP_OK;
|
||||||
|
case NS_ERROR_OUT_OF_MEMORY: return ZIP_ERR_MEMORY;
|
||||||
|
case NS_ERROR_FILE_DISK_FULL: return ZIP_ERR_DISK;
|
||||||
|
case NS_ERROR_FILE_CORRUPTED: return ZIP_ERR_CORRUPT;
|
||||||
|
case NS_ERROR_ILLEGAL_VALUE: return ZIP_ERR_PARAM;
|
||||||
|
case NS_ERROR_FILE_TARGET_DOES_NOT_EXIST: return ZIP_ERR_FNF;
|
||||||
|
case NS_ERROR_NOT_IMPLEMENTED: return ZIP_ERR_UNSUPPORTED;
|
||||||
|
default: return ZIP_ERR_GENERAL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
nsJAR::nsJAR()
|
nsJAR::nsJAR()
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
nsJAR::~nsJAR()
|
nsJAR::~nsJAR()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS2(nsJAR, nsIZip, nsIJAR);
|
NS_IMPL_ISUPPORTS1(nsJAR, nsIZipReader);
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::Open(const char *aZipFileName, PRInt32 *_retval)
|
nsJAR::Init(nsFileSpec& zipFile)
|
||||||
{
|
{
|
||||||
*_retval = mZip.OpenArchive(aZipFileName);
|
mZipFile = zipFile;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::Extract(const char *aFilename, const char *aOutname, PRInt32 *_retval)
|
nsJAR::Open()
|
||||||
{
|
{
|
||||||
*_retval = mZip.ExtractFile(aFilename, aOutname);
|
const char* path = mZipFile.GetNativePathCString();
|
||||||
|
PRInt32 err = mZip.OpenArchive(path);
|
||||||
|
return ziperr2nsresult(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsJAR::Close()
|
||||||
|
{
|
||||||
|
PRInt32 err = mZip.CloseArchive();
|
||||||
|
return ziperr2nsresult(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsJAR::Extract(const char *zipEntry, nsFileSpec& outFile)
|
||||||
|
{
|
||||||
|
const char* path = outFile.GetNativePathCString();
|
||||||
|
PRInt32 err = mZip.ExtractFile(zipEntry, path);
|
||||||
|
return ziperr2nsresult(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsJAR::GetEntry(const char *zipEntry, nsIZipEntry* *result)
|
||||||
|
{
|
||||||
|
nsZipItem item;
|
||||||
|
PRInt32 err = mZip.GetItem(zipEntry, &item);
|
||||||
|
|
||||||
|
nsJARItem* jarItem = new nsJARItem();
|
||||||
|
if (jarItem == nsnull)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
err = jarItem->Init(&item);
|
||||||
|
if (err != ZIP_OK) {
|
||||||
|
delete jarItem;
|
||||||
|
return ziperr2nsresult(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
NS_ADDREF(jarItem);
|
||||||
|
*result = jarItem;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJAR::Find(const char *aPattern, nsISimpleEnumerator **_retval)
|
nsJAR::FindEntries(const char *aPattern, nsISimpleEnumerator **_retval)
|
||||||
{
|
{
|
||||||
if (!_retval)
|
if (!_retval)
|
||||||
return NS_ERROR_INVALID_POINTER;
|
return NS_ERROR_INVALID_POINTER;
|
||||||
|
|
||||||
nsZipFind *find = mZip.FindInit(aPattern);
|
nsZipFind *find = mZip.FindInit(aPattern);
|
||||||
if (!find)
|
if (!find)
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
nsISimpleEnumerator *zipEnum = new nsJAREnumerator(find);
|
nsISimpleEnumerator *zipEnum = new nsJAREnumerator(find);
|
||||||
if (!zipEnum)
|
if (!zipEnum)
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
NS_ADDREF( zipEnum );
|
NS_ADDREF( zipEnum );
|
||||||
|
|
||||||
*_retval = zipEnum;
|
*_retval = zipEnum;
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
|
@ -101,8 +180,6 @@ nsJAR::GetInputStream(const char *aFilename, nsIInputStream **_retval)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
// nsJAREnumerator constructor and destructor
|
// nsJAREnumerator constructor and destructor
|
||||||
//----------------------------------------------
|
//----------------------------------------------
|
||||||
|
@ -176,10 +253,15 @@ nsJAREnumerator::GetNext(nsISupports** aResult)
|
||||||
}
|
}
|
||||||
|
|
||||||
// pack into an nsIJARItem
|
// pack into an nsIJARItem
|
||||||
nsIJARItem* jarItem = new nsJARItem(mCurr);
|
nsJARItem* jarItem = new nsJARItem();
|
||||||
if(jarItem)
|
if(jarItem)
|
||||||
{
|
{
|
||||||
jarItem->AddRef();
|
PRInt32 err = jarItem->Init(mCurr);
|
||||||
|
if (err != ZIP_OK) {
|
||||||
|
delete jarItem;
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
NS_ADDREF(jarItem);
|
||||||
*aResult = jarItem;
|
*aResult = jarItem;
|
||||||
mIsCurrStale = PR_TRUE; // we just gave this one away
|
mIsCurrStale = PR_TRUE; // we just gave this one away
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
@ -195,30 +277,15 @@ nsJAREnumerator::GetNext(nsISupports** aResult)
|
||||||
// nsJARItem constructors and destructor
|
// nsJARItem constructors and destructor
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
nsJARItem::nsJARItem()
|
nsJARItem::nsJARItem()
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
nsJARItem::nsJARItem(nsZipItem* aOther)
|
|
||||||
{
|
{
|
||||||
NS_INIT_ISUPPORTS();
|
NS_INIT_ISUPPORTS();
|
||||||
name = PL_strndup( aOther->name, aOther->namelen );
|
|
||||||
namelen = aOther->namelen;
|
|
||||||
|
|
||||||
offset = aOther->offset;
|
|
||||||
headerloc = aOther->headerloc;
|
|
||||||
compression = aOther->compression;
|
|
||||||
size = aOther->size;
|
|
||||||
realsize = aOther->realsize;
|
|
||||||
crc32 = aOther->crc32;
|
|
||||||
|
|
||||||
next = nsnull; // unused by a JARItem
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsJARItem::~nsJARItem()
|
nsJARItem::~nsJARItem()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IMPL_ISUPPORTS(nsJARItem, nsIJARItem::GetIID());
|
NS_IMPL_ISUPPORTS1(nsJARItem, nsIZipEntry);
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
// nsJARItem::GetName
|
// nsJARItem::GetName
|
||||||
|
@ -275,7 +342,7 @@ nsJARItem::GetSize(PRUint32 *aSize)
|
||||||
// nsJARItem::GetRealSize
|
// nsJARItem::GetRealSize
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJARItem::GetRealsize(PRUint32 *aRealsize)
|
nsJARItem::GetRealSize(PRUint32 *aRealsize)
|
||||||
{
|
{
|
||||||
if (!aRealsize)
|
if (!aRealsize)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
@ -290,7 +357,7 @@ nsJARItem::GetRealsize(PRUint32 *aRealsize)
|
||||||
// nsJARItem::GetCrc32
|
// nsJARItem::GetCrc32
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
nsJARItem::GetCrc32(PRUint32 *aCrc32)
|
nsJARItem::GetCRC32(PRUint32 *aCrc32)
|
||||||
{
|
{
|
||||||
if (!aCrc32)
|
if (!aCrc32)
|
||||||
return NS_ERROR_NULL_POINTER;
|
return NS_ERROR_NULL_POINTER;
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#ifndef nsJAR_h__
|
#ifndef nsJAR_h__
|
||||||
#define nsJAR_h__
|
#define nsJAR_h__
|
||||||
|
|
||||||
|
#include "nsIZipReader.h"
|
||||||
#include "prtypes.h"
|
#include "prtypes.h"
|
||||||
#include "nsIJAR.h"
|
|
||||||
#include "nsIEnumerator.h"
|
#include "nsIEnumerator.h"
|
||||||
#include "nsZipArchive.h"
|
#include "nsZipArchive.h"
|
||||||
#include "zipfile.h"
|
#include "zipfile.h"
|
||||||
|
@ -44,22 +44,23 @@ class nsIInputStream;
|
||||||
* This class allows nsZipArchive to remain non-XPCOM yet still be loadable
|
* This class allows nsZipArchive to remain non-XPCOM yet still be loadable
|
||||||
* by Mozilla.
|
* by Mozilla.
|
||||||
*------------------------------------------------------------------------*/
|
*------------------------------------------------------------------------*/
|
||||||
class nsJAR : public nsIJAR
|
class nsJAR : public nsIZipReader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
nsJAR();
|
nsJAR();
|
||||||
virtual ~nsJAR();
|
virtual ~nsJAR();
|
||||||
|
|
||||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_JAR_CID );
|
NS_DEFINE_STATIC_CID_ACCESSOR( NS_ZIPREADER_CID );
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
NS_DECL_NSIZIP
|
NS_DECL_NSIZIPREADER
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
nsZipArchive mZip;
|
nsFileSpec mZipFile;
|
||||||
|
nsZipArchive mZip;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -71,16 +72,12 @@ class nsJAR : public nsIJAR
|
||||||
* An individual JAR entry. A set of nsJARItems macthing a
|
* An individual JAR entry. A set of nsJARItems macthing a
|
||||||
* supplied pattern are returned in a nsJAREnumerator.
|
* supplied pattern are returned in a nsJAREnumerator.
|
||||||
*/
|
*/
|
||||||
class nsJARItem : public nsZipItem, public nsIJARItem
|
class nsJARItem : public nsZipItem, public nsIZipEntry
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSIZIPENTRY
|
||||||
|
|
||||||
//NS_DEFINE_STATIC_CID_ACCESSOR( NS_JARITEM_CID );
|
|
||||||
|
|
||||||
NS_DECL_NSIJARITEM
|
|
||||||
|
|
||||||
nsJARItem(nsZipItem* aOther);
|
|
||||||
nsJARItem();
|
nsJARItem();
|
||||||
virtual ~nsJARItem();
|
virtual ~nsJARItem();
|
||||||
};
|
};
|
||||||
|
@ -98,12 +95,7 @@ class nsJAREnumerator : public nsISimpleEnumerator
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
NS_DECL_NSISIMPLEENUMERATOR
|
||||||
//NS_DEFINE_STATIC_CID_ACCESSOR( NS_JARENUMERATOR_CID );
|
|
||||||
|
|
||||||
// nsISimpleEnumerator methods
|
|
||||||
NS_IMETHOD HasMoreElements(PRBool* aResult);
|
|
||||||
NS_IMETHOD GetNext(nsISupports** aResult);
|
|
||||||
|
|
||||||
nsJAREnumerator(nsZipFind *aFind);
|
nsJAREnumerator(nsZipFind *aFind);
|
||||||
virtual ~nsJAREnumerator();
|
virtual ~nsJAREnumerator();
|
||||||
|
|
|
@ -17,12 +17,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nsNetUtil.h"
|
#include "nsNeckoUtil.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIFileSpec.h"
|
#include "nsIFileSpec.h"
|
||||||
#include "nsSpecialSystemDirectory.h"
|
#include "nsSpecialSystemDirectory.h"
|
||||||
#include "nsJARDownloadListener.h"
|
|
||||||
#include "nsJARChannel.h"
|
#include "nsJARChannel.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "nsIFileTransportService.h"
|
#include "nsIFileTransportService.h"
|
||||||
|
@ -31,7 +30,7 @@
|
||||||
|
|
||||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
||||||
static NS_DEFINE_CID(kJARCID, NS_JAR_CID);
|
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -456,25 +455,29 @@ NS_IMETHODIMP
|
||||||
nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
rv = nsComponentManager::CreateInstance(kJARCID,
|
rv = nsComponentManager::CreateInstance(kZipReaderCID,
|
||||||
nsnull,
|
nsnull,
|
||||||
NS_GET_IID(nsIJAR),
|
NS_GET_IID(nsIZipReader),
|
||||||
getter_AddRefs(mJAR));
|
getter_AddRefs(mJAR));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
char* path;
|
nsFileSpec fs;
|
||||||
rv = mJARBaseFile->GetNativePath(&path);
|
rv = mJARBaseFile->GetFileSpec(&fs);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
PRInt32 retVal;
|
rv = mJAR->Init(fs);
|
||||||
rv = mJAR->Open(path, &retVal); // XXX this retVal sucks! -- fix nsIJAR interface
|
if (NS_FAILED(rv)) return rv;
|
||||||
nsCRT::free(path);
|
|
||||||
if (NS_FAILED(rv) || retVal) return rv;
|
rv = mJAR->Open();
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
rv = mJAR->ItemSize(mJAREntry, (PRUint32*)&mContentLength);
|
|
||||||
|
nsCOMPtr<nsIZipEntry> entry;
|
||||||
|
rv = mJAR->GetEntry(mJAREntry, getter_AddRefs(entry));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = entry->GetRealSize((PRUint32*)contentLength);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
*contentLength = mContentLength;
|
|
||||||
return GetContentType(contentType);
|
return GetContentType(contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@
|
||||||
#include "nsIJARChannel.h"
|
#include "nsIJARChannel.h"
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
#include "nsIJARProtocolHandler.h"
|
#include "nsIJARProtocolHandler.h"
|
||||||
#include "nsJARDownloadListener.h"
|
#include "nsIJARURI.h"
|
||||||
#include "nsIFileSystem.h"
|
#include "nsIFileSystem.h"
|
||||||
#include "nsIFileChannel.h"
|
#include "nsIFileChannel.h"
|
||||||
#include "nsIJAR.h"
|
#include "nsIZipReader.h"
|
||||||
#include "nsIFileChannel.h"
|
#include "nsIFileChannel.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ protected:
|
||||||
nsCOMPtr<nsIURI> mJARBaseURI;
|
nsCOMPtr<nsIURI> mJARBaseURI;
|
||||||
nsCOMPtr<nsIFileChannel> mJARBaseFile;
|
nsCOMPtr<nsIFileChannel> mJARBaseFile;
|
||||||
char* mJAREntry;
|
char* mJAREntry;
|
||||||
nsCOMPtr<nsIJAR> mJAR;
|
nsCOMPtr<nsIZipReader> mJAR;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsJARChannel_h__
|
#endif // nsJARChannel_h__
|
||||||
|
|
|
@ -53,12 +53,8 @@ static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
|
||||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIJAR_IID, NS_IJAR_IID);
|
static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID);
|
||||||
static NS_DEFINE_IID(kJAR_CID, NS_JAR_CID);
|
static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIJARFactory_IID, NS_IJARFactory_IID);
|
|
||||||
static NS_DEFINE_IID(kJARFactory_CID, NS_JARFactory_CID);
|
|
||||||
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -151,7 +147,7 @@ nsJARModule::GetClassObject(nsIComponentManager *aCompMgr,
|
||||||
// Choose the appropriate factory, based on the desired instance
|
// Choose the appropriate factory, based on the desired instance
|
||||||
// class type (aClass).
|
// class type (aClass).
|
||||||
nsCOMPtr<nsIGenericFactory> fact;
|
nsCOMPtr<nsIGenericFactory> fact;
|
||||||
if (aClass.Equals(kJAR_CID)) {
|
if (aClass.Equals(kZipReaderCID)) {
|
||||||
if (!mFactory) {
|
if (!mFactory) {
|
||||||
// Create and save away the factory object for creating
|
// Create and save away the factory object for creating
|
||||||
// new instances of JAR. This way if we are called
|
// new instances of JAR. This way if we are called
|
||||||
|
@ -188,7 +184,7 @@ struct Components {
|
||||||
|
|
||||||
// The list of components we register
|
// The list of components we register
|
||||||
static Components gComponents[] = {
|
static Components gComponents[] = {
|
||||||
{ "LibJAR Component", &kJAR_CID,
|
{ "Zip Reader", &kZipReaderCID,
|
||||||
"component://netscape/libjar", },
|
"component://netscape/libjar", },
|
||||||
};
|
};
|
||||||
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
#define NUM_COMPONENTS (sizeof(gComponents) / sizeof(gComponents[0]))
|
||||||
|
|
|
@ -29,16 +29,6 @@
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsJARChannel.h"
|
#include "nsJARChannel.h"
|
||||||
|
|
||||||
//temp vars
|
|
||||||
/**
|
|
||||||
#include "nsIZip.h"
|
|
||||||
#include "nsIJAR.h"
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsIMIMEService.h"
|
|
||||||
#define DEFAULT_TYPE "text/html"
|
|
||||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
|
||||||
static NS_DEFINE_CID(kJARCID, NS_JAR_CID);
|
|
||||||
**/
|
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID);
|
static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID);
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nsJARURI.h"
|
#include "nsJARURI.h"
|
||||||
#include "nsNetUtil.h"
|
#include "nsNeckoUtil.h"
|
||||||
#include "nsIIOService.h"
|
#include "nsIIOService.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIJAR.h"
|
#include "nsIZipReader.h"
|
||||||
|
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
|
|
||||||
|
|
|
@ -289,6 +289,54 @@ PRInt32 nsZipArchive::OpenArchive( const char * aArchiveName )
|
||||||
return BuildFileList();
|
return BuildFileList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------
|
||||||
|
// nsZipArchive::CloseArchive
|
||||||
|
//---------------------------------------------
|
||||||
|
PRInt32 nsZipArchive::CloseArchive()
|
||||||
|
{
|
||||||
|
// close the file if open
|
||||||
|
if ( mFd != 0 ) {
|
||||||
|
PR_Close(mFd);
|
||||||
|
}
|
||||||
|
|
||||||
|
// delete nsZipItems in table
|
||||||
|
nsZipItem* pItem;
|
||||||
|
for ( int i = 0; i < ZIP_TABSIZE; ++i)
|
||||||
|
{
|
||||||
|
pItem = mFiles[i];
|
||||||
|
while ( pItem != 0 )
|
||||||
|
{
|
||||||
|
mFiles[i] = pItem->next;
|
||||||
|
delete pItem;
|
||||||
|
pItem = mFiles[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ZIP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------
|
||||||
|
// nsZipArchive::ItemSize
|
||||||
|
//---------------------------------------------
|
||||||
|
PRInt32 nsZipArchive::GetItem( const char * aFilename, nsZipItem *result)
|
||||||
|
{
|
||||||
|
//-- Parameter validity check
|
||||||
|
if (aFilename == 0)
|
||||||
|
return ZIP_ERR_PARAM;
|
||||||
|
|
||||||
|
//PRInt32 result;
|
||||||
|
nsZipItem* aItem;
|
||||||
|
|
||||||
|
//-- find file information
|
||||||
|
aItem = GetFileItem( aFilename );
|
||||||
|
if ( aItem == 0 )
|
||||||
|
{
|
||||||
|
return ZIP_ERR_FNF;
|
||||||
|
}
|
||||||
|
|
||||||
|
memcpy(result, &aItem, sizeof(aItem)); // copy struct
|
||||||
|
return ZIP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//---------------------------------------------
|
//---------------------------------------------
|
||||||
// nsZipArchive::ReadInit
|
// nsZipArchive::ReadInit
|
||||||
//---------------------------------------------
|
//---------------------------------------------
|
||||||
|
@ -1145,23 +1193,7 @@ nsZipArchive::nsZipArchive()
|
||||||
|
|
||||||
nsZipArchive::~nsZipArchive()
|
nsZipArchive::~nsZipArchive()
|
||||||
{
|
{
|
||||||
// close the file if open
|
(void)CloseArchive();
|
||||||
if ( mFd != 0 ) {
|
|
||||||
PR_Close(mFd);
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete nsZipItems in table
|
|
||||||
nsZipItem* pItem;
|
|
||||||
for ( int i = 0; i < ZIP_TABSIZE; ++i)
|
|
||||||
{
|
|
||||||
pItem = mFiles[i];
|
|
||||||
while ( pItem != 0 )
|
|
||||||
{
|
|
||||||
mFiles[i] = pItem->next;
|
|
||||||
delete pItem;
|
|
||||||
pItem = mFiles[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1179,6 +1211,28 @@ nsZipItem::~nsZipItem()
|
||||||
delete [] name;
|
delete [] name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PRInt32
|
||||||
|
nsZipItem::Init(nsZipItem* other)
|
||||||
|
{
|
||||||
|
if (name) delete[] name;
|
||||||
|
name = (char*)PR_Malloc(other->namelen);
|
||||||
|
if (name == 0)
|
||||||
|
return ZIP_ERR_MEMORY;
|
||||||
|
memcpy(name, other->name, other->namelen);
|
||||||
|
|
||||||
|
namelen = other->namelen;
|
||||||
|
offset = other->offset;
|
||||||
|
headerloc = other->headerloc;
|
||||||
|
compression = other->compression;
|
||||||
|
size = other->size;
|
||||||
|
realsize = other->realsize;
|
||||||
|
crc32 = other->crc32;
|
||||||
|
mode = other->mode;
|
||||||
|
next = 0; // don't copy next
|
||||||
|
|
||||||
|
return ZIP_OK;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
// nsZipRead constructor and destructor
|
// nsZipRead constructor and destructor
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
@ -1226,8 +1280,6 @@ nsZipArchive* nsZipFind::GetArchive()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
// helper functions
|
// helper functions
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
|
|
|
@ -62,6 +62,8 @@ public:
|
||||||
nsZipItem();
|
nsZipItem();
|
||||||
~nsZipItem();
|
~nsZipItem();
|
||||||
|
|
||||||
|
PRInt32 Init(nsZipItem* other);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//-- prevent copies and assignments
|
//-- prevent copies and assignments
|
||||||
nsZipItem& operator=(const nsZipItem& rhs);
|
nsZipItem& operator=(const nsZipItem& rhs);
|
||||||
|
@ -100,6 +102,19 @@ public:
|
||||||
*/
|
*/
|
||||||
PRInt32 OpenArchive( const char * aArchiveName );
|
PRInt32 OpenArchive( const char * aArchiveName );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes an open archive.
|
||||||
|
*/
|
||||||
|
PRInt32 CloseArchive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GetItem
|
||||||
|
*
|
||||||
|
* @param aFilename Name of file in the archive
|
||||||
|
* @return status code
|
||||||
|
*/
|
||||||
|
PRInt32 GetItem(const char * aFilename, nsZipItem *result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ReadInit
|
* ReadInit
|
||||||
*
|
*
|
||||||
|
|
|
@ -157,6 +157,26 @@ interface nsIIOService : nsISupports
|
||||||
in nsIInputStream inStr,
|
in nsIInputStream inStr,
|
||||||
in nsILoadGroup group,
|
in nsILoadGroup group,
|
||||||
in nsIURI originalURI);
|
in nsIURI originalURI);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility for protocol implementors -- extracts the scheme from a URL
|
||||||
|
* string, consistently and according to spec.
|
||||||
|
* @param urlString - the URL string to parse
|
||||||
|
* @param schemeStartPos - the resulting starting position of the scheme substring
|
||||||
|
* (may skip over whitespace)
|
||||||
|
* @param schemeEndPos - the resulting ending position of the scheme substring
|
||||||
|
* (the position of the colon)
|
||||||
|
* @param scheme - an allocated substring containing the scheme. If this parameter
|
||||||
|
* is null going into the routine, then the scheme is not allocated and
|
||||||
|
* returned. Free with nsCRT::free.
|
||||||
|
*
|
||||||
|
* @return NS_OK - if successful
|
||||||
|
* @return NS_ERROR_MALFORMED_URI - if the urlString is not of the right form
|
||||||
|
*/
|
||||||
|
void extractScheme(in string urlString,
|
||||||
|
out unsigned long schemeStartPos,
|
||||||
|
out unsigned long schemeEndPos,
|
||||||
|
out string scheme);
|
||||||
};
|
};
|
||||||
|
|
||||||
%{C++
|
%{C++
|
||||||
|
|
|
@ -138,27 +138,41 @@ nsIOService::GetProtocolHandler(const char* scheme, nsIProtocolHandler* *result)
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static nsresult
|
NS_IMETHODIMP
|
||||||
GetScheme(const char* inURI, char* *scheme)
|
nsIOService::ExtractScheme(const char* inURI, PRUint32 *startPos, PRUint32 *endPos,
|
||||||
|
char* *scheme)
|
||||||
{
|
{
|
||||||
// search for something up to a colon, and call it the scheme
|
// search for something up to a colon, and call it the scheme
|
||||||
NS_ASSERTION(inURI, "null pointer");
|
NS_ASSERTION(inURI, "null pointer");
|
||||||
if (!inURI) return NS_ERROR_NULL_POINTER;
|
if (!inURI) return NS_ERROR_NULL_POINTER;
|
||||||
char c;
|
|
||||||
const char* URI = inURI;
|
|
||||||
PRUint8 length = 0;
|
|
||||||
// skip leading white space
|
|
||||||
while (nsString::IsSpace(*URI))
|
|
||||||
URI++;
|
|
||||||
while ((c = *URI++) != '\0') {
|
|
||||||
if (c == ':') {
|
|
||||||
char* newScheme = (char *)PR_Malloc(length+1);
|
|
||||||
if (newScheme == nsnull)
|
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
|
||||||
|
|
||||||
nsCRT::memcpy(newScheme, inURI, length);
|
const char* uri = inURI;
|
||||||
newScheme[length] = '\0';
|
|
||||||
*scheme = newScheme;
|
// skip leading white space
|
||||||
|
while (nsString::IsSpace(*uri))
|
||||||
|
uri++;
|
||||||
|
|
||||||
|
PRUint32 start = uri - inURI;
|
||||||
|
if (startPos) {
|
||||||
|
*startPos = start;
|
||||||
|
}
|
||||||
|
|
||||||
|
PRUint32 length = 0;
|
||||||
|
char c;
|
||||||
|
while ((c = *uri++) != '\0') {
|
||||||
|
if (c == ':') {
|
||||||
|
if (endPos) {
|
||||||
|
*endPos = start + length + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scheme) {
|
||||||
|
char* str = (char*)nsAllocator::Alloc(length + 1);
|
||||||
|
if (str == nsnull)
|
||||||
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
|
nsCRT::memcpy(str, &inURI[start], length);
|
||||||
|
str[length] = '\0';
|
||||||
|
*scheme = str;
|
||||||
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
else if (nsString::IsAlpha(c)) {
|
else if (nsString::IsAlpha(c)) {
|
||||||
|
@ -177,7 +191,7 @@ nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
nsIURI* base;
|
nsIURI* base;
|
||||||
char* scheme;
|
char* scheme;
|
||||||
rv = GetScheme(aSpec, &scheme);
|
rv = ExtractScheme(aSpec, nsnull, nsnull, &scheme);
|
||||||
if (NS_SUCCEEDED(rv)) {
|
if (NS_SUCCEEDED(rv)) {
|
||||||
// then aSpec is absolute
|
// then aSpec is absolute
|
||||||
// ignore aBaseURI in this case
|
// ignore aBaseURI in this case
|
||||||
|
|
|
@ -23,6 +23,11 @@
|
||||||
#include "nsIChannel.idl"
|
#include "nsIChannel.idl"
|
||||||
|
|
||||||
interface nsISimpleEnumerator;
|
interface nsISimpleEnumerator;
|
||||||
|
native nsFileSpec(nsFileSpec);
|
||||||
|
|
||||||
|
%{C++
|
||||||
|
#include "nsFileSpec.h"
|
||||||
|
%}
|
||||||
|
|
||||||
[scriptable, uuid(73025830-0ce2-11d3-9331-00104ba0fd40)]
|
[scriptable, uuid(73025830-0ce2-11d3-9331-00104ba0fd40)]
|
||||||
interface nsIFileChannel : nsIChannel
|
interface nsIFileChannel : nsIChannel
|
||||||
|
@ -117,5 +122,10 @@ interface nsIFileChannel : nsIChannel
|
||||||
* the Query portion of the URI is used as the argument string.
|
* the Query portion of the URI is used as the argument string.
|
||||||
*/
|
*/
|
||||||
void Execute(in string args);
|
void Execute(in string args);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* XXX Until we eliminate nsFileSpec...
|
||||||
|
*/
|
||||||
|
[noscript] void GetFileSpec(out nsFileSpec spec);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -721,6 +721,13 @@ nsFileChannel::Execute(const char *args)
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NS_IMETHODIMP
|
||||||
|
nsFileChannel::GetFileSpec(nsFileSpec *spec)
|
||||||
|
{
|
||||||
|
*spec = mSpec;
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
nsresult
|
nsresult
|
||||||
|
|
|
@ -17,12 +17,11 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nsNetUtil.h"
|
#include "nsNeckoUtil.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIFileSpec.h"
|
#include "nsIFileSpec.h"
|
||||||
#include "nsSpecialSystemDirectory.h"
|
#include "nsSpecialSystemDirectory.h"
|
||||||
#include "nsJARDownloadListener.h"
|
|
||||||
#include "nsJARChannel.h"
|
#include "nsJARChannel.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "nsIFileTransportService.h"
|
#include "nsIFileTransportService.h"
|
||||||
|
@ -31,7 +30,7 @@
|
||||||
|
|
||||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
||||||
static NS_DEFINE_CID(kJARCID, NS_JAR_CID);
|
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -456,25 +455,29 @@ NS_IMETHODIMP
|
||||||
nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||||
{
|
{
|
||||||
nsresult rv;
|
nsresult rv;
|
||||||
rv = nsComponentManager::CreateInstance(kJARCID,
|
rv = nsComponentManager::CreateInstance(kZipReaderCID,
|
||||||
nsnull,
|
nsnull,
|
||||||
NS_GET_IID(nsIJAR),
|
NS_GET_IID(nsIZipReader),
|
||||||
getter_AddRefs(mJAR));
|
getter_AddRefs(mJAR));
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
char* path;
|
nsFileSpec fs;
|
||||||
rv = mJARBaseFile->GetNativePath(&path);
|
rv = mJARBaseFile->GetFileSpec(&fs);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
PRInt32 retVal;
|
rv = mJAR->Init(fs);
|
||||||
rv = mJAR->Open(path, &retVal); // XXX this retVal sucks! -- fix nsIJAR interface
|
if (NS_FAILED(rv)) return rv;
|
||||||
nsCRT::free(path);
|
|
||||||
if (NS_FAILED(rv) || retVal) return rv;
|
rv = mJAR->Open();
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
rv = mJAR->ItemSize(mJAREntry, (PRUint32*)&mContentLength);
|
|
||||||
|
nsCOMPtr<nsIZipEntry> entry;
|
||||||
|
rv = mJAR->GetEntry(mJAREntry, getter_AddRefs(entry));
|
||||||
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
|
rv = entry->GetRealSize((PRUint32*)contentLength);
|
||||||
if (NS_FAILED(rv)) return rv;
|
if (NS_FAILED(rv)) return rv;
|
||||||
|
|
||||||
*contentLength = mContentLength;
|
|
||||||
return GetContentType(contentType);
|
return GetContentType(contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,10 @@
|
||||||
#include "nsIJARChannel.h"
|
#include "nsIJARChannel.h"
|
||||||
#include "nsIStreamListener.h"
|
#include "nsIStreamListener.h"
|
||||||
#include "nsIJARProtocolHandler.h"
|
#include "nsIJARProtocolHandler.h"
|
||||||
#include "nsJARDownloadListener.h"
|
#include "nsIJARURI.h"
|
||||||
#include "nsIFileSystem.h"
|
#include "nsIFileSystem.h"
|
||||||
#include "nsIFileChannel.h"
|
#include "nsIFileChannel.h"
|
||||||
#include "nsIJAR.h"
|
#include "nsIZipReader.h"
|
||||||
#include "nsIFileChannel.h"
|
#include "nsIFileChannel.h"
|
||||||
#include "nsCOMPtr.h"
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ protected:
|
||||||
nsCOMPtr<nsIURI> mJARBaseURI;
|
nsCOMPtr<nsIURI> mJARBaseURI;
|
||||||
nsCOMPtr<nsIFileChannel> mJARBaseFile;
|
nsCOMPtr<nsIFileChannel> mJARBaseFile;
|
||||||
char* mJAREntry;
|
char* mJAREntry;
|
||||||
nsCOMPtr<nsIJAR> mJAR;
|
nsCOMPtr<nsIZipReader> mJAR;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // nsJARChannel_h__
|
#endif // nsJARChannel_h__
|
||||||
|
|
|
@ -29,16 +29,6 @@
|
||||||
#include "nsIURL.h"
|
#include "nsIURL.h"
|
||||||
#include "nsJARChannel.h"
|
#include "nsJARChannel.h"
|
||||||
|
|
||||||
//temp vars
|
|
||||||
/**
|
|
||||||
#include "nsIZip.h"
|
|
||||||
#include "nsIJAR.h"
|
|
||||||
#include "nsCOMPtr.h"
|
|
||||||
#include "nsIMIMEService.h"
|
|
||||||
#define DEFAULT_TYPE "text/html"
|
|
||||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
|
||||||
static NS_DEFINE_CID(kJARCID, NS_JAR_CID);
|
|
||||||
**/
|
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID);
|
static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID);
|
||||||
|
|
||||||
|
|
|
@ -17,12 +17,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "nsJARURI.h"
|
#include "nsJARURI.h"
|
||||||
#include "nsNetUtil.h"
|
#include "nsNeckoUtil.h"
|
||||||
#include "nsIIOService.h"
|
#include "nsIIOService.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
#include "nsIJAR.h"
|
#include "nsIZipReader.h"
|
||||||
|
|
||||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||||
|
|
||||||
|
|
|
@ -117,8 +117,8 @@ nsInstallInfo::GetLocalFile(char **aPath)
|
||||||
static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID);
|
static NS_DEFINE_IID(kISoftwareUpdateIID, NS_ISOFTWAREUPDATE_IID);
|
||||||
static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
|
static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIJARIID, NS_IJAR_IID);
|
static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID);
|
||||||
static NS_DEFINE_IID(kJARCID, NS_JAR_CID);
|
static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||||
|
|
||||||
nsInstall::nsInstall()
|
nsInstall::nsInstall()
|
||||||
{
|
{
|
||||||
|
@ -143,7 +143,7 @@ nsInstall::nsInstall()
|
||||||
mInstallArguments = "";
|
mInstallArguments = "";
|
||||||
|
|
||||||
// mJarFileData is an opaque handle to the jarfile.
|
// mJarFileData is an opaque handle to the jarfile.
|
||||||
nsresult rv = nsComponentManager::CreateInstance(kJARCID, nsnull, kIJARIID,
|
nsresult rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, kIZipReaderIID,
|
||||||
(void**) &mJarFileData);
|
(void**) &mJarFileData);
|
||||||
|
|
||||||
nsISoftwareUpdate *su;
|
nsISoftwareUpdate *su;
|
||||||
|
@ -2143,13 +2143,15 @@ nsInstall::Confirm(nsString& string, PRBool* aReturn)
|
||||||
PRInt32
|
PRInt32
|
||||||
nsInstall::OpenJARFile(void)
|
nsInstall::OpenJARFile(void)
|
||||||
{
|
{
|
||||||
PRInt32 result;
|
nsresult rv = mJarFileData->Init(nsFileSpec(mJarFileLocation));
|
||||||
|
|
||||||
nsresult rv = mJarFileData->Open( nsAutoCString(mJarFileLocation), &result );
|
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return UNEXPECTED_ERROR;
|
return UNEXPECTED_ERROR;
|
||||||
|
|
||||||
return result;
|
rv = mJarFileData->Open();
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return UNEXPECTED_ERROR;
|
||||||
|
|
||||||
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -2207,7 +2209,7 @@ nsInstall::ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedNa
|
||||||
// We will overwrite what is in the way. is this something that we want to do?
|
// We will overwrite what is in the way. is this something that we want to do?
|
||||||
extractHereSpec->Delete(PR_FALSE);
|
extractHereSpec->Delete(PR_FALSE);
|
||||||
|
|
||||||
nsresult rv = mJarFileData->Extract( nsAutoCString(aJarfile), nsNSPRPath( *extractHereSpec ), &result );
|
nsresult rv = mJarFileData->Extract( nsAutoCString(aJarfile), *extractHereSpec );
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
{
|
{
|
||||||
if (extractHereSpec != nsnull)
|
if (extractHereSpec != nsnull)
|
||||||
|
@ -2310,7 +2312,7 @@ nsInstall::ExtractDirEntries(const nsString& directory, nsVoidArray *paths)
|
||||||
{
|
{
|
||||||
char *buf;
|
char *buf;
|
||||||
nsISimpleEnumerator *jarEnum = nsnull;
|
nsISimpleEnumerator *jarEnum = nsnull;
|
||||||
nsIJARItem *currJARItem = nsnull;
|
nsIZipEntry *currZipEntry = nsnull;
|
||||||
|
|
||||||
if ( paths )
|
if ( paths )
|
||||||
{
|
{
|
||||||
|
@ -2318,7 +2320,7 @@ nsInstall::ExtractDirEntries(const nsString& directory, nsVoidArray *paths)
|
||||||
pattern += "/*";
|
pattern += "/*";
|
||||||
PRInt32 prefix_length = directory.Length()+1; // account for slash
|
PRInt32 prefix_length = directory.Length()+1; // account for slash
|
||||||
|
|
||||||
nsresult rv = mJarFileData->Find( nsAutoCString(pattern), &jarEnum );
|
nsresult rv = mJarFileData->FindEntries( nsAutoCString(pattern), &jarEnum );
|
||||||
if (NS_FAILED(rv) || !jarEnum)
|
if (NS_FAILED(rv) || !jarEnum)
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
|
|
||||||
|
@ -2326,11 +2328,11 @@ nsInstall::ExtractDirEntries(const nsString& directory, nsVoidArray *paths)
|
||||||
rv = jarEnum->HasMoreElements(&bMore);
|
rv = jarEnum->HasMoreElements(&bMore);
|
||||||
while (bMore && NS_SUCCEEDED(rv))
|
while (bMore && NS_SUCCEEDED(rv))
|
||||||
{
|
{
|
||||||
rv = jarEnum->GetNext( (nsISupports**) &currJARItem );
|
rv = jarEnum->GetNext( (nsISupports**) &currZipEntry );
|
||||||
if (currJARItem)
|
if (currZipEntry)
|
||||||
{
|
{
|
||||||
// expensive 'buf' callee malloc per iteration!
|
// expensive 'buf' callee malloc per iteration!
|
||||||
rv = currJARItem->GetName(&buf);
|
rv = currZipEntry->GetName(&buf);
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
goto handle_err;
|
goto handle_err;
|
||||||
if (buf)
|
if (buf)
|
||||||
|
@ -2346,7 +2348,7 @@ nsInstall::ExtractDirEntries(const nsString& directory, nsVoidArray *paths)
|
||||||
|
|
||||||
PR_FREEIF( buf );
|
PR_FREEIF( buf );
|
||||||
}
|
}
|
||||||
NS_IF_RELEASE(currJARItem);
|
NS_IF_RELEASE(currZipEntry);
|
||||||
}
|
}
|
||||||
rv = jarEnum->HasMoreElements(&bMore);
|
rv = jarEnum->HasMoreElements(&bMore);
|
||||||
}
|
}
|
||||||
|
@ -2357,7 +2359,7 @@ nsInstall::ExtractDirEntries(const nsString& directory, nsVoidArray *paths)
|
||||||
|
|
||||||
handle_err:
|
handle_err:
|
||||||
NS_IF_RELEASE(jarEnum);
|
NS_IF_RELEASE(jarEnum);
|
||||||
NS_IF_RELEASE(currJARItem);
|
NS_IF_RELEASE(currZipEntry);
|
||||||
return EXTRACTION_FAILED;
|
return EXTRACTION_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
#include "nsIComponentManager.h"
|
#include "nsIComponentManager.h"
|
||||||
#include "nsIProperties.h"
|
#include "nsIProperties.h"
|
||||||
#include "nsIEnumerator.h"
|
#include "nsIEnumerator.h"
|
||||||
#include "nsIJAR.h"
|
#include "nsIZipReader.h"
|
||||||
|
|
||||||
class nsInstallInfo
|
class nsInstallInfo
|
||||||
{
|
{
|
||||||
|
@ -266,7 +266,7 @@ class nsInstall
|
||||||
JSObject* mWinProfileObject;
|
JSObject* mWinProfileObject;
|
||||||
|
|
||||||
nsString mJarFileLocation;
|
nsString mJarFileLocation;
|
||||||
nsIJAR* mJarFileData;
|
nsIZipReader* mJarFileData;
|
||||||
|
|
||||||
nsString mInstallArguments;
|
nsString mInstallArguments;
|
||||||
nsString mInstallURL;
|
nsString mInstallURL;
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include "nsSoftwareUpdateIIDs.h"
|
#include "nsSoftwareUpdateIIDs.h"
|
||||||
|
|
||||||
#include "nsInstall.h"
|
#include "nsInstall.h"
|
||||||
//#include "zipfile.h" // replaced by nsIJAR.h
|
//#include "zipfile.h" // replaced by nsIZipReader.h
|
||||||
|
|
||||||
#include "nsRepository.h"
|
#include "nsRepository.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
|
@ -41,7 +41,8 @@
|
||||||
|
|
||||||
#include "nsIEventQueueService.h"
|
#include "nsIEventQueueService.h"
|
||||||
#include "nsIEnumerator.h"
|
#include "nsIEnumerator.h"
|
||||||
#include "nsIJAR.h"
|
#include "nsIZipReader.h"
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
|
|
||||||
static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
|
static NS_DEFINE_IID(kSoftwareUpdateCID, NS_SoftwareUpdate_CID);
|
||||||
|
|
||||||
|
@ -119,27 +120,26 @@ XPInstallErrorReporter(JSContext *cx, const char *message, JSErrorReport *report
|
||||||
static PRInt32
|
static PRInt32
|
||||||
GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *scriptLength)
|
GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *scriptLength)
|
||||||
{
|
{
|
||||||
nsIJAR* hZip = nsnull;
|
nsCOMPtr<nsIZipReader> hZip;
|
||||||
PRInt32 result = NS_OK;
|
PRInt32 result = NS_OK;
|
||||||
|
|
||||||
*scriptBuffer = nsnull;
|
*scriptBuffer = nsnull;
|
||||||
*scriptLength = 0;
|
*scriptLength = 0;
|
||||||
|
|
||||||
static NS_DEFINE_IID(kIJARIID, NS_IJAR_IID);
|
static NS_DEFINE_IID(kIZipReaderIID, NS_IZIPREADER_IID);
|
||||||
static NS_DEFINE_IID(kJARCID, NS_JAR_CID);
|
static NS_DEFINE_IID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||||
nsresult rv = nsComponentManager::CreateInstance(kJARCID, nsnull, kIJARIID,
|
nsresult rv = nsComponentManager::CreateInstance(kZipReaderCID, nsnull, kIZipReaderIID,
|
||||||
(void**) &hZip);
|
getter_AddRefs(hZip));
|
||||||
// Open the jarfile
|
if (NS_FAILED(rv))
|
||||||
if ( NS_SUCCEEDED(rv) && hZip)
|
|
||||||
rv = hZip->Open( jarFile, &result );
|
|
||||||
|
|
||||||
if ( NS_FAILED(rv) || result != 0 )
|
|
||||||
{
|
|
||||||
// early bail-out
|
|
||||||
NS_IF_RELEASE(hZip);
|
|
||||||
return nsInstall::CANT_READ_ARCHIVE;
|
return nsInstall::CANT_READ_ARCHIVE;
|
||||||
}
|
|
||||||
|
|
||||||
|
rv = hZip->Init(nsFileSpec(jarFile));
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return nsInstall::CANT_READ_ARCHIVE;
|
||||||
|
|
||||||
|
rv = hZip->Open();
|
||||||
|
if (NS_FAILED(rv))
|
||||||
|
return nsInstall::CANT_READ_ARCHIVE;
|
||||||
|
|
||||||
// Extract the install.js file to the temporary directory
|
// Extract the install.js file to the temporary directory
|
||||||
nsSpecialSystemDirectory installJSFileSpec(nsSpecialSystemDirectory::OS_TemporaryDirectory);
|
nsSpecialSystemDirectory installJSFileSpec(nsSpecialSystemDirectory::OS_TemporaryDirectory);
|
||||||
|
@ -147,8 +147,8 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *
|
||||||
installJSFileSpec.MakeUnique();
|
installJSFileSpec.MakeUnique();
|
||||||
|
|
||||||
// Extract the install.js file.
|
// Extract the install.js file.
|
||||||
rv = hZip->Extract( "install.js", nsNSPRPath(installJSFileSpec), &result );
|
rv = hZip->Extract("install.js", installJSFileSpec);
|
||||||
if ( NS_SUCCEEDED(rv) && result == 0 )
|
if ( NS_SUCCEEDED(rv) )
|
||||||
{
|
{
|
||||||
// Read it into a buffer
|
// Read it into a buffer
|
||||||
char* buffer;
|
char* buffer;
|
||||||
|
@ -190,8 +190,6 @@ GetInstallScriptFromJarfile(const char* jarFile, char** scriptBuffer, PRUint32 *
|
||||||
result = nsInstall::NO_INSTALL_SCRIPT;
|
result = nsInstall::NO_INSTALL_SCRIPT;
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_IF_RELEASE( hZip );
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче