OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_PARSER_H_ | 5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_ |
6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_ | 6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
9 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
10 #include "base/string16.h" | 13 #include "base/string16.h" |
11 #include "base/time.h" | 14 #include "base/time.h" |
12 #include "net/ftp/ftp_server_type_histograms.h" | |
13 | 15 |
14 namespace net { | 16 namespace net { |
15 | 17 |
16 struct FtpDirectoryListingEntry { | 18 struct FtpDirectoryListingEntry { |
17 enum Type { | 19 enum Type { |
18 FILE, | 20 FILE, |
19 DIRECTORY, | 21 DIRECTORY, |
20 SYMLINK, | 22 SYMLINK, |
21 }; | 23 }; |
22 | 24 |
23 Type type; | 25 Type type; |
24 string16 name; | 26 string16 name; // Name (UTF-16-encoded). |
| 27 std::string raw_name; // Name in original character encoding. |
25 int64 size; // File size, in bytes. -1 if not applicable. | 28 int64 size; // File size, in bytes. -1 if not applicable. |
26 | 29 |
27 // Last modified time, in local time zone. | 30 // Last modified time, in local time zone. |
28 base::Time last_modified; | 31 base::Time last_modified; |
29 }; | 32 }; |
30 | 33 |
31 class FtpDirectoryListingParser { | 34 // Parses an FTP directory listing |text|. On success fills in |entries|. |
32 public: | 35 // Returns network error code. |
33 virtual ~FtpDirectoryListingParser(); | 36 int ParseFtpDirectoryListing(const std::string& text, |
34 | 37 const base::Time& current_time, |
35 virtual FtpServerType GetServerType() const = 0; | 38 std::vector<FtpDirectoryListingEntry>* entries); |
36 | |
37 // Adds |line| to the internal parsing buffer. Returns true on success. | |
38 virtual bool ConsumeLine(const string16& line) = 0; | |
39 | |
40 // Called after all input has been consumed. Returns true if the parser | |
41 // recognizes all received data as a valid listing. | |
42 virtual bool OnEndOfInput() = 0; | |
43 | |
44 // Returns true if there is at least one FtpDirectoryListingEntry available. | |
45 virtual bool EntryAvailable() const = 0; | |
46 | |
47 // Returns the next entry. It is an error to call this function unless | |
48 // EntryAvailable returns true. | |
49 virtual FtpDirectoryListingEntry PopEntry() = 0; | |
50 }; | |
51 | 39 |
52 } // namespace net | 40 } // namespace net |
53 | 41 |
54 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_ | 42 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSER_H_ |
OLD | NEW |