~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/netwerk/streamconv/converters/nsMultiMixedConv.h

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
#ifndef __nsmultimixedconv__h__
 
38
#define __nsmultimixedconv__h__
 
39
 
 
40
#include "nsIStreamConverter.h"
 
41
#include "nsIChannel.h"
 
42
#include "nsIURI.h"
 
43
#include "nsString.h"
 
44
#include "nsXPIDLString.h"
 
45
#include "nsCOMPtr.h"
 
46
#include "nsIByteRangeRequest.h"
 
47
 
 
48
#define NS_MULTIMIXEDCONVERTER_CID                         \
 
49
{ /* 7584CE90-5B25-11d3-A175-0050041CAF44 */         \
 
50
    0x7584ce90,                                      \
 
51
    0x5b25,                                          \
 
52
    0x11d3,                                          \
 
53
    {0xa1, 0x75, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44}       \
 
54
}
 
55
 
 
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.
 
62
//
 
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.
 
66
//
 
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.
 
71
//
 
72
// NOTE: this MIME-type is used by HTTP, *not* SMTP, or IMAP.
 
73
//
 
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.
 
77
//
 
78
// Implementation assumptions:
 
79
//  Assumed structue:
 
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)
 
84
//  data
 
85
//  --BoundaryToken-- (end delimited by final "--")
 
86
//
 
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.
 
90
//  
 
91
//
 
92
 
 
93
class nsMultiMixedConv : public nsIStreamConverter {
 
94
public:
 
95
    NS_DECL_ISUPPORTS
 
96
    NS_DECL_NSISTREAMCONVERTER
 
97
    NS_DECL_NSISTREAMLISTENER
 
98
    NS_DECL_NSIREQUESTOBSERVER
 
99
 
 
100
    nsMultiMixedConv();
 
101
    virtual ~nsMultiMixedConv();
 
102
 
 
103
protected:
 
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);
 
112
 
 
113
    // member data
 
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()
 
117
 
 
118
    nsCString           mToken;
 
119
    PRUint32            mTokenLen;
 
120
 
 
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;
 
127
    
 
128
    char                *mBuffer;
 
129
    PRUint32            mBufLen;
 
130
    PRUint32            mTotalSent;
 
131
    PRBool              mFirstOnData;   // used to determine if we're in our first OnData callback.
 
132
 
 
133
    // The following members are for tracking the byte ranges in
 
134
    // multipart/mixed content which specified the 'Content-Range:'
 
135
    // header...
 
136
    PRInt32             mByteRangeStart;
 
137
    PRInt32             mByteRangeEnd;
 
138
    PRBool              mIsByteRangeRequest;
 
139
};
 
140
 
 
141
#endif /* __nsmultimixedconv__h__ */