diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/ftp/ftp_directory_listing_buffer.cc | 7 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_buffer.h | 17 | ||||
-rw-r--r-- | net/ftp/ftp_directory_listing_parsers.h | 5 |
3 files changed, 23 insertions, 6 deletions
diff --git a/net/ftp/ftp_directory_listing_buffer.cc b/net/ftp/ftp_directory_listing_buffer.cc index 8e3ee39..e41cb9e 100644 --- a/net/ftp/ftp_directory_listing_buffer.cc +++ b/net/ftp/ftp_directory_listing_buffer.cc @@ -67,6 +67,9 @@ int FtpDirectoryListingBuffer::ProcessRemainingData() { if (rv != OK) return rv; + if (!buffer_.empty()) + return ERR_INVALID_RESPONSE; + return ParseLines(); } @@ -79,6 +82,10 @@ FtpDirectoryListingEntry FtpDirectoryListingBuffer::PopEntry() { return current_parser_->PopEntry(); } +FtpServerType FtpDirectoryListingBuffer::GetServerType() const { + return (current_parser_ ? current_parser_->GetServerType() : SERVER_UNKNOWN); +} + bool FtpDirectoryListingBuffer::ConvertToDetectedEncoding( const std::string& from, string16* to) { std::string encoding(encoding_.empty() ? "ascii" : encoding_); diff --git a/net/ftp/ftp_directory_listing_buffer.h b/net/ftp/ftp_directory_listing_buffer.h index eaa237e..9489135 100644 --- a/net/ftp/ftp_directory_listing_buffer.h +++ b/net/ftp/ftp_directory_listing_buffer.h @@ -12,16 +12,17 @@ #include "base/basictypes.h" #include "base/string16.h" #include "base/time.h" +#include "net/ftp/ftp_server_type_histograms.h" namespace net { - + struct FtpDirectoryListingEntry; class FtpDirectoryListingParser; - + class FtpDirectoryListingBuffer { public: FtpDirectoryListingBuffer(); - + ~FtpDirectoryListingBuffer(); // Called when data is received from the data socket. Returns network @@ -38,9 +39,13 @@ class FtpDirectoryListingBuffer { // unless EntryAvailable returns true. FtpDirectoryListingEntry PopEntry(); + // Returns recognized server type. It is valid to call this function at any + // time, although it will return SERVER_UNKNOWN if it doesn't know the answer. + FtpServerType GetServerType() const; + 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); @@ -60,11 +65,11 @@ class FtpDirectoryListingBuffer { // 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_; diff --git a/net/ftp/ftp_directory_listing_parsers.h b/net/ftp/ftp_directory_listing_parsers.h index 62a23cf..6906861 100644 --- a/net/ftp/ftp_directory_listing_parsers.h +++ b/net/ftp/ftp_directory_listing_parsers.h @@ -33,6 +33,8 @@ class FtpDirectoryListingParser { public: virtual ~FtpDirectoryListingParser(); + virtual FtpServerType GetServerType() const = 0; + // Adds |line| to the internal parsing buffer. Returns true on success. virtual bool ConsumeLine(const string16& line) = 0; @@ -50,6 +52,7 @@ class FtpLsDirectoryListingParser : public FtpDirectoryListingParser { FtpLsDirectoryListingParser(); // FtpDirectoryListingParser methods: + virtual FtpServerType GetServerType() const { return SERVER_LSL; } virtual bool ConsumeLine(const string16& line); virtual bool EntryAvailable() const; virtual FtpDirectoryListingEntry PopEntry(); @@ -67,6 +70,7 @@ class FtpWindowsDirectoryListingParser : public FtpDirectoryListingParser { FtpWindowsDirectoryListingParser(); // FtpDirectoryListingParser methods: + virtual FtpServerType GetServerType() const { return SERVER_DOS; } virtual bool ConsumeLine(const string16& line); virtual bool EntryAvailable() const; virtual FtpDirectoryListingEntry PopEntry(); @@ -83,6 +87,7 @@ class FtpVmsDirectoryListingParser : public FtpDirectoryListingParser { FtpVmsDirectoryListingParser(); // FtpDirectoryListingParser methods: + virtual FtpServerType GetServerType() const { return SERVER_VMS; } virtual bool ConsumeLine(const string16& line); virtual bool EntryAvailable() const; virtual FtpDirectoryListingEntry PopEntry(); |