OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 return ERR_NOT_IMPLEMENTED; | 241 return ERR_NOT_IMPLEMENTED; |
242 } | 242 } |
243 | 243 |
244 int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, | 244 int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, |
245 OldCompletionCallback* callback, | 245 OldCompletionCallback* callback, |
246 const BoundNetLog& net_log) { | 246 const BoundNetLog& net_log) { |
247 net_log_ = net_log; | 247 net_log_ = net_log; |
248 request_ = request_info; | 248 request_ = request_info; |
249 | 249 |
250 if (request_->url.has_username()) { | 250 if (request_->url.has_username()) { |
251 GetIdentityFromURL(request_->url, &username_, &password_); | 251 string16 username; |
| 252 string16 password; |
| 253 GetIdentityFromURL(request_->url, &username, &password); |
| 254 credentials_.Set(username, password); |
252 } else { | 255 } else { |
253 username_ = ASCIIToUTF16("anonymous"); | 256 credentials_.Set(ASCIIToUTF16("anonymous"), |
254 password_ = ASCIIToUTF16("chrome@example.com"); | 257 ASCIIToUTF16("chrome@example.com")); |
255 } | 258 } |
256 | 259 |
257 DetectTypecode(); | 260 DetectTypecode(); |
258 | 261 |
259 next_state_ = STATE_CTRL_RESOLVE_HOST; | 262 next_state_ = STATE_CTRL_RESOLVE_HOST; |
260 int rv = DoLoop(OK); | 263 int rv = DoLoop(OK); |
261 if (rv == ERR_IO_PENDING) | 264 if (rv == ERR_IO_PENDING) |
262 user_callback_ = callback; | 265 user_callback_ = callback; |
263 return rv; | 266 return rv; |
264 } | 267 } |
265 | 268 |
266 int FtpNetworkTransaction::RestartWithAuth(const string16& username, | 269 int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials, |
267 const string16& password, | |
268 OldCompletionCallback* callback) { | 270 OldCompletionCallback* callback) { |
269 ResetStateForRestart(); | 271 ResetStateForRestart(); |
270 | 272 |
271 username_ = username; | 273 credentials_ = credentials; |
272 password_ = password; | |
273 | 274 |
274 next_state_ = STATE_CTRL_RESOLVE_HOST; | 275 next_state_ = STATE_CTRL_RESOLVE_HOST; |
275 int rv = DoLoop(OK); | 276 int rv = DoLoop(OK); |
276 if (rv == ERR_IO_PENDING) | 277 if (rv == ERR_IO_PENDING) |
277 user_callback_ = callback; | 278 user_callback_ = callback; |
278 return rv; | 279 return rv; |
279 } | 280 } |
280 | 281 |
281 int FtpNetworkTransaction::Read(IOBuffer* buf, | 282 int FtpNetworkTransaction::Read(IOBuffer* buf, |
282 int buf_len, | 283 int buf_len, |
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 read_ctrl_buf_, | 662 read_ctrl_buf_, |
662 kCtrlBufLen, | 663 kCtrlBufLen, |
663 &io_callback_); | 664 &io_callback_); |
664 } | 665 } |
665 | 666 |
666 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { | 667 int FtpNetworkTransaction::DoCtrlReadComplete(int result) { |
667 if (result == 0) { | 668 if (result == 0) { |
668 // Some servers (for example Pure-FTPd) apparently close the control | 669 // Some servers (for example Pure-FTPd) apparently close the control |
669 // connection when anonymous login is not permitted. For more details | 670 // connection when anonymous login is not permitted. For more details |
670 // see http://crbug.com/25023. | 671 // see http://crbug.com/25023. |
671 if (command_sent_ == COMMAND_USER && username_ == ASCIIToUTF16("anonymous")) | 672 if (command_sent_ == COMMAND_USER && |
| 673 credentials_.username() == ASCIIToUTF16("anonymous")) { |
672 response_.needs_auth = true; | 674 response_.needs_auth = true; |
| 675 } |
673 return Stop(ERR_EMPTY_RESPONSE); | 676 return Stop(ERR_EMPTY_RESPONSE); |
674 } | 677 } |
675 if (result < 0) | 678 if (result < 0) |
676 return Stop(result); | 679 return Stop(result); |
677 | 680 |
678 ctrl_response_buffer_->ConsumeData(read_ctrl_buf_->data(), result); | 681 ctrl_response_buffer_->ConsumeData(read_ctrl_buf_->data(), result); |
679 | 682 |
680 if (!ctrl_response_buffer_->ResponseAvailable()) { | 683 if (!ctrl_response_buffer_->ResponseAvailable()) { |
681 // Read more data from the control socket. | 684 // Read more data from the control socket. |
682 next_state_ = STATE_CTRL_READ; | 685 next_state_ = STATE_CTRL_READ; |
(...skipping 25 matching lines...) Expand all Loading... |
708 } else { | 711 } else { |
709 next_state_ = STATE_CTRL_WRITE; | 712 next_state_ = STATE_CTRL_WRITE; |
710 } | 713 } |
711 return OK; | 714 return OK; |
712 } | 715 } |
713 | 716 |
714 // FTP Commands and responses | 717 // FTP Commands and responses |
715 | 718 |
716 // USER Command. | 719 // USER Command. |
717 int FtpNetworkTransaction::DoCtrlWriteUSER() { | 720 int FtpNetworkTransaction::DoCtrlWriteUSER() { |
718 std::string command = "USER " + UTF16ToUTF8(username_); | 721 std::string command = "USER " + UTF16ToUTF8(credentials_.username()); |
719 | 722 |
720 if (!IsValidFTPCommandString(command)) | 723 if (!IsValidFTPCommandString(command)) |
721 return Stop(ERR_MALFORMED_IDENTITY); | 724 return Stop(ERR_MALFORMED_IDENTITY); |
722 | 725 |
723 next_state_ = STATE_CTRL_READ; | 726 next_state_ = STATE_CTRL_READ; |
724 return SendFtpCommand(command, COMMAND_USER); | 727 return SendFtpCommand(command, COMMAND_USER); |
725 } | 728 } |
726 | 729 |
727 int FtpNetworkTransaction::ProcessResponseUSER( | 730 int FtpNetworkTransaction::ProcessResponseUSER( |
728 const FtpCtrlResponse& response) { | 731 const FtpCtrlResponse& response) { |
(...skipping 10 matching lines...) Expand all Loading... |
739 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); | 742 return Stop(GetNetErrorCodeForFtpResponseCode(response.status_code)); |
740 default: | 743 default: |
741 NOTREACHED(); | 744 NOTREACHED(); |
742 return Stop(ERR_UNEXPECTED); | 745 return Stop(ERR_UNEXPECTED); |
743 } | 746 } |
744 return OK; | 747 return OK; |
745 } | 748 } |
746 | 749 |
747 // PASS command. | 750 // PASS command. |
748 int FtpNetworkTransaction::DoCtrlWritePASS() { | 751 int FtpNetworkTransaction::DoCtrlWritePASS() { |
749 std::string command = "PASS " + UTF16ToUTF8(password_); | 752 std::string command = "PASS " + UTF16ToUTF8(credentials_.password()); |
750 | 753 |
751 if (!IsValidFTPCommandString(command)) | 754 if (!IsValidFTPCommandString(command)) |
752 return Stop(ERR_MALFORMED_IDENTITY); | 755 return Stop(ERR_MALFORMED_IDENTITY); |
753 | 756 |
754 next_state_ = STATE_CTRL_READ; | 757 next_state_ = STATE_CTRL_READ; |
755 return SendFtpCommand(command, COMMAND_PASS); | 758 return SendFtpCommand(command, COMMAND_PASS); |
756 } | 759 } |
757 | 760 |
758 int FtpNetworkTransaction::ProcessResponsePASS( | 761 int FtpNetworkTransaction::ProcessResponsePASS( |
759 const FtpCtrlResponse& response) { | 762 const FtpCtrlResponse& response) { |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1329 if (!had_error_type[type]) { | 1332 if (!had_error_type[type]) { |
1330 had_error_type[type] = true; | 1333 had_error_type[type] = true; |
1331 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", | 1334 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorHappened", |
1332 type, NUM_OF_NET_ERROR_TYPES); | 1335 type, NUM_OF_NET_ERROR_TYPES); |
1333 } | 1336 } |
1334 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", | 1337 UMA_HISTOGRAM_ENUMERATION("Net.FtpDataConnectionErrorCount", |
1335 type, NUM_OF_NET_ERROR_TYPES); | 1338 type, NUM_OF_NET_ERROR_TYPES); |
1336 } | 1339 } |
1337 | 1340 |
1338 } // namespace net | 1341 } // namespace net |
OLD | NEW |