Skip to content
Snippets Groups Projects
Commit f6136787 authored by valeski%netscape.com's avatar valeski%netscape.com
Browse files

nsFtpStreamListenerEvent.h - explicit #include "nsString.h" (fix build prob on linux)

nsFtpConnectionThread.*    - added the passive data connection mode (PASV) state
parent 6a3daef8
No related branches found
No related tags found
No related merge requests found
......@@ -72,6 +72,7 @@ NS_IMETHODIMP
nsFtpConnectionThread::Run() {
nsresult rv;
nsITransport* lCPipe = nsnull;
nsITransport* lDPipe = nsnull;
mState = FTP_S_USER;
......@@ -90,11 +91,11 @@ nsFtpConnectionThread::Run() {
if (NS_FAILED(rv)) return rv;
// get the output stream so we can write to the server
rv = lCPipe->OpenOutputStream(&mOutStream);
rv = lCPipe->OpenOutputStream(&mCOutStream);
if (NS_FAILED(rv)) return rv;
// get the input stream so we can read data from the server.
rv = lCPipe->OpenInputStream(&mInStream);
rv = lCPipe->OpenInputStream(&mCInStream);
if (NS_FAILED(rv)) return rv;
......@@ -144,7 +145,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (NS_FAILED(rv)) return rv;
if (bytes < bufLen) {
......@@ -178,7 +179,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// PR_smprintf(buffer, "PASS %.256s\r\n", mPassword);
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (NS_FAILED(rv)) return rv;
if (bytes < bufLen) {
......@@ -207,7 +208,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (NS_FAILED(rv)) return rv;
if (bytes < bufLen) {
......@@ -246,7 +247,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (NS_FAILED(rv)) return rv;
if (bytes < bufLen) {
......@@ -274,7 +275,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (bytes < bufLen) {
break;
......@@ -304,7 +305,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (bytes < bufLen) {
break;
......@@ -403,6 +404,102 @@ nsFtpConnectionThread::Run() {
}
// END: FTP_R_PWD
//////////////////////////////
//// DATA CONNECTION STATES
//////////////////////////////
case FTP_S_PASV:
buffer = "PASV\r\n";
bufLen = PL_strlen(buffer);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (bytes < bufLen) {
break;
}
mState = FTP_READ_BUF;
mNextState = FTP_R_PASV;
break;
// FTP: FTP_S_PASV
case FTP_R_PASV:
{
PRInt32 h0, h1, h2, h3, p0, p1;
PRInt32 port;
if (mResponseCode != 2) {
// failed. increment to port.
mState = FTP_S_PORT;
mUsePasv = PR_FALSE;
break;
}
mUsePasv = PR_TRUE;
char *ptr = nsnull;
char *response = mResponseMsg.ToNewCString();
if (!response)
return NS_ERROR_OUT_OF_MEMORY;
// The returned address string can be of the form
// (xxx,xxx,xxx,xxx,ppp,ppp) or
// xxx,xxx,xxx,xxx,ppp,ppp (without parens)
ptr = response;
while (*ptr++) {
if (*ptr == '(') {
// move just beyond the open paren
ptr++;
break;
}
if (*ptr == ',') {
ptr--;
// backup to the start of the digits
while ( (*ptr >= '0') && (*ptr <= '9'))
ptr--;
ptr++; // get back onto the numbers
break;
}
} // end while
PRInt32 fields = PR_sscanf(ptr,
#ifdef __alpha
"%d,%d,%d,%d,%d,%d",
#else
"%ld,%ld,%ld,%ld,%ld,%ld",
#endif
&h0, &h1, &h2, &h3, &p0, &p1);
if (fields < 6) {
// bad format. we'll try PORT, but it's probably over.
mState = FTP_S_PORT;
mUsePasv = PR_FALSE;
break;
}
port = ((PRInt32) (p0<<8)) + p1;
char host[17];
PR_smprintf(host, "%ld.%ld.%ld.%ld", h0, h1, h2, h3);
// now we know where to connect our data channel
rv = sts->CreateTransport(host, port, &lDPipe); // the command channel
if (NS_FAILED(rv)) return rv;
if (mAction == GET) {
// get the input stream so we can read data from the server.
rv = lDPipe->OpenInputStream(&mDInStream);
if (NS_FAILED(rv)) return rv;
} else {
// get the output stream so we can write to the server
rv = lDPipe->OpenOutputStream(&mDOutStream);
if (NS_FAILED(rv)) return rv;
}
// we're connected figure out what type of transfer we're doing (ascii or binary)
break;
}
// FTP: FTP_R_PASV
//////////////////////////////
//// ACTION STATES
//////////////////////////////
......@@ -417,7 +514,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (bytes < bufLen) {
break;
......@@ -450,7 +547,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (bytes < bufLen) {
break;
......@@ -482,7 +579,7 @@ nsFtpConnectionThread::Run() {
bufLen = PL_strlen(buffer);
// send off the command
rv = mOutStream->Write(buffer, bufLen, &bytes);
rv = mCOutStream->Write(buffer, bufLen, &bytes);
if (bytes < bufLen) {
break;
......@@ -508,6 +605,9 @@ nsFtpConnectionThread::Run() {
} // END: switch
} // END: event loop/message pump/while loop
// Close the data channel
NS_IF_RELEASE(lDPipe);
// Close the command channel
NS_RELEASE(lCPipe);
}
......@@ -550,11 +650,11 @@ nsFtpConnectionThread::Read(void) {
PRUint32 read, len;
nsresult rv;
char *buffer = nsnull;
rv = mInStream->GetLength(&len);
rv = mCInStream->GetLength(&len);
if (NS_FAILED(rv)) return rv;
buffer = new char[len+1];
if (!buffer) return 0; // XXX need a better return code
rv = mInStream->Read(buffer, len, &read);
rv = mCInStream->Read(buffer, len, &read);
if (NS_FAILED(rv)) {
delete [] buffer;
return rv;
......
......@@ -21,6 +21,7 @@
#include "nsIServiceManager.h"
#include "nsIStreamListener.h"
#include "nsIOutputStream.h"
#include "nsIUrl.h"
#include "nsString2.h"
#include "plevent.h"
......@@ -109,13 +110,22 @@ private:
void SetSystInternals(void);
FTP_STATE FindActionState(void);
// Private members
PLEventQueue* mEventQueue; // used to communicate outside this thread
nsIUrl* mUrl;
FTP_STATE mState; // the current state
FTP_STATE mNextState; // the next state
FTP_ACTION mAction; // the higher level action
nsIInputStream* mInStream;
nsIOutputStream* mOutStream;
nsIInputStream* mCInStream; // command channel input
nsIOutputStream* mCOutStream; // command channel output
//nsString2 mDataAddress; // the host:port combo for the data connection
nsIInputStream* mDInStream; // data channel input
nsIOutputStream* mDOutStream; // data channel output
PRInt32 mResponseCode; // the last command response code.
nsString2 mResponseMsg; // the last command response text
nsString2 mUsername;
......@@ -130,7 +140,6 @@ private:
PRBool mConnected;
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.
......
......@@ -22,6 +22,7 @@
#include "plevent.h"
#include "nscore.h"
#include "nsString.h"
class nsFtpStreamListenerEvent : public PLEvent {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment