diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp index 377dd457cfe..7c975997be5 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.cpp @@ -53,9 +53,9 @@ static NS_DEFINE_CID(kPrefCID, NS_PREF_CID); static NS_DEFINE_CID(kWalletServiceCID, NS_WALLETSERVICE_CID); static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); +static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID); -static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); #if defined(PR_LOGGING) @@ -504,10 +504,8 @@ nsFtpState::OnStopRequest(nsIRequest *request, nsISupports *aContext, Connect(); return NS_OK; } - - if (NS_FAILED(aStatus)) // aStatus will be NS_OK if we are sucessfully disconnecing the control connection. - StopProcessing(); - + + StopProcessing(); return NS_OK; } @@ -542,9 +540,7 @@ nsFtpState::EstablishControlConnection() // if we succeed, return. Otherwise, we need to // create a transport - rv = mControlConnection->Connect(); - if (NS_SUCCEEDED(rv)) - return rv; + return NS_OK; } #if defined(PR_LOGGING) else @@ -555,15 +551,24 @@ nsFtpState::EstablishControlConnection() } PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x) creating control\n", this)); - - mState = FTP_READ_BUF; - mNextState = FTP_S_USER; - + nsXPIDLCString host; rv = mURL->GetHost(getter_Copies(host)); if (NS_FAILED(rv)) return rv; + + nsCOMPtr transport; + // build our own + rv = CreateTransport(host, + mPort, + FTP_COMMAND_CHANNEL_SEG_SIZE, + FTP_COMMAND_CHANNEL_MAX_SIZE, + getter_AddRefs(transport)); // the command transport + if (NS_FAILED(rv)) return rv; + + mState = FTP_READ_BUF; + mNextState = FTP_S_USER; - mControlConnection = new nsFtpControlConnection(host, mPort); + mControlConnection = new nsFtpControlConnection(transport); if (!mControlConnection) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(mControlConnection); @@ -1449,14 +1454,11 @@ nsFtpState::R_pasv() { const char* hostStr = mIPv6ServerAddress ? mIPv6ServerAddress : host.get(); // now we know where to connect our data channel - nsCOMPtr sts = do_GetService(kSocketTransportServiceCID, &rv); - - rv = sts->CreateTransport(hostStr, - port, - nsnull, -1, - FTP_DATA_CHANNEL_SEG_SIZE, - FTP_DATA_CHANNEL_MAX_SIZE, - getter_AddRefs(mDPipe)); // the data channel + rv = CreateTransport(hostStr, + port, + FTP_DATA_CHANNEL_SEG_SIZE, + FTP_DATA_CHANNEL_MAX_SIZE, + getter_AddRefs(mDPipe)); // the data channel if (NS_FAILED(rv)) return FTP_ERROR; PR_LOG(gFTPLog, PR_LOG_DEBUG, ("(%x) Created Data Transport (%s:%x)\n", this, hostStr, port)); @@ -1840,10 +1842,11 @@ nsFtpState::KillControlConnection() { nsresult rv = nsFtpProtocolHandler::InsertConnection(mURL, NS_STATIC_CAST(nsISupports*, (nsIStreamListener*)mControlConnection)); // Can't cache it? Kill it then. - mControlConnection->Disconnect(rv); + if (NS_FAILED(rv)) + mControlConnection->Disconnect(); } else - mControlConnection->Disconnect(NS_BINDING_ABORTED); + mControlConnection->Disconnect(); NS_RELEASE(mControlConnection); @@ -1986,6 +1989,19 @@ nsFtpState::DataConnectionEstablished() return NS_OK; } +nsresult +nsFtpState::CreateTransport(const char * host, PRInt32 port, PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize, nsITransport** o_pTrans) +{ + nsresult rv; + + nsCOMPtr sts = + do_GetService(kSocketTransportServiceCID, &rv); + + return sts->CreateTransport(host, port, nsnull, PRUint32(-1), + bufferSegmentSize, + bufferMaxSize, + o_pTrans); +} nsresult nsFtpState::SendFTPCommand(nsCString& command) diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h index bc1a75cc6c2..ba2966370c2 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpConnectionThread.h @@ -133,6 +133,11 @@ private: void MoveToNextState(FTP_STATE nextState); nsresult Process(); + + virtual nsresult CreateTransport(const char * host, PRInt32 port, + PRUint32 bufferSegmentSize, PRUint32 bufferMaxSize, + nsITransport** o_pTrans); + void KillControlConnection(); nsresult StopProcessing(); nsresult EstablishControlConnection(); diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp b/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp index 1dcc7c2e031..a8f6bfd4b77 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.cpp @@ -21,21 +21,17 @@ */ -#include "nsFTPChannel.h" #include "nsFtpControlConnection.h" #include "prlog.h" #include "nsIPipe.h" #include "nsIInputStream.h" #include "nsIStreamProvider.h" -#include "nsISocketTransportService.h" #include "nsISocketTransport.h" #if defined(PR_LOGGING) extern PRLogModuleInfo* gFTPLog; #endif /* PR_LOGGING */ -static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID); - class nsFtpStreamProvider : public nsIStreamProvider { public: NS_DECL_ISUPPORTS @@ -110,18 +106,16 @@ nsrefcnt nsFtpControlConnection::Release(void) { // mPipe has a reference to |this| caused by AsyncRead() // Break this cycle by calling disconnect. - Disconnect(NS_BINDING_ABORTED); + Disconnect(); } return count; } -nsFtpControlConnection::nsFtpControlConnection(const char* host, PRUint32 port) +nsFtpControlConnection::nsFtpControlConnection(nsITransport* socketTransport) +: mCPipe(socketTransport) { NS_INIT_REFCNT(); PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("(%x) nsFtpControlConnection created", this)); - - mHost = host; - mPort = port; mServerType = 0; mConnected = PR_FALSE; @@ -152,46 +146,36 @@ nsFtpControlConnection::IsAlive() nsresult nsFtpControlConnection::Connect() { + if (!mCPipe) + return NS_ERROR_NULL_POINTER; + nsresult rv; - - if (!mCPipe) { - nsCOMPtr transport; - // build our own - nsCOMPtr sts = do_GetService(kSocketTransportServiceCID, &rv); - rv = sts->CreateTransport(mHost, - mPort, - nsnull, -1, - FTP_COMMAND_CHANNEL_SEG_SIZE, - FTP_COMMAND_CHANNEL_MAX_SIZE, - getter_AddRefs(mCPipe)); // the command transport - if (NS_FAILED(rv)) return rv; - } - - nsCOMPtr sTrans (do_QueryInterface(mCPipe)); - if (!sTrans) - return NS_ERROR_FAILURE; - - sTrans->SetReuseConnection(PR_TRUE); - nsCOMPtr inStream; - + +#ifdef DOUGT_IS_SICK + nsCOMPtr sTrans = do_QueryInterface(mCPipe); + if (!sTrans) return NS_ERROR_FAILURE; + rv = sTrans->SetSocketTimeout(25); + if (NS_FAILED(rv)) return rv; +#endif + rv = NS_NewPipe(getter_AddRefs(inStream), getter_AddRefs(mOutStream), 64, // segmentSize 256, // maxSize PR_TRUE, - PR_TRUE); - + PR_TRUE); + if (NS_FAILED(rv)) return rv; - + nsCOMPtr provider; NS_NEWXPCOM(provider, nsFtpStreamProvider); if (!provider) return NS_ERROR_OUT_OF_MEMORY; - + // setup the stream provider to get data from the pipe. NS_STATIC_CAST(nsFtpStreamProvider*, - NS_STATIC_CAST(nsIStreamProvider*, provider))->mInStream = inStream; - + NS_STATIC_CAST(nsIStreamProvider*, provider))->mInStream = inStream; + rv = mCPipe->AsyncWrite(provider, NS_STATIC_CAST(nsISupports*, (nsIStreamListener*)this), 0, PRUint32(-1), @@ -205,23 +189,21 @@ nsFtpControlConnection::Connect() nsnull, 0, PRUint32(-1), 0, getter_AddRefs(mReadRequest)); + if (NS_FAILED(rv)) return rv; + mConnected = PR_TRUE; - return rv; + return NS_OK; } nsresult -nsFtpControlConnection::Disconnect(nsresult status) +nsFtpControlConnection::Disconnect() { if (!mConnected) return NS_ERROR_FAILURE; - PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("(%x) nsFtpControlConnection disconnecting (%x)", this, status)); - - if (NS_FAILED(status)) { - mConnected = PR_FALSE; - } - - if (mWriteRequest) mWriteRequest->Cancel(status); - if (mReadRequest) mReadRequest->Cancel(status); + PR_LOG(gFTPLog, PR_LOG_ALWAYS, ("(%x) nsFtpControlConnection disconnecting", this)); + mConnected = PR_FALSE; + if (mWriteRequest) mWriteRequest->Cancel(NS_BINDING_ABORTED); + if (mReadRequest) mReadRequest->Cancel(NS_BINDING_ABORTED); return NS_OK; } diff --git a/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.h b/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.h index d955423ae10..04a94201ce0 100644 --- a/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.h +++ b/mozilla/netwerk/protocol/ftp/src/nsFtpControlConnection.h @@ -25,7 +25,6 @@ #include "nsCOMPtr.h" -#include "nsIURI.h" #include "nsIStreamListener.h" #include "nsIRequest.h" #include "nsITransport.h" @@ -40,11 +39,11 @@ public: NS_DECL_NSISTREAMLISTENER NS_DECL_NSIREQUESTOBSERVER - nsFtpControlConnection(const char* host, PRUint32 port); + nsFtpControlConnection(nsITransport* socketTransport); virtual ~nsFtpControlConnection(); nsresult Connect(); - nsresult Disconnect(nsresult status); + nsresult Disconnect(); nsresult Write(nsCString& command, PRBool suspend); void GetReadRequest(nsIRequest** request) { NS_IF_ADDREF(*request=mReadRequest); } @@ -63,9 +62,6 @@ private: PRLock* mLock; // protects mListener. - nsCAutoString mHost; - PRUint32 mPort; - nsCOMPtr mReadRequest; nsCOMPtr mWriteRequest; nsCOMPtr mCPipe;