OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/ftp/ftp_network_transaction.h" | 5 #include "net/ftp/ftp_network_transaction.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "net/base/address_list.h" | 16 #include "net/base/address_list.h" |
17 #include "net/base/escape.h" | 17 #include "net/base/escape.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/port_util.h" | 19 #include "net/base/port_util.h" |
20 #include "net/base/url_util.h" | 20 #include "net/base/url_util.h" |
21 #include "net/ftp/ftp_request_info.h" | 21 #include "net/ftp/ftp_request_info.h" |
22 #include "net/ftp/ftp_util.h" | 22 #include "net/ftp/ftp_util.h" |
23 #include "net/log/net_log.h" | 23 #include "net/log/net_log.h" |
| 24 #include "net/log/net_log_event_type.h" |
24 #include "net/socket/client_socket_factory.h" | 25 #include "net/socket/client_socket_factory.h" |
25 #include "net/socket/stream_socket.h" | 26 #include "net/socket/stream_socket.h" |
26 #include "url/url_constants.h" | 27 #include "url/url_constants.h" |
27 | 28 |
28 namespace net { | 29 namespace net { |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 const char kCRLF[] = "\r\n"; | 33 const char kCRLF[] = "\r\n"; |
33 | 34 |
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 } | 456 } |
456 | 457 |
457 command_sent_ = cmd; | 458 command_sent_ = cmd; |
458 | 459 |
459 write_command_buf_ = new IOBufferWithSize(command.length() + 2); | 460 write_command_buf_ = new IOBufferWithSize(command.length() + 2); |
460 write_buf_ = new DrainableIOBuffer(write_command_buf_.get(), | 461 write_buf_ = new DrainableIOBuffer(write_command_buf_.get(), |
461 write_command_buf_->size()); | 462 write_command_buf_->size()); |
462 memcpy(write_command_buf_->data(), command.data(), command.length()); | 463 memcpy(write_command_buf_->data(), command.data(), command.length()); |
463 memcpy(write_command_buf_->data() + command.length(), kCRLF, 2); | 464 memcpy(write_command_buf_->data() + command.length(), kCRLF, 2); |
464 | 465 |
465 net_log_.AddEvent(NetLog::TYPE_FTP_COMMAND_SENT, | 466 net_log_.AddEvent(NetLogEventType::FTP_COMMAND_SENT, |
466 NetLog::StringCallback("command", &command_for_log)); | 467 NetLog::StringCallback("command", &command_for_log)); |
467 | 468 |
468 next_state_ = STATE_CTRL_WRITE; | 469 next_state_ = STATE_CTRL_WRITE; |
469 return OK; | 470 return OK; |
470 } | 471 } |
471 | 472 |
472 std::string FtpNetworkTransaction::GetRequestPathForFtpCommand( | 473 std::string FtpNetworkTransaction::GetRequestPathForFtpCommand( |
473 bool is_directory) const { | 474 bool is_directory) const { |
474 std::string path(current_remote_directory_); | 475 std::string path(current_remote_directory_); |
475 if (request_->url.has_path()) { | 476 if (request_->url.has_path()) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
647 if (result == OK) | 648 if (result == OK) |
648 next_state_ = STATE_CTRL_CONNECT; | 649 next_state_ = STATE_CTRL_CONNECT; |
649 return result; | 650 return result; |
650 } | 651 } |
651 | 652 |
652 int FtpNetworkTransaction::DoCtrlConnect() { | 653 int FtpNetworkTransaction::DoCtrlConnect() { |
653 next_state_ = STATE_CTRL_CONNECT_COMPLETE; | 654 next_state_ = STATE_CTRL_CONNECT_COMPLETE; |
654 ctrl_socket_ = socket_factory_->CreateTransportClientSocket( | 655 ctrl_socket_ = socket_factory_->CreateTransportClientSocket( |
655 addresses_, NULL, net_log_.net_log(), net_log_.source()); | 656 addresses_, NULL, net_log_.net_log(), net_log_.source()); |
656 net_log_.AddEvent( | 657 net_log_.AddEvent( |
657 NetLog::TYPE_FTP_CONTROL_CONNECTION, | 658 NetLogEventType::FTP_CONTROL_CONNECTION, |
658 ctrl_socket_->NetLog().source().ToEventParametersCallback()); | 659 ctrl_socket_->NetLog().source().ToEventParametersCallback()); |
659 return ctrl_socket_->Connect(io_callback_); | 660 return ctrl_socket_->Connect(io_callback_); |
660 } | 661 } |
661 | 662 |
662 int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { | 663 int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { |
663 if (result == OK) { | 664 if (result == OK) { |
664 // Put the peer's IP address and port into the response. | 665 // Put the peer's IP address and port into the response. |
665 IPEndPoint ip_endpoint; | 666 IPEndPoint ip_endpoint; |
666 result = ctrl_socket_->GetPeerAddress(&ip_endpoint); | 667 result = ctrl_socket_->GetPeerAddress(&ip_endpoint); |
667 if (result == OK) { | 668 if (result == OK) { |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1224 // Connect to the same host as the control socket to prevent PASV port | 1225 // Connect to the same host as the control socket to prevent PASV port |
1225 // scanning attacks. | 1226 // scanning attacks. |
1226 int rv = ctrl_socket_->GetPeerAddress(&ip_endpoint); | 1227 int rv = ctrl_socket_->GetPeerAddress(&ip_endpoint); |
1227 if (rv != OK) | 1228 if (rv != OK) |
1228 return Stop(rv); | 1229 return Stop(rv); |
1229 data_address = AddressList::CreateFromIPAddress( | 1230 data_address = AddressList::CreateFromIPAddress( |
1230 ip_endpoint.address(), data_connection_port_); | 1231 ip_endpoint.address(), data_connection_port_); |
1231 data_socket_ = socket_factory_->CreateTransportClientSocket( | 1232 data_socket_ = socket_factory_->CreateTransportClientSocket( |
1232 data_address, NULL, net_log_.net_log(), net_log_.source()); | 1233 data_address, NULL, net_log_.net_log(), net_log_.source()); |
1233 net_log_.AddEvent( | 1234 net_log_.AddEvent( |
1234 NetLog::TYPE_FTP_DATA_CONNECTION, | 1235 NetLogEventType::FTP_DATA_CONNECTION, |
1235 data_socket_->NetLog().source().ToEventParametersCallback()); | 1236 data_socket_->NetLog().source().ToEventParametersCallback()); |
1236 return data_socket_->Connect(io_callback_); | 1237 return data_socket_->Connect(io_callback_); |
1237 } | 1238 } |
1238 | 1239 |
1239 int FtpNetworkTransaction::DoDataConnectComplete(int result) { | 1240 int FtpNetworkTransaction::DoDataConnectComplete(int result) { |
1240 if (result != OK && use_epsv_) { | 1241 if (result != OK && use_epsv_) { |
1241 // It's possible we hit a broken server, sadly. They can break in different | 1242 // It's possible we hit a broken server, sadly. They can break in different |
1242 // ways. Some time out, some reset a connection. Fall back to PASV. | 1243 // ways. Some time out, some reset a connection. Fall back to PASV. |
1243 // TODO(phajdan.jr): https://crbug.com/526723: remember it for future | 1244 // TODO(phajdan.jr): https://crbug.com/526723: remember it for future |
1244 // transactions with this server. | 1245 // transactions with this server. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1370 if (!had_error_type[type]) { | 1371 if (!had_error_type[type]) { |
1371 had_error_type[type] = true; | 1372 had_error_type[type] = true; |
1372 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1373 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
1373 type, NUM_OF_NET_ERROR_TYPES); | 1374 type, NUM_OF_NET_ERROR_TYPES); |
1374 } | 1375 } |
1375 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1376 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
1376 type, NUM_OF_NET_ERROR_TYPES); | 1377 type, NUM_OF_NET_ERROR_TYPES); |
1377 } | 1378 } |
1378 | 1379 |
1379 } // namespace net | 1380 } // namespace net |
OLD | NEW |