started socket transport code

This commit is contained in:
valeski%netscape.com 1999-04-14 23:11:56 +00:00
parent cb7e7a95c4
commit 1fb9f3a060
2 changed files with 61 additions and 10 deletions

View File

@ -16,12 +16,25 @@
* Reserved.
*/
// ftp implementation
#include "nsFtpProtocolConnection.h"
#include "nscore.h"
#include "nsIUrl.h"
#include "nsIFtpEventSink.h"
#include "nsISocketTransportService.h"
#include "nsIServiceManager.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
// There are actually two transport connections established for an
// ftp connection. One is used for the command channel , and
// the other for the data channel. The command channel is the first
// connection made and is used to negotiate the second, data, channel.
// The data channel is driven by the command channel and is either
// initiated by the server (PORT command) or by the client (PASV command).
// Client initiation is the most command case and is attempted first.
nsFtpProtocolConnection::nsFtpProtocolConnection()
: mUrl(nsnull), mEventSink(nsnull), mPasv(TRUE),
@ -59,6 +72,9 @@ nsresult
nsFtpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink) {
nsresult rv;
if (mConnected)
return NS_ERROR_NOT_IMPLEMENTED;
mUrl = url;
NS_ADDREF(mUrl);
@ -72,17 +88,17 @@ nsFtpProtocolConnection::Init(nsIUrl* url, nsISupports* eventSink) {
NS_IMETHODIMP
nsFtpProtocolConnection::Cancel(void) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFtpProtocolConnection::Suspend(void) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFtpProtocolConnection::Resume(void) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
@ -92,7 +108,25 @@ nsFtpProtocolConnection::Resume(void) {
// establishes the connection and initiates the file transfer.
NS_IMETHODIMP
nsFtpProtocolConnection::Open(nsIUrl* url, nsISupports* eventSink) {
return NS_OK;
nsresult rv;
mState = FTP_CONNECT;
NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
if(NS_FAILED(rv)) return rv;
// Create the command channel transport
// const char *host;
// const PRInt32 port;
// rv = url->GetHost(&host);
// if (NS_FAILED(rv)) return rv;
// port = url->GetPort();
// nsITransport *cPipe; // the command channel
// rv = sts->CreateTransport(host, port, *cPipe);
// if(NS_FAILED(rv)) return rv;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
@ -100,17 +134,17 @@ nsFtpProtocolConnection::GetContentType(char* *contentType) {
// XXX for ftp we need to do a file extension-to-type mapping lookup
// XXX in some hash table/registry of mime-types
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFtpProtocolConnection::GetInputStream(nsIInputStream* *result) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFtpProtocolConnection::GetOutputStream(nsIOutputStream* *result) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -119,12 +153,12 @@ nsFtpProtocolConnection::GetOutputStream(nsIOutputStream* *result) {
NS_IMETHODIMP
nsFtpProtocolConnection::Get(void) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsFtpProtocolConnection::Put(void) {
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
@ -132,7 +166,7 @@ nsFtpProtocolConnection::UsePASV(PRBool aComm) {
if (mConnected)
return NS_ERROR_NOT_IMPLEMENTED;
mPasv = aComm;
return NS_OK;
return NS_ERROR_NOT_IMPLEMENTED;
}
////////////////////////////////////////////////////////////////////////////////
@ -140,6 +174,7 @@ nsFtpProtocolConnection::UsePASV(PRBool aComm) {
NS_IMETHODIMP
nsFtpProtocolConnection::OnStartBinding(nsISupports* context) {
// up call OnStartBinding
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -147,6 +182,7 @@ NS_IMETHODIMP
nsFtpProtocolConnection::OnStopBinding(nsISupports* context,
nsresult aStatus,
nsIString* aMsg) {
// up call OnStopBinding
return NS_ERROR_NOT_IMPLEMENTED;
}
@ -160,6 +196,16 @@ nsFtpProtocolConnection::OnDataAvailable(nsISupports* context,
PRUint32 aLength) {
// each hunk of data that comes in is evaluated, appropriate action
// is taken and the state is incremented.
switch(mState) {
case FTP_CONNECT:
case FTP_S_PASV:
case FTP_R_PASV:
case FTP_S_PORT:
case FTP_R_PORT:
case FTP_COMPLETE:
default:
;
}
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -16,11 +16,14 @@
* Reserved.
*/
// ftp implementation header
#ifndef nsFtpProtocolConnection_h___
#define nsFtpProtocolConnection_h___
#include "nsIFtpProtocolConnection.h"
#include "nsIStreamListener.h"
#include "nsITransport.h"
class nsIConnectionGroup;
class nsIFtpEventSink;
@ -94,6 +97,8 @@ protected:
PRBool mPasv;
PRBool mConnected;
FTP_STATE mState;
nsITransport* mCPipe; // the command channel
nsITransport* mDPipe; // the data channel
};
#endif /* nsFtpProtocolConnection_h___ */