| 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_directory_listing_parser.h" | 5 #include "net/ftp/ftp_directory_listing_parser.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/i18n/encoding_detection.h" | 9 #include "base/i18n/encoding_detection.h" |
| 10 #include "base/i18n/icu_string_conversions.h" | 10 #include "base/i18n/icu_string_conversions.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Fills in |raw_name| for all |entries| using |encoding|. Returns network | 25 // Fills in |raw_name| for all |entries| using |encoding|. Returns network |
| 26 // error code. | 26 // error code. |
| 27 int FillInRawName(const std::string& encoding, | 27 int FillInRawName(const std::string& encoding, |
| 28 std::vector<FtpDirectoryListingEntry>* entries) { | 28 std::vector<FtpDirectoryListingEntry>* entries) { |
| 29 for (size_t i = 0; i < entries->size(); i++) { | 29 for (size_t i = 0; i < entries->size(); i++) { |
| 30 if (!base::UTF16ToCodepage(entries->at(i).name, encoding.c_str(), | 30 if (!base::UTF16ToCodepage(entries->at(i).name, encoding.c_str(), |
| 31 base::OnStringConversionError::FAIL, | 31 base::OnStringConversionError::SUBSTITUTE, |
| 32 &entries->at(i).raw_name)) { | 32 &entries->at(i).raw_name)) { |
| 33 return ERR_ENCODING_CONVERSION_FAILED; | 33 return ERR_ENCODING_CONVERSION_FAILED; |
| 34 } | 34 } |
| 35 } | 35 } |
| 36 | 36 |
| 37 return OK; | 37 return OK; |
| 38 } | 38 } |
| 39 | 39 |
| 40 // Parses |text| as an FTP directory listing. Fills in |entries| | 40 // Parses |text| as an FTP directory listing. Fills in |entries| |
| 41 // and |server_type| and returns network error code. | 41 // and |server_type| and returns network error code. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 const base::Time& current_time, | 84 const base::Time& current_time, |
| 85 std::vector<FtpDirectoryListingEntry>* entries, | 85 std::vector<FtpDirectoryListingEntry>* entries, |
| 86 FtpServerType* server_type) { | 86 FtpServerType* server_type) { |
| 87 std::string encoding; | 87 std::string encoding; |
| 88 if (!base::DetectEncoding(text, &encoding)) | 88 if (!base::DetectEncoding(text, &encoding)) |
| 89 return ERR_ENCODING_DETECTION_FAILED; | 89 return ERR_ENCODING_DETECTION_FAILED; |
| 90 const char* encoding_name = encoding.c_str(); | 90 const char* encoding_name = encoding.c_str(); |
| 91 | 91 |
| 92 base::string16 converted_text; | 92 base::string16 converted_text; |
| 93 if (base::CodepageToUTF16(text, encoding_name, | 93 if (base::CodepageToUTF16(text, encoding_name, |
| 94 base::OnStringConversionError::FAIL, | 94 base::OnStringConversionError::SUBSTITUTE, |
| 95 &converted_text)) { | 95 &converted_text)) { |
| 96 const char* const kNewlineSeparators[] = {"\n", "\r\n"}; | 96 const char* const kNewlineSeparators[] = {"\n", "\r\n"}; |
| 97 | 97 |
| 98 for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) { | 98 for (size_t j = 0; j < arraysize(kNewlineSeparators); j++) { |
| 99 int rv = ParseListing(converted_text, | 99 int rv = ParseListing(converted_text, |
| 100 base::ASCIIToUTF16(kNewlineSeparators[j]), | 100 base::ASCIIToUTF16(kNewlineSeparators[j]), |
| 101 encoding_name, current_time, entries, server_type); | 101 encoding_name, current_time, entries, server_type); |
| 102 if (rv == OK) | 102 if (rv == OK) |
| 103 return rv; | 103 return rv; |
| 104 } | 104 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 int ParseFtpDirectoryListing(const std::string& text, | 119 int ParseFtpDirectoryListing(const std::string& text, |
| 120 const base::Time& current_time, | 120 const base::Time& current_time, |
| 121 std::vector<FtpDirectoryListingEntry>* entries) { | 121 std::vector<FtpDirectoryListingEntry>* entries) { |
| 122 FtpServerType server_type = SERVER_UNKNOWN; | 122 FtpServerType server_type = SERVER_UNKNOWN; |
| 123 int rv = DecodeAndParse(text, current_time, entries, &server_type); | 123 int rv = DecodeAndParse(text, current_time, entries, &server_type); |
| 124 UpdateFtpServerTypeHistograms(server_type); | 124 UpdateFtpServerTypeHistograms(server_type); |
| 125 return rv; | 125 return rv; |
| 126 } | 126 } |
| 127 | 127 |
| 128 } // namespace net | 128 } // namespace net |
| OLD | NEW |