| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // 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_util.h" | 9 #include "base/string_util.h" |
| 10 #include "net/ftp/ftp_util.h" | 10 #include "net/ftp/ftp_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 text[0] != 'l' && text[0] != 'p' && text[0] != 's' && | 35 text[0] != 'l' && text[0] != 'p' && text[0] != 's' && |
| 36 text[0] != '-') | 36 text[0] != '-') |
| 37 return false; | 37 return false; |
| 38 | 38 |
| 39 return (LooksLikeUnixPermission(text.substr(1, 3)) && | 39 return (LooksLikeUnixPermission(text.substr(1, 3)) && |
| 40 LooksLikeUnixPermission(text.substr(4, 3)) && | 40 LooksLikeUnixPermission(text.substr(4, 3)) && |
| 41 LooksLikeUnixPermission(text.substr(7, 3)) && | 41 LooksLikeUnixPermission(text.substr(7, 3)) && |
| 42 (text.substr(10).empty() || text.substr(10) == ASCIIToUTF16("+"))); | 42 (text.substr(10).empty() || text.substr(10) == ASCIIToUTF16("+"))); |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool DetectColumnOffset(const std::vector<string16>& columns, int* offset) { | 45 bool DetectColumnOffset(const std::vector<string16>& columns, |
| 46 const base::Time& current_time, int* offset) { |
| 46 base::Time time; | 47 base::Time time; |
| 47 | 48 |
| 48 if (columns.size() >= 8 && | 49 if (columns.size() >= 8 && |
| 49 net::FtpUtil::LsDateListingToTime(columns[5], columns[6], columns[7], | 50 net::FtpUtil::LsDateListingToTime(columns[5], columns[6], columns[7], |
| 50 &time)) { | 51 current_time, &time)) { |
| 51 // Standard listing, exactly like ls -l. | 52 // Standard listing, exactly like ls -l. |
| 52 *offset = 2; | 53 *offset = 2; |
| 53 return true; | 54 return true; |
| 54 } | 55 } |
| 55 | 56 |
| 56 if (columns.size() >= 7 && | 57 if (columns.size() >= 7 && |
| 57 net::FtpUtil::LsDateListingToTime(columns[4], columns[5], columns[6], | 58 net::FtpUtil::LsDateListingToTime(columns[4], columns[5], columns[6], |
| 58 &time)) { | 59 current_time, &time)) { |
| 59 // wu-ftpd listing, no "number of links" column. | 60 // wu-ftpd listing, no "number of links" column. |
| 60 *offset = 1; | 61 *offset = 1; |
| 61 return true; | 62 return true; |
| 62 } | 63 } |
| 63 | 64 |
| 64 if (columns.size() >= 6 && | 65 if (columns.size() >= 6 && |
| 65 net::FtpUtil::LsDateListingToTime(columns[3], columns[4], columns[5], | 66 net::FtpUtil::LsDateListingToTime(columns[3], columns[4], columns[5], |
| 66 &time)) { | 67 current_time, &time)) { |
| 67 // Xplain FTP Server listing for folders, like this: | 68 // Xplain FTP Server listing for folders, like this: |
| 68 // drwxr-xr-x folder 0 Jul 17 2006 online | 69 // drwxr-xr-x folder 0 Jul 17 2006 online |
| 69 *offset = 0; | 70 *offset = 0; |
| 70 return true; | 71 return true; |
| 71 } | 72 } |
| 72 | 73 |
| 73 // Unrecognized listing style. | 74 // Unrecognized listing style. |
| 74 return false; | 75 return false; |
| 75 } | 76 } |
| 76 | 77 |
| 77 } // namespace | 78 } // namespace |
| 78 | 79 |
| 79 namespace net { | 80 namespace net { |
| 80 | 81 |
| 81 FtpDirectoryListingParserLs::FtpDirectoryListingParserLs() | 82 FtpDirectoryListingParserLs::FtpDirectoryListingParserLs( |
| 83 const base::Time& current_time) |
| 82 : received_nonempty_line_(false), | 84 : received_nonempty_line_(false), |
| 83 received_total_line_(false) { | 85 received_total_line_(false), |
| 86 current_time_(current_time) { |
| 84 } | 87 } |
| 85 | 88 |
| 86 bool FtpDirectoryListingParserLs::ConsumeLine(const string16& line) { | 89 bool FtpDirectoryListingParserLs::ConsumeLine(const string16& line) { |
| 87 if (line.empty() && !received_nonempty_line_) { | 90 if (line.empty() && !received_nonempty_line_) { |
| 88 // Allow empty lines only at the beginning of the listing. For example VMS | 91 // Allow empty lines only at the beginning of the listing. For example VMS |
| 89 // systems in Unix emulation mode add an empty line before the first listing | 92 // systems in Unix emulation mode add an empty line before the first listing |
| 90 // entry. | 93 // entry. |
| 91 return true; | 94 return true; |
| 92 } | 95 } |
| 93 received_nonempty_line_ = true; | 96 received_nonempty_line_ = true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 int total_number; | 109 int total_number; |
| 107 if (!StringToInt(columns[1], &total_number)) | 110 if (!StringToInt(columns[1], &total_number)) |
| 108 return false; | 111 return false; |
| 109 if (total_number < 0) | 112 if (total_number < 0) |
| 110 return false; | 113 return false; |
| 111 | 114 |
| 112 return true; | 115 return true; |
| 113 } | 116 } |
| 114 | 117 |
| 115 int column_offset; | 118 int column_offset; |
| 116 if (!DetectColumnOffset(columns, &column_offset)) | 119 if (!DetectColumnOffset(columns, current_time_, &column_offset)) |
| 117 return false; | 120 return false; |
| 118 | 121 |
| 119 // We may receive file names containing spaces, which can make the number of | 122 // We may receive file names containing spaces, which can make the number of |
| 120 // columns arbitrarily large. We will handle that later. For now just make | 123 // columns arbitrarily large. We will handle that later. For now just make |
| 121 // sure we have all the columns that should normally be there. | 124 // sure we have all the columns that should normally be there. |
| 122 if (columns.size() < 7U + column_offset) | 125 if (columns.size() < 7U + column_offset) |
| 123 return false; | 126 return false; |
| 124 | 127 |
| 125 if (!LooksLikeUnixPermissionsListing(columns[0])) | 128 if (!LooksLikeUnixPermissionsListing(columns[0])) |
| 126 return false; | 129 return false; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 137 if (!StringToInt64(columns[2 + column_offset], &entry.size)) | 140 if (!StringToInt64(columns[2 + column_offset], &entry.size)) |
| 138 return false; | 141 return false; |
| 139 if (entry.size < 0) | 142 if (entry.size < 0) |
| 140 return false; | 143 return false; |
| 141 if (entry.type != FtpDirectoryListingEntry::FILE) | 144 if (entry.type != FtpDirectoryListingEntry::FILE) |
| 142 entry.size = -1; | 145 entry.size = -1; |
| 143 | 146 |
| 144 if (!FtpUtil::LsDateListingToTime(columns[3 + column_offset], | 147 if (!FtpUtil::LsDateListingToTime(columns[3 + column_offset], |
| 145 columns[4 + column_offset], | 148 columns[4 + column_offset], |
| 146 columns[5 + column_offset], | 149 columns[5 + column_offset], |
| 150 current_time_, |
| 147 &entry.last_modified)) { | 151 &entry.last_modified)) { |
| 148 return false; | 152 return false; |
| 149 } | 153 } |
| 150 | 154 |
| 151 entry.name = FtpUtil::GetStringPartAfterColumns(line, 6 + column_offset); | 155 entry.name = FtpUtil::GetStringPartAfterColumns(line, 6 + column_offset); |
| 152 if (entry.type == FtpDirectoryListingEntry::SYMLINK) { | 156 if (entry.type == FtpDirectoryListingEntry::SYMLINK) { |
| 153 string16::size_type pos = entry.name.rfind(ASCIIToUTF16(" -> ")); | 157 string16::size_type pos = entry.name.rfind(ASCIIToUTF16(" -> ")); |
| 154 if (pos == string16::npos) | 158 if (pos == string16::npos) |
| 155 return false; | 159 return false; |
| 156 entry.name = entry.name.substr(0, pos); | 160 entry.name = entry.name.substr(0, pos); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 168 return !entries_.empty(); | 172 return !entries_.empty(); |
| 169 } | 173 } |
| 170 | 174 |
| 171 FtpDirectoryListingEntry FtpDirectoryListingParserLs::PopEntry() { | 175 FtpDirectoryListingEntry FtpDirectoryListingParserLs::PopEntry() { |
| 172 FtpDirectoryListingEntry entry = entries_.front(); | 176 FtpDirectoryListingEntry entry = entries_.front(); |
| 173 entries_.pop(); | 177 entries_.pop(); |
| 174 return entry; | 178 return entry; |
| 175 } | 179 } |
| 176 | 180 |
| 177 } // namespace net | 181 } // namespace net |
| OLD | NEW |