2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-19 02:01:16 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-08-27 18:10:21 +04:00
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* 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/
|
1999-08-27 18:10:21 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1999-08-27 18:10:21 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-19 02:01:16 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-19 02:01:16 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-29 00:14:13 +04:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-19 02:01:16 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-19 02:01:16 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-08-29 18:09:16 +04:00
|
|
|
#ifndef __nsmultimixedconv__h__
|
|
|
|
#define __nsmultimixedconv__h__
|
1999-08-27 18:10:21 +04:00
|
|
|
|
1999-08-26 18:53:01 +04:00
|
|
|
#include "nsIStreamConverter.h"
|
1999-08-27 18:10:21 +04:00
|
|
|
#include "nsIChannel.h"
|
|
|
|
#include "nsIURI.h"
|
2000-03-31 14:19:31 +04:00
|
|
|
#include "nsString.h"
|
2000-04-15 01:27:32 +04:00
|
|
|
#include "nsXPIDLString.h"
|
1999-11-11 03:34:01 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2005-01-09 23:43:35 +03:00
|
|
|
#include "nsInt64.h"
|
2001-05-19 02:22:15 +04:00
|
|
|
#include "nsIByteRangeRequest.h"
|
2005-10-04 02:27:20 +04:00
|
|
|
#include "nsIMultiPartChannel.h"
|
|
|
|
#include "nsAutoPtr.h"
|
1999-08-26 18:53:01 +04:00
|
|
|
|
|
|
|
#define NS_MULTIMIXEDCONVERTER_CID \
|
|
|
|
{ /* 7584CE90-5B25-11d3-A175-0050041CAF44 */ \
|
|
|
|
0x7584ce90, \
|
|
|
|
0x5b25, \
|
|
|
|
0x11d3, \
|
|
|
|
{0xa1, 0x75, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44} \
|
|
|
|
}
|
|
|
|
|
2005-10-04 02:27:20 +04:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
class nsPartChannel : public nsIChannel,
|
|
|
|
public nsIByteRangeRequest,
|
|
|
|
public nsIMultiPartChannel
|
|
|
|
{
|
|
|
|
public:
|
2010-04-10 20:10:21 +04:00
|
|
|
nsPartChannel(nsIChannel *aMultipartChannel, PRUint32 aPartID,
|
|
|
|
nsIStreamListener* aListener);
|
2005-10-04 02:27:20 +04:00
|
|
|
|
|
|
|
void InitializeByteRange(PRInt64 aStart, PRInt64 aEnd);
|
|
|
|
void SetIsLastPart() { mIsLastPart = PR_TRUE; }
|
2010-04-10 20:10:21 +04:00
|
|
|
nsresult SendOnStartRequest(nsISupports* aContext);
|
|
|
|
nsresult SendOnDataAvailable(nsISupports* aContext, nsIInputStream* aStream,
|
|
|
|
PRUint32 aOffset, PRUint32 aLen);
|
|
|
|
nsresult SendOnStopRequest(nsISupports* aContext, nsresult aStatus);
|
2005-10-04 02:27:20 +04: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 20:10:21 +04:00
|
|
|
nsCOMPtr<nsIStreamListener> mListener;
|
2005-10-04 02:27:20 +04:00
|
|
|
|
|
|
|
nsresult mStatus;
|
|
|
|
nsLoadFlags mLoadFlags;
|
|
|
|
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
nsCString mContentType;
|
|
|
|
nsCString mContentCharset;
|
|
|
|
nsCString mContentDisposition;
|
2009-08-12 12:51:46 +04:00
|
|
|
PRUint64 mContentLength;
|
2005-10-04 02:27:20 +04:00
|
|
|
|
|
|
|
PRBool mIsByteRangeRequest;
|
|
|
|
nsInt64 mByteRangeStart;
|
|
|
|
nsInt64 mByteRangeEnd;
|
|
|
|
|
|
|
|
PRUint32 mPartID; // unique ID that can be used to identify
|
|
|
|
// this part of the multipart document
|
|
|
|
PRBool mIsLastPart;
|
|
|
|
};
|
|
|
|
|
1999-08-27 19:12:40 +04: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
|
2000-04-15 01:27:32 +04:00
|
|
|
// 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-16 08:12:08 +04:00
|
|
|
// linebreaks can be either CRLF or LFLF. linebreaks preceding
|
2000-04-15 01:27:32 +04:00
|
|
|
// boundary tokens are considered part of the data. BoundaryToken
|
|
|
|
// is any opaque string.
|
|
|
|
//
|
|
|
|
//
|
1999-08-26 18:53:01 +04:00
|
|
|
|
2001-05-30 02:10:50 +04:00
|
|
|
class nsMultiMixedConv : public nsIStreamConverter {
|
1999-08-26 18:53:01 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
1999-08-27 19:12:40 +04:00
|
|
|
NS_DECL_NSISTREAMCONVERTER
|
|
|
|
NS_DECL_NSISTREAMLISTENER
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
1999-08-26 18:53:01 +04:00
|
|
|
|
|
|
|
nsMultiMixedConv();
|
1999-08-26 18:55:14 +04:00
|
|
|
virtual ~nsMultiMixedConv();
|
2000-04-15 01:27:32 +04:00
|
|
|
|
|
|
|
protected:
|
2000-04-18 17:42:40 +04:00
|
|
|
nsresult SendStart(nsIChannel *aChannel);
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult SendStop(nsresult aStatus);
|
2000-04-18 17:42:40 +04:00
|
|
|
nsresult SendData(char *aBuffer, PRUint32 aLen);
|
|
|
|
nsresult ParseHeaders(nsIChannel *aChannel, char *&aPtr,
|
|
|
|
PRUint32 &aLen, PRBool *_retval);
|
2001-05-19 02:22:15 +04:00
|
|
|
PRInt32 PushOverLine(char *&aPtr, PRUint32 &aLen);
|
2000-04-15 01:27:32 +04:00
|
|
|
char *FindToken(char *aCursor, PRUint32 aLen);
|
|
|
|
nsresult BufferData(char *aData, PRUint32 aLen);
|
|
|
|
|
1999-08-26 18:53:01 +04:00
|
|
|
// member data
|
1999-11-11 03:34:01 +03:00
|
|
|
PRBool mNewPart; // Are we processing the beginning of a part?
|
2001-05-30 02:10:50 +04:00
|
|
|
PRBool mProcessingHeaders;
|
1999-11-11 03:34:01 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> mFinalListener; // this guy gets the converted data via his OnDataAvailable()
|
2000-04-15 01:27:32 +04:00
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCString mToken;
|
2000-04-15 01:27:32 +04:00
|
|
|
PRUint32 mTokenLen;
|
|
|
|
|
2005-10-04 02:27:20 +04:00
|
|
|
nsRefPtr<nsPartChannel> mPartChannel; // the channel for the given part we're processing.
|
1999-08-27 18:10:21 +04:00
|
|
|
// one channel per part.
|
2000-04-18 17:42:40 +04:00
|
|
|
nsCOMPtr<nsISupports> mContext;
|
2000-03-02 23:42:27 +03:00
|
|
|
nsCString mContentType;
|
2002-02-06 06:39:04 +03:00
|
|
|
nsCString mContentDisposition;
|
2009-08-12 12:51:46 +04:00
|
|
|
PRUint64 mContentLength;
|
2000-04-15 01:27:32 +04:00
|
|
|
|
|
|
|
char *mBuffer;
|
|
|
|
PRUint32 mBufLen;
|
2009-08-12 12:51:46 +04:00
|
|
|
PRUint64 mTotalSent;
|
2001-02-27 15:33:12 +03:00
|
|
|
PRBool mFirstOnData; // used to determine if we're in our first OnData callback.
|
2001-05-19 02:22:15 +04:00
|
|
|
|
2001-05-30 02:10:50 +04:00
|
|
|
// The following members are for tracking the byte ranges in
|
|
|
|
// multipart/mixed content which specified the 'Content-Range:'
|
|
|
|
// header...
|
2005-01-09 23:43:35 +03:00
|
|
|
nsInt64 mByteRangeStart;
|
|
|
|
nsInt64 mByteRangeEnd;
|
2001-05-19 02:22:15 +04:00
|
|
|
PRBool mIsByteRangeRequest;
|
2005-01-15 20:47:23 +03:00
|
|
|
|
|
|
|
PRUint32 mCurrentPartID;
|
1999-08-26 18:53:01 +04:00
|
|
|
};
|
|
|
|
|
1999-08-29 18:09:16 +04:00
|
|
|
#endif /* __nsmultimixedconv__h__ */
|