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

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

Issue 4182002: FTP: fix directory listing parser for ftp://ftp.dd-wrt.com/others/juno6/ (Closed)
Patch Set: typo Created 10 years, 1 month 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) 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 return true; 120 return true;
121 } 121 }
122 122
123 int column_offset; 123 int column_offset;
124 if (!DetectColumnOffset(columns, current_time_, &column_offset)) 124 if (!DetectColumnOffset(columns, current_time_, &column_offset))
125 return false; 125 return false;
126 126
127 // We may receive file names containing spaces, which can make the number of 127 // We may receive file names containing spaces, which can make the number of
128 // columns arbitrarily large. We will handle that later. For now just make 128 // columns arbitrarily large. We will handle that later. For now just make
129 // sure we have all the columns that should normally be there. 129 // sure we have all the columns that should normally be there.
130 if (columns.size() < 7U + column_offset) 130 if (columns.size() < 6U + column_offset)
wtc 2010/10/28 01:05:41 It would be nice to document what are the 6 column
Paweł Hajdan Jr. 2010/10/28 07:15:34 Good idea, done.
131 return false; 131 return false;
132 132
133 if (!LooksLikeUnixPermissionsListing(columns[0])) 133 if (!LooksLikeUnixPermissionsListing(columns[0]))
134 return false; 134 return false;
135 135
136 FtpDirectoryListingEntry entry; 136 FtpDirectoryListingEntry entry;
137 if (columns[0][0] == 'l') { 137 if (columns[0][0] == 'l') {
138 entry.type = FtpDirectoryListingEntry::SYMLINK; 138 entry.type = FtpDirectoryListingEntry::SYMLINK;
139 } else if (columns[0][0] == 'd') { 139 } else if (columns[0][0] == 'd') {
140 entry.type = FtpDirectoryListingEntry::DIRECTORY; 140 entry.type = FtpDirectoryListingEntry::DIRECTORY;
(...skipping 17 matching lines...) Expand all
158 158
159 if (!FtpUtil::LsDateListingToTime(columns[3 + column_offset], 159 if (!FtpUtil::LsDateListingToTime(columns[3 + column_offset],
160 columns[4 + column_offset], 160 columns[4 + column_offset],
161 columns[5 + column_offset], 161 columns[5 + column_offset],
162 current_time_, 162 current_time_,
163 &entry.last_modified)) { 163 &entry.last_modified)) {
164 return false; 164 return false;
165 } 165 }
166 166
167 entry.name = FtpUtil::GetStringPartAfterColumns(line, 6 + column_offset); 167 entry.name = FtpUtil::GetStringPartAfterColumns(line, 6 + column_offset);
168
169 if (entry.name.empty()) {
170 // Some FTP servers send listing entries with empty names. It's not obvious
171 // how to display such an entry, so we ignore them. We don't want to make
172 // the parsing fail at this point though. Other entries can still be useful.
173 return true;
174 }
175
168 if (entry.type == FtpDirectoryListingEntry::SYMLINK) { 176 if (entry.type == FtpDirectoryListingEntry::SYMLINK) {
169 string16::size_type pos = entry.name.rfind(ASCIIToUTF16(" -> ")); 177 string16::size_type pos = entry.name.rfind(ASCIIToUTF16(" -> "));
170 178
171 // We don't require the " -> " to be present. Some FTP servers don't send 179 // We don't require the " -> " to be present. Some FTP servers don't send
172 // the symlink target, possibly for security reasons. 180 // the symlink target, possibly for security reasons.
173 if (pos != string16::npos) 181 if (pos != string16::npos)
174 entry.name = entry.name.substr(0, pos); 182 entry.name = entry.name.substr(0, pos);
175 } 183 }
176 184
177 entries_.push(entry); 185 entries_.push(entry);
178 return true; 186 return true;
179 } 187 }
180 188
181 bool FtpDirectoryListingParserLs::OnEndOfInput() { 189 bool FtpDirectoryListingParserLs::OnEndOfInput() {
182 return true; 190 return true;
183 } 191 }
184 192
185 bool FtpDirectoryListingParserLs::EntryAvailable() const { 193 bool FtpDirectoryListingParserLs::EntryAvailable() const {
186 return !entries_.empty(); 194 return !entries_.empty();
187 } 195 }
188 196
189 FtpDirectoryListingEntry FtpDirectoryListingParserLs::PopEntry() { 197 FtpDirectoryListingEntry FtpDirectoryListingParserLs::PopEntry() {
190 FtpDirectoryListingEntry entry = entries_.front(); 198 FtpDirectoryListingEntry entry = entries_.front();
191 entries_.pop(); 199 entries_.pop();
192 return entry; 200 return entry;
193 } 201 }
194 202
195 } // namespace net 203 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698