Add logging.store and logging.uploadStored to thunk.js for Hangouts.
[chromium-blink-merge.git] / net / ftp / ftp_directory_listing_parser_windows.cc
blobf394b1705ad0510dab6e0b6c29d06fe3a1eb2af0
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/ftp/ftp_directory_listing_parser_windows.h"
7 #include <vector>
9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_split.h"
11 #include "base/strings/string_util.h"
12 #include "base/time/time.h"
13 #include "net/ftp/ftp_directory_listing_parser.h"
14 #include "net/ftp/ftp_util.h"
16 namespace net {
18 bool ParseFtpDirectoryListingWindows(
19 const std::vector<base::string16>& lines,
20 std::vector<FtpDirectoryListingEntry>* entries) {
21 for (size_t i = 0; i < lines.size(); i++) {
22 if (lines[i].empty())
23 continue;
25 std::vector<base::string16> columns;
26 base::SplitString(base::CollapseWhitespace(lines[i], false), ' ', &columns);
28 // Every line of the listing consists of the following:
30 // 1. date
31 // 2. time
32 // 3. size in bytes (or "<DIR>" for directories)
33 // 4. filename (may be empty or contain spaces)
35 // For now, make sure we have 1-3, and handle 4 later.
36 if (columns.size() < 3)
37 return false;
39 FtpDirectoryListingEntry entry;
40 if (base::EqualsASCII(columns[2], "<DIR>")) {
41 entry.type = FtpDirectoryListingEntry::DIRECTORY;
42 entry.size = -1;
43 } else {
44 entry.type = FtpDirectoryListingEntry::FILE;
45 if (!base::StringToInt64(columns[2], &entry.size))
46 return false;
47 if (entry.size < 0)
48 return false;
51 if (!FtpUtil::WindowsDateListingToTime(columns[0],
52 columns[1],
53 &entry.last_modified)) {
54 return false;
57 entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 3);
58 if (entry.name.empty()) {
59 // Some FTP servers send listing entries with empty names.
60 // It's not obvious how to display such an entry, so ignore them.
61 // We don't want to make the parsing fail at this point though.
62 // Other entries can still be useful.
63 continue;
66 entries->push_back(entry);
69 return true;
72 } // namespace net