From 98af313adf7ff32b6beee698d5dbed200f1e77a8 Mon Sep 17 00:00:00 2001 From: Michal Novotny Date: Mon, 23 Feb 2009 19:28:17 +0100 Subject: [PATCH] Bug 474434 - Active ftp sessions are not closed when clearing recent history; r=bzbarsky sr=cbiesinger --- browser/base/content/sanitize.js | 8 ++--- .../ftp/src/nsFtpControlConnection.cpp | 7 ++-- .../protocol/ftp/src/nsFtpControlConnection.h | 1 + .../protocol/ftp/src/nsFtpProtocolHandler.cpp | 32 +++++++++++++++---- .../protocol/ftp/src/nsFtpProtocolHandler.h | 9 ++++++ netwerk/protocol/http/src/nsHttpHandler.cpp | 4 +++ 6 files changed, 48 insertions(+), 13 deletions(-) diff --git a/browser/base/content/sanitize.js b/browser/base/content/sanitize.js index 3efcdfbc4ef..1663fc1a947 100644 --- a/browser/base/content/sanitize.js +++ b/browser/base/content/sanitize.js @@ -327,10 +327,10 @@ Sanitizer.prototype = { .getService(Components.interfaces.nsISecretDecoderRing); sdr.logoutAndTeardown(); - // clear plain HTTP auth sessions - var authMgr = Components.classes['@mozilla.org/network/http-auth-manager;1'] - .getService(Components.interfaces.nsIHttpAuthManager); - authMgr.clearAll(); + // clear FTP and plain HTTP auth sessions + var os = Components.classes["@mozilla.org/observer-service;1"] + .getService(Components.interfaces.nsIObserverService); + os.notifyObservers(null, "net:clear-active-logins", null); }, get canClear() diff --git a/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp b/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp index 15c7c458901..329fa2cbe84 100644 --- a/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp +++ b/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp @@ -38,6 +38,7 @@ #include "nsFTPChannel.h" #include "nsFtpControlConnection.h" +#include "nsFtpProtocolHandler.h" #include "prlog.h" #include "nsIPipe.h" #include "nsIInputStream.h" @@ -95,8 +96,10 @@ nsFtpControlConnection::OnInputStreamReady(nsIAsyncInputStream *stream) return NS_OK; } -nsFtpControlConnection::nsFtpControlConnection(const nsCSubstring& host, PRUint32 port) - : mServerType(0), mHost(host), mPort(port) +nsFtpControlConnection::nsFtpControlConnection(const nsCSubstring& host, + PRUint32 port) + : mServerType(0), mSessionId(gFtpHandler->GetSessionId()), mHost(host) + , mPort(port) { LOG_ALWAYS(("FTP:CC created @%p", this)); } diff --git a/netwerk/protocol/ftp/src/nsFtpControlConnection.h b/netwerk/protocol/ftp/src/nsFtpControlConnection.h index d89c82f7a76..6b603509b58 100644 --- a/netwerk/protocol/ftp/src/nsFtpControlConnection.h +++ b/netwerk/protocol/ftp/src/nsFtpControlConnection.h @@ -102,6 +102,7 @@ public: nsString mPassword; PRInt32 mSuspendedWrite; nsCString mPwd; + PRUint32 mSessionId; private: nsCString mHost; diff --git a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp index bc69e896b4b..6290a0b0d50 100644 --- a/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp +++ b/netwerk/protocol/ftp/src/nsFtpProtocolHandler.cpp @@ -94,6 +94,7 @@ nsFtpProtocolHandler *gFtpHandler = nsnull; nsFtpProtocolHandler::nsFtpProtocolHandler() : mIdleTimeout(-1) + , mSessionId(0) { #if defined(PR_LOGGING) if (!gFTPLog) @@ -138,11 +139,16 @@ nsFtpProtocolHandler::Init() nsCOMPtr observerService = do_GetService("@mozilla.org/observer-service;1"); - if (observerService) + if (observerService) { observerService->AddObserver(this, "network:offline-about-to-go-offline", PR_TRUE); - + + observerService->AddObserver(this, + "net:clear-active-logins", + PR_TRUE); + } + return NS_OK; } @@ -295,7 +301,10 @@ nsFtpProtocolHandler::InsertConnection(nsIURI *aKey, nsFtpControlConnection *aCo { NS_ASSERTION(aConn, "null pointer"); NS_ASSERTION(aKey, "null pointer"); - + + if (aConn->mSessionId != mSessionId) + return NS_ERROR_FAILURE; + nsCAutoString spec; aKey->GetPrePath(spec); @@ -375,13 +384,22 @@ nsFtpProtocolHandler::Observe(nsISupports *aSubject, if (NS_SUCCEEDED(rv)) mIdleTimeout = timeout; } else if (!strcmp(aTopic, "network:offline-about-to-go-offline")) { - PRUint32 i; - for (i=0;i mRootConnectionList; nsCOMPtr mCacheSession; PRInt32 mIdleTimeout; + + // When "clear active logins" is performed, all idle connection are dropped + // and mSessionId is incremented. When nsFtpState wants to insert idle + // connection we refuse to cache if its mSessionId is different (i.e. + // control connection had been created before last "clear active logins" was + // performed. + PRUint32 mSessionId; }; //----------------------------------------------------------------------------- diff --git a/netwerk/protocol/http/src/nsHttpHandler.cpp b/netwerk/protocol/http/src/nsHttpHandler.cpp index fa9b5e1f1ba..6a3708ba545 100644 --- a/netwerk/protocol/http/src/nsHttpHandler.cpp +++ b/netwerk/protocol/http/src/nsHttpHandler.cpp @@ -284,6 +284,7 @@ nsHttpHandler::Init() mObserverService->AddObserver(this, "profile-change-net-teardown", PR_TRUE); mObserverService->AddObserver(this, "profile-change-net-restore", PR_TRUE); mObserverService->AddObserver(this, NS_XPCOM_SHUTDOWN_OBSERVER_ID, PR_TRUE); + mObserverService->AddObserver(this, "net:clear-active-logins", PR_TRUE); } StartPruneDeadConnectionsTimer(); @@ -1727,6 +1728,9 @@ nsHttpHandler::Observe(nsISupports *subject, if (mConnMgr) mConnMgr->PruneDeadConnections(); } + else if (strcmp(topic, "net:clear-active-logins") == 0) { + mAuthCache.ClearAll(); + } return NS_OK; }