1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim:set et ts=4 sts=4 sw=4 cin: */
3 : /* ***** BEGIN LICENSE BLOCK *****
4 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 : *
6 : * The contents of this file are subject to the Mozilla Public License Version
7 : * 1.1 (the "License"); you may not use this file except in compliance with
8 : * the License. You may obtain a copy of the License at
9 : * http://www.mozilla.org/MPL/
10 : *
11 : * Software distributed under the License is distributed on an "AS IS" basis,
12 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 : * for the specific language governing rights and limitations under the
14 : * License.
15 : *
16 : * The Original Code is mozilla.org code.
17 : *
18 : * The Initial Developer of the Original Code is
19 : * Netscape Communications Corporation.
20 : * Portions created by the Initial Developer are Copyright (C) 1998
21 : * the Initial Developer. All Rights Reserved.
22 : *
23 : * Contributor(s):
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsFtpControlConnection_h___
40 : #define nsFtpControlConnection_h___
41 :
42 : #include "nsCOMPtr.h"
43 :
44 : #include "nsIURI.h"
45 : #include "nsIStreamListener.h"
46 : #include "nsIRequest.h"
47 : #include "nsISocketTransport.h"
48 : #include "nsIOutputStream.h"
49 : #include "nsIAsyncInputStream.h"
50 : #include "nsAutoPtr.h"
51 : #include "nsString.h"
52 :
53 : class nsIProxyInfo;
54 : class nsITransportEventSink;
55 :
56 17 : class nsFtpControlConnectionListener : public nsISupports {
57 : public:
58 : /**
59 : * Called when a chunk of data arrives on the control connection.
60 : * @param data
61 : * The new data or null if an error occurred.
62 : * @param dataLen
63 : * The data length in bytes.
64 : */
65 : virtual void OnControlDataAvailable(const char *data, PRUint32 dataLen) = 0;
66 :
67 : /**
68 : * Called when an error occurs on the control connection.
69 : * @param status
70 : * A failure code providing more info about the error.
71 : */
72 : virtual void OnControlError(nsresult status) = 0;
73 : };
74 :
75 : class nsFtpControlConnection : public nsIInputStreamCallback
76 : {
77 : public:
78 : NS_DECL_ISUPPORTS
79 : NS_DECL_NSIINPUTSTREAMCALLBACK
80 :
81 : nsFtpControlConnection(const nsCSubstring& host, PRUint32 port);
82 : ~nsFtpControlConnection();
83 :
84 : nsresult Connect(nsIProxyInfo* proxyInfo, nsITransportEventSink* eventSink);
85 : nsresult Disconnect(nsresult status);
86 : nsresult Write(const nsCSubstring& command);
87 :
88 : bool IsAlive();
89 :
90 0 : nsITransport *Transport() { return mSocket; }
91 :
92 : /**
93 : * Call this function to be notified asynchronously when there is data
94 : * available for the socket. The listener passed to this method replaces
95 : * any existing listener, and the listener can be null to disconnect the
96 : * previous listener.
97 : */
98 : nsresult WaitData(nsFtpControlConnectionListener *listener);
99 :
100 : PRUint32 mServerType; // what kind of server is it.
101 : nsString mPassword;
102 : PRInt32 mSuspendedWrite;
103 : nsCString mPwd;
104 : PRUint32 mSessionId;
105 :
106 : private:
107 : nsCString mHost;
108 : PRUint32 mPort;
109 :
110 : nsCOMPtr<nsISocketTransport> mSocket;
111 : nsCOMPtr<nsIOutputStream> mSocketOutput;
112 : nsCOMPtr<nsIAsyncInputStream> mSocketInput;
113 :
114 : nsRefPtr<nsFtpControlConnectionListener> mListener;
115 : };
116 :
117 : #endif
|