|
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 |
|
6 #ifndef nsFtpProtocolHandler_h__ |
|
7 #define nsFtpProtocolHandler_h__ |
|
8 |
|
9 #include "nsFtpControlConnection.h" |
|
10 #include "nsIProxiedProtocolHandler.h" |
|
11 #include "nsTArray.h" |
|
12 #include "nsITimer.h" |
|
13 #include "nsIObserver.h" |
|
14 #include "nsWeakReference.h" |
|
15 |
|
16 class nsICacheSession; |
|
17 |
|
18 //----------------------------------------------------------------------------- |
|
19 |
|
20 class nsFtpProtocolHandler : public nsIProxiedProtocolHandler |
|
21 , public nsIObserver |
|
22 , public nsSupportsWeakReference |
|
23 { |
|
24 public: |
|
25 NS_DECL_THREADSAFE_ISUPPORTS |
|
26 NS_DECL_NSIPROTOCOLHANDLER |
|
27 NS_DECL_NSIPROXIEDPROTOCOLHANDLER |
|
28 NS_DECL_NSIOBSERVER |
|
29 |
|
30 nsFtpProtocolHandler(); |
|
31 virtual ~nsFtpProtocolHandler(); |
|
32 |
|
33 nsresult Init(); |
|
34 |
|
35 // FTP Connection list access |
|
36 nsresult InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn); |
|
37 nsresult RemoveConnection(nsIURI *aKey, nsFtpControlConnection **aConn); |
|
38 uint32_t GetSessionId() { return mSessionId; } |
|
39 |
|
40 uint8_t GetDataQoSBits() { return mDataQoSBits; } |
|
41 uint8_t GetControlQoSBits() { return mControlQoSBits; } |
|
42 |
|
43 private: |
|
44 // Stuff for the timer callback function |
|
45 struct timerStruct { |
|
46 nsCOMPtr<nsITimer> timer; |
|
47 nsFtpControlConnection *conn; |
|
48 char *key; |
|
49 |
|
50 timerStruct() : conn(nullptr), key(nullptr) {} |
|
51 |
|
52 ~timerStruct() { |
|
53 if (timer) |
|
54 timer->Cancel(); |
|
55 if (key) |
|
56 nsMemory::Free(key); |
|
57 if (conn) { |
|
58 conn->Disconnect(NS_ERROR_ABORT); |
|
59 NS_RELEASE(conn); |
|
60 } |
|
61 } |
|
62 }; |
|
63 |
|
64 static void Timeout(nsITimer *aTimer, void *aClosure); |
|
65 void ClearAllConnections(); |
|
66 |
|
67 nsTArray<timerStruct*> mRootConnectionList; |
|
68 |
|
69 nsCOMPtr<nsICacheSession> mCacheSession; |
|
70 int32_t mIdleTimeout; |
|
71 |
|
72 // When "clear active logins" is performed, all idle connection are dropped |
|
73 // and mSessionId is incremented. When nsFtpState wants to insert idle |
|
74 // connection we refuse to cache if its mSessionId is different (i.e. |
|
75 // control connection had been created before last "clear active logins" was |
|
76 // performed. |
|
77 uint32_t mSessionId; |
|
78 |
|
79 uint8_t mControlQoSBits; |
|
80 uint8_t mDataQoSBits; |
|
81 }; |
|
82 |
|
83 //----------------------------------------------------------------------------- |
|
84 |
|
85 extern nsFtpProtocolHandler *gFtpHandler; |
|
86 |
|
87 #ifdef PR_LOGGING |
|
88 extern PRLogModuleInfo* gFTPLog; |
|
89 #endif |
|
90 |
|
91 #endif // !nsFtpProtocolHandler_h__ |