1999-10-26 23:43:26 +04:00
|
|
|
/* nsJARInputStream.cpp
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Netscape Communicator source code.
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1999 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Mitch Stoltz <mstoltz@netscape.com>
|
|
|
|
*/
|
|
|
|
#include "nsJARInputStream.h"
|
|
|
|
#include "zipfile.h" // defines ZIP error codes
|
|
|
|
#include "nsZipArchive.h"
|
|
|
|
|
|
|
|
|
|
|
|
/*---------------------------------------------
|
|
|
|
* nsISupports implementation
|
|
|
|
*--------------------------------------------*/
|
|
|
|
|
2001-01-24 01:10:34 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputStream, nsIInputStream);
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
/*----------------------------------------------------------
|
|
|
|
* nsJARInputStream implementation
|
|
|
|
*--------------------------------------------------------*/
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::Available(PRUint32 *_retval)
|
|
|
|
{
|
2000-03-30 11:41:37 +04:00
|
|
|
if (Zip() == 0)
|
1999-10-26 23:43:26 +04:00
|
|
|
*_retval = 0;
|
|
|
|
else
|
2000-03-30 11:41:37 +04:00
|
|
|
*_retval = Zip()->Available(mReadInfo);
|
1999-10-26 23:43:26 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-02-14 04:57:01 +03:00
|
|
|
nsJARInputStream::Read(char* buf, PRUint32 count, PRUint32 *bytesRead)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2000-03-30 11:41:37 +04:00
|
|
|
if (Zip() == nsnull)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2000-02-14 04:57:01 +03:00
|
|
|
*bytesRead = 0;
|
2000-01-29 03:03:57 +03:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
2000-03-30 11:41:37 +04:00
|
|
|
PRInt32 err = Zip()->Read(mReadInfo, buf, count, bytesRead);
|
|
|
|
#ifdef DEBUG_warren
|
2000-10-29 02:17:53 +04:00
|
|
|
// printf("read %d from %s\n", *bytesRead, mEntryName);
|
2000-03-30 11:41:37 +04:00
|
|
|
#endif
|
|
|
|
return err == ZIP_OK ? NS_OK : NS_ERROR_FAILURE;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
2000-08-22 11:03:33 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::ReadSegments(nsWriteSegmentFun writer, void * closure, PRUint32 count, PRUint32 *_retval)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("ReadSegments");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::GetNonBlocking(PRBool *aNonBlocking)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("GetNonBlocking");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::GetObserver(nsIInputStreamObserver * *aObserver)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("GetObserver");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::SetObserver(nsIInputStreamObserver * aObserver)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("SetObserver");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-10-26 23:43:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARInputStream::Close()
|
|
|
|
{
|
2000-04-05 04:12:20 +04:00
|
|
|
NS_IF_RELEASE(mJAR);
|
1999-11-03 02:46:09 +03:00
|
|
|
delete mReadInfo;
|
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2000-07-12 07:10:33 +04:00
|
|
|
nsJARInputStream::Init(nsJAR* aJAR, const char* aFilename)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
2000-03-30 11:41:37 +04:00
|
|
|
if (!aFilename)
|
1999-10-26 23:43:26 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
2000-03-30 11:41:37 +04:00
|
|
|
mJAR = aJAR;
|
|
|
|
NS_ADDREF(mJAR);
|
|
|
|
mEntryName = nsCRT::strdup(aFilename);
|
2000-01-29 03:03:57 +03:00
|
|
|
|
1999-11-03 02:46:09 +03:00
|
|
|
PRInt32 result;
|
2000-03-30 11:41:37 +04:00
|
|
|
result = Zip()->ReadInit(mEntryName, &mReadInfo);
|
1999-10-26 23:43:26 +04:00
|
|
|
if (result != ZIP_OK)
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-02-14 04:57:01 +03:00
|
|
|
return NS_OK;
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsJARInputStream::Create(nsISupports* ignored, const nsIID& aIID, void* *aResult)
|
|
|
|
{
|
|
|
|
nsJARInputStream* is = new nsJARInputStream();
|
|
|
|
if (is == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(is);
|
|
|
|
nsresult rv = is->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(is);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------
|
|
|
|
// nsJARInputStream constructor and destructor
|
|
|
|
//----------------------------------------------
|
|
|
|
|
2000-01-29 03:03:57 +03:00
|
|
|
nsJARInputStream::nsJARInputStream()
|
2000-03-30 11:41:37 +04:00
|
|
|
: mJAR(nsnull), mEntryName(nsnull), mReadInfo(nsnull)
|
1999-10-26 23:43:26 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsJARInputStream::~nsJARInputStream()
|
|
|
|
{
|
2000-01-29 03:03:57 +03:00
|
|
|
Close();
|
2000-03-30 11:41:37 +04:00
|
|
|
if (mEntryName) nsCRT::free(mEntryName);
|
1999-10-26 23:43:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|