mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 22:01:30 +00:00
Modification to the libjar XPCOM interface in order to use it with XPInstall; facilitating ressurection of XPInstall on Unix.
This commit is contained in:
parent
89b9ded2af
commit
dbf800ebea
@ -25,6 +25,10 @@ include $(DEPTH)/config/autoconf.mk
|
||||
MODULE = jar
|
||||
LIBRARY_NAME = jar$(VERSION_NUMBER)
|
||||
|
||||
XPIDLSRCS=nsIZip.idl \
|
||||
nsIJAR.idl \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = \
|
||||
nsZipArchive.cpp \
|
||||
nsJAR.cpp \
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!gmake
|
||||
#!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
|
||||
@ -35,7 +35,11 @@ DLLNAME=jar$(VERSION_NUMBER)
|
||||
DLL=$(OBJDIR)\$(DLLNAME).dll
|
||||
MAPFILE=$(DLLNAME).map
|
||||
|
||||
EXPORTS=zipfile.h nsIJAR.h nsIZip.h nsJARIIDs.h
|
||||
XPIDLSRCS=.\nsIZip.idl \
|
||||
.\nsIJAR.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS=zipfile.h
|
||||
|
||||
OBJS=.\$(OBJDIR)\nsZipArchive.obj \
|
||||
.\$(OBJDIR)\nsJAR.obj \
|
||||
@ -61,11 +65,11 @@ LLIBS= \
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
$(RM) $(OBJS)
|
||||
$(RM) $(DIST)\bin\$(DLLNAME).dll
|
||||
$(RM) $(DIST)\bin\components\$(DLLNAME).dll
|
||||
$(RM) $(DIST)\lib\$(DLLNAME).lib
|
||||
|
||||
|
@ -1,48 +0,0 @@
|
||||
/* -*- 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:
|
||||
* Don Bragg <dbragg@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef nsIJAR_h__
|
||||
#define nsIJAR_h__
|
||||
|
||||
|
||||
#include "nsJARIIDs.h"
|
||||
#include "nsIZip.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
#include "nsIFactory.h"
|
||||
|
||||
|
||||
class nsIJAR : public nsIZip
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR( NS_IJAR_IID );
|
||||
|
||||
/* This interface will be filled with other "JAR"-related functions. */
|
||||
/* The term "JAR" is in reference to security as opposed to "Zip"
|
||||
* which is a non-secure archive format. */
|
||||
};
|
||||
|
||||
|
||||
#endif // nsIJAR_h__
|
72
modules/libjar/nsIJAR.idl
Normal file
72
modules/libjar/nsIJAR.idl
Normal file
@ -0,0 +1,72 @@
|
||||
/* -*- 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 "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>
|
||||
* Don Bragg <dbragg@netscape.com>
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIZip.idl"
|
||||
|
||||
%{C++
|
||||
#define NS_JAR_CID \
|
||||
{ /* 04501DB3-0409-11d3-BCF8-00805F0E1353*/ \
|
||||
0x04501DB3, \
|
||||
0x0409, \
|
||||
0x11d3, \
|
||||
{0xbc, 0xf8, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
};
|
||||
|
||||
#define NS_IJARFactory_IID \
|
||||
{ /* 04501DB4-0409-11d3-BCF8-00805F0E1353 */ \
|
||||
0x04501DB4, \
|
||||
0x0409, \
|
||||
0x11d3, \
|
||||
{0xbc, 0xf8, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
};
|
||||
|
||||
#define NS_JARFactory_CID \
|
||||
{ /* 04501DB5-0409-11d3-BCF8-00805F0E1353 */ \
|
||||
0x04501DB5, \
|
||||
0x0409, \
|
||||
0x11d3, \
|
||||
{0xbc, 0xf8, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
|
||||
};
|
||||
%}
|
||||
|
||||
[uuid(04501DB2-0409-11d3-BCF8-00805F0E1353)]
|
||||
interface nsIJAR : nsIZip
|
||||
{
|
||||
/* This interface will be filled with other "JAR"-related functions. */
|
||||
/* The term "JAR" is in reference to security as opposed to "Zip"
|
||||
* which is a non-secure archive format. */
|
||||
|
||||
};
|
||||
|
||||
[uuid(70993CAD-2922-11d3-A431-0060B0EB5963)]
|
||||
interface nsIJARItem : nsISupports
|
||||
{
|
||||
readonly attribute string name;
|
||||
readonly attribute PRUint16 compression;
|
||||
readonly attribute PRUint32 size;
|
||||
readonly attribute PRUint32 realsize;
|
||||
readonly attribute PRUint32 crc32;
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
/* -*- 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 "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License at
|
||||
@ -21,30 +21,29 @@
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Don Bragg <dbragg@netscape.com>
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
|
||||
#ifndef nsIZip_h__
|
||||
#define nsIZip_h__
|
||||
|
||||
#include "nsZipIIDs.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
%{C++
|
||||
#include "nsIFactory.h"
|
||||
|
||||
#include "nsZipArchive.h"
|
||||
#define NS_ZIP_CID \
|
||||
{ /* CEB5BDB2-121D-11d3-BCFB-00805F0E1353*/ \
|
||||
0xCEB5BDB2, \
|
||||
0x121D, \
|
||||
0x11d3, \
|
||||
{0xBC, 0xFB, 0x00, 0x80, 0x5F, 0x0E, 0x13, 0x53} \
|
||||
};
|
||||
%}
|
||||
|
||||
|
||||
class nsIZip : public nsISupports
|
||||
[uuid(CEB5BDB1-121D-11d3-BCFB-00805F0E1353)]
|
||||
interface nsIZip : nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR( NS_IZip_IID );
|
||||
|
||||
NS_IMETHOD Open(const char * zipFileName, PRInt32 *result)=0;
|
||||
|
||||
NS_IMETHOD Extract(const char * aFilename,const char * aOutname, PRInt32 *result)=0;
|
||||
|
||||
NS_IMETHOD Find( const char * aPattern, nsZipFind *aResult )=0;
|
||||
PRInt32 Open(in string aZipFileName);
|
||||
PRInt32 Extract(in string aFilename, in string aOutname);
|
||||
nsISimpleEnumerator Find(in string aPattern);
|
||||
};
|
||||
|
||||
#endif // nsIZip_h__
|
@ -20,6 +20,7 @@
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*/
|
||||
#include <string.h>
|
||||
|
||||
@ -34,7 +35,7 @@
|
||||
#include "nsRepository.h"
|
||||
#include "nsIComponentManager.h"
|
||||
|
||||
#include "nsZipIIDs.h"
|
||||
#include "nsIZip.h"
|
||||
#include "nsJAR.h"
|
||||
|
||||
/* XPCOM includes */
|
||||
@ -55,8 +56,8 @@ static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
static NS_DEFINE_IID(kIJAR_IID, NS_IJAR_IID);
|
||||
static NS_DEFINE_IID(kJAR_CID, NS_JAR_CID);
|
||||
|
||||
static NS_DEFINE_IID(kIZip_IID, NS_IZip_IID);
|
||||
static NS_DEFINE_IID(kZip_CID, NS_Zip_CID);
|
||||
static NS_DEFINE_IID(kIZip_IID, NS_IZIP_IID);
|
||||
static NS_DEFINE_IID(kZip_CID, NS_ZIP_CID);
|
||||
|
||||
/*---------------------------------------------
|
||||
* nsJAR::QueryInterface implementation
|
||||
@ -106,6 +107,7 @@ NS_IMPL_RELEASE(nsJAR)
|
||||
*---------------------------------------------------------*/
|
||||
nsJAR::nsJAR()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
@ -115,23 +117,229 @@ nsJAR::~nsJAR()
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Open(const char* zipFileName, PRInt32 *aResult)
|
||||
nsJAR::Open(const char *aZipFileName, PRInt32 *_retval)
|
||||
{
|
||||
*aResult = zip.OpenArchive(zipFileName);
|
||||
*_retval = zip.OpenArchive(aZipFileName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Extract(const char * aFilename, const char * aOutname, PRInt32 *aResult)
|
||||
nsJAR::Extract(const char *aFilename, const char *aOutname, PRInt32 *_retval)
|
||||
{
|
||||
*aResult = zip.ExtractFile(aFilename, aOutname);
|
||||
*_retval = zip.ExtractFile(aFilename, aOutname);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Find(const char *aPattern, nsISimpleEnumerator **_retval)
|
||||
{
|
||||
if (!_retval)
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
|
||||
nsZipFind *find = zip.FindInit(aPattern);
|
||||
if (!find)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsISimpleEnumerator *zipEnum = new nsJAREnumerator(find);
|
||||
if (!zipEnum)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF( zipEnum );
|
||||
|
||||
*_retval = zipEnum;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------
|
||||
// nsJAREnumerator constructor and destructor
|
||||
//----------------------------------------------
|
||||
|
||||
nsJAREnumerator::nsJAREnumerator(nsZipFind *aFind)
|
||||
: mFind(aFind),
|
||||
mCurr(nsnull),
|
||||
mIsCurrStale(PR_TRUE)
|
||||
{
|
||||
mArchive = mFind->GetArchive();
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsJAREnumerator::~nsJAREnumerator()
|
||||
{
|
||||
mArchive->FindFree(mFind);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsJAREnumerator, nsISimpleEnumerator::GetIID());
|
||||
|
||||
//----------------------------------------------
|
||||
// nsJAREnumerator::HasMoreElements
|
||||
//----------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJAR::Find( const char * aPattern, nsZipFind *aResult)
|
||||
nsJAREnumerator::HasMoreElements(PRBool* aResult)
|
||||
{
|
||||
aResult = zip.FindInit(aPattern);
|
||||
return NS_OK;
|
||||
PRInt32 err;
|
||||
|
||||
if (!mFind)
|
||||
return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
// try to get the next element
|
||||
if (mIsCurrStale)
|
||||
{
|
||||
err = mArchive->FindNext( mFind, &mCurr );
|
||||
if (err == ZIP_ERR_FNF)
|
||||
{
|
||||
*aResult = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
if (err != ZIP_OK)
|
||||
return NS_ERROR_FAILURE; // no error translation
|
||||
|
||||
mIsCurrStale = PR_FALSE;
|
||||
}
|
||||
|
||||
*aResult = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------
|
||||
// nsJAREnumerator::GetNext
|
||||
//----------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJAREnumerator::GetNext(nsISupports** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
PRBool bMore;
|
||||
|
||||
// check if the current item is "stale"
|
||||
if (mIsCurrStale)
|
||||
{
|
||||
rv = HasMoreElements( &bMore );
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
if (bMore == PR_FALSE)
|
||||
{
|
||||
*aResult = nsnull; // null return value indicates no more elements
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
// pack into an nsIJARItem
|
||||
nsIJARItem* jarItem = new nsJARItem(mCurr);
|
||||
jarItem->AddRef();
|
||||
*aResult = jarItem;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//-------------------------------------------------
|
||||
// nsJARItem constructors and destructor
|
||||
//-------------------------------------------------
|
||||
nsJARItem::nsJARItem()
|
||||
{
|
||||
}
|
||||
|
||||
nsJARItem::nsJARItem(nsZipItem* aOther)
|
||||
{
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsJARItem, nsIJARItem::GetIID());
|
||||
|
||||
//------------------------------------------
|
||||
// nsJARItem::GetName
|
||||
//------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJARItem::GetName(char * *aName)
|
||||
{
|
||||
char *namedup;
|
||||
|
||||
if ( !aName )
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if ( !name )
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
namedup = PL_strndup( name, namelen );
|
||||
if ( !namedup )
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
*aName = namedup;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// nsJARItem::GetCompression
|
||||
//------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJARItem::GetCompression(PRUint16 *aCompression)
|
||||
{
|
||||
if (!aCompression)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!compression)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aCompression = compression;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// nsJARItem::GetSize
|
||||
//------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJARItem::GetSize(PRUint32 *aSize)
|
||||
{
|
||||
if (!aSize)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!size)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aSize = size;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// nsJARItem::GetRealSize
|
||||
//------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJARItem::GetRealsize(PRUint32 *aRealsize)
|
||||
{
|
||||
if (!aRealsize)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!realsize)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aRealsize = realsize;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// nsJARItem::GetCrc32
|
||||
//------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsJARItem::GetCrc32(PRUint32 *aCrc32)
|
||||
{
|
||||
if (!aCrc32)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!crc32)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
*aCrc32 = crc32;
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -20,6 +20,7 @@
|
||||
*
|
||||
* Contributors:
|
||||
* Don Bragg <dbragg@netscape.com>
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*/
|
||||
|
||||
|
||||
@ -27,8 +28,10 @@
|
||||
#define nsJAR_h__
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsJARIIDs.h"
|
||||
#include "nsIJAR.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsZipArchive.h"
|
||||
#include "zipfile.h"
|
||||
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
@ -40,10 +43,6 @@
|
||||
*------------------------------------------------------------------------*/
|
||||
class nsJAR : public nsIJAR
|
||||
{
|
||||
//private:
|
||||
|
||||
nsZipArchive zip;
|
||||
|
||||
public:
|
||||
|
||||
nsJAR();
|
||||
@ -53,12 +52,71 @@ class nsJAR : public nsIJAR
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHODIMP Open(const char* zipFileName, PRInt32 *aResult);
|
||||
|
||||
NS_IMETHODIMP Extract(const char * aFilename, const char * aOutname, PRInt32 *aResult);
|
||||
NS_IMETHOD Open(const char *aZipFileName, PRInt32 *_retval);
|
||||
NS_IMETHOD Extract(const char *aFilename, const char *aOutname, PRInt32 *_retval);
|
||||
NS_IMETHOD Find(const char *aPattern, nsISimpleEnumerator **_retval);
|
||||
|
||||
private:
|
||||
|
||||
NS_IMETHODIMP Find( const char * aPattern, nsZipFind *aResult);
|
||||
nsZipArchive zip;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* nsJARItem
|
||||
*
|
||||
* An individual JAR entry. A set of nsJARItems macthing a
|
||||
* supplied pattern are returned in a nsJAREnumerator.
|
||||
*/
|
||||
class nsJARItem : public nsZipItem, public nsIJARItem
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//NS_DEFINE_STATIC_CID_ACCESSOR( NS_JARITEM_CID );
|
||||
|
||||
// nsIJARItem methods
|
||||
NS_IMETHOD GetName(char * *aName);
|
||||
NS_IMETHOD GetCompression(PRUint16 *aCompression);
|
||||
NS_IMETHOD GetSize(PRUint32 *aSize);
|
||||
NS_IMETHOD GetRealsize(PRUint32 *aRealsize);
|
||||
NS_IMETHOD GetCrc32(PRUint32 *aCrc32);
|
||||
|
||||
nsJARItem(nsZipItem* aOther);
|
||||
nsJARItem();
|
||||
virtual ~nsJARItem();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* nsJAREnumerator
|
||||
*
|
||||
* Enumerates a list of files in a zip archive
|
||||
* (based on a pattern match in its member nsZipFind).
|
||||
*/
|
||||
class nsJAREnumerator : public nsISimpleEnumerator
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//NS_DEFINE_STATIC_CID_ACCESSOR( NS_JARENUMERATOR_CID );
|
||||
|
||||
// nsISimpleEnumerator methods
|
||||
NS_IMETHOD HasMoreElements(PRBool* aResult);
|
||||
NS_IMETHOD GetNext(nsISupports** aResult);
|
||||
|
||||
nsJAREnumerator(nsZipFind *aFind);
|
||||
virtual ~nsJAREnumerator();
|
||||
|
||||
protected:
|
||||
nsZipArchive *mArchive; // pointer extracted from mFind for efficiency
|
||||
nsZipFind *mFind;
|
||||
nsZipItem *mCurr; // raw pointer to an nsZipItem owned by mArchive -- DON'T delete
|
||||
PRBool mIsCurrStale;
|
||||
};
|
||||
|
||||
#endif /* nsJAR_h__ */
|
||||
|
@ -31,14 +31,13 @@
|
||||
#include "prlog.h"
|
||||
|
||||
#include "xp_regexp.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#include "nsJAR.h"
|
||||
#include "nsIJARFactory.h"
|
||||
|
||||
/* XPCOM includes */
|
||||
//#include "nsIComponentManager.h"
|
||||
|
||||
|
||||
/*********************************
|
||||
@ -197,22 +196,52 @@ NSGetFactory(nsISupports* serviceMgr,
|
||||
* XPCOM registry stuff
|
||||
*---------------------------------------------------------*/
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSRegisterSelf(nsISupports* aServiceMgr, const char *path)
|
||||
NSRegisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult result;
|
||||
#ifdef NS_DEBUG
|
||||
printf("*** Libjar is being registered\n");
|
||||
#endif
|
||||
|
||||
printf("*** Libjar is being registered\n");
|
||||
nsRepository::RegisterComponent(kJAR_CID, NULL, NULL, path, PR_TRUE, PR_TRUE);
|
||||
nsresult rv;
|
||||
|
||||
return NS_OK;
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->RegisterComponent(kJAR_CID,
|
||||
NULL, NULL, path,
|
||||
PR_TRUE, PR_TRUE);
|
||||
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
extern "C" NS_EXPORT nsresult
|
||||
NSUnregisterSelf(nsISupports* aServiceMgr, const char *path)
|
||||
NSUnregisterSelf(nsISupports* aServMgr, const char *path)
|
||||
{
|
||||
nsresult result;
|
||||
//nsRepository::UnregisterFactory(kJAR_CID, path);
|
||||
return NS_OK;
|
||||
#ifdef NS_DEBUG
|
||||
printf("*** Libjar is being unregistered\n");
|
||||
#endif
|
||||
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIComponentManager* compMgr;
|
||||
rv = servMgr->GetService(kComponentManagerCID,
|
||||
nsIComponentManager::GetIID(),
|
||||
(nsISupports**)&compMgr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = compMgr->UnregisterComponent(kJAR_CID, path);
|
||||
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*/
|
||||
|
||||
/*
|
||||
@ -60,6 +61,8 @@ static PRUint32 xtolong(unsigned char *ll);
|
||||
* C API wrapper for nsZipArchive
|
||||
*--------------------------------------------*/
|
||||
|
||||
#ifdef STANDALONE
|
||||
|
||||
/**
|
||||
* ZIP_OpenArchive
|
||||
*
|
||||
@ -175,7 +178,7 @@ PR_PUBLIC_API(void*) ZIP_FindInit( void* hZip, const char * pattern )
|
||||
|
||||
|
||||
/**
|
||||
* ZIP_FindInit
|
||||
* ZIP_FindNext
|
||||
*
|
||||
* Puts the next name in the passed buffer. Returns ZIP_ERR_SMALLBUF when
|
||||
* the name is too large for the buffer, and ZIP_ERR_FNF when there are no
|
||||
@ -187,6 +190,8 @@ PR_PUBLIC_API(void*) ZIP_FindInit( void* hZip, const char * pattern )
|
||||
*/
|
||||
PR_PUBLIC_API(PRInt32) ZIP_FindNext( void* hFind, char * outbuf, PRUint16 bufsize )
|
||||
{
|
||||
PRInt32 status;
|
||||
|
||||
/*--- error check args ---*/
|
||||
if ( hFind == 0 )
|
||||
return ZIP_ERR_PARAM;
|
||||
@ -196,7 +201,19 @@ PR_PUBLIC_API(PRInt32) ZIP_FindNext( void* hFind, char * outbuf, PRUint16 bufsiz
|
||||
return ZIP_ERR_PARAM; /* whatever it is isn't one of ours! */
|
||||
|
||||
/*--- return next filename file ---*/
|
||||
return find->mArchive->FindNext( find, outbuf, bufsize );
|
||||
nsZipItem* item;
|
||||
status = find->mArchive->FindNext( find, &item );
|
||||
if ( status == ZIP_OK )
|
||||
{
|
||||
if ( bufsize > item->namelen )
|
||||
{
|
||||
PL_strcpy( outbuf, item->name );
|
||||
}
|
||||
else
|
||||
status = ZIP_ERR_SMALLBUF;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@ -222,6 +239,8 @@ PR_PUBLIC_API(PRInt32) ZIP_FindFree( void* hFind )
|
||||
return find->mArchive->FindFree( find );
|
||||
}
|
||||
|
||||
#endif /* STANDALONE */
|
||||
|
||||
|
||||
|
||||
|
||||
@ -329,14 +348,14 @@ nsZipFind* nsZipArchive::FindInit( const char * aPattern )
|
||||
//---------------------------------------------
|
||||
// nsZipArchive::FindNext
|
||||
//---------------------------------------------
|
||||
PRInt32 nsZipArchive::FindNext( nsZipFind* aFind, char * aBuf, PRUint16 aSize )
|
||||
PRInt32 nsZipArchive::FindNext( nsZipFind* aFind, nsZipItem** aResult)
|
||||
{
|
||||
PRInt32 status;
|
||||
PRBool found = PR_FALSE;
|
||||
PRUint16 slot = aFind->mSlot;
|
||||
nsZipItem* item = aFind->mItem;
|
||||
|
||||
if ( aFind->mArchive != this || aBuf == 0 )
|
||||
if ( aFind->mArchive != this )
|
||||
return ZIP_ERR_PARAM;
|
||||
|
||||
// we start from last match, look for next
|
||||
@ -362,25 +381,14 @@ PRInt32 nsZipArchive::FindNext( nsZipFind* aFind, char * aBuf, PRUint16 aSize )
|
||||
|
||||
if ( found )
|
||||
{
|
||||
if ( aSize > item->namelen )
|
||||
{
|
||||
PL_strcpy( aBuf, item->name );
|
||||
*aResult = item;
|
||||
aFind->mSlot = slot;
|
||||
aFind->mItem = item;
|
||||
status = ZIP_OK;
|
||||
}
|
||||
else
|
||||
status = ZIP_ERR_SMALLBUF;
|
||||
}
|
||||
else
|
||||
status = ZIP_ERR_FNF;
|
||||
|
||||
// save state for next Find. For 'smallbuf' we give user another chance
|
||||
// to find this same match.
|
||||
if ( status != ZIP_ERR_SMALLBUF )
|
||||
{
|
||||
aFind->mSlot = slot;
|
||||
aFind->mItem = item;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@ -401,7 +409,6 @@ PRInt32 nsZipArchive::FindFree( nsZipFind* aFind )
|
||||
|
||||
|
||||
|
||||
|
||||
//***********************************************************
|
||||
// nsZipArchive -- private implementation
|
||||
//***********************************************************
|
||||
@ -541,13 +548,7 @@ PRInt32 nsZipArchive::CopyItemToDisk( const nsZipItem* aItem, const char* aOutna
|
||||
return ZIP_ERR_MEMORY;
|
||||
|
||||
//-- find start of file in archive
|
||||
#ifndef STANDALONE
|
||||
if ( PR_Seek( mFd, aItem->offset, PR_SEEK_SET ) != (PRInt32)aItem->offset )
|
||||
#else
|
||||
// For standalone, PR_Seek() is stubbed with fseek(), which returns 0
|
||||
// if successfull, otherwise a non-zero.
|
||||
if ( PR_Seek( mFd, aItem->offset, PR_SEEK_SET ) != 0 )
|
||||
#endif
|
||||
{
|
||||
status = ZIP_ERR_CORRUPT;
|
||||
goto cleanup;
|
||||
@ -655,13 +656,7 @@ PRInt32 nsZipArchive::InflateItemToDisk( const nsZipItem* aItem, const char* aOu
|
||||
}
|
||||
|
||||
//-- find start of file in archive
|
||||
#ifndef STANDALONE
|
||||
if ( PR_Seek( mFd, aItem->offset, PR_SEEK_SET ) != (PRInt32)aItem->offset )
|
||||
#else
|
||||
// For standalone, PR_Seek() is stubbed with fseek(), which returns 0
|
||||
// if successfull, otherwise a non-zero.
|
||||
if ( PR_Seek( mFd, aItem->offset, PR_SEEK_SET ) != 0 )
|
||||
#endif
|
||||
{
|
||||
status = ZIP_ERR_CORRUPT;
|
||||
goto cleanup;
|
||||
@ -839,6 +834,17 @@ nsZipFind::~nsZipFind()
|
||||
PL_strfree( mPattern );
|
||||
}
|
||||
|
||||
//------------------------------------------
|
||||
// nsZipFind::GetArchive
|
||||
//------------------------------------------
|
||||
nsZipArchive* nsZipFind::GetArchive()
|
||||
{
|
||||
if (!mArchive)
|
||||
return NULL;
|
||||
|
||||
return mArchive;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -876,3 +882,5 @@ static PRUint32 xtolong (unsigned char *ll)
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
@ -20,8 +20,11 @@
|
||||
*
|
||||
* Contributors:
|
||||
* Daniel Veditz <dveditz@netscape.com>
|
||||
* Samir Gehani <sgehani@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef nsZipArchive_h_
|
||||
#define nsZipArchive_h_
|
||||
|
||||
#define ZIP_MAGIC 0x5A49505FL /* "ZIP_" */
|
||||
#define ZIPFIND_MAGIC 0x5A495046L /* "ZIPF" */
|
||||
@ -30,7 +33,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
class nsZipFind;
|
||||
|
||||
/**
|
||||
@ -61,6 +63,7 @@ private:
|
||||
//-- prevent copies and assignments
|
||||
nsZipItem& operator=(const nsZipItem& rhs);
|
||||
nsZipItem(const nsZipItem& rhs);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -119,10 +122,9 @@ public:
|
||||
* FindNext
|
||||
*
|
||||
* @param aFind the Find structure returned by FindInit
|
||||
* @param aBuf A buffer to hold filenames that match pattern
|
||||
* @param aSize size of the buffer
|
||||
* @param aResult the next item that matches the pattern
|
||||
*/
|
||||
PRInt32 FindNext( nsZipFind* aFind, char * aBuf, PRUint16 aSize );
|
||||
PRInt32 FindNext( nsZipFind* aFind, nsZipItem** aResult);
|
||||
|
||||
PRInt32 FindFree( nsZipFind *aFind );
|
||||
|
||||
@ -155,14 +157,19 @@ private:
|
||||
class nsZipFind
|
||||
{
|
||||
friend class nsZipArchive;
|
||||
#ifdef STANDALONE
|
||||
friend PRInt32 ZIP_FindNext( void*, char*, PRUint16 );
|
||||
friend PRInt32 ZIP_FindFree( void* );
|
||||
#endif
|
||||
|
||||
public:
|
||||
const PRInt32 kMagic;
|
||||
|
||||
nsZipFind( nsZipArchive* aZip, char* aPattern, PRBool regExp );
|
||||
~nsZipFind();
|
||||
|
||||
nsZipArchive* GetArchive();
|
||||
|
||||
private:
|
||||
nsZipArchive* mArchive;
|
||||
char* mPattern;
|
||||
@ -174,3 +181,5 @@ private:
|
||||
nsZipFind& operator=(const nsZipFind& rhs);
|
||||
nsZipFind(const nsZipFind& rhs);
|
||||
};
|
||||
|
||||
#endif /* nsZipArchive_h_ */
|
@ -44,6 +44,7 @@
|
||||
#define ZIP_ERR_UNSUPPORTED -7
|
||||
#define ZIP_ERR_SMALLBUF -8
|
||||
|
||||
#ifdef STANDALONE
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
@ -84,4 +85,7 @@ PR_EXTERN(PRInt32) ZIP_FindFree( void* hFind );
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* STANDALONE */
|
||||
|
||||
|
||||
#endif /* _zipfile_h */
|
||||
|
Loading…
Reference in New Issue
Block a user