nsFtpControlConnection.h 2.5 KB

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