Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: net/ftp/ftp_directory_listing_parser_ls.cc

Issue 11418296: FTP: misc fixes resulting from my testing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: fixes Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // s or S - setuid/setgid bit set 27 // s, S or l - setuid/setgid bit set
28 // t or T - "sticky" bit set 28 // t or T - "sticky" bit set
29 return ((text[0] == 'r' || text[0] == '-') && 29 return ((text[0] == 'r' || text[0] == '-') &&
30 (text[1] == 'w' || text[1] == '-') && 30 (text[1] == 'w' || text[1] == '-') &&
31 (text[2] == 'x' || text[2] == 's' || text[2] == 'S' || 31 (text[2] == 'x' || text[2] == '-' ||
32 text[2] == 't' || text[2] == 'T' || text[2] == '-')); 32 text[2] == 's' || text[2] == 'S' || text[2] == 'l' ||
33 text[2] == 't' || text[2] == 'T'));
33 } 34 }
34 35
35 bool LooksLikeUnixPermissionsListing(const string16& text) { 36 bool LooksLikeUnixPermissionsListing(const string16& text) {
36 if (text.length() < 7) 37 if (text.length() < 7)
37 return false; 38 return false;
38 39
39 // Do not check the first character (entry type). There are many weird 40 // 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 41 // servers that use special file types (for example Plan9 and append-only
41 // files). Fortunately, the rest of the permission listing is more consistent. 42 // files). Fortunately, the rest of the permission listing is more consistent.
42 43
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns); 174 base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns);
174 175
175 // Some FTP servers put a "total n" line at the beginning of the listing 176 // 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 177 // (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 178 // 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 179 // be in different languages (at least English and German have been seen
179 // in the field). 180 // in the field).
180 if (columns.size() == 2 && !received_total_line) { 181 if (columns.size() == 2 && !received_total_line) {
181 received_total_line = true; 182 received_total_line = true;
182 183
183 int total_number; 184 int64 total_number;
184 if (!base::StringToInt(columns[1], &total_number)) 185 if (!base::StringToInt64(columns[1], &total_number))
185 return false; 186 return false;
186 if (total_number < 0) 187 if (total_number < 0)
187 return false; 188 return false;
188 189
189 continue; 190 continue;
190 } 191 }
191 192
192 FtpDirectoryListingEntry entry; 193 FtpDirectoryListingEntry entry;
193 194
194 size_t column_offset; 195 size_t column_offset;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 entry.name = entry.name.substr(0, pos); 259 entry.name = entry.name.substr(0, pos);
259 } 260 }
260 261
261 entries->push_back(entry); 262 entries->push_back(entry);
262 } 263 }
263 264
264 return true; 265 return true;
265 } 266 }
266 267
267 } // namespace net 268 } // namespace net
OLDNEW
« no previous file with comments | « net/data/ftp/dir-listing-netware-3.expected ('k') | net/ftp/ftp_directory_listing_parser_ls_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698