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