| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <deque> | 9 #include <deque> |
| 10 #include <set> | 10 #include <set> |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 // Returns recognized server type. It is valid to call this function at any | 45 // Returns recognized server type. It is valid to call this function at any |
| 46 // time, although it will return SERVER_UNKNOWN if it doesn't know the answer. | 46 // time, although it will return SERVER_UNKNOWN if it doesn't know the answer. |
| 47 FtpServerType GetServerType() const; | 47 FtpServerType GetServerType() const; |
| 48 | 48 |
| 49 const std::string& encoding() const { return encoding_; } | 49 const std::string& encoding() const { return encoding_; } |
| 50 | 50 |
| 51 private: | 51 private: |
| 52 typedef std::set<FtpDirectoryListingParser*> ParserSet; | 52 typedef std::set<FtpDirectoryListingParser*> ParserSet; |
| 53 | 53 |
| 54 // Converts the string |from| to detected encoding and stores it in |to|. | 54 // Decodes the raw buffer using specified |encoding|. On success |
| 55 // Returns true on success. | 55 // clears the raw buffer and appends data to |converted_buffer_|. |
| 56 bool ConvertToDetectedEncoding(const std::string& from, string16* to); | 56 // Returns network error code. |
| 57 int DecodeBufferUsingEncoding(const std::string& encoding); |
| 57 | 58 |
| 58 // Tries to extract full lines from the raw buffer, converting them to the | 59 // Converts the raw buffer to UTF-16. Returns network error code. |
| 59 // detected encoding. Returns network error code. | 60 int ConvertBufferToUTF16(); |
| 60 int ExtractFullLinesFromBuffer(); | 61 |
| 62 // Extracts lines from the converted buffer, and puts them in |lines_|. |
| 63 void ExtractFullLinesFromBuffer(); |
| 64 |
| 65 // Consumes the raw buffer (i.e. does the character set conversion |
| 66 // and line splitting). Returns network error code. |
| 67 int ConsumeBuffer(); |
| 61 | 68 |
| 62 // Tries to parse full lines stored in |lines_|. Returns network error code. | 69 // Tries to parse full lines stored in |lines_|. Returns network error code. |
| 63 int ParseLines(); | 70 int ParseLines(); |
| 64 | 71 |
| 65 // Called when we received the entire input. Propagates that info to remaining | 72 // Called when we received the entire input. Propagates that info to remaining |
| 66 // parsers. Returns network error code. | 73 // parsers. Returns network error code. |
| 67 int OnEndOfInput(); | 74 int OnEndOfInput(); |
| 68 | 75 |
| 69 // Detected encoding of the response (empty if unknown or ASCII). | 76 // Detected encoding of the response (empty if unknown). |
| 70 std::string encoding_; | 77 std::string encoding_; |
| 71 | 78 |
| 72 // Buffer to keep not-yet-split data. | 79 // Buffer to keep data before character set conversion. |
| 73 std::string buffer_; | 80 std::string buffer_; |
| 74 | 81 |
| 82 // Buffer to keep data before line splitting. |
| 83 string16 converted_buffer_; |
| 84 |
| 75 // CRLF-delimited lines, without the CRLF, not yet consumed by parser. | 85 // CRLF-delimited lines, without the CRLF, not yet consumed by parser. |
| 76 std::deque<string16> lines_; | 86 std::deque<string16> lines_; |
| 77 | 87 |
| 78 // A collection of parsers for different listing styles. The parsers are owned | 88 // A collection of parsers for different listing styles. The parsers are owned |
| 79 // by this FtpDirectoryListingBuffer. | 89 // by this FtpDirectoryListingBuffer. |
| 80 ParserSet parsers_; | 90 ParserSet parsers_; |
| 81 | 91 |
| 82 // When we're sure about the listing format, its parser is stored in | 92 // When we're sure about the listing format, its parser is stored in |
| 83 // |current_parser_|. | 93 // |current_parser_|. |
| 84 FtpDirectoryListingParser* current_parser_; | 94 FtpDirectoryListingParser* current_parser_; |
| 85 | 95 |
| 86 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingBuffer); | 96 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingBuffer); |
| 87 }; | 97 }; |
| 88 | 98 |
| 89 } // namespace net | 99 } // namespace net |
| 90 | 100 |
| 91 #endif // NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ | 101 #endif // NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_ |
| OLD | NEW |