| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 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 | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ | 5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ |
| 6 #define NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ | 6 #define NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/string16.h" | 13 #include "base/string16.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "net/ftp/ftp_server_type_histograms.h" |
| 15 | 16 |
| 16 namespace net { | 17 namespace net { |
| 17 | 18 |
| 18 struct FtpDirectoryListingEntry; | 19 struct FtpDirectoryListingEntry; |
| 19 class FtpDirectoryListingParser; | 20 class FtpDirectoryListingParser; |
| 20 | 21 |
| 21 class FtpDirectoryListingBuffer { | 22 class FtpDirectoryListingBuffer { |
| 22 public: | 23 public: |
| 23 FtpDirectoryListingBuffer(); | 24 FtpDirectoryListingBuffer(); |
| 24 | 25 |
| 25 ~FtpDirectoryListingBuffer(); | 26 ~FtpDirectoryListingBuffer(); |
| 26 | 27 |
| 27 // Called when data is received from the data socket. Returns network | 28 // Called when data is received from the data socket. Returns network |
| 28 // error code. | 29 // error code. |
| 29 int ConsumeData(const char* data, int data_length); | 30 int ConsumeData(const char* data, int data_length); |
| 30 | 31 |
| 31 // Called when all received data has been consumed by this buffer. Tells the | 32 // Called when all received data has been consumed by this buffer. Tells the |
| 32 // buffer to try to parse remaining raw data and returns network error code. | 33 // buffer to try to parse remaining raw data and returns network error code. |
| 33 int ProcessRemainingData(); | 34 int ProcessRemainingData(); |
| 34 | 35 |
| 35 bool EntryAvailable() const; | 36 bool EntryAvailable() const; |
| 36 | 37 |
| 37 // Returns the next entry. It is an error to call this function | 38 // Returns the next entry. It is an error to call this function |
| 38 // unless EntryAvailable returns true. | 39 // unless EntryAvailable returns true. |
| 39 FtpDirectoryListingEntry PopEntry(); | 40 FtpDirectoryListingEntry PopEntry(); |
| 40 | 41 |
| 42 // Returns recognized server type. It is valid to call this function at any |
| 43 // time, although it will return SERVER_UNKNOWN if it doesn't know the answer. |
| 44 FtpServerType GetServerType() const; |
| 45 |
| 41 private: | 46 private: |
| 42 typedef std::set<FtpDirectoryListingParser*> ParserSet; | 47 typedef std::set<FtpDirectoryListingParser*> ParserSet; |
| 43 | 48 |
| 44 // Converts the string |from| to detected encoding and stores it in |to|. | 49 // Converts the string |from| to detected encoding and stores it in |to|. |
| 45 // Returns true on success. | 50 // Returns true on success. |
| 46 bool ConvertToDetectedEncoding(const std::string& from, string16* to); | 51 bool ConvertToDetectedEncoding(const std::string& from, string16* to); |
| 47 | 52 |
| 48 // Tries to extract full lines from the raw buffer, converting them to the | 53 // Tries to extract full lines from the raw buffer, converting them to the |
| 49 // detected encoding. Returns network error code. | 54 // detected encoding. Returns network error code. |
| 50 int ExtractFullLinesFromBuffer(); | 55 int ExtractFullLinesFromBuffer(); |
| 51 | 56 |
| 52 // Tries to parse full lines stored in |lines_|. Returns network error code. | 57 // Tries to parse full lines stored in |lines_|. Returns network error code. |
| 53 int ParseLines(); | 58 int ParseLines(); |
| 54 | 59 |
| 55 // Detected encoding of the response (empty if unknown or ASCII). | 60 // Detected encoding of the response (empty if unknown or ASCII). |
| 56 std::string encoding_; | 61 std::string encoding_; |
| 57 | 62 |
| 58 // Buffer to keep not-yet-split data. | 63 // Buffer to keep not-yet-split data. |
| 59 std::string buffer_; | 64 std::string buffer_; |
| 60 | 65 |
| 61 // CRLF-delimited lines, without the CRLF, not yet consumed by parser. | 66 // CRLF-delimited lines, without the CRLF, not yet consumed by parser. |
| 62 std::deque<string16> lines_; | 67 std::deque<string16> lines_; |
| 63 | 68 |
| 64 // A collection of parsers for different listing styles. The parsers are owned | 69 // A collection of parsers for different listing styles. The parsers are owned |
| 65 // by this FtpDirectoryListingBuffer. | 70 // by this FtpDirectoryListingBuffer. |
| 66 ParserSet parsers_; | 71 ParserSet parsers_; |
| 67 | 72 |
| 68 // When we're sure about the listing format, its parser is stored in | 73 // When we're sure about the listing format, its parser is stored in |
| 69 // |current_parser_|. | 74 // |current_parser_|. |
| 70 FtpDirectoryListingParser* current_parser_; | 75 FtpDirectoryListingParser* current_parser_; |
| 71 | 76 |
| 72 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingBuffer); | 77 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingBuffer); |
| 73 }; | 78 }; |
| 74 | 79 |
| 75 } // namespace net | 80 } // namespace net |
| 76 | 81 |
| 77 #endif // NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ | 82 #endif // NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ |
| OLD | NEW |