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_directory_listing_parser_ls.h" | 5 #include "net/ftp/ftp_directory_listing_parser_ls.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "net/ftp/ftp_directory_listing_parser.h" | 14 #include "net/ftp/ftp_directory_listing_parser.h" |
15 #include "net/ftp/ftp_util.h" | 15 #include "net/ftp/ftp_util.h" |
16 | 16 |
17 namespace { | 17 namespace { |
18 | 18 |
19 bool TwoColumnDateListingToTime(const base::string16& date, | 19 bool TwoColumnDateListingToTime(const base::string16& date, |
20 const base::string16& time, | 20 const base::string16& time, |
21 base::Time* result) { | 21 base::Time* result) { |
22 base::Time::Exploded time_exploded = { 0 }; | 22 base::Time::Exploded time_exploded = {0}; |
23 | 23 |
24 // Date should be in format YYYY-MM-DD. | 24 // Date should be in format YYYY-MM-DD. |
25 std::vector<base::string16> date_parts; | 25 std::vector<base::string16> date_parts; |
26 base::SplitString(date, '-', &date_parts); | 26 base::SplitString(date, '-', &date_parts); |
27 if (date_parts.size() != 3) | 27 if (date_parts.size() != 3) |
28 return false; | 28 return false; |
29 if (!base::StringToInt(date_parts[0], &time_exploded.year)) | 29 if (!base::StringToInt(date_parts[0], &time_exploded.year)) |
30 return false; | 30 return false; |
31 if (!base::StringToInt(date_parts[1], &time_exploded.month)) | 31 if (!base::StringToInt(date_parts[1], &time_exploded.month)) |
32 return false; | 32 return false; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 current_time, | 99 current_time, |
100 modification_time)) { | 100 modification_time)) { |
101 *size = columns[i - 3]; | 101 *size = columns[i - 3]; |
102 *offset = i; | 102 *offset = i; |
103 return true; | 103 return true; |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 // Some FTP listings use a different date format. | 107 // Some FTP listings use a different date format. |
108 for (size_t i = 5U; i < columns.size(); i++) { | 108 for (size_t i = 5U; i < columns.size(); i++) { |
109 if (TwoColumnDateListingToTime(columns[i - 1], | 109 if (TwoColumnDateListingToTime( |
110 columns[i], | 110 columns[i - 1], columns[i], modification_time)) { |
111 modification_time)) { | |
112 *size = columns[i - 2]; | 111 *size = columns[i - 2]; |
113 *offset = i; | 112 *offset = i; |
114 return true; | 113 return true; |
115 } | 114 } |
116 } | 115 } |
117 | 116 |
118 return false; | 117 return false; |
119 } | 118 } |
120 | 119 |
121 } // namespace | 120 } // namespace |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 | 204 |
206 if (column_offset == columns.size() - 1) { | 205 if (column_offset == columns.size() - 1) { |
207 // If the end of the date listing is the last column, there is no file | 206 // If the end of the date listing is the last column, there is no file |
208 // name. Some FTP servers send listing entries with empty names. | 207 // name. Some FTP servers send listing entries with empty names. |
209 // It's not obvious how to display such an entry, so we ignore them. | 208 // It's not obvious how to display such an entry, so we ignore them. |
210 // We don't want to make the parsing fail at this point though. | 209 // We don't want to make the parsing fail at this point though. |
211 // Other entries can still be useful. | 210 // Other entries can still be useful. |
212 continue; | 211 continue; |
213 } | 212 } |
214 | 213 |
215 entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], | 214 entry.name = |
216 column_offset + 1); | 215 FtpUtil::GetStringPartAfterColumns(lines[i], column_offset + 1); |
217 | 216 |
218 if (entry.type == FtpDirectoryListingEntry::SYMLINK) { | 217 if (entry.type == FtpDirectoryListingEntry::SYMLINK) { |
219 base::string16::size_type pos = | 218 base::string16::size_type pos = |
220 entry.name.rfind(base::ASCIIToUTF16(" -> ")); | 219 entry.name.rfind(base::ASCIIToUTF16(" -> ")); |
221 | 220 |
222 // We don't require the " -> " to be present. Some FTP servers don't send | 221 // We don't require the " -> " to be present. Some FTP servers don't send |
223 // the symlink target, possibly for security reasons. | 222 // the symlink target, possibly for security reasons. |
224 if (pos != base::string16::npos) | 223 if (pos != base::string16::npos) |
225 entry.name = entry.name.substr(0, pos); | 224 entry.name = entry.name.substr(0, pos); |
226 } | 225 } |
227 | 226 |
228 entries->push_back(entry); | 227 entries->push_back(entry); |
229 } | 228 } |
230 | 229 |
231 return true; | 230 return true; |
232 } | 231 } |
233 | 232 |
234 } // namespace net | 233 } // namespace net |
OLD | NEW |