Backing out ftp state reduction due to regressions. See 211729. r=darin, a=dbaron

This commit is contained in:
dougt%meer.net 2003-07-09 20:48:15 +00:00
parent 5518559ede
commit e5666ff654
2 changed files with 101 additions and 17 deletions

View File

@ -590,9 +590,10 @@ nsFtpState::EstablishControlConnection()
// read cached variables into us. // read cached variables into us.
mServerType = mControlConnection->mServerType; mServerType = mControlConnection->mServerType;
mPwd = mControlConnection->mPwd;
mPassword = mControlConnection->mPassword; mPassword = mControlConnection->mPassword;
mTryingCachedControl = PR_TRUE; mTryingCachedControl = PR_TRUE;
// we're already connected to this server, skip login. // we're already connected to this server, skip login.
mState = FTP_S_PASV; mState = FTP_S_PASV;
mResponseCode = 530; //assume the control connection was dropped. mResponseCode = 530; //assume the control connection was dropped.
@ -794,6 +795,41 @@ nsFtpState::Process()
break; break;
// CWD
case FTP_S_CWD:
rv = S_cwd();
if (NS_FAILED(rv))
mInternalError = NS_ERROR_FTP_CWD;
MoveToNextState(FTP_R_CWD);
break;
case FTP_R_CWD:
mState = R_cwd();
if (FTP_ERROR == mState)
mInternalError = NS_ERROR_FTP_CWD;
break;
// PWD
case FTP_S_PWD:
rv = S_pwd();
if (NS_FAILED(rv))
mInternalError = NS_ERROR_FTP_PWD;
MoveToNextState(FTP_R_PWD);
break;
case FTP_R_PWD:
mState = R_pwd();
if (FTP_ERROR == mState)
mInternalError = NS_ERROR_FTP_PWD;
break;
// LIST // LIST
case FTP_S_LIST: case FTP_S_LIST:
rv = S_list(); rv = S_list();
@ -1130,6 +1166,58 @@ nsFtpState::R_pass() {
} }
nsresult
nsFtpState::S_pwd() {
nsCString pwdStr("PWD" CRLF);
return SendFTPCommand(pwdStr);
}
FTP_STATE
nsFtpState::R_pwd() {
if (mResponseCode/100 != 2)
return FTP_ERROR;
if (mServerType != FTP_VMS_TYPE) {
nsCAutoString respStr(mResponseMsg);
PRInt32 pos = respStr.FindChar('"');
if (pos > -1) {
respStr.Cut(0,pos+1);
pos = respStr.FindChar('"');
if (pos > -1) {
respStr.Truncate(pos);
if (respStr.Last() != '/')
respStr.Append("/");
mPwd = respStr;
}
}
}
return FTP_S_TYPE;
}
nsresult
nsFtpState::S_cwd() {
nsCAutoString cwdStr(mPath);
if (cwdStr.IsEmpty() || cwdStr.First() != '/')
cwdStr.Insert(mPwd,0);
cwdStr.Insert("CWD ",0);
cwdStr.Append(CRLF);
return SendFTPCommand(cwdStr);
}
FTP_STATE
nsFtpState::R_cwd() {
if (mResponseCode/100 == 2) {
if (mAction == PUT)
return FTP_S_STOR;
return FTP_S_LIST;
}
return FTP_ERROR;
}
nsresult nsresult
nsFtpState::S_acct() { nsFtpState::S_acct() {
nsCString acctString("ACCT noaccount" CRLF); nsCString acctString("ACCT noaccount" CRLF);
@ -1179,7 +1267,7 @@ nsFtpState::R_syst() {
mServerType = FTP_UNIX_TYPE; mServerType = FTP_UNIX_TYPE;
} }
return FTP_S_TYPE; return FTP_S_PWD;
} }
if (mResponseCode/100 == 5) { if (mResponseCode/100 == 5) {
@ -1187,7 +1275,7 @@ nsFtpState::R_syst() {
// No clue. We will just hope it is UNIX type server. // No clue. We will just hope it is UNIX type server.
mServerType = FTP_UNIX_TYPE; mServerType = FTP_UNIX_TYPE;
return FTP_S_TYPE; return FTP_S_PWD;
} }
return FTP_ERROR; return FTP_ERROR;
} }
@ -1373,12 +1461,7 @@ nsFtpState::S_list() {
mDRequestForwarder->SetEntityID(nsnull); mDRequestForwarder->SetEntityID(nsnull);
nsCAutoString listString("LIST"); nsCAutoString listString("LIST" CRLF);
if (!mPath.IsEmpty()) {
listString.Append(" ");
listString.Append(mPath);
}
listString.Append(CRLF);
return SendFTPCommand(listString); return SendFTPCommand(listString);
} }
@ -1457,7 +1540,7 @@ nsFtpState::R_retr() {
return FTP_S_PASV; return FTP_S_PASV;
} }
return FTP_S_LIST; return FTP_S_CWD;
} }
@ -1791,15 +1874,10 @@ nsFtpState::R_pasv() {
} }
} }
if (mRETRFailed) { if (mRETRFailed || mPath.IsEmpty() || mPath.Last() == '/') {
return FTP_S_LIST; return FTP_S_CWD;
} }
// These next two line will break any FTP server the returns tar.gz when issuing
// a RETR for a directory.
// if (mPath.IsEmpty())
// return FTP_S_LIST;
return FTP_S_SIZE; return FTP_S_SIZE;
} }
@ -2228,6 +2306,7 @@ nsFtpState::KillControlConnection() {
// Store connection persistant data // Store connection persistant data
mControlConnection->mServerType = mServerType; mControlConnection->mServerType = mServerType;
mControlConnection->mPassword = mPassword; mControlConnection->mPassword = mPassword;
mControlConnection->mPwd = mPwd;
nsresult rv = gFtpHandler->InsertConnection(mURI, mControlConnection); nsresult rv = gFtpHandler->InsertConnection(mURI, mControlConnection);
// Can't cache it? Kill it then. // Can't cache it? Kill it then.
mControlConnection->Disconnect(rv); mControlConnection->Disconnect(rv);

View File

@ -89,6 +89,8 @@ typedef enum _FTP_STATE {
FTP_S_SYST, FTP_R_SYST, FTP_S_SYST, FTP_R_SYST,
FTP_S_ACCT, FTP_R_ACCT, FTP_S_ACCT, FTP_R_ACCT,
FTP_S_TYPE, FTP_R_TYPE, FTP_S_TYPE, FTP_R_TYPE,
FTP_S_CWD, FTP_R_CWD,
FTP_S_PWD, FTP_R_PWD,
FTP_S_SIZE, FTP_R_SIZE, FTP_S_SIZE, FTP_R_SIZE,
FTP_S_MDTM, FTP_R_MDTM, FTP_S_MDTM, FTP_R_MDTM,
FTP_S_REST, FTP_R_REST, FTP_S_REST, FTP_R_REST,
@ -143,6 +145,8 @@ private:
nsresult S_syst(); FTP_STATE R_syst(); nsresult S_syst(); FTP_STATE R_syst();
nsresult S_type(); FTP_STATE R_type(); nsresult S_type(); FTP_STATE R_type();
nsresult S_cwd(); FTP_STATE R_cwd();
nsresult S_pwd(); FTP_STATE R_pwd();
nsresult S_size(); FTP_STATE R_size(); nsresult S_size(); FTP_STATE R_size();
nsresult S_mdtm(); FTP_STATE R_mdtm(); nsresult S_mdtm(); FTP_STATE R_mdtm();
@ -206,6 +210,7 @@ private:
nsCOMPtr<nsIURI> mURI; // the uri we're connecting to nsCOMPtr<nsIURI> mURI; // the uri we're connecting to
PRInt32 mPort; // the port to connect to PRInt32 mPort; // the port to connect to
nsCString mPath; // the url's path nsCString mPath; // the url's path
nsCString mPwd; // login Path
// ****** other vars // ****** other vars
nsCOMPtr<nsIInputStream> mWriteStream; // This stream is written to the server. nsCOMPtr<nsIInputStream> mWriteStream; // This stream is written to the server.