diff --git a/modules/libjar/Makefile.in b/modules/libjar/Makefile.in index 90b16b85625e..73e6097820c7 100644 --- a/modules/libjar/Makefile.in +++ b/modules/libjar/Makefile.in @@ -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 \ diff --git a/modules/libjar/makefile.win b/modules/libjar/makefile.win index d371b369ef84..5429fe509d85 100644 --- a/modules/libjar/makefile.win +++ b/modules/libjar/makefile.win @@ -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 diff --git a/modules/libjar/nsIJAR.h b/modules/libjar/nsIJAR.h deleted file mode 100644 index 781f12965fe6..000000000000 --- a/modules/libjar/nsIJAR.h +++ /dev/null @@ -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 - */ - - -#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__ diff --git a/modules/libjar/nsIJAR.idl b/modules/libjar/nsIJAR.idl new file mode 100644 index 000000000000..0052e46715cf --- /dev/null +++ b/modules/libjar/nsIJAR.idl @@ -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 + * Don Bragg + * Samir Gehani + */ + +#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; +}; diff --git a/modules/libjar/nsIZip.h b/modules/libjar/nsIZip.idl similarity index 57% rename from modules/libjar/nsIZip.h rename to modules/libjar/nsIZip.idl index 173e1a53f7e6..afcf9d3ffa3c 100644 --- a/modules/libjar/nsIZip.h +++ b/modules/libjar/nsIZip.idl @@ -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 * Don Bragg + * Samir Gehani */ +#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__ diff --git a/modules/libjar/nsJAR.cpp b/modules/libjar/nsJAR.cpp index 5e9013026c94..d6b2f0c50a8c 100644 --- a/modules/libjar/nsJAR.cpp +++ b/modules/libjar/nsJAR.cpp @@ -20,6 +20,7 @@ * * Contributors: * Daniel Veditz + * Samir Gehani */ #include @@ -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; +} diff --git a/modules/libjar/nsJAR.h b/modules/libjar/nsJAR.h index cd0effd9b664..20a518aa1ca4 100644 --- a/modules/libjar/nsJAR.h +++ b/modules/libjar/nsJAR.h @@ -20,6 +20,7 @@ * * Contributors: * Don Bragg + * Samir Gehani */ @@ -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__ */ diff --git a/modules/libjar/nsJARFactory.cpp b/modules/libjar/nsJARFactory.cpp index 99ad0910705c..4ef93ecf1f51 100644 --- a/modules/libjar/nsJARFactory.cpp +++ b/modules/libjar/nsJARFactory.cpp @@ -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 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 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; } diff --git a/modules/libjar/nsZipArchive.cpp b/modules/libjar/nsZipArchive.cpp index ffe310407764..17d44791037f 100644 --- a/modules/libjar/nsZipArchive.cpp +++ b/modules/libjar/nsZipArchive.cpp @@ -20,6 +20,7 @@ * * Contributors: * Daniel Veditz + * Samir Gehani */ /* @@ -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; } + + diff --git a/modules/libjar/nsZipArchive.h b/modules/libjar/nsZipArchive.h index 93213eb616ce..92e7ff6e3a3c 100644 --- a/modules/libjar/nsZipArchive.h +++ b/modules/libjar/nsZipArchive.h @@ -20,8 +20,11 @@ * * Contributors: * Daniel Veditz + * Samir Gehani */ +#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_ */ \ No newline at end of file diff --git a/modules/libjar/zipfile.h b/modules/libjar/zipfile.h index ca810e3ef6e0..3a4dc92f5619 100644 --- a/modules/libjar/zipfile.h +++ b/modules/libjar/zipfile.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 */