1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Bradley Baetz <bbaetz@cs.mcgill.ca>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #ifndef nsFtpProtocolHandler_h__
40 : #define nsFtpProtocolHandler_h__
41 :
42 : #include "nsFtpControlConnection.h"
43 : #include "nsIServiceManager.h"
44 : #include "nsIProxiedProtocolHandler.h"
45 : #include "nsTArray.h"
46 : #include "nsIIOService.h"
47 : #include "nsITimer.h"
48 : #include "nsIObserverService.h"
49 : #include "nsICacheSession.h"
50 : #include "nsIObserver.h"
51 : #include "nsWeakReference.h"
52 : #include "nsCRT.h"
53 :
54 : class nsITimer;
55 : class nsIStreamListener;
56 :
57 : //-----------------------------------------------------------------------------
58 :
59 : class nsFtpProtocolHandler : public nsIProxiedProtocolHandler
60 : , public nsIObserver
61 : , public nsSupportsWeakReference
62 : {
63 : public:
64 : NS_DECL_ISUPPORTS
65 : NS_DECL_NSIPROTOCOLHANDLER
66 : NS_DECL_NSIPROXIEDPROTOCOLHANDLER
67 : NS_DECL_NSIOBSERVER
68 :
69 : nsFtpProtocolHandler();
70 : virtual ~nsFtpProtocolHandler();
71 :
72 : nsresult Init();
73 :
74 : // FTP Connection list access
75 : nsresult InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn);
76 : nsresult RemoveConnection(nsIURI *aKey, nsFtpControlConnection **aConn);
77 0 : PRUint32 GetSessionId() { return mSessionId; }
78 :
79 0 : PRUint8 GetDataQoSBits() { return mDataQoSBits; }
80 0 : PRUint8 GetControlQoSBits() { return mControlQoSBits; }
81 :
82 : private:
83 : // Stuff for the timer callback function
84 : struct timerStruct {
85 : nsCOMPtr<nsITimer> timer;
86 : nsFtpControlConnection *conn;
87 : char *key;
88 :
89 0 : timerStruct() : conn(nsnull), key(nsnull) {}
90 :
91 0 : ~timerStruct() {
92 0 : if (timer)
93 0 : timer->Cancel();
94 0 : if (key)
95 0 : nsMemory::Free(key);
96 0 : if (conn) {
97 0 : conn->Disconnect(NS_ERROR_ABORT);
98 0 : NS_RELEASE(conn);
99 : }
100 0 : }
101 : };
102 :
103 : static void Timeout(nsITimer *aTimer, void *aClosure);
104 : void ClearAllConnections();
105 :
106 : nsTArray<timerStruct*> mRootConnectionList;
107 :
108 : nsCOMPtr<nsICacheSession> mCacheSession;
109 : PRInt32 mIdleTimeout;
110 :
111 : // When "clear active logins" is performed, all idle connection are dropped
112 : // and mSessionId is incremented. When nsFtpState wants to insert idle
113 : // connection we refuse to cache if its mSessionId is different (i.e.
114 : // control connection had been created before last "clear active logins" was
115 : // performed.
116 : PRUint32 mSessionId;
117 :
118 : PRUint8 mControlQoSBits;
119 : PRUint8 mDataQoSBits;
120 : };
121 :
122 : //-----------------------------------------------------------------------------
123 :
124 : extern nsFtpProtocolHandler *gFtpHandler;
125 :
126 : #ifdef PR_LOGGING
127 : extern PRLogModuleInfo* gFTPLog;
128 : #endif
129 :
130 : #endif // !nsFtpProtocolHandler_h__
|