| 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" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 class FtpDirectoryListingParser { | 32 class FtpDirectoryListingParser { |
| 33 public: | 33 public: |
| 34 virtual ~FtpDirectoryListingParser(); | 34 virtual ~FtpDirectoryListingParser(); |
| 35 | 35 |
| 36 virtual FtpServerType GetServerType() const = 0; | 36 virtual FtpServerType GetServerType() const = 0; |
| 37 | 37 |
| 38 // Adds |line| to the internal parsing buffer. Returns true on success. | 38 // Adds |line| to the internal parsing buffer. Returns true on success. |
| 39 virtual bool ConsumeLine(const string16& line) = 0; | 39 virtual bool ConsumeLine(const string16& line) = 0; |
| 40 | 40 |
| 41 // Called after all input has been consumed. Returns true if the parser |
| 42 // recognizes all received data as a valid listing. |
| 43 virtual bool OnEndOfInput() = 0; |
| 44 |
| 41 // Returns true if there is at least one FtpDirectoryListingEntry available. | 45 // Returns true if there is at least one FtpDirectoryListingEntry available. |
| 42 virtual bool EntryAvailable() const = 0; | 46 virtual bool EntryAvailable() const = 0; |
| 43 | 47 |
| 44 // Returns the next entry. It is an error to call this function unless | 48 // Returns the next entry. It is an error to call this function unless |
| 45 // EntryAvailable returns true. | 49 // EntryAvailable returns true. |
| 46 virtual FtpDirectoryListingEntry PopEntry() = 0; | 50 virtual FtpDirectoryListingEntry PopEntry() = 0; |
| 47 }; | 51 }; |
| 48 | 52 |
| 49 // Parser for "ls -l"-style directory listing. | 53 // Parser for "ls -l"-style directory listing. |
| 50 class FtpLsDirectoryListingParser : public FtpDirectoryListingParser { | 54 class FtpLsDirectoryListingParser : public FtpDirectoryListingParser { |
| 51 public: | 55 public: |
| 52 FtpLsDirectoryListingParser(); | 56 FtpLsDirectoryListingParser(); |
| 53 | 57 |
| 54 // FtpDirectoryListingParser methods: | 58 // FtpDirectoryListingParser methods: |
| 55 virtual FtpServerType GetServerType() const { return SERVER_LS; } | 59 virtual FtpServerType GetServerType() const { return SERVER_LS; } |
| 56 virtual bool ConsumeLine(const string16& line); | 60 virtual bool ConsumeLine(const string16& line); |
| 61 virtual bool OnEndOfInput(); |
| 57 virtual bool EntryAvailable() const; | 62 virtual bool EntryAvailable() const; |
| 58 virtual FtpDirectoryListingEntry PopEntry(); | 63 virtual FtpDirectoryListingEntry PopEntry(); |
| 59 | 64 |
| 60 private: | 65 private: |
| 61 bool received_nonempty_line_; | 66 bool received_nonempty_line_; |
| 62 | 67 |
| 63 std::queue<FtpDirectoryListingEntry> entries_; | 68 std::queue<FtpDirectoryListingEntry> entries_; |
| 64 | 69 |
| 65 DISALLOW_COPY_AND_ASSIGN(FtpLsDirectoryListingParser); | 70 DISALLOW_COPY_AND_ASSIGN(FtpLsDirectoryListingParser); |
| 66 }; | 71 }; |
| 67 | 72 |
| 68 class FtpWindowsDirectoryListingParser : public FtpDirectoryListingParser { | 73 class FtpWindowsDirectoryListingParser : public FtpDirectoryListingParser { |
| 69 public: | 74 public: |
| 70 FtpWindowsDirectoryListingParser(); | 75 FtpWindowsDirectoryListingParser(); |
| 71 | 76 |
| 72 // FtpDirectoryListingParser methods: | 77 // FtpDirectoryListingParser methods: |
| 73 virtual FtpServerType GetServerType() const { return SERVER_WINDOWS; } | 78 virtual FtpServerType GetServerType() const { return SERVER_WINDOWS; } |
| 74 virtual bool ConsumeLine(const string16& line); | 79 virtual bool ConsumeLine(const string16& line); |
| 80 virtual bool OnEndOfInput(); |
| 75 virtual bool EntryAvailable() const; | 81 virtual bool EntryAvailable() const; |
| 76 virtual FtpDirectoryListingEntry PopEntry(); | 82 virtual FtpDirectoryListingEntry PopEntry(); |
| 77 | 83 |
| 78 private: | 84 private: |
| 79 std::queue<FtpDirectoryListingEntry> entries_; | 85 std::queue<FtpDirectoryListingEntry> entries_; |
| 80 | 86 |
| 81 DISALLOW_COPY_AND_ASSIGN(FtpWindowsDirectoryListingParser); | 87 DISALLOW_COPY_AND_ASSIGN(FtpWindowsDirectoryListingParser); |
| 82 }; | 88 }; |
| 83 | 89 |
| 84 // Parser for VMS-style directory listing (including variants). | 90 // Parser for VMS-style directory listing (including variants). |
| 85 class FtpVmsDirectoryListingParser : public FtpDirectoryListingParser { | 91 class FtpVmsDirectoryListingParser : public FtpDirectoryListingParser { |
| 86 public: | 92 public: |
| 87 FtpVmsDirectoryListingParser(); | 93 FtpVmsDirectoryListingParser(); |
| 88 | 94 |
| 89 // FtpDirectoryListingParser methods: | 95 // FtpDirectoryListingParser methods: |
| 90 virtual FtpServerType GetServerType() const { return SERVER_VMS; } | 96 virtual FtpServerType GetServerType() const { return SERVER_VMS; } |
| 91 virtual bool ConsumeLine(const string16& line); | 97 virtual bool ConsumeLine(const string16& line); |
| 98 virtual bool OnEndOfInput(); |
| 92 virtual bool EntryAvailable() const; | 99 virtual bool EntryAvailable() const; |
| 93 virtual FtpDirectoryListingEntry PopEntry(); | 100 virtual FtpDirectoryListingEntry PopEntry(); |
| 94 | 101 |
| 95 private: | 102 private: |
| 96 // Consumes listing line which is expected to be a directory listing entry | 103 // Consumes listing line which is expected to be a directory listing entry |
| 97 // (and not a comment etc). Returns true on success. | 104 // (and not a comment etc). Returns true on success. |
| 98 bool ConsumeEntryLine(const string16& line); | 105 bool ConsumeEntryLine(const string16& line); |
| 99 | 106 |
| 100 enum State { | 107 enum State { |
| 101 STATE_INITIAL, | 108 STATE_INITIAL, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 122 bool last_is_directory_; | 129 bool last_is_directory_; |
| 123 | 130 |
| 124 std::queue<FtpDirectoryListingEntry> entries_; | 131 std::queue<FtpDirectoryListingEntry> entries_; |
| 125 | 132 |
| 126 DISALLOW_COPY_AND_ASSIGN(FtpVmsDirectoryListingParser); | 133 DISALLOW_COPY_AND_ASSIGN(FtpVmsDirectoryListingParser); |
| 127 }; | 134 }; |
| 128 | 135 |
| 129 } // namespace net | 136 } // namespace net |
| 130 | 137 |
| 131 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ | 138 #endif // NET_FTP_FTP_DIRECTORY_LISTING_PARSERS_H_ |
| OLD | NEW |