Bug 474434 - Active ftp sessions are not closed when clearing recent history; r=bzbarsky sr=cbiesinger

This commit is contained in:
Michal Novotny 2009-02-23 19:28:17 +01:00
parent 7afd1bbd24
commit 5e7c0ee5dd
6 changed files with 48 additions and 13 deletions

View File

@ -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()

View File

@ -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));
}

View File

@ -102,6 +102,7 @@ public:
nsString mPassword;
PRInt32 mSuspendedWrite;
nsCString mPwd;
PRUint32 mSessionId;
private:
nsCString mHost;

View File

@ -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<nsIObserverService> 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.Length();++i)
delete mRootConnectionList[i];
mRootConnectionList.Clear();
ClearAllConnections();
} else if (!strcmp(aTopic, "net:clear-active-logins")) {
ClearAllConnections();
mSessionId++;
} else {
NS_NOTREACHED("unexpected topic");
}
return NS_OK;
}
void
nsFtpProtocolHandler::ClearAllConnections()
{
PRUint32 i;
for (i=0;i<mRootConnectionList.Length();++i)
delete mRootConnectionList[i];
mRootConnectionList.Clear();
}

View File

@ -74,6 +74,7 @@ public:
// FTP Connection list access
nsresult InsertConnection(nsIURI *aKey, nsFtpControlConnection *aConn);
nsresult RemoveConnection(nsIURI *aKey, nsFtpControlConnection **aConn);
PRUint32 GetSessionId() { return mSessionId; }
private:
// Stuff for the timer callback function
@ -97,11 +98,19 @@ private:
};
static void Timeout(nsITimer *aTimer, void *aClosure);
void ClearAllConnections();
nsTArray<timerStruct*> mRootConnectionList;
nsCOMPtr<nsICacheSession> 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;
};
//-----------------------------------------------------------------------------

View File

@ -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;
}