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/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
10 #include "base/string_split.h" | 10 #include "base/string_split.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.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 LooksLikeUnixPermission(const string16& text) { | 19 bool LooksLikeUnixPermission(const string16& text) { |
20 if (text.length() != 3) | 20 if (text.length() != 3) |
21 return false; | 21 return false; |
22 | 22 |
23 // Meaning of the flags: | 23 // Meaning of the flags: |
24 // r - file is readable | 24 // r - file is readable |
25 // w - file is writable | 25 // w - file is writable |
26 // x - file is executable | 26 // x - file is executable |
27 // l - unknown | |
mmenke
2012/12/03 21:59:05
A quick search got me to "http://www.unix.com/tips
| |
27 // s or S - setuid/setgid bit set | 28 // s or S - setuid/setgid bit set |
28 // t or T - "sticky" bit set | 29 // t or T - "sticky" bit set |
29 return ((text[0] == 'r' || text[0] == '-') && | 30 return ((text[0] == 'r' || text[0] == '-') && |
30 (text[1] == 'w' || text[1] == '-') && | 31 (text[1] == 'w' || text[1] == '-') && |
31 (text[2] == 'x' || text[2] == 's' || text[2] == 'S' || | 32 (text[2] == 'x' || text[2] == 'l' || |
33 text[2] == 's' || text[2] == 'S' || | |
32 text[2] == 't' || text[2] == 'T' || text[2] == '-')); | 34 text[2] == 't' || text[2] == 'T' || text[2] == '-')); |
33 } | 35 } |
34 | 36 |
35 bool LooksLikeUnixPermissionsListing(const string16& text) { | 37 bool LooksLikeUnixPermissionsListing(const string16& text) { |
36 if (text.length() < 7) | 38 if (text.length() < 7) |
37 return false; | 39 return false; |
38 | 40 |
39 // Do not check the first character (entry type). There are many weird | 41 // Do not check the first character (entry type). There are many weird |
40 // servers that use special file types (for example Plan9 and append-only | 42 // servers that use special file types (for example Plan9 and append-only |
41 // files). Fortunately, the rest of the permission listing is more consistent. | 43 // files). Fortunately, the rest of the permission listing is more consistent. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
173 base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns); | 175 base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns); |
174 | 176 |
175 // Some FTP servers put a "total n" line at the beginning of the listing | 177 // Some FTP servers put a "total n" line at the beginning of the listing |
176 // (n is an integer). Allow such a line, but only once, and only if it's | 178 // (n is an integer). Allow such a line, but only once, and only if it's |
177 // the first non-empty line. Do not match the word exactly, because it may | 179 // the first non-empty line. Do not match the word exactly, because it may |
178 // be in different languages (at least English and German have been seen | 180 // be in different languages (at least English and German have been seen |
179 // in the field). | 181 // in the field). |
180 if (columns.size() == 2 && !received_total_line) { | 182 if (columns.size() == 2 && !received_total_line) { |
181 received_total_line = true; | 183 received_total_line = true; |
182 | 184 |
183 int total_number; | 185 int64 total_number; |
184 if (!base::StringToInt(columns[1], &total_number)) | 186 if (!base::StringToInt64(columns[1], &total_number)) |
185 return false; | 187 return false; |
186 if (total_number < 0) | 188 if (total_number < 0) |
187 return false; | 189 return false; |
188 | 190 |
189 continue; | 191 continue; |
190 } | 192 } |
191 | 193 |
192 FtpDirectoryListingEntry entry; | 194 FtpDirectoryListingEntry entry; |
193 | 195 |
194 size_t column_offset; | 196 size_t column_offset; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 entry.name = entry.name.substr(0, pos); | 260 entry.name = entry.name.substr(0, pos); |
259 } | 261 } |
260 | 262 |
261 entries->push_back(entry); | 263 entries->push_back(entry); |
262 } | 264 } |
263 | 265 |
264 return true; | 266 return true; |
265 } | 267 } |
266 | 268 |
267 } // namespace net | 269 } // namespace net |
OLD | NEW |