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

Unified Diff: net/ftp/ftp_directory_listing_parser_os2.cc

Issue 7590011: FTP: add directory listing parser for OS/2 format. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes Created 9 years, 4 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/ftp/ftp_directory_listing_parser_os2.h ('k') | net/ftp/ftp_directory_listing_parser_os2_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ftp/ftp_directory_listing_parser_os2.cc
diff --git a/net/ftp/ftp_directory_listing_parser_os2.cc b/net/ftp/ftp_directory_listing_parser_os2.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6d493b800eadee7dd3f0391ab6a15cd70e6c3d1e
--- /dev/null
+++ b/net/ftp/ftp_directory_listing_parser_os2.cc
@@ -0,0 +1,77 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/ftp/ftp_directory_listing_parser_os2.h"
+
+#include <vector>
+
+#include "base/string_number_conversions.h"
+#include "base/string_split.h"
+#include "base/string_util.h"
+#include "base/time.h"
+#include "net/ftp/ftp_directory_listing_parser.h"
+#include "net/ftp/ftp_util.h"
+
+namespace net {
+
+bool ParseFtpDirectoryListingOS2(
+ const std::vector<string16>& lines,
+ std::vector<FtpDirectoryListingEntry>* entries) {
+ for (size_t i = 0; i < lines.size(); i++) {
+ if (lines[i].empty())
+ continue;
+
+ std::vector<string16> columns;
+ base::SplitString(CollapseWhitespace(lines[i], false), ' ', &columns);
+
+ // Every line of the listing consists of the following:
+ //
+ // 1. size in bytes (0 for directories)
+ // 2. type (A for files, DIR for directories)
+ // 3. date
+ // 4. time
+ // 5. filename (may be empty or contain spaces)
+ //
+ // For now, make sure we have 1-4, and handle 5 later.
+ if (columns.size() < 4)
+ return false;
+
+ FtpDirectoryListingEntry entry;
+ if (!base::StringToInt64(columns[0], &entry.size))
+ return false;
+ if (EqualsASCII(columns[1], "DIR")) {
+ if (entry.size != 0)
+ return false;
+ entry.type = FtpDirectoryListingEntry::DIRECTORY;
+ entry.size = -1;
+ } else if (EqualsASCII(columns[1], "A")) {
+ entry.type = FtpDirectoryListingEntry::FILE;
+ if (entry.size < 0)
+ return false;
+ } else {
+ return false;
+ }
+
+ if (!FtpUtil::WindowsDateListingToTime(columns[2],
+ columns[3],
+ &entry.last_modified)) {
+ return false;
+ }
+
+ entry.name = FtpUtil::GetStringPartAfterColumns(lines[i], 4);
+ if (entry.name.empty()) {
+ // Some FTP servers send listing entries with empty names.
+ // It's not obvious how to display such an entry, so ignore them.
+ // We don't want to make the parsing fail at this point though.
+ // Other entries can still be useful.
+ continue;
+ }
+
+ entries->push_back(entry);
+ }
+
+ return true;
+}
+
+} // namespace net
« no previous file with comments | « net/ftp/ftp_directory_listing_parser_os2.h ('k') | net/ftp/ftp_directory_listing_parser_os2_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698