2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifndef __nsmultimixedconv__h__
|
|
|
|
#define __nsmultimixedconv__h__
|
|
|
|
|
|
|
|
#include "nsIStreamConverter.h"
|
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIByteRangeRequest.h"
|
|
|
|
#include "nsIMultiPartChannel.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2012-06-05 20:18:25 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#define NS_MULTIMIXEDCONVERTER_CID \
|
|
|
|
{ /* 7584CE90-5B25-11d3-A175-0050041CAF44 */ \
|
|
|
|
0x7584ce90, \
|
|
|
|
0x5b25, \
|
|
|
|
0x11d3, \
|
|
|
|
{0xa1, 0x75, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44} \
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// nsPartChannel is a "dummy" channel which represents an individual part of
|
|
|
|
// a multipart/mixed stream...
|
|
|
|
//
|
|
|
|
// Instances on this channel are passed out to the consumer through the
|
|
|
|
// nsIStreamListener interface.
|
|
|
|
//
|
2012-06-05 20:18:25 -07:00
|
|
|
class nsPartChannel MOZ_FINAL : public nsIChannel,
|
|
|
|
public nsIByteRangeRequest,
|
|
|
|
public nsIMultiPartChannel
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-08-22 08:56:38 -07:00
|
|
|
nsPartChannel(nsIChannel *aMultipartChannel, uint32_t aPartID,
|
2010-04-10 09:10:21 -07:00
|
|
|
nsIStreamListener* aListener);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
void InitializeByteRange(int64_t aStart, int64_t aEnd);
|
2011-10-17 07:59:28 -07:00
|
|
|
void SetIsLastPart() { mIsLastPart = true; }
|
2010-04-10 09:10:21 -07:00
|
|
|
nsresult SendOnStartRequest(nsISupports* aContext);
|
|
|
|
nsresult SendOnDataAvailable(nsISupports* aContext, nsIInputStream* aStream,
|
2012-09-05 19:41:02 -07:00
|
|
|
uint64_t aOffset, uint32_t aLen);
|
2010-04-10 09:10:21 -07:00
|
|
|
nsresult SendOnStopRequest(nsISupports* aContext, nsresult aStatus);
|
2011-09-09 15:41:04 -07:00
|
|
|
/* SetContentDisposition expects the full value of the Content-Disposition
|
|
|
|
* header */
|
|
|
|
void SetContentDisposition(const nsACString& aContentDispositionHeader);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIREQUEST
|
|
|
|
NS_DECL_NSICHANNEL
|
|
|
|
NS_DECL_NSIBYTERANGEREQUEST
|
|
|
|
NS_DECL_NSIMULTIPARTCHANNEL
|
|
|
|
|
|
|
|
protected:
|
|
|
|
~nsPartChannel();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIChannel> mMultipartChannel;
|
2010-04-10 09:10:21 -07:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsresult mStatus;
|
|
|
|
nsLoadFlags mLoadFlags;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
nsCString mContentType;
|
|
|
|
nsCString mContentCharset;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mContentDisposition;
|
2011-09-09 15:41:04 -07:00
|
|
|
nsString mContentDispositionFilename;
|
|
|
|
nsCString mContentDispositionHeader;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mContentLength;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsByteRangeRequest;
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mByteRangeStart;
|
|
|
|
int64_t mByteRangeEnd;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mPartID; // unique ID that can be used to identify
|
2007-03-22 10:30:00 -07:00
|
|
|
// this part of the multipart document
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsLastPart;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// The nsMultiMixedConv stream converter converts a stream of type "multipart/x-mixed-replace"
|
|
|
|
// to it's subparts. There was some debate as to whether or not the functionality desired
|
|
|
|
// when HTTP confronted this type required a stream converter. After all, this type really
|
|
|
|
// prompts various viewer related actions rather than stream conversion. There simply needs
|
|
|
|
// to be a piece in place that can strip out the multiple parts of a stream of this type, and
|
|
|
|
// "display" them accordingly.
|
|
|
|
//
|
|
|
|
// With that said, this "stream converter" spends more time packaging up the sub parts of the
|
|
|
|
// main stream and sending them off the destination stream listener, than doing any real
|
|
|
|
// stream parsing/converting.
|
|
|
|
//
|
|
|
|
// WARNING: This converter requires that it's destination stream listener be able to handle
|
|
|
|
// multiple OnStartRequest(), OnDataAvailable(), and OnStopRequest() call combinations.
|
|
|
|
// Each series represents the beginning, data production, and ending phase of each sub-
|
|
|
|
// part of the original stream.
|
|
|
|
//
|
|
|
|
// NOTE: this MIME-type is used by HTTP, *not* SMTP, or IMAP.
|
|
|
|
//
|
|
|
|
// NOTE: For reference, a general description of how this MIME type should be handled via
|
|
|
|
// HTTP, see http://home.netscape.com/assist/net_sites/pushpull.html . Note that
|
|
|
|
// real world server content deviates considerably from this overview.
|
|
|
|
//
|
|
|
|
// Implementation assumptions:
|
|
|
|
// Assumed structue:
|
|
|
|
// --BoundaryToken[\r]\n
|
|
|
|
// content-type: foo/bar[\r]\n
|
|
|
|
// ... (other headers if any)
|
|
|
|
// [\r]\n (second line feed to delimit end of headers)
|
|
|
|
// data
|
|
|
|
// --BoundaryToken-- (end delimited by final "--")
|
|
|
|
//
|
2010-04-15 21:12:08 -07:00
|
|
|
// linebreaks can be either CRLF or LFLF. linebreaks preceding
|
2007-03-22 10:30:00 -07:00
|
|
|
// boundary tokens are considered part of the data. BoundaryToken
|
|
|
|
// is any opaque string.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
class nsMultiMixedConv : public nsIStreamConverter {
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSISTREAMCONVERTER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
|
|
|
|
|
|
|
nsMultiMixedConv();
|
|
|
|
virtual ~nsMultiMixedConv();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsresult SendStart(nsIChannel *aChannel);
|
|
|
|
nsresult SendStop(nsresult aStatus);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SendData(char *aBuffer, uint32_t aLen);
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult ParseHeaders(nsIChannel *aChannel, char *&aPtr,
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t &aLen, bool *_retval);
|
|
|
|
int32_t PushOverLine(char *&aPtr, uint32_t &aLen);
|
|
|
|
char *FindToken(char *aCursor, uint32_t aLen);
|
|
|
|
nsresult BufferData(char *aData, uint32_t aLen);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// member data
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mNewPart; // Are we processing the beginning of a part?
|
|
|
|
bool mProcessingHeaders;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsIStreamListener> mFinalListener; // this guy gets the converted data via his OnDataAvailable()
|
|
|
|
|
|
|
|
nsCString mToken;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mTokenLen;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsRefPtr<nsPartChannel> mPartChannel; // the channel for the given part we're processing.
|
|
|
|
// one channel per part.
|
|
|
|
nsCOMPtr<nsISupports> mContext;
|
|
|
|
nsCString mContentType;
|
|
|
|
nsCString mContentDisposition;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint64_t mContentLength;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
char *mBuffer;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mBufLen;
|
|
|
|
uint64_t mTotalSent;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mFirstOnData; // used to determine if we're in our first OnData callback.
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The following members are for tracking the byte ranges in
|
|
|
|
// multipart/mixed content which specified the 'Content-Range:'
|
|
|
|
// header...
|
2012-08-22 08:56:38 -07:00
|
|
|
int64_t mByteRangeStart;
|
|
|
|
int64_t mByteRangeEnd;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsByteRangeRequest;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mCurrentPartID;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* __nsmultimixedconv__h__ */
|