summaryrefslogtreecommitdiffstats
path: root/net/ftp
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 16:29:53 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-18 16:29:53 +0000
commitcca048bf67b8a044dc69c54f9fd691ef9143b865 (patch)
tree8f0ab3fade412b43b73fc98bcd1bf5a160c13ae9 /net/ftp
parent8b30662b7ca998a481c9dae66d8b6b05db47b38a (diff)
downloadchromium_src-cca048bf67b8a044dc69c54f9fd691ef9143b865.zip
chromium_src-cca048bf67b8a044dc69c54f9fd691ef9143b865.tar.gz
chromium_src-cca048bf67b8a044dc69c54f9fd691ef9143b865.tar.bz2
Various cleanups FTP-related.
- use better name for FTP LIST parsing code in about:credits - don't open a second data socket - add a comment explaining why we close the data socket at one point TEST=Covered by net_unittests. BUG=none Review URL: http://codereview.chromium.org/207014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@26575 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp')
-rw-r--r--net/ftp/ftp_network_transaction.cc8
-rw-r--r--net/ftp/ftp_network_transaction_unittest.cc31
2 files changed, 11 insertions, 28 deletions
diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc
index 753aee2..e1a4114caf 100644
--- a/net/ftp/ftp_network_transaction.cc
+++ b/net/ftp/ftp_network_transaction.cc
@@ -865,7 +865,10 @@ int FtpNetworkTransaction::ProcessResponseRETR(
DCHECK(!retr_failed_); // Should not get here twice.
retr_failed_ = true;
- next_state_ = STATE_CTRL_WRITE_PASV;
+
+ // It's possible that RETR failed because the path is a directory.
+ // Try CWD next, to see if that's the case.
+ next_state_ = STATE_CTRL_WRITE_CWD;
break;
default:
NOTREACHED();
@@ -1023,7 +1026,8 @@ int FtpNetworkTransaction::DoDataRead() {
if (data_socket_ == NULL || !data_socket_->IsConnected()) {
// If we don't destroy the data socket completely, some servers will wait
- // for us (http://crbug.com/21127).
+ // for us (http://crbug.com/21127). The half-closed TCP connection needs
+ // to be closed on our side too.
data_socket_.reset();
// No more data so send QUIT Command now and wait for response.
diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc
index 95b1e8e..140a37d 100644
--- a/net/ftp/ftp_network_transaction_unittest.cc
+++ b/net/ftp/ftp_network_transaction_unittest.cc
@@ -47,7 +47,6 @@ class FtpMockControlSocket : public DynamicMockSocket {
PRE_MDTM,
PRE_LIST,
PRE_RETR,
- PRE_PASV2,
PRE_CWD,
PRE_QUIT,
QUIT
@@ -83,7 +82,7 @@ class FtpMockControlSocket : public DynamicMockSocket {
"200 TYPE is now 8-bit binary\r\n");
case PRE_PASV:
return Verify("PASV\r\n", data, PRE_SIZE,
- "227 Entering Passive Mode (127,0,0,1,123,456)\r\n");
+ "227 Entering Passive Mode 127,0,0,1,123,456\r\n");
case PRE_QUIT:
return Verify("QUIT\r\n", data, QUIT, "221 Goodbye.\r\n");
default:
@@ -171,12 +170,8 @@ class FtpMockControlSocketDirectoryListing : public FtpMockControlSocket {
return Verify("MDTM /\r\n", data, PRE_RETR,
"213 20070221112533\r\n");
case PRE_RETR:
- return Verify("RETR /\r\n", data, PRE_PASV2,
+ return Verify("RETR /\r\n", data, PRE_CWD,
"550 Can't download directory\r\n");
- case PRE_PASV2:
- // Parser should also accept format without parentheses.
- return Verify("PASV\r\n", data, PRE_CWD,
- "227 Entering Passive Mode 127,0,0,1,123,456\r\n");
case PRE_CWD:
return Verify("CWD /\r\n", data, PRE_LIST, "200 OK\r\n");
case PRE_LIST:
@@ -298,9 +293,6 @@ class FtpMockControlSocketFileDownloadRetrFail
if (InjectFault())
return MockWriteResult(true, data.length());
switch (state()) {
- case PRE_PASV2:
- return Verify("PASV\r\n", data, PRE_CWD,
- "227 Entering Passive Mode (127,0,0,1,123,456)\r\n");
case PRE_CWD:
return Verify("CWD /file\r\n", data, PRE_QUIT,
"550 file is a directory\r\n");
@@ -391,12 +383,9 @@ class FtpNetworkTransactionTest : public PlatformTest {
MockRead data_reads[] = {
MockRead(mock_data.c_str()),
};
- // TODO(phajdan.jr): FTP transaction should not open two data sockets.
- StaticMockSocket data_socket1(data_reads, NULL);
- StaticMockSocket data_socket2(data_reads, NULL);
+ StaticMockSocket data_socket(data_reads, NULL);
mock_socket_factory_.AddMockSocket(ctrl_socket);
- mock_socket_factory_.AddMockSocket(&data_socket1);
- mock_socket_factory_.AddMockSocket(&data_socket2);
+ mock_socket_factory_.AddMockSocket(&data_socket);
FtpRequestInfo request_info = GetRequestInfo(request);
EXPECT_EQ(LOAD_STATE_IDLE, transaction_.GetLoadState());
ASSERT_EQ(ERR_IO_PENDING,
@@ -774,16 +763,6 @@ TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailMdtm) {
OK);
}
-TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailPasv2) {
- FtpMockControlSocketDirectoryListing ctrl_socket;
- TransactionFailHelper(&ctrl_socket,
- "ftp://host",
- FtpMockControlSocket::PRE_PASV2,
- FtpMockControlSocket::PRE_QUIT,
- "500 failed pasv\r\n",
- ERR_FAILED);
-}
-
TEST_F(FtpNetworkTransactionTest, DirectoryTransactionFailCwd) {
FtpMockControlSocketDirectoryListing ctrl_socket;
TransactionFailHelper(&ctrl_socket,
@@ -899,7 +878,7 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransactionFileNotFound) {
TransactionFailHelper(&ctrl_socket,
"ftp://host/file",
FtpMockControlSocket::PRE_RETR,
- FtpMockControlSocket::PRE_PASV2,
+ FtpMockControlSocket::PRE_CWD,
"550 cannot open file\r\n",
ERR_FILE_NOT_FOUND);
}