1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is Mozilla.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 2002
19 * the Initial Developer. All Rights Reserved.
22 * Darin Fisher <darin@netscape.com>
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 MPL, 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 MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #ifndef nsAHttpTransaction_h__
39 #define nsAHttpTransaction_h__
41 #include "nsISupports.h"
43 class nsAHttpConnection
;
44 class nsAHttpSegmentReader
;
45 class nsAHttpSegmentWriter
;
46 class nsIInterfaceRequestor
;
48 //----------------------------------------------------------------------------
49 // Abstract base class for a HTTP transaction:
51 // A transaction is a "sink" for the response data. The connection pushes
52 // data to the transaction by writing to it. The transaction supports
53 // WriteSegments and may refuse to accept data if its buffers are full (its
54 // write function returns NS_BASE_STREAM_WOULD_BLOCK in this case).
55 //----------------------------------------------------------------------------
57 class nsAHttpTransaction
: public nsISupports
60 // called by the connection when it takes ownership of the transaction.
61 virtual void SetConnection(nsAHttpConnection
*) = 0;
63 // called by the connection to get security callbacks to set on the
65 virtual void GetSecurityCallbacks(nsIInterfaceRequestor
**) = 0;
67 // called to report socket status (see nsITransportEventSink)
68 virtual void OnTransportStatus(nsresult status
, PRUint64 progress
) = 0;
70 // called to check the transaction status.
71 virtual PRBool
IsDone() = 0;
72 virtual nsresult
Status() = 0;
74 // called to find out how much request data is available for writing.
75 virtual PRUint32
Available() = 0;
77 // called to read request data from the transaction.
78 virtual nsresult
ReadSegments(nsAHttpSegmentReader
*reader
,
79 PRUint32 count
, PRUint32
*countRead
) = 0;
81 // called to write response data to the transaction.
82 virtual nsresult
WriteSegments(nsAHttpSegmentWriter
*writer
,
83 PRUint32 count
, PRUint32
*countWritten
) = 0;
85 // called to close the transaction
86 virtual void Close(nsresult reason
) = 0;
89 #define NS_DECL_NSAHTTPTRANSACTION \
90 void SetConnection(nsAHttpConnection *); \
91 void GetSecurityCallbacks(nsIInterfaceRequestor **); \
92 void OnTransportStatus(nsresult status, PRUint64 progress); \
95 PRUint32 Available(); \
96 nsresult ReadSegments(nsAHttpSegmentReader *, PRUint32, PRUint32 *); \
97 nsresult WriteSegments(nsAHttpSegmentWriter *, PRUint32, PRUint32 *); \
98 void Close(nsresult reason);
100 //-----------------------------------------------------------------------------
101 // nsAHttpSegmentReader
102 //-----------------------------------------------------------------------------
104 class nsAHttpSegmentReader
107 // any returned failure code stops segment iteration
108 virtual nsresult
OnReadSegment(const char *segment
,
110 PRUint32
*countRead
) = 0;
113 #define NS_DECL_NSAHTTPSEGMENTREADER \
114 nsresult OnReadSegment(const char *, PRUint32, PRUint32 *);
116 //-----------------------------------------------------------------------------
117 // nsAHttpSegmentWriter
118 //-----------------------------------------------------------------------------
120 class nsAHttpSegmentWriter
123 // any returned failure code stops segment iteration
124 virtual nsresult
OnWriteSegment(char *segment
,
126 PRUint32
*countWritten
) = 0;
129 #define NS_DECL_NSAHTTPSEGMENTWRITER \
130 nsresult OnWriteSegment(char *, PRUint32, PRUint32 *);
132 #endif // nsAHttpTransaction_h__