nsFtpProtocolHandler.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef nsFtpProtocolHandler_h__
  6. #define nsFtpProtocolHandler_h__
  7. #include "nsFtpControlConnection.h"
  8. #include "nsIProxiedProtocolHandler.h"
  9. #include "nsTArray.h"
  10. #include "nsITimer.h"
  11. #include "nsIObserver.h"
  12. #include "nsWeakReference.h"
  13. //-----------------------------------------------------------------------------
  14. class nsFtpProtocolHandler final : public nsIProxiedProtocolHandler
  15. , public nsIObserver
  16. , public nsSupportsWeakReference
  17. {
  18. public:
  19. NS_DECL_THREADSAFE_ISUPPORTS
  20. NS_DECL_NSIPROTOCOLHANDLER
  21. NS_DECL_NSIPROXIEDPROTOCOLHANDLER
  22. NS_DECL_NSIOBSERVER
  23. nsFtpProtocolHandler();
  24. nsresult Init();
  25. // FTP Connection list access
  26. nsresult InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn);
  27. nsresult RemoveConnection(nsIURI *aKey, nsFtpControlConnection **aConn);
  28. uint32_t GetSessionId() { return mSessionId; }
  29. uint8_t GetDataQoSBits() { return mDataQoSBits; }
  30. uint8_t GetControlQoSBits() { return mControlQoSBits; }
  31. private:
  32. virtual ~nsFtpProtocolHandler();
  33. // Stuff for the timer callback function
  34. struct timerStruct {
  35. nsCOMPtr<nsITimer> timer;
  36. RefPtr<nsFtpControlConnection> conn;
  37. char *key;
  38. timerStruct() : key(nullptr) {}
  39. ~timerStruct() {
  40. if (timer)
  41. timer->Cancel();
  42. if (key)
  43. free(key);
  44. if (conn) {
  45. conn->Disconnect(NS_ERROR_ABORT);
  46. }
  47. }
  48. };
  49. static void Timeout(nsITimer *aTimer, void *aClosure);
  50. void ClearAllConnections();
  51. nsTArray<timerStruct*> mRootConnectionList;
  52. int32_t mIdleTimeout;
  53. // When "clear active logins" is performed, all idle connection are dropped
  54. // and mSessionId is incremented. When nsFtpState wants to insert idle
  55. // connection we refuse to cache if its mSessionId is different (i.e.
  56. // control connection had been created before last "clear active logins" was
  57. // performed.
  58. uint32_t mSessionId;
  59. uint8_t mControlQoSBits;
  60. uint8_t mDataQoSBits;
  61. };
  62. //-----------------------------------------------------------------------------
  63. extern nsFtpProtocolHandler *gFtpHandler;
  64. #include "mozilla/Logging.h"
  65. extern mozilla::LazyLogModule gFTPLog;
  66. #endif // !nsFtpProtocolHandler_h__