|
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 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef nsFtpControlConnection_h___ |
|
8 #define nsFtpControlConnection_h___ |
|
9 |
|
10 #include "nsCOMPtr.h" |
|
11 |
|
12 #include "nsISocketTransport.h" |
|
13 #include "nsIAsyncInputStream.h" |
|
14 #include "nsAutoPtr.h" |
|
15 #include "nsString.h" |
|
16 #include "mozilla/Attributes.h" |
|
17 |
|
18 class nsIOutputStream; |
|
19 class nsIProxyInfo; |
|
20 class nsITransportEventSink; |
|
21 |
|
22 class nsFtpControlConnectionListener : public nsISupports { |
|
23 public: |
|
24 /** |
|
25 * Called when a chunk of data arrives on the control connection. |
|
26 * @param data |
|
27 * The new data or null if an error occurred. |
|
28 * @param dataLen |
|
29 * The data length in bytes. |
|
30 */ |
|
31 virtual void OnControlDataAvailable(const char *data, uint32_t dataLen) = 0; |
|
32 |
|
33 /** |
|
34 * Called when an error occurs on the control connection. |
|
35 * @param status |
|
36 * A failure code providing more info about the error. |
|
37 */ |
|
38 virtual void OnControlError(nsresult status) = 0; |
|
39 }; |
|
40 |
|
41 class nsFtpControlConnection MOZ_FINAL : public nsIInputStreamCallback |
|
42 { |
|
43 public: |
|
44 NS_DECL_ISUPPORTS |
|
45 NS_DECL_NSIINPUTSTREAMCALLBACK |
|
46 |
|
47 nsFtpControlConnection(const nsCSubstring& host, uint32_t port); |
|
48 ~nsFtpControlConnection(); |
|
49 |
|
50 nsresult Connect(nsIProxyInfo* proxyInfo, nsITransportEventSink* eventSink); |
|
51 nsresult Disconnect(nsresult status); |
|
52 nsresult Write(const nsCSubstring& command); |
|
53 |
|
54 bool IsAlive(); |
|
55 |
|
56 nsITransport *Transport() { return mSocket; } |
|
57 |
|
58 /** |
|
59 * Call this function to be notified asynchronously when there is data |
|
60 * available for the socket. The listener passed to this method replaces |
|
61 * any existing listener, and the listener can be null to disconnect the |
|
62 * previous listener. |
|
63 */ |
|
64 nsresult WaitData(nsFtpControlConnectionListener *listener); |
|
65 |
|
66 uint32_t mServerType; // what kind of server is it. |
|
67 nsString mPassword; |
|
68 int32_t mSuspendedWrite; |
|
69 nsCString mPwd; |
|
70 uint32_t mSessionId; |
|
71 bool mUseUTF8; |
|
72 |
|
73 private: |
|
74 nsCString mHost; |
|
75 uint32_t mPort; |
|
76 |
|
77 nsCOMPtr<nsISocketTransport> mSocket; |
|
78 nsCOMPtr<nsIOutputStream> mSocketOutput; |
|
79 nsCOMPtr<nsIAsyncInputStream> mSocketInput; |
|
80 |
|
81 nsRefPtr<nsFtpControlConnectionListener> mListener; |
|
82 }; |
|
83 |
|
84 #endif |