| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 27 matching lines...) Expand all Loading... |
| 38 text[0] != 'l' && text[0] != 'p' && text[0] != 's' && | 38 text[0] != 'l' && text[0] != 'p' && text[0] != 's' && |
| 39 text[0] != '-') | 39 text[0] != '-') |
| 40 return false; | 40 return false; |
| 41 | 41 |
| 42 return (LooksLikeUnixPermission(text.substr(1, 3)) && | 42 return (LooksLikeUnixPermission(text.substr(1, 3)) && |
| 43 LooksLikeUnixPermission(text.substr(4, 3)) && | 43 LooksLikeUnixPermission(text.substr(4, 3)) && |
| 44 LooksLikeUnixPermission(text.substr(7, 3)) && | 44 LooksLikeUnixPermission(text.substr(7, 3)) && |
| 45 (text.substr(10).empty() || text.substr(10) == ASCIIToUTF16("+"))); | 45 (text.substr(10).empty() || text.substr(10) == ASCIIToUTF16("+"))); |
| 46 } | 46 } |
| 47 | 47 |
| 48 bool LooksLikePermissionDeniedError(const string16& text) { |
| 49 // Try to recognize a three-part colon-separated error message: |
| 50 // |
| 51 // 1. ftpd server name |
| 52 // 2. directory name (often just ".") |
| 53 // 3. message text (usually "Permission denied") |
| 54 std::vector<string16> parts; |
| 55 base::SplitString(CollapseWhitespace(text, false), ':', &parts); |
| 56 |
| 57 if (parts.size() != 3) |
| 58 return false; |
| 59 |
| 60 return parts[2] == ASCIIToUTF16("Permission denied"); |
| 61 } |
| 62 |
| 48 bool DetectColumnOffset(const std::vector<string16>& columns, | 63 bool DetectColumnOffset(const std::vector<string16>& columns, |
| 49 const base::Time& current_time, int* offset) { | 64 const base::Time& current_time, int* offset) { |
| 50 base::Time time; | 65 base::Time time; |
| 51 | 66 |
| 52 if (columns.size() >= 8 && | 67 if (columns.size() >= 8 && |
| 53 net::FtpUtil::LsDateListingToTime(columns[5], columns[6], columns[7], | 68 net::FtpUtil::LsDateListingToTime(columns[5], columns[6], columns[7], |
| 54 current_time, &time)) { | 69 current_time, &time)) { |
| 55 // Standard listing, exactly like ls -l. | 70 // Standard listing, exactly like ls -l. |
| 56 *offset = 2; | 71 *offset = 2; |
| 57 return true; | 72 return true; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 int total_number; | 133 int total_number; |
| 119 if (!base::StringToInt(columns[1], &total_number)) | 134 if (!base::StringToInt(columns[1], &total_number)) |
| 120 return false; | 135 return false; |
| 121 if (total_number < 0) | 136 if (total_number < 0) |
| 122 return false; | 137 return false; |
| 123 | 138 |
| 124 return true; | 139 return true; |
| 125 } | 140 } |
| 126 | 141 |
| 127 int column_offset; | 142 int column_offset; |
| 128 if (!DetectColumnOffset(columns, current_time_, &column_offset)) | 143 if (!DetectColumnOffset(columns, current_time_, &column_offset)) { |
| 129 return false; | 144 // If we can't recognize a normal listing line, maybe it's an error? |
| 145 // In that case, just ignore the error, but still recognize the data |
| 146 // as valid listing. |
| 147 return LooksLikePermissionDeniedError(line); |
| 148 } |
| 130 | 149 |
| 131 // We may receive file names containing spaces, which can make the number of | 150 // We may receive file names containing spaces, which can make the number of |
| 132 // columns arbitrarily large. We will handle that later. For now just make | 151 // columns arbitrarily large. We will handle that later. For now just make |
| 133 // sure we have all the columns that should normally be there: | 152 // sure we have all the columns that should normally be there: |
| 134 // | 153 // |
| 135 // 1. permission listing | 154 // 1. permission listing |
| 136 // 2. number of links (optional) | 155 // 2. number of links (optional) |
| 137 // 3. owner name | 156 // 3. owner name |
| 138 // 4. group name (optional) | 157 // 4. group name (optional) |
| 139 // 5. size in bytes | 158 // 5. size in bytes |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 return !entries_.empty(); | 229 return !entries_.empty(); |
| 211 } | 230 } |
| 212 | 231 |
| 213 FtpDirectoryListingEntry FtpDirectoryListingParserLs::PopEntry() { | 232 FtpDirectoryListingEntry FtpDirectoryListingParserLs::PopEntry() { |
| 214 FtpDirectoryListingEntry entry = entries_.front(); | 233 FtpDirectoryListingEntry entry = entries_.front(); |
| 215 entries_.pop(); | 234 entries_.pop(); |
| 216 return entry; | 235 return entry; |
| 217 } | 236 } |
| 218 | 237 |
| 219 } // namespace net | 238 } // namespace net |
| OLD | NEW |