michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsFtpProtocolHandler_h__ michael@0: #define nsFtpProtocolHandler_h__ michael@0: michael@0: #include "nsFtpControlConnection.h" michael@0: #include "nsIProxiedProtocolHandler.h" michael@0: #include "nsTArray.h" michael@0: #include "nsITimer.h" michael@0: #include "nsIObserver.h" michael@0: #include "nsWeakReference.h" michael@0: michael@0: class nsICacheSession; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: class nsFtpProtocolHandler : public nsIProxiedProtocolHandler michael@0: , public nsIObserver michael@0: , public nsSupportsWeakReference michael@0: { michael@0: public: michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: NS_DECL_NSIPROTOCOLHANDLER michael@0: NS_DECL_NSIPROXIEDPROTOCOLHANDLER michael@0: NS_DECL_NSIOBSERVER michael@0: michael@0: nsFtpProtocolHandler(); michael@0: virtual ~nsFtpProtocolHandler(); michael@0: michael@0: nsresult Init(); michael@0: michael@0: // FTP Connection list access michael@0: nsresult InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn); michael@0: nsresult RemoveConnection(nsIURI *aKey, nsFtpControlConnection **aConn); michael@0: uint32_t GetSessionId() { return mSessionId; } michael@0: michael@0: uint8_t GetDataQoSBits() { return mDataQoSBits; } michael@0: uint8_t GetControlQoSBits() { return mControlQoSBits; } michael@0: michael@0: private: michael@0: // Stuff for the timer callback function michael@0: struct timerStruct { michael@0: nsCOMPtr timer; michael@0: nsFtpControlConnection *conn; michael@0: char *key; michael@0: michael@0: timerStruct() : conn(nullptr), key(nullptr) {} michael@0: michael@0: ~timerStruct() { michael@0: if (timer) michael@0: timer->Cancel(); michael@0: if (key) michael@0: nsMemory::Free(key); michael@0: if (conn) { michael@0: conn->Disconnect(NS_ERROR_ABORT); michael@0: NS_RELEASE(conn); michael@0: } michael@0: } michael@0: }; michael@0: michael@0: static void Timeout(nsITimer *aTimer, void *aClosure); michael@0: void ClearAllConnections(); michael@0: michael@0: nsTArray mRootConnectionList; michael@0: michael@0: nsCOMPtr mCacheSession; michael@0: int32_t mIdleTimeout; michael@0: michael@0: // When "clear active logins" is performed, all idle connection are dropped michael@0: // and mSessionId is incremented. When nsFtpState wants to insert idle michael@0: // connection we refuse to cache if its mSessionId is different (i.e. michael@0: // control connection had been created before last "clear active logins" was michael@0: // performed. michael@0: uint32_t mSessionId; michael@0: michael@0: uint8_t mControlQoSBits; michael@0: uint8_t mDataQoSBits; michael@0: }; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: extern nsFtpProtocolHandler *gFtpHandler; michael@0: michael@0: #ifdef PR_LOGGING michael@0: extern PRLogModuleInfo* gFTPLog; michael@0: #endif michael@0: michael@0: #endif // !nsFtpProtocolHandler_h__