Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes
nsMIMEInputStream Class Reference

The MIME stream separates headers and a datastream. More...

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

List of all members.

Classes

struct  ReadSegmentsState

Public Member Functions

 nsMIMEInputStream ()
virtual ~nsMIMEInputStream ()
NS_DECL_ISUPPORTS
NS_DECL_NSIINPUTSTREAM
NS_DECL_NSIMIMEINPUTSTREAM
NS_DECL_NSISEEKABLESTREAM
NS_METHOD 
Init ()
void addHeader (in string name, in string value)
 Adds an additional header to the stream on the form "name: value".
void setData (in nsIInputStream stream)
 Sets data-stream.
void close ()
 Close the stream.
unsigned long available ()
unsigned long read (in charPtr aBuf, in unsigned long aCount)
 Read data from the stream.
unsigned long readSegments (in nsWriteSegmentFun aWriter, in voidPtr aClosure, in unsigned long aCount)
 Low-level read method that has access to the stream's underlying buffer.
boolean isNonBlocking ()
void seek (in long whence, in long long offset)
 seek
long long tell ()
 tell
void setEOF ()
 setEOF

Public Attributes

attribute boolean addContentLength
 When true a "Content-Length" header is automatically added to the stream.
const PRInt32 NS_SEEK_SET = 0
const PRInt32 NS_SEEK_CUR = 1
const PRInt32 NS_SEEK_END = 2

Private Member Functions

void InitStreams ()

Static Private Member Functions

static NS_METHOD ReadSegCb (nsIInputStream *aIn, void *aClosure, const char *aFromRawSegment, PRUint32 aToOffset, PRUint32 aCount, PRUint32 *aWriteCount)

Private Attributes

nsCString mHeaders
nsCOMPtr< nsIStringInputStreammHeaderStream
nsCString mContentLength
nsCOMPtr< nsIStringInputStreammCLStream
nsCOMPtr< nsIInputStreammData
nsCOMPtr< nsIMultiplexInputStreammStream
PRPackedBool mAddContentLength
PRPackedBool mStartedReading

Detailed Description

The MIME stream separates headers and a datastream.

It also allows automatic creation of the content-length header.

Definition at line 51 of file nsMIMEInputStream.cpp.


Class Documentation

struct nsMIMEInputStream::ReadSegmentsState

Definition at line 69 of file nsMIMEInputStream.cpp.

Collaboration diagram for nsMIMEInputStream::ReadSegmentsState:
Class Members
void * mClosure
nsIInputStream * mThisStream
nsWriteSegmentFun mWriter

Constructor & Destructor Documentation

Definition at line 100 of file nsMIMEInputStream.cpp.

{
}

Member Function Documentation

void nsIMIMEInputStream::addHeader ( in string  name,
in string  value 
) [inherited]

Adds an additional header to the stream on the form "name: value".

May not be called once the stream has been started to be read.

Parameters:
namename of the header
valuevalue of the header
unsigned long nsIInputStream::available ( ) [inherited]
Returns:
number of bytes currently available in the stream
void nsIInputStream::close ( ) [inherited]

Close the stream.

Definition at line 104 of file nsMIMEInputStream.cpp.

{
    nsresult rv = NS_OK;
    mStream = do_CreateInstance("@mozilla.org/io/multiplex-input-stream;1",
                                &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    mHeaderStream = do_CreateInstance("@mozilla.org/io/string-input-stream;1",
                                      &rv);
    NS_ENSURE_SUCCESS(rv, rv);
    mCLStream = do_CreateInstance("@mozilla.org/io/string-input-stream;1", &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsIInputStream> headerStream = do_QueryInterface(mHeaderStream);
    nsCOMPtr<nsIInputStream> clStream = do_QueryInterface(mCLStream);
    rv = mStream->AppendStream(headerStream);
    NS_ENSURE_SUCCESS(rv, rv);
    rv = mStream->AppendStream(clStream);
    NS_ENSURE_SUCCESS(rv, rv);

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 177 of file nsMIMEInputStream.cpp.

{
    NS_ASSERTION(!mStartedReading,
                 "Don't call initStreams twice without rewinding");

    mStartedReading = PR_TRUE;

    // We'll use the content-length stream to add the final \r\n
    if (mAddContentLength) {
        PRUint32 cl = 0;
        if (mData) {
            mData->Available(&cl);
        }
        mContentLength.AssignLiteral("Content-Length: ");
        mContentLength.AppendInt((PRInt32)cl);
        mContentLength.AppendLiteral("\r\n\r\n");
    }
    else {
        mContentLength.AssignLiteral("\r\n");
    }
    mCLStream->ShareData(mContentLength.get(), -1);
    mHeaderStream->ShareData(mHeaders.get(), -1);
}

Here is the call graph for this function:

Returns:
true if stream is non-blocking
unsigned long nsIInputStream::read ( in charPtr  aBuf,
in unsigned long  aCount 
) [inherited]

Read data from the stream.

Parameters:
aBufthe buffer into which the data is to be read
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount).
0 if reached end of file
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure
NS_METHOD nsMIMEInputStream::ReadSegCb ( nsIInputStream aIn,
void aClosure,
const char *  aFromRawSegment,
PRUint32  aToOffset,
PRUint32  aCount,
PRUint32 aWriteCount 
) [static, private]

Definition at line 241 of file nsMIMEInputStream.cpp.

{
    ReadSegmentsState* state = (ReadSegmentsState*)aClosure;
    return  (state->mWriter)(state->mThisStream,
                             state->mClosure,
                             aFromRawSegment,
                             aToOffset,
                             aCount,
                             aWriteCount);
}
unsigned long nsIInputStream::readSegments ( in nsWriteSegmentFun  aWriter,
in voidPtr  aClosure,
in unsigned long  aCount 
) [inherited]

Low-level read method that has access to the stream's underlying buffer.

The writer function may be called multiple times for segmented buffers. ReadSegments is expected to keep calling the writer until either there is nothing left to read or the writer returns an error. ReadSegments should not call the writer with zero bytes to consume.

Parameters:
aWriterthe "consumer" of the data to be read
aClosureopaque parameter passed to writer
aCountthe maximum number of bytes to be read
Returns:
number of bytes read (may be less than aCount)
0 if reached end of file (or if aWriter refused to consume data)
Exceptions:
NS_BASE_STREAM_WOULD_BLOCKif reading from the input stream would block the calling thread (non-blocking mode only)
<other-error>on failure

NOTE: this function may be unimplemented if a stream has no underlying buffer (e.g., socket input stream).

void nsISeekableStream::seek ( in long  whence,
in long long  offset 
) [inherited]

seek

This method moves the stream offset of the steam implementing this interface.

Parameters:
whencespecifies how to interpret the 'offset' parameter in setting the stream offset associated with the implementing stream.
offsetspecifies a value, in bytes, that is used in conjunction with the 'whence' parameter to set the stream offset of the implementing stream. A negative value causes seeking in the reverse direction.

Sets data-stream.

May not be called once the stream has been started to be read. The cursor of the new stream should be located at the beginning of the stream if the implementation of the nsIMIMEInputStream also is used as an nsISeekableStream.

Parameters:
streamstream containing the data for the stream

setEOF

This method truncates the stream at the current offset.

tell

This method reports the current offset, in bytes, from the start of the stream.


Member Data Documentation

When true a "Content-Length" header is automatically added to the stream.

The value of the content-length is automatically calculated using the available() method on the data stream. The value is recalculated every time the stream is rewinded to the start. Not allowed to be changed once the stream has been started to be read.

Definition at line 56 of file nsIMIMEInputStream.idl.

Definition at line 86 of file nsMIMEInputStream.cpp.

Definition at line 82 of file nsMIMEInputStream.cpp.

Definition at line 81 of file nsMIMEInputStream.cpp.

Definition at line 84 of file nsMIMEInputStream.cpp.

Definition at line 78 of file nsMIMEInputStream.cpp.

Definition at line 79 of file nsMIMEInputStream.cpp.

Definition at line 87 of file nsMIMEInputStream.cpp.

Definition at line 85 of file nsMIMEInputStream.cpp.

Definition at line 62 of file nsISeekableStream.idl.

Definition at line 68 of file nsISeekableStream.idl.

Definition at line 56 of file nsISeekableStream.idl.


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