OLD | NEW |
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_vms.h" | 5 #include "net/ftp/ftp_directory_listing_parser_vms.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 *parsed_filename = StringToLowerASCII(filename_parts[0]); | 47 *parsed_filename = StringToLowerASCII(filename_parts[0]); |
48 *type = FtpDirectoryListingEntry::DIRECTORY; | 48 *type = FtpDirectoryListingEntry::DIRECTORY; |
49 } else { | 49 } else { |
50 *parsed_filename = StringToLowerASCII(listing_parts[0]); | 50 *parsed_filename = StringToLowerASCII(listing_parts[0]); |
51 *type = FtpDirectoryListingEntry::FILE; | 51 *type = FtpDirectoryListingEntry::FILE; |
52 } | 52 } |
53 return true; | 53 return true; |
54 } | 54 } |
55 | 55 |
56 bool ParseVmsFilesize(const base::string16& input, int64* size) { | 56 bool ParseVmsFilesize(const base::string16& input, int64* size) { |
57 if (ContainsOnlyChars(input, ASCIIToUTF16("*"))) { | 57 if (ContainsOnlyChars(input, base::ASCIIToUTF16("*"))) { |
58 // Response consisting of asterisks means unknown size. | 58 // Response consisting of asterisks means unknown size. |
59 *size = -1; | 59 *size = -1; |
60 return true; | 60 return true; |
61 } | 61 } |
62 | 62 |
63 // VMS's directory listing gives us file size in blocks. We assume that | 63 // VMS's directory listing gives us file size in blocks. We assume that |
64 // the block size is 512 bytes. It doesn't give accurate file size, but is the | 64 // the block size is 512 bytes. It doesn't give accurate file size, but is the |
65 // best information we have. | 65 // best information we have. |
66 const int kBlockSize = 512; | 66 const int kBlockSize = 512; |
67 | 67 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 | 134 |
135 bool LooksLikeVMSError(const base::string16& text) { | 135 bool LooksLikeVMSError(const base::string16& text) { |
136 static const char* kPermissionDeniedMessages[] = { | 136 static const char* kPermissionDeniedMessages[] = { |
137 "%RMS-E-FNF", // File not found. | 137 "%RMS-E-FNF", // File not found. |
138 "%RMS-E-PRV", // Access denied. | 138 "%RMS-E-PRV", // Access denied. |
139 "%SYSTEM-F-NOPRIV", | 139 "%SYSTEM-F-NOPRIV", |
140 "privilege", | 140 "privilege", |
141 }; | 141 }; |
142 | 142 |
143 for (size_t i = 0; i < arraysize(kPermissionDeniedMessages); i++) { | 143 for (size_t i = 0; i < arraysize(kPermissionDeniedMessages); i++) { |
144 if (text.find(ASCIIToUTF16(kPermissionDeniedMessages[i])) != | 144 if (text.find(base::ASCIIToUTF16(kPermissionDeniedMessages[i])) != |
145 base::string16::npos) | 145 base::string16::npos) |
146 return true; | 146 return true; |
147 } | 147 } |
148 | 148 |
149 return false; | 149 return false; |
150 } | 150 } |
151 | 151 |
152 bool VmsDateListingToTime(const std::vector<base::string16>& columns, | 152 bool VmsDateListingToTime(const std::vector<base::string16>& columns, |
153 base::Time* time) { | 153 base::Time* time) { |
154 DCHECK_EQ(4U, columns.size()); | 154 DCHECK_EQ(4U, columns.size()); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 // Sometimes the listing doesn't end with a "Total" line, but | 204 // Sometimes the listing doesn't end with a "Total" line, but |
205 // it's only okay when it contains some errors (it's needed | 205 // it's only okay when it contains some errors (it's needed |
206 // to distinguish it from "ls -l" format). | 206 // to distinguish it from "ls -l" format). |
207 bool seen_error = false; | 207 bool seen_error = false; |
208 | 208 |
209 for (size_t i = 0; i < lines.size(); i++) { | 209 for (size_t i = 0; i < lines.size(); i++) { |
210 if (lines[i].empty()) | 210 if (lines[i].empty()) |
211 continue; | 211 continue; |
212 | 212 |
213 if (StartsWith(lines[i], ASCIIToUTF16("Total of "), true)) { | 213 if (StartsWith(lines[i], base::ASCIIToUTF16("Total of "), true)) { |
214 // After the "total" line, all following lines must be empty. | 214 // After the "total" line, all following lines must be empty. |
215 for (size_t j = i + 1; j < lines.size(); j++) | 215 for (size_t j = i + 1; j < lines.size(); j++) |
216 if (!lines[j].empty()) | 216 if (!lines[j].empty()) |
217 return false; | 217 return false; |
218 | 218 |
219 return true; | 219 return true; |
220 } | 220 } |
221 | 221 |
222 if (!seen_header) { | 222 if (!seen_header) { |
223 seen_header = true; | 223 seen_header = true; |
(...skipping 17 matching lines...) Expand all Loading... |
241 i++; | 241 i++; |
242 | 242 |
243 // This refers to the continuation line. | 243 // This refers to the continuation line. |
244 if (LooksLikeVMSError(lines[i])) { | 244 if (LooksLikeVMSError(lines[i])) { |
245 seen_error = true; | 245 seen_error = true; |
246 continue; | 246 continue; |
247 } | 247 } |
248 | 248 |
249 // Join the current and next line and split them into columns. | 249 // Join the current and next line and split them into columns. |
250 base::SplitString( | 250 base::SplitString( |
251 CollapseWhitespace(lines[i - 1] + ASCIIToUTF16(" ") + lines[i], | 251 CollapseWhitespace(lines[i - 1] + base::ASCIIToUTF16(" ") + lines[i], |
252 false), | 252 false), |
253 ' ', | 253 ' ', |
254 &columns); | 254 &columns); |
255 } | 255 } |
256 | 256 |
257 FtpDirectoryListingEntry entry; | 257 FtpDirectoryListingEntry entry; |
258 if (!ParseVmsFilename(columns[0], &entry.name, &entry.type)) | 258 if (!ParseVmsFilename(columns[0], &entry.name, &entry.type)) |
259 return false; | 259 return false; |
260 | 260 |
261 // There are different variants of a VMS listing. Some display | 261 // There are different variants of a VMS listing. Some display |
(...skipping 22 matching lines...) Expand all Loading... |
284 entries->push_back(entry); | 284 entries->push_back(entry); |
285 } | 285 } |
286 | 286 |
287 // The only place where we return true is after receiving the "Total" line, | 287 // The only place where we return true is after receiving the "Total" line, |
288 // that should be present in every VMS listing. Alternatively, if the listing | 288 // that should be present in every VMS listing. Alternatively, if the listing |
289 // contains error messages, it's OK not to have the "Total" line. | 289 // contains error messages, it's OK not to have the "Total" line. |
290 return seen_error; | 290 return seen_error; |
291 } | 291 } |
292 | 292 |
293 } // namespace net | 293 } // namespace net |
OLD | NEW |