1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
37
#ifndef __nsmultimixedconv__h__
38
#define __nsmultimixedconv__h__
40
#include "nsIStreamConverter.h"
41
#include "nsIChannel.h"
44
#include "nsXPIDLString.h"
46
#include "nsIByteRangeRequest.h"
48
#define NS_MULTIMIXEDCONVERTER_CID \
49
{ /* 7584CE90-5B25-11d3-A175-0050041CAF44 */ \
53
{0xa1, 0x75, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44} \
56
// The nsMultiMixedConv stream converter converts a stream of type "multipart/x-mixed-replace"
57
// to it's subparts. There was some debate as to whether or not the functionality desired
58
// when HTTP confronted this type required a stream converter. After all, this type really
59
// prompts various viewer related actions rather than stream conversion. There simply needs
60
// to be a piece in place that can strip out the multiple parts of a stream of this type, and
61
// "display" them accordingly.
63
// With that said, this "stream converter" spends more time packaging up the sub parts of the
64
// main stream and sending them off the destination stream listener, than doing any real
65
// stream parsing/converting.
67
// WARNING: This converter requires that it's destination stream listener be able to handle
68
// multiple OnStartRequest(), OnDataAvailable(), and OnStopRequest() call combinations.
69
// Each series represents the beginning, data production, and ending phase of each sub-
70
// part of the original stream.
72
// NOTE: this MIME-type is used by HTTP, *not* SMTP, or IMAP.
74
// NOTE: For reference, a general description of how this MIME type should be handled via
75
// HTTP, see http://home.netscape.com/assist/net_sites/pushpull.html . Note that
76
// real world server content deviates considerably from this overview.
78
// Implementation assumptions:
80
// --BoundaryToken[\r]\n
81
// content-type: foo/bar[\r]\n
82
// ... (other headers if any)
83
// [\r]\n (second line feed to delimit end of headers)
85
// --BoundaryToken-- (end delimited by final "--")
87
// linebreaks can be either CRLF or LFLF. linebreaks preceeding
88
// boundary tokens are considered part of the data. BoundaryToken
89
// is any opaque string.
93
class nsMultiMixedConv : public nsIStreamConverter {
96
NS_DECL_NSISTREAMCONVERTER
97
NS_DECL_NSISTREAMLISTENER
98
NS_DECL_NSIREQUESTOBSERVER
101
virtual ~nsMultiMixedConv();
104
nsresult SendStart(nsIChannel *aChannel);
105
nsresult SendStop(nsresult aStatus);
106
nsresult SendData(char *aBuffer, PRUint32 aLen);
107
nsresult ParseHeaders(nsIChannel *aChannel, char *&aPtr,
108
PRUint32 &aLen, PRBool *_retval);
109
PRInt32 PushOverLine(char *&aPtr, PRUint32 &aLen);
110
char *FindToken(char *aCursor, PRUint32 aLen);
111
nsresult BufferData(char *aData, PRUint32 aLen);
114
PRBool mNewPart; // Are we processing the beginning of a part?
115
PRBool mProcessingHeaders;
116
nsCOMPtr<nsIStreamListener> mFinalListener; // this guy gets the converted data via his OnDataAvailable()
121
nsCOMPtr<nsIChannel>mPartChannel; // the channel for the given part we're processing.
122
// one channel per part.
123
nsCOMPtr<nsISupports> mContext;
124
nsCString mContentType;
125
nsCString mContentDisposition;
126
PRInt32 mContentLength;
131
PRBool mFirstOnData; // used to determine if we're in our first OnData callback.
133
// The following members are for tracking the byte ranges in
134
// multipart/mixed content which specified the 'Content-Range:'
136
PRInt32 mByteRangeStart;
137
PRInt32 mByteRangeEnd;
138
PRBool mIsByteRangeRequest;
141
#endif /* __nsmultimixedconv__h__ */