| 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_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" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // x - file is executable | 26 // x - file is executable |
| 27 // s or S - setuid/setgid bit set | 27 // s or S - 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] == 's' || text[2] == 'S' || |
| 32 text[2] == 't' || text[2] == 'T' || text[2] == '-')); | 32 text[2] == 't' || text[2] == 'T' || text[2] == '-')); |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool LooksLikeUnixPermissionsListing(const string16& text) { | 35 bool LooksLikeUnixPermissionsListing(const string16& text) { |
| 36 if (text.length() < 10) | 36 if (text.length() < 7) |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 // Do not check the first character (entry type). There are many weird | 39 // 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 | 40 // servers that use special file types (for example Plan9 and append-only |
| 41 // files). Fortunately, the rest of the permission listing is more consistent. | 41 // files). Fortunately, the rest of the permission listing is more consistent. |
| 42 | 42 |
| 43 // Do not check the rest of the string. Some servers fail to properly | 43 // Do not check the rest of the string. Some servers fail to properly |
| 44 // separate this column from the next column (number of links), resulting | 44 // separate this column from the next column (number of links), resulting |
| 45 // in additional characters at the end. Also, sometimes there is a "+" | 45 // in additional characters at the end. Also, sometimes there is a "+" |
| 46 // sign at the end indicating the file has ACLs set. | 46 // sign at the end indicating the file has ACLs set. |
| 47 |
| 48 // In fact, we don't even expect three "rwx" triplets of permission |
| 49 // listing, as some FTP servers like Hylafax only send two. |
| 47 return (LooksLikeUnixPermission(text.substr(1, 3)) && | 50 return (LooksLikeUnixPermission(text.substr(1, 3)) && |
| 48 LooksLikeUnixPermission(text.substr(4, 3)) && | 51 LooksLikeUnixPermission(text.substr(4, 3))); |
| 49 LooksLikeUnixPermission(text.substr(7, 3))); | |
| 50 } | 52 } |
| 51 | 53 |
| 52 bool LooksLikePermissionDeniedError(const string16& text) { | 54 bool LooksLikePermissionDeniedError(const string16& text) { |
| 53 // Try to recognize a three-part colon-separated error message: | 55 // Try to recognize a three-part colon-separated error message: |
| 54 // | 56 // |
| 55 // 1. ftpd server name | 57 // 1. ftpd server name |
| 56 // 2. directory name (often just ".") | 58 // 2. directory name (often just ".") |
| 57 // 3. message text (usually "Permission denied") | 59 // 3. message text (usually "Permission denied") |
| 58 std::vector<string16> parts; | 60 std::vector<string16> parts; |
| 59 base::SplitString(CollapseWhitespace(text, false), ':', &parts); | 61 base::SplitString(CollapseWhitespace(text, false), ':', &parts); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 entry.name = entry.name.substr(0, pos); | 213 entry.name = entry.name.substr(0, pos); |
| 212 } | 214 } |
| 213 | 215 |
| 214 entries->push_back(entry); | 216 entries->push_back(entry); |
| 215 } | 217 } |
| 216 | 218 |
| 217 return true; | 219 return true; |
| 218 } | 220 } |
| 219 | 221 |
| 220 } // namespace net | 222 } // namespace net |
| OLD | NEW |