1999-06-05 01:41:47 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The contents of this file are subject to the Netscape Public
|
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.mozilla.org/NPL/
|
1999-06-05 01:41:47 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* Software distributed under the License is distributed on an "AS
|
|
|
|
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
|
|
|
* implied. See the License for the specific language governing
|
|
|
|
* rights and limitations under the License.
|
1999-06-05 01:41:47 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1999-06-05 01:41:47 +04:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-06-05 01:41:47 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "msgCore.h"
|
|
|
|
#include "nsMsgProtocol.h"
|
1999-06-06 00:21:27 +04:00
|
|
|
#include "nsIMsgMailNewsUrl.h"
|
1999-07-29 04:42:25 +04:00
|
|
|
#include "nsISocketTransportService.h"
|
|
|
|
#include "nsXPIDLString.h"
|
1999-09-01 08:09:07 +04:00
|
|
|
#include "nsSpecialSystemDirectory.h"
|
1999-09-12 09:05:28 +04:00
|
|
|
#include "nsILoadGroup.h"
|
1999-07-29 04:42:25 +04:00
|
|
|
#include "nsIIOService.h"
|
2001-02-21 23:38:08 +03:00
|
|
|
#include "nsNetUtil.h"
|
2001-03-13 01:41:28 +03:00
|
|
|
#include "nsIFileChannel.h"
|
1999-11-22 17:41:20 +03:00
|
|
|
#include "nsFileStream.h"
|
2001-02-21 23:38:08 +03:00
|
|
|
#include "nsIFileTransportService.h"
|
2000-02-26 04:04:50 +03:00
|
|
|
#include "nsIDNSService.h"
|
2000-07-08 05:10:30 +04:00
|
|
|
#include "nsIMsgWindow.h"
|
2000-05-04 01:16:22 +04:00
|
|
|
#include "nsIMsgStatusFeedback.h"
|
2001-06-29 08:05:38 +04:00
|
|
|
#include "nsIWebProgressListener.h"
|
2001-04-08 04:40:30 +04:00
|
|
|
#include "nsIPipe.h"
|
2001-04-07 07:33:56 +04:00
|
|
|
#include "nsIPrompt.h"
|
2001-07-16 06:40:48 +04:00
|
|
|
#include "prprf.h"
|
2001-06-05 02:47:15 +04:00
|
|
|
#include "nsIStringBundle.h"
|
1999-06-05 01:41:47 +04:00
|
|
|
|
1999-07-29 04:42:25 +04:00
|
|
|
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
2001-04-08 04:40:30 +04:00
|
|
|
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
2001-06-05 02:47:15 +04:00
|
|
|
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
2001-04-08 04:40:30 +04:00
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsMsgProtocol)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsMsgProtocol)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMsgProtocol)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
2001-04-08 04:40:30 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIChannel)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequest)
|
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
1999-06-05 01:41:47 +04:00
|
|
|
|
2001-06-05 02:47:15 +04:00
|
|
|
static PRUnichar *GetStringByID(PRInt32 stringID);
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
nsMsgProtocol::nsMsgProtocol(nsIURI * aURL)
|
1999-06-05 01:41:47 +04:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
m_flags = 0;
|
1999-07-29 04:42:25 +04:00
|
|
|
m_startPosition = 0;
|
|
|
|
m_readCount = 0;
|
2001-04-10 10:01:08 +04:00
|
|
|
mLoadFlags = 0;
|
1999-06-05 01:41:47 +04:00
|
|
|
m_socketIsOpen = PR_FALSE;
|
1999-09-01 08:09:07 +04:00
|
|
|
|
|
|
|
m_tempMsgFileSpec = nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory);
|
|
|
|
m_tempMsgFileSpec += "tempMessage.eml";
|
2000-11-17 23:47:31 +03:00
|
|
|
mSuppressListenerNotifications = PR_FALSE;
|
2000-04-13 09:54:45 +04:00
|
|
|
InitFromURI(aURL);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgProtocol::InitFromURI(nsIURI *aUrl)
|
|
|
|
{
|
|
|
|
m_url = aUrl;
|
2000-04-06 07:23:21 +04:00
|
|
|
|
2000-04-13 09:54:45 +04:00
|
|
|
nsCOMPtr <nsIMsgMailNewsUrl> mailUrl = do_QueryInterface(aUrl);
|
|
|
|
if (mailUrl)
|
2000-05-04 01:16:22 +04:00
|
|
|
{
|
2000-04-06 07:23:21 +04:00
|
|
|
mailUrl->GetLoadGroup(getter_AddRefs(m_loadGroup));
|
2000-05-04 01:16:22 +04:00
|
|
|
nsCOMPtr<nsIMsgStatusFeedback> statusFeedback;
|
|
|
|
mailUrl->GetStatusFeedback(getter_AddRefs(statusFeedback));
|
|
|
|
mProgressEventSink = do_QueryInterface(statusFeedback);
|
|
|
|
}
|
2000-04-13 09:54:45 +04:00
|
|
|
return NS_OK;
|
1999-06-05 01:41:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsMsgProtocol::~nsMsgProtocol()
|
|
|
|
{}
|
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
nsresult
|
|
|
|
nsMsgProtocol::OpenNetworkSocketWithInfo(const char * aHostName,
|
|
|
|
PRInt32 aGetPort,
|
|
|
|
const char *connectionType,
|
|
|
|
nsIInterfaceRequestor* callbacks)
|
1999-06-05 01:41:47 +04:00
|
|
|
{
|
2000-02-27 02:11:45 +03:00
|
|
|
NS_ENSURE_ARG(aHostName);
|
1999-06-05 01:41:47 +04:00
|
|
|
|
2000-02-27 02:11:45 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsISocketTransportService> socketService (do_GetService(kSocketTransportServiceCID));
|
|
|
|
NS_ENSURE_TRUE(socketService, NS_ERROR_FAILURE);
|
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
// with socket connections we want to read as much data as arrives
|
|
|
|
m_readCount = -1;
|
|
|
|
m_startPosition = 0;
|
1999-07-29 04:42:25 +04:00
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
rv = socketService->CreateTransportOfType(connectionType, aHostName,
|
|
|
|
aGetPort, nsnull, -1, 0, 0,
|
|
|
|
getter_AddRefs(m_transport));
|
2000-02-27 02:11:45 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-07-29 04:42:25 +04:00
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
m_transport->SetNotificationCallbacks(callbacks, PR_FALSE);
|
2000-02-27 02:11:45 +03:00
|
|
|
m_socketIsOpen = PR_FALSE;
|
2001-03-06 08:10:33 +03:00
|
|
|
return SetupTransportState();
|
2000-02-27 02:11:45 +03:00
|
|
|
}
|
1999-07-29 04:42:25 +04:00
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
// open a connection on this url
|
|
|
|
nsresult
|
|
|
|
nsMsgProtocol::OpenNetworkSocket(nsIURI * aURL, const char *connectionType,
|
|
|
|
nsIInterfaceRequestor* callbacks)
|
2000-02-27 02:11:45 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aURL);
|
1999-06-05 01:41:47 +04:00
|
|
|
|
2000-02-27 02:11:45 +03:00
|
|
|
nsXPIDLCString hostName;
|
2001-03-06 08:10:33 +03:00
|
|
|
PRInt32 port = 0;
|
2000-02-27 02:11:45 +03:00
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
aURL->GetPort(&port);
|
|
|
|
aURL->GetHost(getter_Copies(hostName));
|
2000-02-27 02:11:45 +03:00
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
return OpenNetworkSocketWithInfo(hostName, port, connectionType, callbacks);
|
1999-06-05 01:41:47 +04:00
|
|
|
}
|
|
|
|
|
2001-04-30 02:43:57 +04:00
|
|
|
nsresult nsMsgProtocol::GetFileFromURL(nsIURI * aURL, nsIFile **aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURL);
|
|
|
|
NS_ENSURE_ARG_POINTER(aResult);
|
|
|
|
// extract the file path from the uri...
|
|
|
|
nsXPIDLCString filePath;
|
|
|
|
aURL->GetPath(getter_Copies(filePath));
|
|
|
|
char * urlSpec = PR_smprintf("file://%s", (const char *) filePath);
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
// dougt - there should be an easier way!
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
if (NS_FAILED(rv = NS_NewURI(getter_AddRefs(uri), urlSpec)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(uri);
|
|
|
|
if (!fileURL) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return fileURL->GetFile(aResult);
|
|
|
|
// dougt
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgProtocol::OpenFileSocket(nsIURI * aURL, PRUint32 aStartPosition, PRInt32 aReadCount)
|
1999-06-05 01:41:47 +04:00
|
|
|
{
|
1999-07-29 04:42:25 +04:00
|
|
|
// mscott - file needs to be encoded directly into aURL. I should be able to get
|
|
|
|
// rid of this method completely.
|
|
|
|
|
1999-06-05 01:41:47 +04:00
|
|
|
nsresult rv = NS_OK;
|
1999-07-29 04:42:25 +04:00
|
|
|
m_startPosition = aStartPosition;
|
|
|
|
m_readCount = aReadCount;
|
2001-04-30 02:43:57 +04:00
|
|
|
nsCOMPtr <nsIFile> file;
|
1999-07-29 04:42:25 +04:00
|
|
|
|
2001-04-30 02:43:57 +04:00
|
|
|
rv = GetFileFromURL(aURL, getter_AddRefs(file));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-07-29 04:42:25 +04:00
|
|
|
|
2001-04-30 02:43:57 +04:00
|
|
|
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-02-21 23:38:08 +03:00
|
|
|
|
2001-04-30 02:43:57 +04:00
|
|
|
rv = fts->CreateTransport(file, PR_RDWR | PR_CREATE_FILE,
|
|
|
|
0664, getter_AddRefs(m_transport));
|
|
|
|
m_socketIsOpen = PR_FALSE;
|
1999-06-05 01:41:47 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgProtocol::SetupTransportState()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
if (!m_socketIsOpen && m_transport)
|
1999-06-05 01:41:47 +04:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
rv = m_transport->OpenOutputStream(0, PRUint32(-1), 0, getter_AddRefs(m_outputStream));
|
1999-06-05 01:41:47 +04:00
|
|
|
|
1999-07-29 04:42:25 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create an output stream");
|
|
|
|
// we want to open the stream
|
1999-06-05 01:41:47 +04:00
|
|
|
} // if m_transport
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgProtocol::CloseSocket()
|
|
|
|
{
|
2000-03-12 09:40:25 +03:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-06-05 01:41:47 +04:00
|
|
|
// release all of our socket state
|
|
|
|
m_socketIsOpen = PR_FALSE;
|
|
|
|
m_outputStream = null_nsCOMPtr();
|
2000-03-12 09:40:25 +03:00
|
|
|
|
|
|
|
// we need to call Cancel so that we remove the socket transport from the mActiveTransportList. see bug #30648
|
2001-02-21 23:38:08 +03:00
|
|
|
if (m_request) {
|
|
|
|
rv = m_request->Cancel(NS_BINDING_ABORTED);
|
2000-03-12 09:40:25 +03:00
|
|
|
}
|
2001-02-21 23:38:08 +03:00
|
|
|
m_request = 0;
|
|
|
|
m_transport = 0;
|
1999-06-05 01:41:47 +04:00
|
|
|
|
2000-03-12 09:40:25 +03:00
|
|
|
return rv;
|
1999-06-05 01:41:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Writes the data contained in dataBuffer into the current output stream. It also informs
|
|
|
|
* the transport layer that this data is now available for transmission.
|
|
|
|
* Returns a positive number for success, 0 for failure (not all the bytes were written to the
|
|
|
|
* stream, etc). We need to make another pass through this file to install an error system (mscott)
|
2000-11-16 02:55:25 +03:00
|
|
|
*
|
2000-11-17 23:47:31 +03:00
|
|
|
* No logging is done in the base implementation, so aSuppressLogging is ignored.
|
1999-06-05 01:41:47 +04:00
|
|
|
*/
|
|
|
|
|
2000-11-17 23:47:31 +03:00
|
|
|
PRInt32 nsMsgProtocol::SendData(nsIURI * aURL, const char * dataBuffer, PRBool aSuppressLogging)
|
1999-06-05 01:41:47 +04:00
|
|
|
{
|
|
|
|
PRUint32 writeCount = 0;
|
|
|
|
PRInt32 status = 0;
|
|
|
|
|
1999-07-29 04:42:25 +04:00
|
|
|
// NS_PRECONDITION(m_outputStream, "oops....we don't have an output stream...how did that happen?");
|
1999-06-05 01:41:47 +04:00
|
|
|
if (dataBuffer && m_outputStream)
|
|
|
|
{
|
1999-08-05 00:35:58 +04:00
|
|
|
status = m_outputStream->Write(dataBuffer, PL_strlen(dataBuffer), &writeCount);
|
1999-06-05 01:41:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
1999-06-06 00:21:27 +04:00
|
|
|
|
|
|
|
// Whenever data arrives from the connection, core netlib notifices the protocol by calling
|
|
|
|
// OnDataAvailable. We then read and process the incoming data from the input stream.
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::OnDataAvailable(nsIRequest *request, nsISupports *ctxt, nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
|
1999-06-06 00:21:27 +04:00
|
|
|
{
|
|
|
|
// right now, this really just means turn around and churn through the state machine
|
1999-07-29 04:42:25 +04:00
|
|
|
nsCOMPtr<nsIURI> uri = do_QueryInterface(ctxt);
|
|
|
|
return ProcessProtocolState(uri, inStr, sourceOffset, count);
|
1999-06-06 00:21:27 +04:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::OnStartRequest(nsIRequest *request, nsISupports *ctxt)
|
1999-06-06 00:21:27 +04:00
|
|
|
{
|
1999-07-29 04:42:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(ctxt, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && aMsgUrl)
|
2000-01-10 02:38:52 +03:00
|
|
|
{
|
1999-09-12 09:05:28 +04:00
|
|
|
rv = aMsgUrl->SetUrlState(PR_TRUE, NS_OK);
|
2000-03-21 09:26:03 +03:00
|
|
|
if (m_loadGroup)
|
2001-02-21 23:38:08 +03:00
|
|
|
m_loadGroup->AddRequest(NS_STATIC_CAST(nsIRequest *, this), nsnull /* context isupports */);
|
2000-01-10 02:38:52 +03:00
|
|
|
}
|
1999-09-12 09:05:28 +04:00
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
// if we are set up as a channel, we should notify our channel listener that we are starting...
|
1999-09-12 09:05:28 +04:00
|
|
|
// so pass in ourself as the channel and not the underlying socket or file channel the protocol
|
|
|
|
// happens to be using
|
2000-11-17 23:47:31 +03:00
|
|
|
if (!mSuppressListenerNotifications && m_channelListener)
|
2000-07-15 03:16:47 +04:00
|
|
|
{
|
|
|
|
if (!m_channelContext)
|
|
|
|
m_channelContext = do_QueryInterface(ctxt);
|
|
|
|
rv = m_channelListener->OnStartRequest(this, m_channelContext);
|
|
|
|
}
|
1999-09-12 09:05:28 +04:00
|
|
|
|
2001-04-30 02:43:57 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-09-12 09:05:28 +04:00
|
|
|
return rv;
|
1999-06-06 00:21:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// stop binding is a "notification" informing us that the stream associated with aURL is going away.
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult aStatus)
|
1999-06-06 00:21:27 +04:00
|
|
|
{
|
1999-07-29 04:42:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
2000-03-21 09:26:03 +03:00
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
// if we are set up as a channel, we should notify our channel listener that we are starting...
|
|
|
|
// so pass in ourself as the channel and not the underlying socket or file channel the protocol
|
|
|
|
// happens to be using
|
2000-11-17 23:47:31 +03:00
|
|
|
if (!mSuppressListenerNotifications && m_channelListener)
|
2001-04-10 10:01:08 +04:00
|
|
|
rv = m_channelListener->OnStopRequest(this, m_channelContext, aStatus);
|
2000-03-12 09:40:25 +03:00
|
|
|
|
2000-07-08 05:10:30 +04:00
|
|
|
nsCOMPtr <nsIMsgMailNewsUrl> msgUrl = do_QueryInterface(ctxt, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && msgUrl)
|
2000-03-21 09:26:03 +03:00
|
|
|
{
|
2000-07-08 05:10:30 +04:00
|
|
|
rv = msgUrl->SetUrlState(PR_FALSE, aStatus);
|
2000-03-21 09:26:03 +03:00
|
|
|
if (m_loadGroup)
|
2001-04-10 10:01:08 +04:00
|
|
|
m_loadGroup->RemoveRequest(NS_STATIC_CAST(nsIRequest *, this), nsnull, aStatus);
|
2000-07-08 05:10:30 +04:00
|
|
|
|
|
|
|
// !NS_BINDING_ABORTED because we don't want to see an alert if the user
|
|
|
|
// cancelled the operation. also, we'll get here because we call Cancel()
|
|
|
|
// to force removal of the nsSocketTransport. see CloseSocket()
|
|
|
|
// bugs #30775 and #30648 relate to this
|
|
|
|
if (NS_FAILED(aStatus) && (aStatus != NS_BINDING_ABORTED))
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrompt> msgPrompt;
|
|
|
|
GetPromptDialogFromUrl(msgUrl , getter_AddRefs(msgPrompt));
|
|
|
|
NS_ENSURE_TRUE(msgPrompt, NS_ERROR_FAILURE);
|
2000-03-21 09:26:03 +03:00
|
|
|
|
2001-06-05 02:47:15 +04:00
|
|
|
PRInt32 errorID;
|
|
|
|
switch (aStatus)
|
2000-07-08 05:10:30 +04:00
|
|
|
{
|
2001-06-05 02:47:15 +04:00
|
|
|
case NS_ERROR_UNKNOWN_HOST:
|
|
|
|
errorID = UNKNOWN_HOST_ERROR;
|
|
|
|
break;
|
|
|
|
case NS_ERROR_CONNECTION_REFUSED:
|
|
|
|
errorID = CONNECTION_REFUSED_ERROR;
|
|
|
|
break;
|
|
|
|
case NS_ERROR_NET_TIMEOUT:
|
|
|
|
errorID = NET_TIMEOUT_ERROR;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errorID = UNKNOWN_ERROR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PRUnichar *errorMsg = GetStringByID(errorID);
|
|
|
|
if (errorMsg == nsnull) {
|
|
|
|
nsAutoString resultString(NS_LITERAL_STRING("[StringID "));
|
|
|
|
resultString.AppendInt(errorID, 10);
|
|
|
|
resultString.Append(NS_LITERAL_STRING("?]"));
|
|
|
|
errorMsg = resultString.ToNewUnicode();
|
|
|
|
} else if (errorID == UNKNOWN_ERROR) {
|
|
|
|
nsAutoString errorString(errorMsg);
|
|
|
|
errorString.Append(NS_LITERAL_STRING(" "));
|
|
|
|
errorString.AppendInt(aStatus, 16);
|
|
|
|
nsMemory::Free(errorMsg);
|
|
|
|
errorMsg = errorString.ToNewUnicode();
|
|
|
|
}
|
|
|
|
rv = msgPrompt->Alert(nsnull, errorMsg);
|
|
|
|
nsMemory::Free(errorMsg);
|
2000-07-08 05:10:30 +04:00
|
|
|
} // if we got an error code
|
|
|
|
} // if we have a mailnews url.
|
2000-02-26 04:04:50 +03:00
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
return rv;
|
1999-06-06 00:21:27 +04:00
|
|
|
}
|
|
|
|
|
2000-07-08 05:10:30 +04:00
|
|
|
nsresult nsMsgProtocol::GetPromptDialogFromUrl(nsIMsgMailNewsUrl * aMsgUrl, nsIPrompt ** aPromptDialog)
|
|
|
|
{
|
|
|
|
// get the nsIPrompt interface from the message window associated wit this url.
|
|
|
|
nsCOMPtr<nsIMsgWindow> msgWindow;
|
|
|
|
aMsgUrl->GetMsgWindow(getter_AddRefs(msgWindow));
|
|
|
|
NS_ENSURE_TRUE(msgWindow, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
msgWindow->GetPromptDialog(aPromptDialog);
|
|
|
|
|
|
|
|
NS_ENSURE_TRUE(*aPromptDialog, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
nsresult nsMsgProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
|
1999-06-06 00:21:27 +04:00
|
|
|
{
|
|
|
|
// okay now kick us off to the next state...
|
|
|
|
// our first state is a process state so drive the state machine...
|
|
|
|
nsresult rv = NS_OK;
|
2000-04-06 07:23:21 +04:00
|
|
|
nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(aURL, &rv);
|
1999-06-06 00:21:27 +04:00
|
|
|
|
2000-07-15 03:16:47 +04:00
|
|
|
if (NS_SUCCEEDED(rv) && aMsgUrl)
|
1999-06-06 00:21:27 +04:00
|
|
|
{
|
2000-12-30 01:49:05 +03:00
|
|
|
PRBool msgIsInLocalCache;
|
|
|
|
aMsgUrl->GetMsgIsInLocalCache(&msgIsInLocalCache);
|
|
|
|
|
1999-06-06 00:21:27 +04:00
|
|
|
rv = aMsgUrl->SetUrlState(PR_TRUE, NS_OK); // set the url as a url currently being run...
|
1999-07-29 04:42:25 +04:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
// if the url is given a stream consumer then we should use it to forward calls to...
|
|
|
|
if (!m_channelListener && aConsumer) // if we don't have a registered listener already
|
|
|
|
{
|
|
|
|
m_channelListener = do_QueryInterface(aConsumer);
|
|
|
|
if (!m_channelContext)
|
|
|
|
m_channelContext = do_QueryInterface(aURL);
|
|
|
|
}
|
1999-09-12 09:05:28 +04:00
|
|
|
|
1999-07-29 04:42:25 +04:00
|
|
|
if (!m_socketIsOpen)
|
|
|
|
{
|
1999-09-18 00:13:59 +04:00
|
|
|
nsCOMPtr<nsISupports> urlSupports = do_QueryInterface(aURL);
|
2001-02-21 23:38:08 +03:00
|
|
|
if (m_transport)
|
2000-07-15 03:16:47 +04:00
|
|
|
{
|
|
|
|
// put us in a state where we are always notified of incoming data
|
2001-02-21 23:38:08 +03:00
|
|
|
rv = m_transport->AsyncRead(this, urlSupports, m_startPosition, m_readCount, 0, getter_AddRefs(m_request));
|
2000-07-15 03:16:47 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "AsyncRead failed");
|
|
|
|
m_socketIsOpen = PR_TRUE; // mark the channel as open
|
|
|
|
}
|
1999-07-29 04:42:25 +04:00
|
|
|
} // if we got an event queue service
|
2000-12-30 01:49:05 +03:00
|
|
|
else if (!msgIsInLocalCache) // the connection is already open so we should begin processing our new url...
|
1999-07-29 04:42:25 +04:00
|
|
|
rv = ProcessProtocolState(aURL, nsnull, 0, 0);
|
1999-06-06 00:21:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
// The rest of this file is mostly nsIChannel mumbo jumbo stuff
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult nsMsgProtocol::SetUrl(nsIURI * aURL)
|
|
|
|
{
|
|
|
|
m_url = dont_QueryInterface(aURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::SetLoadGroup(nsILoadGroup * aLoadGroup)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
|
|
|
m_loadGroup = dont_QueryInterface(aLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetOriginalURI(nsIURI* *aURI)
|
1999-10-26 13:16:24 +04:00
|
|
|
{
|
2000-03-29 07:58:50 +04:00
|
|
|
*aURI = m_originalUrl ? m_originalUrl : m_url;
|
1999-10-26 13:16:24 +04:00
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::SetOriginalURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
m_originalUrl = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetURI(nsIURI* *aURI)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
1999-10-26 13:16:24 +04:00
|
|
|
*aURI = m_url;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::Open(nsIInputStream **_retval)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
NS_NOTREACHED("Open");
|
1999-09-12 09:05:28 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::AsyncOpen(nsIStreamListener *listener, nsISupports *ctxt)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2001-06-06 04:10:09 +04:00
|
|
|
PRInt32 port;
|
|
|
|
nsresult rv = m_url->GetPort(&port);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
nsXPIDLCString scheme;
|
|
|
|
rv = m_url->GetScheme(getter_Copies(scheme));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
|
|
|
|
rv = NS_CheckPortSafety(port, scheme);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
// set the stream listener and then load the url
|
|
|
|
m_channelContext = ctxt;
|
|
|
|
m_channelListener = listener;
|
|
|
|
return LoadUrl(m_url, nsnull);
|
|
|
|
}
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
*aLoadFlags = mLoadFlags;
|
2000-03-21 09:26:03 +03:00
|
|
|
return NS_OK;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::SetLoadFlags(nsLoadFlags aLoadFlags)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
mLoadFlags = aLoadFlags;
|
2000-03-21 09:26:03 +03:00
|
|
|
return NS_OK; // don't fail when trying to set this
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetContentType(char * *aContentType)
|
|
|
|
{
|
1999-10-27 10:48:19 +04:00
|
|
|
// as url dispatching matures, we'll be intelligent and actually start
|
|
|
|
// opening the url before specifying the content type. This will allow
|
|
|
|
// us to optimize the case where the message url actual refers to
|
|
|
|
// a part in the message that has a content type that is not message/rfc822
|
|
|
|
|
2000-06-23 07:11:20 +04:00
|
|
|
if (m_ContentType.IsEmpty())
|
|
|
|
*aContentType = nsCRT::strdup("message/rfc822");
|
|
|
|
else
|
|
|
|
*aContentType = m_ContentType.ToNewCString();
|
1999-09-12 09:05:28 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-08 09:26:04 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::SetContentType(const char *aContentType)
|
|
|
|
{
|
2000-06-23 07:11:20 +04:00
|
|
|
m_ContentType = aContentType;
|
|
|
|
return NS_OK;
|
2000-01-08 09:26:04 +03:00
|
|
|
}
|
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetContentLength(PRInt32 * aContentLength)
|
|
|
|
{
|
|
|
|
*aContentLength = -1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
2001-02-12 06:14:23 +03:00
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-02-12 06:14:23 +03:00
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetName(PRUnichar * *aName)
|
2001-02-12 06:14:23 +03:00
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-02-12 06:14:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsMsgProtocol::SetContentLength(PRInt32 aContentLength)
|
2001-02-12 06:14:23 +03:00
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
2001-01-26 01:07:38 +03:00
|
|
|
}
|
2001-04-08 04:40:30 +04:00
|
|
|
|
1999-09-12 10:28:20 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetOwner(nsISupports * *aPrincipal)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2000-06-23 07:11:20 +04:00
|
|
|
*aPrincipal = mOwner;
|
|
|
|
NS_IF_ADDREF(*aPrincipal);
|
2000-01-06 01:55:04 +03:00
|
|
|
return NS_OK;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
1999-09-12 10:28:20 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::SetOwner(nsISupports * aPrincipal)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2000-06-23 07:11:20 +04:00
|
|
|
mOwner = aPrincipal;
|
|
|
|
return NS_OK;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetLoadGroup(nsILoadGroup * *aLoadGroup)
|
1999-11-17 11:14:52 +03:00
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
*aLoadGroup = m_loadGroup;
|
|
|
|
NS_IF_ADDREF(*aLoadGroup);
|
1999-11-17 11:14:52 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-18 10:36:41 +03:00
|
|
|
nsMsgProtocol::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2000-05-04 01:16:22 +04:00
|
|
|
*aNotificationCallbacks = mCallbacks.get();
|
|
|
|
NS_IF_ADDREF(*aNotificationCallbacks);
|
|
|
|
return NS_OK;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
1999-11-18 10:36:41 +03:00
|
|
|
nsMsgProtocol::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
1999-11-17 11:14:52 +03:00
|
|
|
{
|
2000-05-04 01:16:22 +04:00
|
|
|
mCallbacks = aNotificationCallbacks;
|
|
|
|
|
|
|
|
// Verify that the event sink is http
|
|
|
|
if (mCallbacks)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIProgressEventSink> progressSink;
|
|
|
|
(void)mCallbacks->GetInterface(NS_GET_IID(nsIProgressEventSink),
|
|
|
|
getter_AddRefs(progressSink));
|
|
|
|
// only replace our current progress event sink if we were given a new one..
|
|
|
|
if (progressSink) mProgressEventSink = progressSink;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-17 11:14:52 +03:00
|
|
|
}
|
|
|
|
|
1999-09-12 09:05:28 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// From nsIRequest
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::IsPending(PRBool *result)
|
|
|
|
{
|
|
|
|
*result = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP nsMsgProtocol::GetStatus(nsresult *status)
|
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
if (m_request)
|
|
|
|
return m_request->GetStatus(status);
|
2000-07-27 01:07:01 +04:00
|
|
|
|
|
|
|
*status = NS_ERROR_FAILURE;
|
|
|
|
return *status;
|
2000-03-29 07:58:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::Cancel(nsresult status)
|
1999-09-12 09:05:28 +04:00
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_ASSERTION(m_request,"no channel");
|
2001-04-08 04:40:30 +04:00
|
|
|
if (!m_request)
|
2000-09-22 04:44:08 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
return m_request->Cancel(status);
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::Suspend()
|
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
NS_NOTREACHED("Suspend");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgProtocol::Resume()
|
|
|
|
{
|
2001-04-08 04:40:30 +04:00
|
|
|
NS_NOTREACHED("Resume");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-09-12 09:05:28 +04:00
|
|
|
}
|
1999-11-22 17:41:20 +03:00
|
|
|
|
|
|
|
nsresult nsMsgProtocol::PostMessage(nsIURI* url, nsIFileSpec *fileSpec)
|
|
|
|
{
|
|
|
|
if (!url || !fileSpec) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
#define POST_DATA_BUFFER_SIZE 2048
|
|
|
|
|
|
|
|
// mscott -- this function should be re-written to use the file url code
|
|
|
|
// so it can be asynch
|
|
|
|
nsFileSpec afileSpec;
|
|
|
|
fileSpec->GetFileSpec(&afileSpec);
|
|
|
|
nsInputFileStream * fileStream = new nsInputFileStream(afileSpec,
|
|
|
|
PR_RDONLY, 00700);
|
|
|
|
if (fileStream && fileStream->is_open())
|
|
|
|
{
|
|
|
|
PRInt32 amtInBuffer = 0;
|
|
|
|
PRBool lastLineWasComplete = PR_TRUE;
|
|
|
|
|
|
|
|
PRBool quoteLines = PR_TRUE; // it is always true but I'd like to
|
|
|
|
// generalize this function and then it
|
|
|
|
// might not be
|
|
|
|
char buffer[POST_DATA_BUFFER_SIZE];
|
|
|
|
|
|
|
|
if (quoteLines /* || add_crlf_to_line_endings */)
|
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
char * b = buffer;
|
|
|
|
PRInt32 bsize = POST_DATA_BUFFER_SIZE;
|
|
|
|
amtInBuffer = 0;
|
|
|
|
do {
|
|
|
|
lastLineWasComplete = PR_TRUE;
|
|
|
|
PRInt32 L = 0;
|
|
|
|
if (fileStream->eof())
|
|
|
|
{
|
|
|
|
line = nsnull;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fileStream->readline(b, bsize-5))
|
|
|
|
lastLineWasComplete = PR_FALSE;
|
|
|
|
line = b;
|
|
|
|
|
|
|
|
L = PL_strlen(line);
|
|
|
|
|
|
|
|
/* escape periods only if quote_lines_p is set
|
|
|
|
*/
|
|
|
|
if (quoteLines && lastLineWasComplete && line[0] == '.')
|
|
|
|
{
|
|
|
|
/* This line begins with "." so we need to quote it
|
|
|
|
by adding another "." to the beginning of the line.
|
|
|
|
*/
|
|
|
|
PRInt32 i;
|
|
|
|
line[L+1] = 0;
|
|
|
|
for (i = L; i > 0; i--)
|
|
|
|
line[i] = line[i-1];
|
|
|
|
L++;
|
|
|
|
}
|
|
|
|
|
2001-04-18 09:59:43 +04:00
|
|
|
if (!lastLineWasComplete || (L > 1 && line[L-2] == nsCRT::CR &&
|
|
|
|
line[L-1] == nsCRT::LF))
|
1999-11-22 17:41:20 +03:00
|
|
|
{
|
|
|
|
/* already ok */
|
|
|
|
}
|
2001-04-18 09:59:43 +04:00
|
|
|
else if(L > 0 /* && (line[L-1] == nsCRT::LF || line[L-1] == nsCRT::CR) */)
|
1999-11-22 17:41:20 +03:00
|
|
|
{
|
|
|
|
/* only add the crlf if required
|
|
|
|
* we still need to do all the
|
|
|
|
* if comparisons here to know
|
|
|
|
* if the line was complete
|
|
|
|
*/
|
|
|
|
if(/* add_crlf_to_line_endings */ PR_TRUE)
|
|
|
|
{
|
|
|
|
/* Change newline to CRLF. */
|
2001-04-18 09:59:43 +04:00
|
|
|
line[L++] = nsCRT::CR;
|
|
|
|
line[L++] = nsCRT::LF;
|
1999-11-22 17:41:20 +03:00
|
|
|
line[L] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (L == 0 && !fileStream->eof()
|
|
|
|
/* && add_crlf_to_line_endings */)
|
|
|
|
{
|
|
|
|
// jt ** empty line; output CRLF
|
2001-04-18 09:59:43 +04:00
|
|
|
line[L++] = nsCRT::CR;
|
|
|
|
line[L++] = nsCRT::LF;
|
1999-11-22 17:41:20 +03:00
|
|
|
line[L] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bsize -= L;
|
|
|
|
b += L;
|
|
|
|
amtInBuffer += L;
|
|
|
|
// test hack by mscott. If our buffer is almost full, then
|
|
|
|
// send it off & reset ourselves
|
|
|
|
// to make more room.
|
|
|
|
if (bsize < 100) // i chose 100 arbitrarily.
|
|
|
|
{
|
|
|
|
if (*buffer)
|
|
|
|
SendData(url, buffer);
|
|
|
|
buffer[0] = '\0';
|
|
|
|
b = buffer; // reset buffer
|
|
|
|
bsize = POST_DATA_BUFFER_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
} while (line /* && bsize > 100 */);
|
|
|
|
}
|
|
|
|
|
|
|
|
SendData(url, buffer);
|
|
|
|
delete fileStream;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-04-08 04:40:30 +04:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// nsMsgAsyncWriteProtocol subclass and related helper classes
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class nsMsgProtocolStreamProvider : public nsIStreamProvider
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
nsMsgProtocolStreamProvider() { NS_INIT_REFCNT(); }
|
|
|
|
virtual ~nsMsgProtocolStreamProvider() {}
|
|
|
|
|
|
|
|
void Init(nsMsgAsyncWriteProtocol *aProtInstance, nsIInputStream *aInputStream) { mMsgProtocol = aProtInstance; mInStream = aInputStream;}
|
|
|
|
|
|
|
|
//
|
2001-04-10 10:01:08 +04:00
|
|
|
// nsIRequestObserver implementation ...
|
2001-04-08 04:40:30 +04:00
|
|
|
//
|
|
|
|
NS_IMETHODIMP OnStartRequest(nsIRequest *chan, nsISupports *ctxt) { return NS_OK; }
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP OnStopRequest(nsIRequest *chan, nsISupports *ctxt, nsresult status) { return NS_OK; }
|
2001-04-08 04:40:30 +04:00
|
|
|
|
|
|
|
//
|
|
|
|
// nsIStreamProvider implementation ...
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP OnDataWritable(nsIRequest *aChannel, nsISupports *aContext,
|
|
|
|
nsIOutputStream *aOutStream,
|
|
|
|
PRUint32 aOffset, PRUint32 aCount)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(mInStream, "not initialized");
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRUint32 avail;
|
|
|
|
|
|
|
|
// Write whatever is available in the pipe. If the pipe is empty, then
|
|
|
|
// return NS_BASE_STREAM_WOULD_BLOCK; we will resume the write when there
|
|
|
|
// is more data.
|
|
|
|
|
|
|
|
rv = mInStream->Available(&avail);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (avail == 0)
|
|
|
|
{
|
|
|
|
mMsgProtocol->mSuspendedWrite = PR_TRUE;
|
|
|
|
return NS_BASE_STREAM_WOULD_BLOCK;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 bytesWritten;
|
|
|
|
rv = aOutStream->WriteFrom(mInStream, PR_MIN(avail, aCount), &bytesWritten);
|
|
|
|
// if were full at the time, the input stream may be backed up and we need to read any remains from the last ODA call
|
|
|
|
// before we'll get more ODA calls
|
|
|
|
if (mMsgProtocol->mSuspendedRead)
|
|
|
|
mMsgProtocol->UnblockPostReader();
|
2001-06-29 08:05:38 +04:00
|
|
|
|
|
|
|
mMsgProtocol->UpdateProgress(bytesWritten);
|
2001-04-08 04:40:30 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsMsgAsyncWriteProtocol * mMsgProtocol;
|
|
|
|
nsCOMPtr<nsIInputStream> mInStream;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsMsgProtocolStreamProvider,
|
|
|
|
nsIStreamProvider,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsIRequestObserver)
|
2001-04-08 04:40:30 +04:00
|
|
|
|
|
|
|
class nsMsgFilePostHelper : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
2001-04-08 04:40:30 +04:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
|
|
|
|
|
|
|
nsMsgFilePostHelper() { NS_INIT_REFCNT(); mSuspendedPostFileRead = PR_FALSE;}
|
|
|
|
nsresult Init(nsIOutputStream * aOutStream, nsMsgAsyncWriteProtocol * aProtInstance, nsIFile *aFileToPost);
|
|
|
|
virtual ~nsMsgFilePostHelper() {}
|
|
|
|
nsCOMPtr<nsIRequest> mPostFileRequest;
|
|
|
|
PRBool mSuspendedPostFileRead;
|
2001-06-06 04:44:06 +04:00
|
|
|
void CloseSocket() { mProtInstance = nsnull; }
|
2001-04-08 04:40:30 +04:00
|
|
|
protected:
|
|
|
|
nsCOMPtr<nsIOutputStream> mOutStream;
|
|
|
|
nsMsgAsyncWriteProtocol * mProtInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_THREADSAFE_ADDREF(nsMsgFilePostHelper)
|
|
|
|
NS_IMPL_THREADSAFE_RELEASE(nsMsgFilePostHelper)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMsgFilePostHelper)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
|
2001-04-08 04:40:30 +04:00
|
|
|
NS_INTERFACE_MAP_END_THREADSAFE
|
|
|
|
|
|
|
|
nsresult nsMsgFilePostHelper::Init(nsIOutputStream * aOutStream, nsMsgAsyncWriteProtocol * aProtInstance, nsIFile *aFileToPost)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
mOutStream = aOutStream;
|
|
|
|
mProtInstance = aProtInstance; // mscott work out ref counting issue
|
|
|
|
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITransport> transport;
|
|
|
|
rv = fts->CreateTransport(aFileToPost, PR_RDONLY, 0664, getter_AddRefs(transport));
|
|
|
|
if (transport)
|
|
|
|
{
|
|
|
|
rv = transport->AsyncRead(this, nsnull, 0, -1, 0, getter_AddRefs(mPostFileRequest));
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgFilePostHelper::OnStartRequest(nsIRequest * aChannel, nsISupports *ctxt)
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_IMETHODIMP nsMsgFilePostHelper::OnStopRequest(nsIRequest * aChannel, nsISupports *ctxt, nsresult aStatus)
|
2001-04-08 04:40:30 +04:00
|
|
|
{
|
2001-06-20 03:19:55 +04:00
|
|
|
if (!mProtInstance) return NS_OK;
|
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
if (!mSuspendedPostFileRead)
|
|
|
|
mProtInstance->PostDataFinished();
|
|
|
|
|
|
|
|
mSuspendedPostFileRead = PR_FALSE;
|
|
|
|
mProtInstance->mFilePostHelper = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP nsMsgFilePostHelper::OnDataAvailable(nsIRequest * /* aChannel */, nsISupports *ctxt, nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
|
|
|
|
{
|
2001-06-06 04:44:06 +04:00
|
|
|
if (!mProtInstance) return NS_OK;
|
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
if (mSuspendedPostFileRead)
|
|
|
|
{
|
|
|
|
mProtInstance->UpdateSuspendedReadBytes(count, mProtInstance->mInsertPeriodRequired);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
mProtInstance->ProcessIncomingPostData(inStr, count);
|
|
|
|
|
|
|
|
if (mProtInstance->mSuspendedWrite)
|
|
|
|
{
|
|
|
|
// if we got here then we had suspended the write 'cause we didn't have anymore
|
|
|
|
// data to write (i.e. the pipe went empty). So resume the channel to kick
|
|
|
|
// things off again.
|
|
|
|
mProtInstance->mSuspendedWrite = PR_FALSE;
|
|
|
|
mProtInstance->m_WriteRequest->Resume();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsMsgAsyncWriteProtocol, nsMsgProtocol)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsMsgAsyncWriteProtocol, nsMsgProtocol)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMsgAsyncWriteProtocol)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsMsgProtocol)
|
|
|
|
|
|
|
|
nsMsgAsyncWriteProtocol::nsMsgAsyncWriteProtocol(nsIURI * aURL) : nsMsgProtocol(aURL)
|
|
|
|
{
|
|
|
|
mSuspendedWrite = PR_FALSE;
|
|
|
|
mSuspendedReadBytes = 0;
|
|
|
|
mSuspendedRead = PR_FALSE;
|
|
|
|
mInsertPeriodRequired = PR_FALSE;
|
2001-06-29 08:05:38 +04:00
|
|
|
mGenerateProgressNotifications = PR_FALSE;
|
2001-04-08 04:40:30 +04:00
|
|
|
mSuspendedReadBytesPostPeriod = 0;
|
|
|
|
mFilePostHelper = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMsgAsyncWriteProtocol::~nsMsgAsyncWriteProtocol()
|
|
|
|
{}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::PostMessage(nsIURI* url, nsIFileSpec *fileSpec)
|
|
|
|
{
|
|
|
|
// convert the file spec into a nsIFile....
|
|
|
|
nsFileSpec * spec = new nsFileSpec();
|
|
|
|
fileSpec->GetFileSpec(spec);
|
|
|
|
|
|
|
|
nsCOMPtr<nsILocalFile> file;
|
|
|
|
NS_FileSpecToIFile(spec, getter_AddRefs(file));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
NS_NEWXPCOM(listener, nsMsgFilePostHelper);
|
|
|
|
if (!listener) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
// be sure to initialize some state before posting
|
|
|
|
mSuspendedReadBytes = 0;
|
2001-06-29 08:05:38 +04:00
|
|
|
mNumBytesPosted = 0;
|
|
|
|
fileSpec->GetFileSize(&mFilePostSize);
|
2001-04-08 04:40:30 +04:00
|
|
|
mSuspendedRead = PR_FALSE;
|
|
|
|
mInsertPeriodRequired = PR_FALSE;
|
|
|
|
mSuspendedReadBytesPostPeriod = 0;
|
2001-06-29 08:05:38 +04:00
|
|
|
mGenerateProgressNotifications = PR_TRUE;
|
2001-04-08 04:40:30 +04:00
|
|
|
|
|
|
|
mFilePostHelper = NS_STATIC_CAST(nsMsgFilePostHelper*,NS_STATIC_CAST(nsIStreamListener*, listener));
|
|
|
|
|
|
|
|
NS_STATIC_CAST(nsMsgFilePostHelper*,NS_STATIC_CAST(nsIStreamListener*, listener))->Init(m_outputStream, this, file);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::SuspendPostFileRead()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_mscott
|
|
|
|
printf("suspending post read during send\n");
|
|
|
|
#endif
|
2001-06-02 08:54:51 +04:00
|
|
|
if (mFilePostHelper && !mFilePostHelper->mSuspendedPostFileRead)
|
2001-04-08 04:40:30 +04:00
|
|
|
{
|
|
|
|
// uhoh we need to pause reading in the file until we get unblocked...
|
|
|
|
mFilePostHelper->mPostFileRequest->Suspend();
|
|
|
|
mFilePostHelper->mSuspendedPostFileRead = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::ResumePostFileRead()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_mscott
|
|
|
|
printf("resuming post read during send\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mFilePostHelper)
|
|
|
|
{
|
|
|
|
if (mFilePostHelper->mSuspendedPostFileRead)
|
|
|
|
{
|
|
|
|
mFilePostHelper->mPostFileRequest->Resume();
|
|
|
|
mFilePostHelper->mSuspendedPostFileRead = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else // we must be done with the download so send the '.'
|
|
|
|
{
|
|
|
|
PostDataFinished();
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::UpdateSuspendedReadBytes(PRUint32 aNewBytes, PRBool aAddToPostPeriodByteCount)
|
|
|
|
{
|
|
|
|
// depending on our current state, we'll either add aNewBytes to mSuspendedReadBytes
|
|
|
|
// or mSuspendedReadBytesAfterPeriod.
|
|
|
|
|
|
|
|
mSuspendedRead = PR_TRUE;
|
|
|
|
if (aAddToPostPeriodByteCount)
|
|
|
|
mSuspendedReadBytesPostPeriod += aNewBytes;
|
|
|
|
else
|
|
|
|
mSuspendedReadBytes += aNewBytes;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::PostDataFinished()
|
|
|
|
{
|
|
|
|
SendData(nsnull, CRLF "." CRLF);
|
2001-06-29 08:05:38 +04:00
|
|
|
mGenerateProgressNotifications = PR_FALSE;
|
2001-04-08 04:40:30 +04:00
|
|
|
mPostDataStream = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::ProcessIncomingPostData(nsIInputStream *inStr, PRUint32 count)
|
|
|
|
{
|
2001-06-06 04:44:06 +04:00
|
|
|
if (!m_socketIsOpen) return NS_OK; // kick out if the socket was canceled
|
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
// We need to quote any '.' that occur at the beginning of a line.
|
|
|
|
// but I don't want to waste time reading out the data into a buffer and searching
|
|
|
|
// let's try to leverage nsIBufferedInputStream and see if we can "peek" into the
|
|
|
|
// current contents for this particular case.
|
|
|
|
|
|
|
|
nsCOMPtr<nsISearchableInputStream> bufferInputStr = do_QueryInterface(inStr);
|
|
|
|
NS_ASSERTION(bufferInputStr, "i made a wrong assumption about the type of stream we are getting");
|
|
|
|
NS_ASSERTION(mSuspendedReadBytes == 0, "oops, I missed something");
|
|
|
|
|
|
|
|
if (!mPostDataStream) mPostDataStream = inStr;
|
|
|
|
|
|
|
|
if (bufferInputStr)
|
|
|
|
{
|
|
|
|
PRUint32 amountWritten;
|
|
|
|
|
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
PRBool found = PR_FALSE;
|
|
|
|
PRUint32 offset = 0;
|
|
|
|
bufferInputStr->Search("\012.", PR_TRUE, &found, &offset); // LF.
|
|
|
|
|
|
|
|
if (!found || offset > count)
|
|
|
|
{
|
|
|
|
// push this data into the output stream
|
|
|
|
m_outputStream->WriteFrom(inStr, count, &amountWritten);
|
|
|
|
// store any remains which need read out at a later date
|
|
|
|
if (count > amountWritten) // stream will block
|
|
|
|
{
|
|
|
|
UpdateSuspendedReadBytes(count - amountWritten, PR_FALSE);
|
|
|
|
SuspendPostFileRead();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// count points to the LF in a LF followed by a '.'
|
|
|
|
// go ahead and write up to offset..
|
|
|
|
m_outputStream->WriteFrom(inStr, offset + 1, &amountWritten);
|
|
|
|
count -= amountWritten;
|
|
|
|
if (offset+1 > amountWritten)
|
|
|
|
{
|
|
|
|
UpdateSuspendedReadBytes(offset+1 - amountWritten, PR_FALSE);
|
|
|
|
mInsertPeriodRequired = PR_TRUE;
|
|
|
|
UpdateSuspendedReadBytes(count, mInsertPeriodRequired);
|
|
|
|
SuspendPostFileRead();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write out the extra '.'
|
|
|
|
m_outputStream->Write(".", 1, &amountWritten);
|
|
|
|
if (amountWritten != 1)
|
|
|
|
{
|
|
|
|
mInsertPeriodRequired = PR_TRUE;
|
|
|
|
// once we do write out the '.', if we are now blocked we need to remember the remaining count that comes
|
|
|
|
// after the '.' so we can perform processing on that once we become unblocked.
|
|
|
|
UpdateSuspendedReadBytes(count, mInsertPeriodRequired);
|
|
|
|
SuspendPostFileRead();
|
2001-06-02 08:54:51 +04:00
|
|
|
break;
|
2001-04-08 04:40:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} // while count > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::UnblockPostReader()
|
|
|
|
{
|
|
|
|
PRUint32 amountWritten = 0;
|
2001-06-06 04:44:06 +04:00
|
|
|
|
|
|
|
if (!m_socketIsOpen) return NS_OK; // kick out if the socket was canceled
|
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
if (mSuspendedRead)
|
|
|
|
{
|
|
|
|
// (1) attempt to write out any remaining read bytes we need in order to unblock the reader
|
|
|
|
if (mSuspendedReadBytes > 0 && mPostDataStream)
|
|
|
|
{
|
2001-06-02 08:54:51 +04:00
|
|
|
PRUint32 avail = 0;
|
|
|
|
mPostDataStream->Available(&avail);
|
|
|
|
|
|
|
|
m_outputStream->WriteFrom(mPostDataStream, PR_MIN(avail, mSuspendedReadBytes), &amountWritten);
|
|
|
|
// hmm sometimes my mSuspendedReadBytes is getting out of whack...so for now, reset it
|
|
|
|
// if necessary.
|
|
|
|
if (mSuspendedReadBytes > avail)
|
|
|
|
mSuspendedReadBytes = avail;
|
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
if (mSuspendedReadBytes > amountWritten)
|
|
|
|
mSuspendedReadBytes -= amountWritten;
|
|
|
|
else
|
|
|
|
mSuspendedReadBytes = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (2) if we are now unblocked, and we need to insert a '.' then do so now...
|
|
|
|
if (mInsertPeriodRequired && mSuspendedReadBytes == 0)
|
|
|
|
{
|
|
|
|
amountWritten = 0;
|
|
|
|
m_outputStream->Write(".", 1, &amountWritten);
|
|
|
|
if (amountWritten == 1) // if we succeeded then clear pending '.' flag
|
|
|
|
mInsertPeriodRequired = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// (3) if we inserted a '.' and we still have bytes after the '.' which need processed before the stream is unblocked
|
|
|
|
// then fake an ODA call to handle this now...
|
|
|
|
if (!mInsertPeriodRequired && mSuspendedReadBytesPostPeriod > 0)
|
|
|
|
{
|
|
|
|
// these bytes actually need processed for extra '.''s.....
|
|
|
|
PRUint32 postbytes = mSuspendedReadBytesPostPeriod;
|
|
|
|
mSuspendedReadBytesPostPeriod = 0;
|
|
|
|
ProcessIncomingPostData(mPostDataStream, postbytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
// (4) determine if we are out of the suspended read state...
|
|
|
|
if (mSuspendedReadBytes == 0 && !mInsertPeriodRequired && mSuspendedReadBytesPostPeriod == 0)
|
|
|
|
{
|
|
|
|
mSuspendedRead = PR_FALSE;
|
|
|
|
ResumePostFileRead();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // if we are in the suspended read state
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsMsgAsyncWriteProtocol::SetupTransportState()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!m_outputStream && m_transport)
|
|
|
|
{
|
|
|
|
// first create a pipe which we'll use to write the data we want to send
|
|
|
|
// into.
|
|
|
|
rv = NS_NewPipe(getter_AddRefs(mInStream), getter_AddRefs(m_outputStream),
|
|
|
|
1024, // segmentSize
|
|
|
|
1024*8, // maxSize
|
|
|
|
PR_TRUE,
|
|
|
|
PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamProvider> provider;
|
|
|
|
NS_NEWXPCOM(provider, nsMsgProtocolStreamProvider);
|
|
|
|
if (!provider) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_STATIC_CAST(nsMsgProtocolStreamProvider*,
|
|
|
|
NS_STATIC_CAST(nsIStreamProvider*, provider))->Init(this, mInStream);
|
|
|
|
|
|
|
|
rv = m_transport->AsyncWrite(provider, nsnull, 0, 0, 0, getter_AddRefs(m_WriteRequest));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
} // if m_transport
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-06-06 04:44:06 +04:00
|
|
|
nsresult nsMsgAsyncWriteProtocol::CloseSocket()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsMsgProtocol::CloseSocket();
|
|
|
|
|
|
|
|
// we need to call Cancel so that we remove the socket transport from the mActiveTransportList. see bug #30648
|
|
|
|
if (m_WriteRequest)
|
|
|
|
rv = m_WriteRequest->Cancel(NS_BINDING_ABORTED);
|
|
|
|
|
|
|
|
if (mFilePostHelper)
|
|
|
|
{
|
|
|
|
mFilePostHelper->CloseSocket();
|
|
|
|
mFilePostHelper = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_WriteRequest = 0;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-06-29 08:05:38 +04:00
|
|
|
void nsMsgAsyncWriteProtocol::UpdateProgress(PRUint32 aNewBytes)
|
|
|
|
{
|
|
|
|
if (!mGenerateProgressNotifications) return;
|
|
|
|
|
|
|
|
mNumBytesPosted += aNewBytes;
|
|
|
|
if (mFilePostSize > 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr <nsIMsgMailNewsUrl> mailUrl = do_QueryInterface(m_url);
|
|
|
|
if (!mailUrl) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIMsgStatusFeedback> statusFeedback;
|
|
|
|
mailUrl->GetStatusFeedback(getter_AddRefs(statusFeedback));
|
|
|
|
if (!statusFeedback) return;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIWebProgressListener> webProgressListener (do_QueryInterface(statusFeedback));
|
|
|
|
if (!webProgressListener) return;
|
|
|
|
|
|
|
|
webProgressListener->OnProgressChange(nsnull, m_WriteRequest, mNumBytesPosted, mFilePostSize, mNumBytesPosted, mFilePostSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-04-08 04:40:30 +04:00
|
|
|
PRInt32 nsMsgAsyncWriteProtocol::SendData(nsIURI * aURL, const char * dataBuffer, PRBool aSuppressLogging)
|
|
|
|
{
|
|
|
|
PRUint32 len = nsCRT::strlen(dataBuffer);
|
|
|
|
PRUint32 cnt;
|
|
|
|
nsresult rv = m_outputStream->Write(dataBuffer, len, &cnt);
|
|
|
|
if (NS_SUCCEEDED(rv) && len==cnt)
|
|
|
|
{
|
|
|
|
if (mSuspendedWrite)
|
|
|
|
{
|
|
|
|
// if we got here then we had suspended the write 'cause we didn't have anymore
|
|
|
|
// data to write (i.e. the pipe went empty). So resume the channel to kick
|
|
|
|
// things off again.
|
|
|
|
mSuspendedWrite = PR_FALSE;
|
|
|
|
m_WriteRequest->Resume();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2001-06-05 02:47:15 +04:00
|
|
|
|
|
|
|
#define MSGS_URL "chrome://messenger/locale/messenger.properties"
|
|
|
|
|
|
|
|
PRUnichar *GetStringByID(PRInt32 stringID)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr <nsIStringBundle> sBundle = nsnull;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE (nsIStringBundleService, sBundleService, kStringBundleServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv) || (nsnull == sBundleService))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
rv = sBundleService->CreateBundle(MSGS_URL, getter_AddRefs(sBundle));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
PRUnichar *ptrv = nsnull;
|
|
|
|
rv = sBundle->GetStringFromID(stringID, &ptrv);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return (ptrv);
|
|
|
|
}
|
|
|
|
|