Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/. */
7 #ifndef nsFtpControlConnection_h___
8 #define nsFtpControlConnection_h___
10 #include "nsCOMPtr.h"
12 #include "nsISocketTransport.h"
13 #include "nsIAsyncInputStream.h"
14 #include "nsAutoPtr.h"
15 #include "nsString.h"
16 #include "mozilla/Attributes.h"
18 class nsIOutputStream;
19 class nsIProxyInfo;
20 class nsITransportEventSink;
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;
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 };
41 class nsFtpControlConnection MOZ_FINAL : public nsIInputStreamCallback
42 {
43 public:
44 NS_DECL_ISUPPORTS
45 NS_DECL_NSIINPUTSTREAMCALLBACK
47 nsFtpControlConnection(const nsCSubstring& host, uint32_t port);
48 ~nsFtpControlConnection();
50 nsresult Connect(nsIProxyInfo* proxyInfo, nsITransportEventSink* eventSink);
51 nsresult Disconnect(nsresult status);
52 nsresult Write(const nsCSubstring& command);
54 bool IsAlive();
56 nsITransport *Transport() { return mSocket; }
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);
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;
73 private:
74 nsCString mHost;
75 uint32_t mPort;
77 nsCOMPtr<nsISocketTransport> mSocket;
78 nsCOMPtr<nsIOutputStream> mSocketOutput;
79 nsCOMPtr<nsIAsyncInputStream> mSocketInput;
81 nsRefPtr<nsFtpControlConnectionListener> mListener;
82 };
84 #endif