Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // LICENSE file. | |
| 4 | |
| 5 #include "net/ftp/ftp_directory_listing_parser_netware.h" | |
| 6 | |
| 7 #include <vector> | |
| 8 | |
| 9 #include "base/string_util.h" | |
| 10 #include "net/ftp/ftp_util.h" | |
| 11 | |
| 12 namespace { | |
| 13 | |
| 14 bool LooksLikeNetwarePermissionsListing(const string16& text) { | |
| 15 if (text.length() != 10) | |
| 16 return false; | |
| 17 | |
| 18 if (text[0] != '[' || text[9] != ']') | |
| 19 return false; | |
| 20 return (text[1] == 'R' || text[1] == '-') && | |
| 21 (text[2] == 'W' || text[2] == '-') && | |
| 22 (text[3] == 'C' || text[3] == '-') && | |
| 23 (text[4] == 'E' || text[4] == '-') && | |
| 24 (text[5] == 'A' || text[5] == '-') && | |
| 25 (text[6] == 'F' || text[6] == '-') && | |
| 26 (text[7] == 'M' || text[7] == '-') && | |
| 27 (text[8] == 'S' || text[8] == '-'); | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 namespace net { | |
| 33 | |
| 34 FtpDirectoryListingParserNetware::FtpDirectoryListingParserNetware() | |
| 35 : received_first_line_(false) { | |
| 36 } | |
| 37 | |
| 38 bool FtpDirectoryListingParserNetware::ConsumeLine(const string16& line) { | |
| 39 if (!received_first_line_) { | |
| 40 received_first_line_ = true; | |
| 41 | |
| 42 return StartsWith(line, ASCIIToUTF16("total "), true); | |
| 43 } | |
| 44 | |
| 45 std::vector<string16> columns; | |
| 46 SplitString(CollapseWhitespace(line, false), ' ', &columns); | |
| 47 | |
| 48 if (columns.size() != 8) | |
| 49 return false; | |
| 50 | |
| 51 FtpDirectoryListingEntry entry; | |
| 52 | |
| 53 if (columns[0].length() != 1) | |
| 54 return false; | |
| 55 if (columns[0][0] == 'd') { | |
| 56 entry.type = FtpDirectoryListingEntry::DIRECTORY; | |
| 57 } else if (columns[0][0] == '-') { | |
| 58 entry.type = FtpDirectoryListingEntry::FILE; | |
| 59 } else { | |
| 60 return false; | |
| 61 } | |
| 62 | |
| 63 // Note: on older Netware systems the permissions listing is in the same | |
| 64 // column as the entry type (just there is no space between them). We do not | |
| 65 // support the older format here for simplicity. | |
|
eroman
2009/12/07 19:15:54
is this a compat issue?
| |
| 66 if (!LooksLikeNetwarePermissionsListing(columns[1])) | |
| 67 return false; | |
| 68 | |
| 69 if (!StringToInt64(columns[3], &entry.size)) | |
| 70 return false; | |
| 71 if (entry.size < 0) | |
| 72 return false; | |
| 73 if (entry.type != FtpDirectoryListingEntry::FILE) | |
| 74 entry.size = -1; | |
| 75 | |
| 76 // Netware uses the same date listing format as Unix "ls -l". | |
| 77 if (!FtpUtil::LsDateListingToTime(columns[4], columns[5], columns[6], | |
| 78 &entry.last_modified)) { | |
| 79 return false; | |
| 80 } | |
| 81 | |
| 82 entry.name = columns[7]; | |
| 83 | |
| 84 entries_.push(entry); | |
| 85 return true; | |
| 86 } | |
| 87 | |
| 88 bool FtpDirectoryListingParserNetware::OnEndOfInput() { | |
| 89 return true; | |
| 90 } | |
| 91 | |
| 92 bool FtpDirectoryListingParserNetware::EntryAvailable() const { | |
| 93 return !entries_.empty(); | |
| 94 } | |
| 95 | |
| 96 FtpDirectoryListingEntry FtpDirectoryListingParserNetware::PopEntry() { | |
| 97 FtpDirectoryListingEntry entry = entries_.front(); | |
|
eroman
2009/12/07 19:15:54
Might want to DCHECK(EntryAvailable())
| |
| 98 entries_.pop(); | |
| 99 return entry; | |
| 100 } | |
| 101 | |
| 102 } // namespace net | |
| OLD | NEW |