| 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_PARSERS_H_ | 5 #ifndef NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ |
| 6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ | 6 #define NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "net/ftp/ftp_server_type_histograms.h" | 13 #include "net/ftp/ftp_server_type_histograms.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 struct FtpDirectoryListingEntry { | 17 struct FtpDirectoryListingEntry { |
| 18 enum Type { | 18 enum Type { |
| 19 FILE, | 19 FILE, |
| 20 DIRECTORY, | 20 DIRECTORY, |
| 21 SYMLINK, | 21 SYMLINK, |
| 22 }; | 22 }; |
| 23 | 23 |
| 24 Type type; | 24 Type type; |
| 25 string16 name; | 25 string16 name; |
| 26 int64 size; // File size, in bytes. -1 if not applicable. | 26 int64 size; // File size, in bytes. -1 if not applicable. |
| 27 | 27 |
| 28 // Last modified time, in local time zone. | 28 // Last modified time, in local time zone. |
| 29 base::Time last_modified; | 29 base::Time last_modified; |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 class FtpDirectoryListingParser { | 32 class FtpDirectoryListingParser { |
| 33 public: | 33 public: |
| 34 virtual ~FtpDirectoryListingParser(); | 34 virtual ~FtpDirectoryListingParser(); |
| 35 | 35 |
| 36 // Adds |line| to the internal parsing buffer. Returns true on success. | 36 // Adds |line| to the internal parsing buffer. Returns true on success. |
| 37 virtual bool ConsumeLine(const string16& line) = 0; | 37 virtual bool ConsumeLine(const string16& line) = 0; |
| 38 | 38 |
| 39 // Returns true if there is at least one FtpDirectoryListingEntry available. | 39 // Returns true if there is at least one FtpDirectoryListingEntry available. |
| 40 virtual bool EntryAvailable() const = 0; | 40 virtual bool EntryAvailable() const = 0; |
| 41 | 41 |
| 42 // Returns the next entry. It is an error to call this function unless | 42 // Returns the next entry. It is an error to call this function unless |
| 43 // EntryAvailable returns true. | 43 // EntryAvailable returns true. |
| 44 virtual FtpDirectoryListingEntry PopEntry() = 0; | 44 virtual FtpDirectoryListingEntry PopEntry() = 0; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 // Parser for "ls -l"-style directory listing. |
| 47 class FtpLsDirectoryListingParser : public FtpDirectoryListingParser { | 48 class FtpLsDirectoryListingParser : public FtpDirectoryListingParser { |
| 48 public: | 49 public: |
| 49 FtpLsDirectoryListingParser(); | 50 FtpLsDirectoryListingParser(); |
| 50 | 51 |
| 51 // FtpDirectoryListingParser methods: | 52 // FtpDirectoryListingParser methods: |
| 52 virtual bool ConsumeLine(const string16& line); | 53 virtual bool ConsumeLine(const string16& line); |
| 53 virtual bool EntryAvailable() const; | 54 virtual bool EntryAvailable() const; |
| 54 virtual FtpDirectoryListingEntry PopEntry(); | 55 virtual FtpDirectoryListingEntry PopEntry(); |
| 55 | 56 |
| 56 private: | 57 private: |
| 57 std::queue<FtpDirectoryListingEntry> entries_; | 58 std::queue<FtpDirectoryListingEntry> entries_; |
| 58 | 59 |
| 59 DISALLOW_COPY_AND_ASSIGN(FtpLsDirectoryListingParser); | 60 DISALLOW_COPY_AND_ASSIGN(FtpLsDirectoryListingParser); |
| 60 }; | 61 }; |
| 61 | 62 |
| 63 // Parser for VMS-style directory listing (including variants). |
| 64 class FtpVmsDirectoryListingParser : public FtpDirectoryListingParser { |
| 65 public: |
| 66 FtpVmsDirectoryListingParser(); |
| 67 |
| 68 // FtpDirectoryListingParser methods: |
| 69 virtual bool ConsumeLine(const string16& line); |
| 70 virtual bool EntryAvailable() const; |
| 71 virtual FtpDirectoryListingEntry PopEntry(); |
| 72 |
| 73 private: |
| 74 // Consumes listing line which is expected to be a directory listing entry |
| 75 // (and not a comment etc). Returns true on success. |
| 76 bool ConsumeEntryLine(const string16& line); |
| 77 |
| 78 enum State { |
| 79 STATE_INITIAL, |
| 80 |
| 81 // Indicates that we have received the header, like this: |
| 82 // Directory SYS$SYSDEVICE:[ANONYMOUS] |
| 83 STATE_RECEIVED_HEADER, |
| 84 |
| 85 // Indicates that we have received the first listing entry, like this: |
| 86 // MADGOAT.DIR;1 2 9-MAY-2001 22:23:44.85 |
| 87 STATE_ENTRIES, |
| 88 |
| 89 // Indicates that we have received the last listing entry. |
| 90 STATE_RECEIVED_LAST_ENTRY, |
| 91 |
| 92 // Indicates that we have successfully received all parts of the listing. |
| 93 STATE_END, |
| 94 } state_; |
| 95 |
| 96 // VMS can use two physical lines if the filename is long. The first line will |
| 97 // contain the filename, and the second line everything else. Store the |
| 98 // filename until we receive the next line. |
| 99 string16 last_filename_; |
| 100 bool last_is_directory_; |
| 101 |
| 102 std::queue<FtpDirectoryListingEntry> entries_; |
| 103 |
| 104 DISALLOW_COPY_AND_ASSIGN(FtpVmsDirectoryListingParser); |
| 105 }; |
| 106 |
| 62 } // namespace net | 107 } // namespace net |
| 63 | 108 |
| 64 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ | 109 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ |
| OLD | NEW |