Fixing bugs in jar input streams for jar: protocol.
git-svn-id: svn://10.0.0.236/trunk@64584 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -271,7 +271,7 @@ nsJAR::GetInputStream(const char *aFilename, nsIInputStream **result)
|
||||
{
|
||||
if (!result)
|
||||
return NS_OK;
|
||||
return CreateInputStream(aFilename, this, result);
|
||||
return CreateInputStream(aFilename, result);
|
||||
}
|
||||
|
||||
//-- The following #defines are used by ParseManifest()
|
||||
@@ -414,29 +414,28 @@ nsJAR::GetCertificatePrincipal(const char* aFilename, nsIPrincipal** aPrincipal,
|
||||
//----------------------------------------------
|
||||
|
||||
nsresult
|
||||
nsJAR::CreateInputStream(const char* aFilename, nsJAR* aJAR, nsIInputStream **is)
|
||||
nsJAR::CreateInputStream(const char* aFilename, nsIInputStream **is)
|
||||
{
|
||||
nsresult rv;
|
||||
nsJARInputStream* jis = nsnull;
|
||||
rv = nsJARInputStream::Create(nsnull, NS_GET_IID(nsIInputStream), (void**)&jis);
|
||||
if (!jis) return NS_ERROR_FAILURE;
|
||||
|
||||
rv = jis->Init(aJAR, &mZip, aFilename);
|
||||
rv = jis->Init(this, aFilename);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
*is = (nsIInputStream*)jis;
|
||||
NS_ADDREF(*is);
|
||||
// NS_ADDREF(*is); // done by Create, above
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJAR::LoadEntry(const char* aFilename, char** aBuf,
|
||||
PRUint32* aBufLen)
|
||||
nsJAR::LoadEntry(const char* aFilename, const char** aBuf, PRUint32* aBufLen)
|
||||
{
|
||||
//-- Get a stream for reading the manifest file
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStream> manifestStream;
|
||||
rv = CreateInputStream(aFilename, nsnull, getter_AddRefs(manifestStream));
|
||||
rv = CreateInputStream(aFilename, getter_AddRefs(manifestStream));
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FILE_TARGET_DOES_NOT_EXIST;
|
||||
|
||||
//-- Read the manifest file into memory
|
||||
|
||||
@@ -73,6 +73,8 @@ class nsJAR : public nsIZipReader
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIZIPREADER
|
||||
|
||||
friend class nsJARInputStream;
|
||||
|
||||
private:
|
||||
//-- Private data members
|
||||
@@ -82,9 +84,8 @@ class nsJAR : public nsIZipReader
|
||||
PRBool step1Complete; // True if manifest has been parsed
|
||||
|
||||
//-- Private functions
|
||||
nsresult CreateInputStream(const char* aFilename, nsJAR* aJAR,
|
||||
nsIInputStream** is);
|
||||
nsresult LoadEntry(const char* aFilename, char** aBuf,
|
||||
nsresult CreateInputStream(const char* aFilename, nsIInputStream** is);
|
||||
nsresult LoadEntry(const char* aFilename, const char** aBuf,
|
||||
PRUint32* aBufLen = nsnull);
|
||||
PRInt32 ReadLine(const char** src);
|
||||
nsresult ParseOneFile(const char* filebuf, PRInt16 aFileType,
|
||||
|
||||
@@ -37,10 +37,10 @@ NS_IMPL_ISUPPORTS1(nsJARInputStream, nsIInputStream);
|
||||
NS_IMETHODIMP
|
||||
nsJARInputStream::Available(PRUint32 *_retval)
|
||||
{
|
||||
if (mZip == 0)
|
||||
if (Zip() == 0)
|
||||
*_retval = 0;
|
||||
else
|
||||
*_retval = mZip->Available(mReadInfo);
|
||||
*_retval = Zip()->Available(mReadInfo);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -48,35 +48,38 @@ nsJARInputStream::Available(PRUint32 *_retval)
|
||||
NS_IMETHODIMP
|
||||
nsJARInputStream::Read(char* buf, PRUint32 count, PRUint32 *bytesRead)
|
||||
{
|
||||
if (mZip == nsnull)
|
||||
if (Zip() == nsnull)
|
||||
{
|
||||
*bytesRead = 0;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if( (mZip->Read(mReadInfo, buf, count, bytesRead)) != ZIP_OK )
|
||||
return NS_ERROR_FAILURE;
|
||||
else
|
||||
return NS_OK;
|
||||
PRInt32 err = Zip()->Read(mReadInfo, buf, count, bytesRead);
|
||||
#ifdef DEBUG_warren
|
||||
// printf("read %d from %s\n", *bytesRead, mEntryName);
|
||||
#endif
|
||||
return err == ZIP_OK ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARInputStream::Close()
|
||||
{
|
||||
NS_RELEASE(mJAR);
|
||||
delete mReadInfo;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARInputStream::Init(nsJAR* aJAR, nsZipArchive* aZip, const char* aFilename)
|
||||
nsJARInputStream::Init(nsJAR* aJAR, const char* aFilename)
|
||||
{
|
||||
if (!(aZip && aFilename))
|
||||
if (!aFilename)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
mZip = aZip;
|
||||
mEntryName = (char*)aFilename;
|
||||
mJAR = aJAR;
|
||||
NS_ADDREF(mJAR);
|
||||
mEntryName = nsCRT::strdup(aFilename);
|
||||
|
||||
PRInt32 result;
|
||||
result = mZip->ReadInit(mEntryName, &mReadInfo);
|
||||
result = Zip()->ReadInit(mEntryName, &mReadInfo);
|
||||
if (result != ZIP_OK)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@@ -104,6 +107,7 @@ nsJARInputStream::Create(nsISupports* ignored, const nsIID& aIID, void* *aResult
|
||||
//----------------------------------------------
|
||||
|
||||
nsJARInputStream::nsJARInputStream()
|
||||
: mJAR(nsnull), mEntryName(nsnull), mReadInfo(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
@@ -111,6 +115,7 @@ nsJARInputStream::nsJARInputStream()
|
||||
nsJARInputStream::~nsJARInputStream()
|
||||
{
|
||||
Close();
|
||||
if (mEntryName) nsCRT::free(mEntryName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,13 +56,15 @@ class nsJARInputStream : public nsIInputStream
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult
|
||||
Init(nsJAR* aParser, nsZipArchive* aZip, const char* aFilename);
|
||||
Init(nsJAR* jar, const char* aFilename);
|
||||
|
||||
private:
|
||||
|
||||
char* mEntryName;
|
||||
nsZipArchive* mZip;
|
||||
nsZipRead* mReadInfo;
|
||||
protected:
|
||||
nsZipArchive* Zip() { return &mJAR->mZip; }
|
||||
|
||||
protected:
|
||||
nsJAR* mJAR;
|
||||
char* mEntryName;
|
||||
nsZipRead* mReadInfo;
|
||||
};
|
||||
|
||||
#endif /* nsJAR_h__ */
|
||||
|
||||
Reference in New Issue
Block a user