removed UsePasv from the connection handler. added some more states.

This commit is contained in:
valeski%netscape.com 1999-04-22 20:17:46 +00:00
Родитель 4da56bc3e3
Коммит 6dc1c75626
5 изменённых файлов: 83 добавлений и 40 удалений

Просмотреть файл

@ -20,6 +20,7 @@
#define nsIFtpProtocolConnection_h___
#include "nsIProtocolConnection.h"
#include "nsIStreamListener.h"
// {25029495-F132-11d2-9588-00805F369F95}
#define NS_IFTPPROTOCOLCONNECTION_IID \
@ -32,7 +33,6 @@ public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFTPPROTOCOLCONNECTION_IID);
// PRE connect
NS_IMETHOD UsePASV(PRBool aComm) = 0;
// POST connect
@ -40,6 +40,9 @@ public:
NS_IMETHOD Get(void) = 0;
NS_IMETHOD Put(void) = 0;
NS_IMETHOD SetStreamListener(nsIStreamListener* aListener) = 0;
};
#endif /* nsIIFtpProtocolConnection_h___ */

Просмотреть файл

@ -26,8 +26,7 @@
{ 0xaef15d51, 0xf132, 0x11d2, { 0x95, 0x88, 0x0, 0x80, 0x5f, 0x36, 0x9f, 0x95 } }
class nsIFtpProtocolHandler : public nsIProtocolHandler
{
class nsIFtpProtocolHandler : public nsIProtocolHandler {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFTPPROTOCOLHANDLER_IID);

Просмотреть файл

@ -58,6 +58,8 @@ nsFtpConnectionThread::nsFtpConnectionThread(PLEventQueue* aEventQ, nsIStreamLis
// so we can post events back to them.
mListener = aListener;
NS_ADDREF(mListener);
mAction = GET;
mState = FTP_S_USER;
}
nsFtpConnectionThread::~nsFtpConnectionThread() {
@ -71,7 +73,7 @@ nsFtpConnectionThread::Run() {
nsresult rv;
nsITransport* lCPipe = nsnull;
mState = FTP_CONNECT;
mState = FTP_S_USER;
NS_WITH_SERVICE(nsISocketTransportService, sts, kSocketTransportServiceCID, &rv);
if(NS_FAILED(rv)) return rv;
@ -84,6 +86,18 @@ nsFtpConnectionThread::Run() {
rv = mUrl->GetPort(port);
if (NS_FAILED(rv)) return rv;
rv = sts->CreateTransport(host, port, &lCPipe); // the command channel
if (NS_FAILED(rv)) return rv;
// get the output stream so we can write to the server
rv = lCPipe->OpenOutputStream(&mOutStream);
if (NS_FAILED(rv)) return rv;
// get the input stream so we can read data from the server.
rv = lCPipe->OpenInputStream(&mInStream);
if (NS_FAILED(rv)) return rv;
// tell the user that we've begun the transaction.
nsFtpOnStartBindingEvent* event =
new nsFtpOnStartBindingEvent(mListener, nsnull);
@ -96,17 +110,6 @@ nsFtpConnectionThread::Run() {
return rv;
}
rv = sts->CreateTransport(host, port, &lCPipe); // the command channel
if (NS_FAILED(rv)) return rv;
// get the output stream so we can write to the server
rv = lCPipe->OpenOutputStream(&mOutStream);
if (NS_FAILED(rv)) return rv;
// get the input stream so we can read data from the server.
rv = lCPipe->OpenInputStream(&mInStream);
if (NS_FAILED(rv)) return rv;
while (1) {
nsresult rv;
char *buffer = nsnull; // the buffer to be sent to the server
@ -119,6 +122,9 @@ nsFtpConnectionThread::Run() {
// XXX some of the "buffer"s allocated below in the individual states can be removed
// XXX and replaced with static char or #defines.
switch(mState) {
// Reading state. used after a write in order to retrieve
// the response from the server.
case FTP_READ_BUF:
if (mState == mNextState)
NS_ASSERTION(0, "ftp read state mixup");
@ -128,6 +134,11 @@ nsFtpConnectionThread::Run() {
break;
// END: FTP_READ_BUF
//////////////////////////////
//// CONNECTION SETUP STATES
//////////////////////////////
case FTP_S_USER:
buffer = "USER anonymous";
bufLen = PL_strlen(buffer);
@ -391,17 +402,21 @@ nsFtpConnectionThread::Run() {
}
// END: FTP_R_PWD
case FTP_COMPLETE:
//////////////////////////////
//// ACTION STATES
//////////////////////////////
default:
;
}
}
} // END: switch
} // END: event loop/message pump/while loop
// Close the command channel
//lCPipe->CloseConnection();
NS_RELEASE(lCPipe);
}
nsresult nsFtpConnectionThread::Init(nsIThread* aThread) {
nsresult
nsFtpConnectionThread::Init(nsIThread* aThread) {
/* mThread = aThread;
NS_ADDREF(mThread);
@ -416,6 +431,22 @@ nsresult nsFtpConnectionThread::Init(nsIThread* aThread) {
return NS_OK;
}
nsresult
nsFtpConnectionThread::SetAction(FTP_ACTION aAction) {
if (mConnected)
return NS_ERROR_NOT_IMPLEMENTED;
mAction = aAction;
return NS_OK;
}
nsresult
nsFtpConnectionThread::SetUsePasv(PRBool aUsePasv) {
if (mConnected)
return NS_ERROR_NOT_IMPLEMENTED;
mUsePasv = aUsePasv;
return NS_OK;
}
nsresult
nsFtpConnectionThread::Read(void) {

Просмотреть файл

@ -41,18 +41,18 @@
// ftp states
typedef enum _FTP_STATE {
// Internal states
FTP_CONNECT,
///////////////////////
//// Internal states
///////////////////////
FTP_READ_BUF,
// Command states
///////////////////////
//// Command channel connection setup states
///////////////////////
FTP_S_USER, // send username
FTP_R_USER,
FTP_S_PASS, // send password
FTP_R_PASS,
// FTP_S_REST, // send restart
// FTP_R_REST,
FTP_S_SYST, // send system (interrogates server)
FTP_R_SYST,
FTP_S_ACCT, // send account
@ -61,11 +61,15 @@ typedef enum _FTP_STATE {
FTP_R_MACB,
FTP_S_PWD , // send parent working directory (pwd)
FTP_R_PWD ,
FTP_S_PASV, // send passive
///////////////////////
//// Data channel connection setup states
///////////////////////
FTP_S_PASV, // send passsive
FTP_R_PASV,
FTP_S_PORT, // send port
FTP_R_PORT,
FTP_COMPLETE
FTP_S_PORT, // send port
FTP_R_PORT
} FTP_STATE;
// higher level ftp actions
@ -89,33 +93,36 @@ public:
nsresult Init(nsIThread* aThread);
// user level setup
nsresult SetAction(FTP_ACTION aAction);
nsresult SetUsePasv(PRBool aUsePasv);
private:
nsresult Read(void);
void SetSystInternals(void);
PLEventQueue* mEventQueue; // used to communicate outside this thread
// nsIThread* mThread; // the worker thread
PLEventQueue* mEventQueue; // used to communicate outside this thread
FTP_STATE mState; // the current state
FTP_STATE mNextState; // the next state
FTP_STATE mState; // the current state
FTP_STATE mNextState; // the next state
FTP_ACTION mAction; // the higher level action
nsIInputStream* mInStream;
nsIOutputStream* mOutStream;
PRInt32 mResponseCode; // the last command response code.
nsString2 mResponseMsg; // the last command response text
PRInt32 mResponseCode; // the last command response code.
nsString2 mResponseMsg; // the last command response text
nsString2 mUsername;
nsString2 mPassword;
// these members should be hung off of a specific transport connection
PRInt32 mServerType;
PRBool mPasv;
PRBool mList; // use LIST instead of NLST
PRBool mList; // use LIST instead of NLST
// end "these ...."
PRBool mConnected;
PRBool mUseDefaultPath; // use PWD to figure out path
PRBool mUseDefaultPath; // use PWD to figure out path
PRBool mUsePasv; // use a passive data connection.
nsIUrl* mUrl;
nsIStreamListener* mListener; // the listener we want to call
// during our event firing.
nsIStreamListener* mListener; // the listener we want to call
// during our event firing.
};

Просмотреть файл

@ -114,6 +114,8 @@ nsFtpProtocolConnection::Open(void) {
nsIThread* workerThread = nsnull;
nsFtpConnectionThread* protocolInterpreter =
new nsFtpConnectionThread(mEventQueue, mListener);
NS_ASSERTION(protocolInterpreter, "ftp protocol interpreter alloc failed");
NS_ADDREF(protocolInterpreter);
if (!protocolInterpreter)
return NS_ERROR_OUT_OF_MEMORY;
@ -124,6 +126,7 @@ nsFtpProtocolConnection::Open(void) {
// XXX not sure this is necessary.
protocolInterpreter->Init(workerThread);
NS_RELEASE(protocolInterpreter);
return NS_OK;
}