mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-26 22:32:46 +00:00
Bug 1178991 - smartptr for http converter r=hurley
--HG-- extra : rebase_source : 26ae963839aaf0ad73ecdfd0b11c53e5b1c7ccac
This commit is contained in:
parent
58f89fd9e6
commit
4988c8b53f
@ -15,7 +15,6 @@
|
||||
#include "nsThreadUtils.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
|
||||
// nsISupports implementation
|
||||
NS_IMPL_ISUPPORTS(nsHTTPCompressConv,
|
||||
nsIStreamConverter,
|
||||
@ -24,8 +23,7 @@ NS_IMPL_ISUPPORTS(nsHTTPCompressConv,
|
||||
|
||||
// nsFTPDirListingConv methods
|
||||
nsHTTPCompressConv::nsHTTPCompressConv()
|
||||
: mListener(nullptr)
|
||||
, mMode(HTTP_COMPRESS_IDENTITY)
|
||||
: mMode(HTTP_COMPRESS_IDENTITY)
|
||||
, mOutBuffer(nullptr)
|
||||
, mInpBuffer(nullptr)
|
||||
, mOutBufferLen(0)
|
||||
@ -48,8 +46,6 @@ nsHTTPCompressConv::nsHTTPCompressConv()
|
||||
|
||||
nsHTTPCompressConv::~nsHTTPCompressConv()
|
||||
{
|
||||
NS_IF_RELEASE(mListener);
|
||||
|
||||
if (mInpBuffer)
|
||||
free(mInpBuffer);
|
||||
|
||||
@ -63,38 +59,36 @@ nsHTTPCompressConv::~nsHTTPCompressConv()
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::AsyncConvertData(const char *aFromType,
|
||||
const char *aToType,
|
||||
nsIStreamListener *aListener,
|
||||
nsHTTPCompressConv::AsyncConvertData(const char *aFromType,
|
||||
const char *aToType,
|
||||
nsIStreamListener *aListener,
|
||||
nsISupports *aCtxt)
|
||||
{
|
||||
if (!PL_strncasecmp(aFromType, HTTP_COMPRESS_TYPE, sizeof(HTTP_COMPRESS_TYPE)-1) ||
|
||||
!PL_strncasecmp(aFromType, HTTP_X_COMPRESS_TYPE, sizeof(HTTP_X_COMPRESS_TYPE)-1))
|
||||
!PL_strncasecmp(aFromType, HTTP_X_COMPRESS_TYPE, sizeof(HTTP_X_COMPRESS_TYPE)-1)) {
|
||||
mMode = HTTP_COMPRESS_COMPRESS;
|
||||
|
||||
else if (!PL_strncasecmp(aFromType, HTTP_GZIP_TYPE, sizeof(HTTP_GZIP_TYPE)-1) ||
|
||||
!PL_strncasecmp(aFromType, HTTP_X_GZIP_TYPE, sizeof(HTTP_X_GZIP_TYPE)-1))
|
||||
} else if (!PL_strncasecmp(aFromType, HTTP_GZIP_TYPE, sizeof(HTTP_GZIP_TYPE)-1) ||
|
||||
!PL_strncasecmp(aFromType, HTTP_X_GZIP_TYPE, sizeof(HTTP_X_GZIP_TYPE)-1)) {
|
||||
mMode = HTTP_COMPRESS_GZIP;
|
||||
|
||||
else if (!PL_strncasecmp(aFromType, HTTP_DEFLATE_TYPE, sizeof(HTTP_DEFLATE_TYPE)-1))
|
||||
} else if (!PL_strncasecmp(aFromType, HTTP_DEFLATE_TYPE, sizeof(HTTP_DEFLATE_TYPE)-1)) {
|
||||
mMode = HTTP_COMPRESS_DEFLATE;
|
||||
}
|
||||
|
||||
// hook ourself up with the receiving listener.
|
||||
// hook ourself up with the receiving listener.
|
||||
mListener = aListener;
|
||||
NS_ADDREF(mListener);
|
||||
|
||||
mAsyncConvContext = aCtxt;
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::OnStartRequest(nsIRequest* request, nsISupports *aContext)
|
||||
{
|
||||
return mListener->OnStartRequest(request, aContext);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::OnStopRequest(nsIRequest* request, nsISupports *aContext,
|
||||
nsHTTPCompressConv::OnStopRequest(nsIRequest* request, nsISupports *aContext,
|
||||
nsresult aStatus)
|
||||
{
|
||||
// Framing integrity is enforced for content-encoding: gzip, but not for
|
||||
@ -106,13 +100,13 @@ nsHTTPCompressConv::OnStopRequest(nsIRequest* request, nsISupports *aContext,
|
||||
aStatus = NS_ERROR_NET_PARTIAL_TRANSFER;
|
||||
}
|
||||
return mListener->OnStopRequest(request, aContext, aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
nsISupports *aContext,
|
||||
nsIInputStream *iStr,
|
||||
uint64_t aSourceOffset,
|
||||
nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
nsISupports *aContext,
|
||||
nsIInputStream *iStr,
|
||||
uint64_t aSourceOffset,
|
||||
uint32_t aCount)
|
||||
{
|
||||
nsresult rv = NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
@ -151,7 +145,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
if (mInpBuffer != nullptr && streamLen > mInpBufferLen)
|
||||
{
|
||||
mInpBuffer = (unsigned char *) realloc(mInpBuffer, mInpBufferLen = streamLen);
|
||||
|
||||
|
||||
if (mOutBufferLen < streamLen * 2)
|
||||
mOutBuffer = (unsigned char *) realloc(mOutBuffer, mOutBufferLen = streamLen * 3);
|
||||
|
||||
@ -176,7 +170,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
if (!mStreamInitialized)
|
||||
{
|
||||
memset(&d_stream, 0, sizeof (d_stream));
|
||||
|
||||
|
||||
if (inflateInit(&d_stream) != Z_OK)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -190,7 +184,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
{
|
||||
d_stream.next_out = mOutBuffer;
|
||||
d_stream.avail_out = (uInt)mOutBufferLen;
|
||||
|
||||
|
||||
int code = inflate(&d_stream, Z_NO_FLUSH);
|
||||
unsigned bytesWritten = (uInt)mOutBufferLen - d_stream.avail_out;
|
||||
|
||||
@ -202,7 +196,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
if (NS_FAILED (rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
inflateEnd(&d_stream);
|
||||
mStreamEnded = true;
|
||||
break;
|
||||
@ -253,9 +247,9 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
// reset stream pointers to our original data
|
||||
d_stream.next_in = mInpBuffer;
|
||||
d_stream.avail_in = (uInt)streamLen;
|
||||
}
|
||||
else
|
||||
} else {
|
||||
return NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
}
|
||||
} /* for */
|
||||
}
|
||||
else
|
||||
@ -263,7 +257,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
if (!mStreamInitialized)
|
||||
{
|
||||
memset(&d_stream, 0, sizeof (d_stream));
|
||||
|
||||
|
||||
if (inflateInit2(&d_stream, -MAX_WBITS) != Z_OK)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
@ -277,7 +271,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
{
|
||||
d_stream.next_out = mOutBuffer;
|
||||
d_stream.avail_out = (uInt)mOutBufferLen;
|
||||
|
||||
|
||||
int code = inflate (&d_stream, Z_NO_FLUSH);
|
||||
unsigned bytesWritten = (uInt)mOutBufferLen - d_stream.avail_out;
|
||||
|
||||
@ -289,7 +283,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
if (NS_FAILED (rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
inflateEnd(&d_stream);
|
||||
mStreamEnded = true;
|
||||
break;
|
||||
@ -319,7 +313,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
} /* gzip */
|
||||
break;
|
||||
|
||||
default:
|
||||
default:
|
||||
rv = mListener->OnDataAvailable(request, aContext, iStr, aSourceOffset, aCount);
|
||||
if (NS_FAILED (rv))
|
||||
return rv;
|
||||
@ -332,14 +326,14 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
||||
// XXX/ruslan: need to implement this too
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::Convert(nsIInputStream *aFromStream,
|
||||
const char *aFromType,
|
||||
const char *aToType,
|
||||
nsISupports *aCtxt,
|
||||
nsHTTPCompressConv::Convert(nsIInputStream *aFromStream,
|
||||
const char *aFromType,
|
||||
const char *aToType,
|
||||
nsISupports *aCtxt,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTTPCompressConv::do_OnDataAvailable(nsIRequest* request,
|
||||
@ -391,7 +385,7 @@ nsHTTPCompressConv::check_header(nsIInputStream *iStr, uint32_t streamLen, nsres
|
||||
uint32_t unused;
|
||||
iStr->Read(&c, 1, &unused);
|
||||
streamLen--;
|
||||
|
||||
|
||||
if (mSkipCount == 0 && ((unsigned)c & 0377) != gz_magic[0])
|
||||
{
|
||||
*rs = NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
@ -432,7 +426,7 @@ nsHTTPCompressConv::check_header(nsIInputStream *iStr, uint32_t streamLen, nsres
|
||||
if (mSkipCount == 6)
|
||||
hMode = GZIP_EXTRA0;
|
||||
break;
|
||||
|
||||
|
||||
case GZIP_EXTRA0:
|
||||
if (mFlags & EXTRA_FIELD)
|
||||
{
|
||||
|
@ -43,28 +43,27 @@ public:
|
||||
// nsISupports methods
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
// nsIStreamConverter methods
|
||||
NS_DECL_NSISTREAMCONVERTER
|
||||
|
||||
|
||||
nsHTTPCompressConv ();
|
||||
|
||||
private:
|
||||
|
||||
virtual ~nsHTTPCompressConv ();
|
||||
|
||||
nsIStreamListener *mListener; // this guy gets the converted data via his OnDataAvailable ()
|
||||
CompressMode mMode;
|
||||
nsCOMPtr<nsIStreamListener> mListener; // this guy gets the converted data via his OnDataAvailable ()
|
||||
CompressMode mMode;
|
||||
|
||||
unsigned char *mOutBuffer;
|
||||
unsigned char *mInpBuffer;
|
||||
|
||||
uint32_t mOutBufferLen;
|
||||
uint32_t mInpBufferLen;
|
||||
|
||||
|
||||
nsCOMPtr<nsISupports> mAsyncConvContext;
|
||||
nsCOMPtr<nsIStringInputStream> mStream;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user