diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index 171e6362f685..6d7a6ac3a0ca 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -87,6 +87,7 @@ #include "nsIDocShellTreeOwner.h" #include "nsCURILoader.h" #include "nsIDOMWindow.h" +#include "nsISocketTransportService.h" #include "nsIHTTPChannel.h" // add this to the ick include list...we need it to QI for post data interface #include "nsHTTPEnums.h" diff --git a/mailnews/base/util/nsMsgProtocol.cpp b/mailnews/base/util/nsMsgProtocol.cpp index 25511b6f9cfd..880218268b23 100644 --- a/mailnews/base/util/nsMsgProtocol.cpp +++ b/mailnews/base/util/nsMsgProtocol.cpp @@ -29,10 +29,12 @@ #include "nsILoadGroup.h" #include "nsIIOService.h" #include "nsFileStream.h" +#include "nsINetSupportDialogService.h" +#include "nsIDNSService.h" +static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID); static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); - NS_IMPL_ISUPPORTS3(nsMsgProtocol, nsIStreamListener, nsIStreamObserver, nsIChannel) nsMsgProtocol::nsMsgProtocol(nsIURI * aURL, nsIURI* originalURI) @@ -213,6 +215,31 @@ NS_IMETHODIMP nsMsgProtocol::OnStopRequest(nsIChannel * aChannel, nsISupports *c if (m_channelListener) rv = m_channelListener->OnStopRequest(this, m_channelContext, aStatus, aMsg); + if (NS_FAILED(aStatus)) { + NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &rv); + if (NS_SUCCEEDED(rv) && dialog) { + // todo, put this into a string bundle + nsAutoString alertMsg("unknown error."); + switch (aStatus) { + case NS_ERROR_UNKNOWN_HOST: + // todo, put this into a string bundle + alertMsg = "Failed to connect to the server."; + break; + case NS_ERROR_CONNECTION_REFUSED: + // todo, put this into a string bundle + alertMsg = "Connection refused to the server."; + break; + case NS_ERROR_NET_TIMEOUT: + // todo, put this into a string bundle + alertMsg = "Connection to the server timed out."; + break; + default: + break; + } + dialog->Alert(alertMsg.GetUnicode()); + } + } + return rv; } diff --git a/mailnews/imap/resources/locale/en-US/imapMsgs.properties b/mailnews/imap/resources/locale/en-US/imapMsgs.properties index 89e9ac52012d..2caf61155193 100644 --- a/mailnews/imap/resources/locale/en-US/imapMsgs.properties +++ b/mailnews/imap/resources/locale/en-US/imapMsgs.properties @@ -250,3 +250,14 @@ ## @loc None 5051=Enter your password +## @name IMAP_UNKNOWN_HOST_ERROR +## @loc None +5052=Failed to connect to the server. + +## @name IMAP_IMAP_CONNECTION_REFUSED_ERROR +## @loc None +5053=Connection refused to the server. + +## @name IMAP_NET_TIMEOUT_ERROR +## @loc None +5054=Connection to the server timed out. diff --git a/mailnews/imap/src/nsImapIncomingServer.cpp b/mailnews/imap/src/nsImapIncomingServer.cpp index cca6bb0e5bb7..da04d8ac0e1b 100644 --- a/mailnews/imap/src/nsImapIncomingServer.cpp +++ b/mailnews/imap/src/nsImapIncomingServer.cpp @@ -589,9 +589,9 @@ nsImapIncomingServer::CloseCachedConnections() nsresult rv = m_connectionCache->Count(&cnt); if (NS_FAILED(rv)) return rv; - for (PRUint32 i = 0; i < cnt; i++) + for (PRUint32 i = cnt; i>0; i--) { - aSupport = getter_AddRefs(m_connectionCache->ElementAt(i)); + aSupport = getter_AddRefs(m_connectionCache->ElementAt(i-1)); connection = do_QueryInterface(aSupport); if (connection) rv = connection->TellThreadToDie(PR_TRUE); diff --git a/mailnews/imap/src/nsImapProtocol.cpp b/mailnews/imap/src/nsImapProtocol.cpp index 90367aa64c1b..9d6cd6023909 100644 --- a/mailnews/imap/src/nsImapProtocol.cpp +++ b/mailnews/imap/src/nsImapProtocol.cpp @@ -53,6 +53,7 @@ #include "nsICopyMsgStreamListener.h" #include "nsTextFormatter.h" #include "nsAutoLock.h" +#include "nsIDNSService.h" // for the memory cache... #include "nsINetDataCacheManager.h" @@ -738,7 +739,8 @@ NS_IMETHODIMP nsImapProtocol::Run() me->m_imapMiscellaneousSink = null_nsCOMPtr(); m_iThread = null_nsCOMPtr(); - NS_RELEASE(me); + //this is bogus, we need to find the leak + //NS_RELEASE(me); return NS_OK; } @@ -795,7 +797,7 @@ nsImapProtocol::TellThreadToDie(PRBool isSaveToClose) // if the connection is closed,then don't try to send data // to the connection. - PRBool connectionIsLost = TestFlag(IMAP_CONNECTION_IS_OPEN); + PRBool connectionIsLost = !TestFlag(IMAP_CONNECTION_IS_OPEN); PRBool closeNeeded = GetServerStateParser().GetIMAPstate() == nsImapServerResponseParser::kFolderSelected && isSaveToClose; @@ -906,6 +908,8 @@ nsImapProtocol::ImapThreadMainLoop() ClearFlag(IMAP_FIRST_PASS_IN_THREAD); } + if (DeathSignalReceived()) break; + PR_EnterMonitor(m_urlReadyToRunMonitor); PRStatus err; @@ -936,7 +940,9 @@ void nsImapProtocol::EstablishServerConnection() // record the fact that we've received a greeting for this connection so we don't ever // try to do it again.. - SetFlag(IMAP_RECEIVED_GREETING); + if (serverResponse) { + SetFlag(IMAP_RECEIVED_GREETING); + } if (!nsCRT::strncasecmp(serverResponse, "* OK", 4)) { @@ -1207,8 +1213,10 @@ PRBool nsImapProtocol::ProcessCurrentURL() nsCOMPtr aImapServer = do_QueryInterface(m_server, &rv); if (NS_SUCCEEDED(rv)) aImapServer->RemoveConnection(this); - TellThreadToDie(PR_FALSE); + if (!DeathSignalReceived()) { + TellThreadToDie(PR_FALSE); + } } return anotherUrlRun; } @@ -1271,6 +1279,33 @@ NS_IMETHODIMP nsImapProtocol::OnStartRequest(nsIChannel * /* aChannel */, nsISup NS_IMETHODIMP nsImapProtocol::OnStopRequest(nsIChannel * /* aChannel */, nsISupports *ctxt, nsresult aStatus, const PRUnichar* aMsg) { PR_CEnterMonitor(this); + + PRBool killThread = PR_FALSE; + + if (NS_FAILED(aStatus)) { + switch (aStatus) { + case NS_ERROR_UNKNOWN_HOST: + AlertUserEventUsingId(IMAP_UNKNOWN_HOST_ERROR); + killThread = PR_TRUE; + break; + case NS_ERROR_CONNECTION_REFUSED: + AlertUserEventUsingId(IMAP_CONNECTION_REFUSED_ERROR); + killThread = PR_TRUE; + break; + case NS_ERROR_NET_TIMEOUT: + AlertUserEventUsingId(IMAP_NET_TIMEOUT_ERROR); + killThread = PR_TRUE; + break; + default: + break; + } + + if (killThread == PR_TRUE) { + ClearFlag(IMAP_CONNECTION_IS_OPEN); + TellThreadToDie(PR_FALSE); + } + } + m_channel = null_nsCOMPtr(); m_outputStream = null_nsCOMPtr(); m_inputStream = null_nsCOMPtr(); @@ -3695,10 +3730,10 @@ char* nsImapProtocol::CreateNewLineFromSocket() m_eventQueue->ProcessPendingEvents(); } while (TestFlag(IMAP_WAITING_FOR_DATA) && !DeathSignalReceived()); } - } while (!newLine); // until we get the next line and haven't been interrupted + } while (!newLine && !DeathSignalReceived()); // until we get the next line and haven't been interrupted Log("CreateNewLineFromSocket", nsnull, newLine); - SetConnectionStatus(newLine && numBytesInLine ? 1 : 0); // set > 0 if string is not null or empty + SetConnectionStatus(newLine && numBytesInLine ? 1 : -1); // set > 0 if string is not null or empty return newLine; } diff --git a/mailnews/imap/src/nsImapStringBundle.h b/mailnews/imap/src/nsImapStringBundle.h index 655f45c773f6..9ff22483477e 100644 --- a/mailnews/imap/src/nsImapStringBundle.h +++ b/mailnews/imap/src/nsImapStringBundle.h @@ -83,4 +83,8 @@ NS_END_EXTERN_C #define IMAP_SERVER_SAID 5049 #define IMAP_DONE 5050 #define IMAP_ENTER_PASSWORD_PROMPT_TITLE 5051 +#define IMAP_UNKNOWN_HOST_ERROR 5052 +#define IMAP_CONNECTION_REFUSED_ERROR 5053 +#define IMAP_NET_TIMEOUT_ERROR 5054 + #endif /* _nsImapStringBundle_H__ */ diff --git a/mailnews/news/src/nsNNTPProtocol.cpp b/mailnews/news/src/nsNNTPProtocol.cpp index 592d755f5706..8ce7c579383d 100644 --- a/mailnews/news/src/nsNNTPProtocol.cpp +++ b/mailnews/news/src/nsNNTPProtocol.cpp @@ -448,6 +448,8 @@ nsNNTPProtocol::nsNNTPProtocol(nsIURI * aURL, nsIMsgWindow *aMsgWindow) if (aMsgWindow) { m_msgWindow = aMsgWindow; } + + m_runningURL = null_nsCOMPtr(); } nsNNTPProtocol::~nsNNTPProtocol() @@ -4927,4 +4929,4 @@ nsNNTPProtocol::SetProgressStatus(char *message) } } PR_FREEIF(progressMsg); -} +} diff --git a/mailnews/news/src/nsNntpUrl.cpp b/mailnews/news/src/nsNntpUrl.cpp index a86cf6275b2a..dee213280a82 100644 --- a/mailnews/news/src/nsNntpUrl.cpp +++ b/mailnews/news/src/nsNntpUrl.cpp @@ -248,7 +248,6 @@ NS_IMETHODIMP nsNntpUrl::GetURI(char ** aURI) { nsXPIDLCString spec; GetSpec(getter_Copies(spec)); - char * uri = nsnull; char * baseMessageURI; nsCreateNewsBaseMessageURI(spec, &baseMessageURI); nsCAutoString uriStr; diff --git a/netwerk/base/public/netCore.h b/netwerk/base/public/netCore.h index 22b48d4a73e7..6db21abe6482 100644 --- a/netwerk/base/public/netCore.h +++ b/netwerk/base/public/netCore.h @@ -38,11 +38,7 @@ #define NS_ERROR_NOT_CONNECTED \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 12) -#define NS_ERROR_CONNECTION_REFUSED \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 13) - -#define NS_ERROR_NET_TIMEOUT \ - NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 14) +/* NS_ERROR_CONNECTION_REFUSED and NS_ERROR_NET_TIMEOUT moved to nsISocketTransportService.idl */ #define NS_ERROR_IN_PROGRESS \ NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 15) diff --git a/netwerk/base/public/nsISocketTransportService.idl b/netwerk/base/public/nsISocketTransportService.idl index a040ab4c51ed..f9fff27ceb84 100644 --- a/netwerk/base/public/nsISocketTransportService.idl +++ b/netwerk/base/public/nsISocketTransportService.idl @@ -67,4 +67,9 @@ interface nsISocketTransportService : nsISupports 0x11d2, \ {0x92, 0xb6, 0x00, 0x10, 0x5a, 0x1b, 0x0d, 0x64} \ } + +#define NS_ERROR_CONNECTION_REFUSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 13) + +#define NS_ERROR_NET_TIMEOUT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 14) + %} diff --git a/webshell/src/nsWebShell.cpp b/webshell/src/nsWebShell.cpp index 171e6362f685..6d7a6ac3a0ca 100644 --- a/webshell/src/nsWebShell.cpp +++ b/webshell/src/nsWebShell.cpp @@ -87,6 +87,7 @@ #include "nsIDocShellTreeOwner.h" #include "nsCURILoader.h" #include "nsIDOMWindow.h" +#include "nsISocketTransportService.h" #include "nsIHTTPChannel.h" // add this to the ick include list...we need it to QI for post data interface #include "nsHTTPEnums.h"