| 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_CTRL_RESPONSE_BUFFER_H_ | 5 #ifndef NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ |
| 6 #define NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ | 6 #define NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ |
| 7 | 7 |
| 8 #include <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 | 13 |
| 14 namespace net { | 14 namespace net { |
| 15 | 15 |
| 16 struct FtpCtrlResponse { | 16 struct FtpCtrlResponse { |
| 17 static const int kInvalidStatusCode; | 17 static const int kInvalidStatusCode; |
| 18 | 18 |
| 19 FtpCtrlResponse() : status_code(kInvalidStatusCode) {} | 19 FtpCtrlResponse() : status_code(kInvalidStatusCode) {} |
| 20 | 20 |
| 21 int status_code; // Three-digit status code. | 21 int status_code; // Three-digit status code. |
| 22 std::vector<std::string> lines; // Response lines, without CRLFs. | 22 std::vector<std::string> lines; // Response lines, without CRLFs. |
| 23 }; | 23 }; |
| 24 | 24 |
| 25 class FtpCtrlResponseBuffer { | 25 class FtpCtrlResponseBuffer { |
| 26 public: | 26 public: |
| 27 FtpCtrlResponseBuffer() {} | 27 FtpCtrlResponseBuffer() : multiline_(false) { |
| 28 } |
| 28 | 29 |
| 29 // Called when data is received from the control socket. Returns error code. | 30 // Called when data is received from the control socket. Returns error code. |
| 30 int ConsumeData(const char* data, int data_length); | 31 int ConsumeData(const char* data, int data_length); |
| 31 | 32 |
| 32 bool ResponseAvailable() const { | 33 bool ResponseAvailable() const { |
| 33 return !responses_.empty(); | 34 return !responses_.empty(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 // Returns the next response. It is an error to call this function | 37 // Returns the next response. It is an error to call this function |
| 37 // unless ResponseAvailable returns true. | 38 // unless ResponseAvailable returns true. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 75 |
| 75 static ParsedLine ParseLine(const std::string& line); | 76 static ParsedLine ParseLine(const std::string& line); |
| 76 | 77 |
| 77 void ExtractFullLinesFromBuffer(); | 78 void ExtractFullLinesFromBuffer(); |
| 78 | 79 |
| 79 // We keep not-yet-parsed data in a string buffer. | 80 // We keep not-yet-parsed data in a string buffer. |
| 80 std::string buffer_; | 81 std::string buffer_; |
| 81 | 82 |
| 82 std::queue<ParsedLine> lines_; | 83 std::queue<ParsedLine> lines_; |
| 83 | 84 |
| 85 // True if we are in the middle of parsing a multi-line response. |
| 86 bool multiline_; |
| 87 |
| 84 // When parsing a multiline response, we don't know beforehand if a line | 88 // When parsing a multiline response, we don't know beforehand if a line |
| 85 // will have a continuation. So always store last line of multiline response | 89 // will have a continuation. So always store last line of multiline response |
| 86 // so we can append the continuation to it. | 90 // so we can append the continuation to it. |
| 87 std::string line_buf_; | 91 std::string line_buf_; |
| 88 | 92 |
| 89 // Keep the response data while we add all lines to it. | 93 // Keep the response data while we add all lines to it. |
| 90 FtpCtrlResponse response_buf_; | 94 FtpCtrlResponse response_buf_; |
| 91 | 95 |
| 92 // As we read full responses (possibly multiline), we add them to the queue. | 96 // As we read full responses (possibly multiline), we add them to the queue. |
| 93 std::queue<FtpCtrlResponse> responses_; | 97 std::queue<FtpCtrlResponse> responses_; |
| 94 | 98 |
| 95 DISALLOW_COPY_AND_ASSIGN(FtpCtrlResponseBuffer); | 99 DISALLOW_COPY_AND_ASSIGN(FtpCtrlResponseBuffer); |
| 96 }; | 100 }; |
| 97 | 101 |
| 98 } // namespace net | 102 } // namespace net |
| 99 | 103 |
| 100 #endif // NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ | 104 #endif // NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ |
| OLD | NEW |