Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Private Member Functions | Private Attributes
nsHTTPCompressConv Class Reference

#include <nsHTTPCompressConv.h>

Inheritance diagram for nsHTTPCompressConv:
Inheritance graph
[legend]
Collaboration diagram for nsHTTPCompressConv:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSISTREAMCONVERTER 
nsHTTPCompressConv ()
virtual ~nsHTTPCompressConv ()
nsIInputStream convert (in nsIInputStream aFromStream, in string aFromType, in string aToType, in nsISupports aCtxt)
 SYNCRONOUS VERSION Converts a stream of one type, to a stream of another type.
void asyncConvertData (in string aFromType, in string aToType, in nsIStreamListener aListener, in nsISupports aCtxt)
 ASYNCRONOUS VERSION Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() method from one type to another, pushing the converted data out to the caller via aListener::OnDataAvailable().
void onDataAvailable (in nsIRequest aRequest, in nsISupports aContext, in nsIInputStream aInputStream, in unsigned long aOffset, in unsigned long aCount)
 Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.
void onStartRequest (in nsIRequest aRequest, in nsISupports aContext)
 Called to signify the beginning of an asynchronous request.
void onStopRequest (in nsIRequest aRequest, in nsISupports aContext, in nsresult aStatusCode)
 Called to signify the end of an asynchronous request.

Private Member Functions

nsresult do_OnDataAvailable (nsIRequest *request, nsISupports *aContext, PRUint32 aSourceOffset, char *buffer, PRUint32 aCount)
PRUint32 check_header (nsIInputStream *iStr, PRUint32 streamLen, nsresult *rv)

Private Attributes

nsIStreamListenermListener
CompressMode mMode
unsigned char * mOutBuffer
unsigned char * mInpBuffer
PRUint32 mOutBufferLen
PRUint32 mInpBufferLen
nsCOMPtr< nsISupports > mAsyncConvContext
PRBool mCheckHeaderDone
PRBool mStreamEnded
PRBool mStreamInitialized
PRBool mDummyStreamInitialised
z_stream d_stream
unsigned mLen
unsigned hMode
unsigned mSkipCount
unsigned mFlags

Detailed Description

Definition at line 73 of file nsHTTPCompressConv.h.


Constructor & Destructor Documentation

Definition at line 66 of file nsHTTPCompressConv.cpp.

Here is the caller graph for this function:

Definition at line 83 of file nsHTTPCompressConv.cpp.

{
    NS_IF_RELEASE(mListener);

    if (mInpBuffer)
        nsMemory::Free(mInpBuffer);

    if (mOutBuffer)
        nsMemory::Free(mOutBuffer);

    // For some reason we are not getting Z_STREAM_END.  But this was also seen
    //    for mozilla bug 198133.  Need to handle this case.
    if ((mStreamInitialized == PR_TRUE) && (mStreamEnded == PR_FALSE))
        inflateEnd (&d_stream);
}

Member Function Documentation

void nsIStreamConverter::asyncConvertData ( in string  aFromType,
in string  aToType,
in nsIStreamListener  aListener,
in nsISupports  aCtxt 
) [inherited]

ASYNCRONOUS VERSION Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() method from one type to another, pushing the converted data out to the caller via aListener::OnDataAvailable().

Use this method when you want to proxy (and convert) nsIStreamListener callbacks asynchronously.

Parameters:
aFromTypeThe MIME type of the original/raw data.
aToTypeThe MIME type of the converted data.
aListenerThe listener who receives the converted data.
aCtxtEither an opaque context, or a converter specific context (implementation specific).
PRUint32 nsHTTPCompressConv::check_header ( nsIInputStream iStr,
PRUint32  streamLen,
nsresult rv 
) [private]

Definition at line 403 of file nsHTTPCompressConv.cpp.

{
    nsresult rv;
    enum  { GZIP_INIT = 0, GZIP_OS, GZIP_EXTRA0, GZIP_EXTRA1, GZIP_EXTRA2, GZIP_ORIG, GZIP_COMMENT, GZIP_CRC };
    char c;

    *rs = NS_OK;

    if (mCheckHeaderDone)
        return streamLen;

    while (streamLen)
    {
        switch (hMode)
        {
            case GZIP_INIT:
                iStr->Read (&c, 1, &rv);
                streamLen--;
                
                if (mSkipCount == 0 && ((unsigned)c & 0377) != gz_magic[0])
                {
                    *rs = NS_ERROR_FAILURE;
                    return 0;
                }

                if (mSkipCount == 1 && ((unsigned)c & 0377) != gz_magic[1])
                {
                    *rs = NS_ERROR_FAILURE;
                    return 0;
                }

                if (mSkipCount == 2 && ((unsigned)c & 0377) != Z_DEFLATED)
                {
                    *rs = NS_ERROR_FAILURE;
                    return 0;
                }

                mSkipCount++;
                if (mSkipCount == 4)
                {
                    mFlags = (unsigned) c & 0377;
                    if (mFlags & RESERVED)
                    {
                        *rs = NS_ERROR_FAILURE;
                        return 0;
                    }
                    hMode = GZIP_OS;
                    mSkipCount = 0;
                }
                break;

            case GZIP_OS:
                iStr->Read(&c, 1, &rv);
                streamLen--;
                mSkipCount++;

                if (mSkipCount == 6)
                    hMode = GZIP_EXTRA0;
                break;
        
            case GZIP_EXTRA0:
                if (mFlags & EXTRA_FIELD)
                {
                    iStr->Read(&c, 1, &rv);
                    streamLen--;
                    mLen = (uInt) c & 0377;
                    hMode = GZIP_EXTRA1;
                }
                else
                    hMode = GZIP_ORIG;
                break;

            case GZIP_EXTRA1:
                iStr->Read(&c, 1, &rv);
                streamLen--;
                mLen = ((uInt) c & 0377) << 8;
                mSkipCount = 0;
                hMode = GZIP_EXTRA2;
                break;

            case GZIP_EXTRA2:
                if (mSkipCount == mLen)
                    hMode = GZIP_ORIG;
                else
                {
                    iStr->Read(&c, 1, &rv);
                    streamLen--;
                    mSkipCount++;
                }
                break;

            case GZIP_ORIG:
                if (mFlags & ORIG_NAME)
                {
                    iStr->Read(&c, 1, &rv);
                    streamLen--;
                    if (c == 0)
                        hMode = GZIP_COMMENT;
                }
                else
                    hMode = GZIP_COMMENT;
                break;

            case GZIP_COMMENT:
                if (mFlags & GZIP_COMMENT)
                {
                    iStr->Read(&c, 1, &rv);
                    streamLen--;
                    if (c == 0)
                    {
                        hMode = GZIP_CRC;
                        mSkipCount = 0;
                    }
                }
                else
                {
                    hMode = GZIP_CRC;
                    mSkipCount = 0;
                }
                break;

            case GZIP_CRC:
                if (mFlags & HEAD_CRC)
                {
                    iStr->Read(&c, 1, &rv);
                    streamLen--;
                    mSkipCount++;
                    if (mSkipCount == 2)
                    {
                        mCheckHeaderDone = PR_TRUE;
                        return streamLen;
                    }
                }
                else
                {
                    mCheckHeaderDone = PR_TRUE;
                    return streamLen;
                }
            break;
        }
    }
    return streamLen;
}
nsIInputStream nsIStreamConverter::convert ( in nsIInputStream  aFromStream,
in string  aFromType,
in string  aToType,
in nsISupports  aCtxt 
) [inherited]

SYNCRONOUS VERSION Converts a stream of one type, to a stream of another type.

Use this method when you have a stream you want to convert.

Parameters:
aFromStreamThe stream representing the original/raw data.
aFromTypeThe MIME type of aFromStream.
aToTypeThe MIME type of the returned stream.
aCtxtEither an opaque context, or a converter specific context (implementation specific).
Returns:
The converted stream. NOTE: The returned stream may not already be converted. An efficient stream converter implementation will converter data on demand rather than buffering the converted data until it is used.
nsresult nsHTTPCompressConv::do_OnDataAvailable ( nsIRequest request,
nsISupports *  aContext,
PRUint32  aSourceOffset,
char *  buffer,
PRUint32  aCount 
) [private]

Definition at line 370 of file nsHTTPCompressConv.cpp.

{
    nsresult rv;

    nsCOMPtr<nsIByteArrayInputStream> convertedStreamSup;

    char *lBuf = (char *) nsMemory::Alloc (aCount);
    if (lBuf == NULL)
        return NS_ERROR_OUT_OF_MEMORY;

    memcpy(lBuf, buffer, aCount);

    rv = NS_NewByteArrayInputStream(getter_AddRefs(convertedStreamSup), lBuf, aCount);
    if (NS_FAILED(rv))
        return rv;

    nsCOMPtr<nsIInputStream> convertedStream = do_QueryInterface(convertedStreamSup, &rv);
    if (NS_FAILED(rv))
        return rv;

    return mListener->OnDataAvailable(request, aContext, convertedStream, aSourceOffset, aCount);
}

Here is the call graph for this function:

void nsIStreamListener::onDataAvailable ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsIInputStream  aInputStream,
in unsigned long  aOffset,
in unsigned long  aCount 
) [inherited]

Called when the next chunk of data (corresponding to the request) may be read without blocking the calling thread.

The onDataAvailable impl must read exactly |aCount| bytes of data before returning.

Parameters:
aRequestrequest corresponding to the source of the data
aContextuser defined context
aInputStreaminput stream containing the data chunk
aOffsetNumber of bytes that were sent in previous onDataAvailable calls for this request. In other words, the sum of all previous count parameters. If that number is greater than or equal to 2^32, this parameter will be PR_UINT32_MAX (2^32 - 1).
aCountnumber of bytes available in the stream

NOTE: The aInputStream parameter must implement readSegments.

An exception thrown from onDataAvailable has the side-effect of causing the request to be canceled.

void nsIRequestObserver::onStartRequest ( in nsIRequest  aRequest,
in nsISupports  aContext 
) [inherited]

Called to signify the beginning of an asynchronous request.

Parameters:
aRequestrequest being observed
aContextuser defined context

An exception thrown from onStartRequest has the side-effect of causing the request to be canceled.

Here is the caller graph for this function:

void nsIRequestObserver::onStopRequest ( in nsIRequest  aRequest,
in nsISupports  aContext,
in nsresult  aStatusCode 
) [inherited]

Called to signify the end of an asynchronous request.

This call is always preceded by a call to onStartRequest.

Parameters:
aRequestrequest being observed
aContextuser defined context
aStatusCodereason for stopping (NS_OK if completed successfully)

An exception thrown from onStopRequest is generally ignored.

Here is the caller graph for this function:


Member Data Documentation

Definition at line 108 of file nsHTTPCompressConv.h.

unsigned nsHTTPCompressConv::hMode [private]

Definition at line 109 of file nsHTTPCompressConv.h.

Definition at line 99 of file nsHTTPCompressConv.h.

Definition at line 103 of file nsHTTPCompressConv.h.

Definition at line 106 of file nsHTTPCompressConv.h.

unsigned nsHTTPCompressConv::mFlags [private]

Definition at line 109 of file nsHTTPCompressConv.h.

unsigned char* nsHTTPCompressConv::mInpBuffer [private]

Definition at line 94 of file nsHTTPCompressConv.h.

Definition at line 97 of file nsHTTPCompressConv.h.

unsigned nsHTTPCompressConv::mLen [private]

Definition at line 109 of file nsHTTPCompressConv.h.

Definition at line 90 of file nsHTTPCompressConv.h.

Definition at line 91 of file nsHTTPCompressConv.h.

unsigned char* nsHTTPCompressConv::mOutBuffer [private]

Definition at line 93 of file nsHTTPCompressConv.h.

Definition at line 96 of file nsHTTPCompressConv.h.

unsigned nsHTTPCompressConv::mSkipCount [private]

Definition at line 109 of file nsHTTPCompressConv.h.

Definition at line 104 of file nsHTTPCompressConv.h.

Definition at line 105 of file nsHTTPCompressConv.h.


The documentation for this class was generated from the following files: