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

Unified Diff: net/ftp/ftp_directory_listing_buffer.h

Issue 244008: Beginnings of our own FTP LIST parsing code. (Closed)
Patch Set: test even more (slightly) Created 11 years, 2 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/data/ftp/dir-listing-ls-2.expected ('k') | net/ftp/ftp_directory_listing_buffer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/ftp/ftp_directory_listing_buffer.h
diff --git a/net/ftp/ftp_directory_listing_buffer.h b/net/ftp/ftp_directory_listing_buffer.h
new file mode 100644
index 0000000000000000000000000000000000000000..eaa237e2799d544f6eff53941aa4079e52a7ef3b
--- /dev/null
+++ b/net/ftp/ftp_directory_listing_buffer.h
@@ -0,0 +1,77 @@
+// Copyright (c) 2009 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.
+
+#ifndef NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_
+#define NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_
+
+#include <deque>
+#include <set>
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/string16.h"
+#include "base/time.h"
+
+namespace net {
+
+struct FtpDirectoryListingEntry;
+class FtpDirectoryListingParser;
+
+class FtpDirectoryListingBuffer {
+ public:
+ FtpDirectoryListingBuffer();
+
+ ~FtpDirectoryListingBuffer();
+
+ // Called when data is received from the data socket. Returns network
+ // error code.
+ int ConsumeData(const char* data, int data_length);
+
+ // Called when all received data has been consumed by this buffer. Tells the
+ // buffer to try to parse remaining raw data and returns network error code.
+ int ProcessRemainingData();
+
+ bool EntryAvailable() const;
+
+ // Returns the next entry. It is an error to call this function
+ // unless EntryAvailable returns true.
+ FtpDirectoryListingEntry PopEntry();
+
+ private:
+ typedef std::set<FtpDirectoryListingParser*> ParserSet;
+
+ // Converts the string |from| to detected encoding and stores it in |to|.
+ // Returns true on success.
+ bool ConvertToDetectedEncoding(const std::string& from, string16* to);
+
+ // Tries to extract full lines from the raw buffer, converting them to the
+ // detected encoding. Returns network error code.
+ int ExtractFullLinesFromBuffer();
+
+ // Tries to parse full lines stored in |lines_|. Returns network error code.
+ int ParseLines();
+
+ // Detected encoding of the response (empty if unknown or ASCII).
+ std::string encoding_;
+
+ // Buffer to keep not-yet-split data.
+ std::string buffer_;
+
+ // CRLF-delimited lines, without the CRLF, not yet consumed by parser.
+ std::deque<string16> lines_;
+
+ // A collection of parsers for different listing styles. The parsers are owned
+ // by this FtpDirectoryListingBuffer.
+ ParserSet parsers_;
+
+ // When we're sure about the listing format, its parser is stored in
+ // |current_parser_|.
+ FtpDirectoryListingParser* current_parser_;
+
+ DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingBuffer);
+};
+
+} // namespace net
+
+#endif // NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_
« no previous file with comments | « net/data/ftp/dir-listing-ls-2.expected ('k') | net/ftp/ftp_directory_listing_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698