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

Side by Side Diff: net/ftp/ftp_directory_listing_buffer.h

Issue 6670085: FTP: Detect the character encoding only after the entire listing is received. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: test coverage Created 9 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/ftp/ftp_directory_listing_buffer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_
6 #define NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_
7 #pragma once
8
9 #include <deque>
10 #include <set>
11 #include <string>
12
13 #include "base/basictypes.h"
14 #include "base/string16.h"
15 #include "base/time.h"
16 #include "net/ftp/ftp_server_type_histograms.h"
17
18 namespace net {
19
20 struct FtpDirectoryListingEntry;
21 class FtpDirectoryListingParser;
22
23 class FtpDirectoryListingBuffer {
24 public:
25 // Constructor. When the current time is needed to guess the year on partial
26 // date strings, |current_time| will be used. This allows passing a specific
27 // date during testing.
28 explicit FtpDirectoryListingBuffer(const base::Time& current_time);
29 ~FtpDirectoryListingBuffer();
30
31 // Called when data is received from the data socket. Returns network
32 // error code.
33 int ConsumeData(const char* data, int data_length);
34
35 // Called when all received data has been consumed by this buffer. Tells the
36 // buffer to try to parse remaining raw data and returns network error code.
37 int ProcessRemainingData();
38
39 bool EntryAvailable() const;
40
41 // Returns the next entry. It is an error to call this function
42 // unless EntryAvailable returns true.
43 FtpDirectoryListingEntry PopEntry();
44
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.
47 FtpServerType GetServerType() const;
48
49 const std::string& encoding() const { return encoding_; }
50
51 private:
52 typedef std::set<FtpDirectoryListingParser*> ParserSet;
53
54 // Decodes the raw buffer using specified |encoding|. On success
55 // clears the raw buffer and appends data to |converted_buffer_|.
56 // Returns network error code.
57 int DecodeBufferUsingEncoding(const std::string& encoding);
58
59 // Converts the raw buffer to UTF-16. Returns network error code.
60 int ConvertBufferToUTF16();
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();
68
69 // Tries to parse full lines stored in |lines_|. Returns network error code.
70 int ParseLines();
71
72 // Called when we received the entire input. Propagates that info to remaining
73 // parsers. Returns network error code.
74 int OnEndOfInput();
75
76 // Detected encoding of the response (empty if unknown).
77 std::string encoding_;
78
79 // Buffer to keep data before character set conversion.
80 std::string buffer_;
81
82 // Buffer to keep data before line splitting.
83 string16 converted_buffer_;
84
85 // CRLF-delimited lines, without the CRLF, not yet consumed by parser.
86 std::deque<string16> lines_;
87
88 // A collection of parsers for different listing styles. The parsers are owned
89 // by this FtpDirectoryListingBuffer.
90 ParserSet parsers_;
91
92 // When we're sure about the listing format, its parser is stored in
93 // |current_parser_|.
94 FtpDirectoryListingParser* current_parser_;
95
96 DISALLOW_COPY_AND_ASSIGN(FtpDirectoryListingBuffer);
97 };
98
99 } // namespace net
100
101 #endif // NET_FTP_FTP_DIRECTORY_LISTING_BUFFER_H_
OLDNEW
« no previous file with comments | « no previous file | net/ftp/ftp_directory_listing_buffer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698