| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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 | 5 |
| 6 #ifndef NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ | 6 #ifndef NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ |
| 7 #define NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ | 7 #define NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ |
| 8 #pragma once | 8 #pragma once |
| 9 | 9 |
| 10 #include <queue> | 10 #include <queue> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 struct FtpCtrlResponse { | 18 struct FtpCtrlResponse { |
| 19 static const int kInvalidStatusCode; | 19 static const int kInvalidStatusCode; |
| 20 | 20 |
| 21 FtpCtrlResponse() : status_code(kInvalidStatusCode) {} | 21 FtpCtrlResponse(); |
| 22 ~FtpCtrlResponse(); |
| 22 | 23 |
| 23 int status_code; // Three-digit status code. | 24 int status_code; // Three-digit status code. |
| 24 std::vector<std::string> lines; // Response lines, without CRLFs. | 25 std::vector<std::string> lines; // Response lines, without CRLFs. |
| 25 }; | 26 }; |
| 26 | 27 |
| 27 class FtpCtrlResponseBuffer { | 28 class FtpCtrlResponseBuffer { |
| 28 public: | 29 public: |
| 29 FtpCtrlResponseBuffer() : multiline_(false) {} | 30 FtpCtrlResponseBuffer(); |
| 31 ~FtpCtrlResponseBuffer(); |
| 30 | 32 |
| 31 // Called when data is received from the control socket. Returns error code. | 33 // Called when data is received from the control socket. Returns error code. |
| 32 int ConsumeData(const char* data, int data_length); | 34 int ConsumeData(const char* data, int data_length); |
| 33 | 35 |
| 34 bool ResponseAvailable() const { | 36 bool ResponseAvailable() const { |
| 35 return !responses_.empty(); | 37 return !responses_.empty(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 // Returns the next response. It is an error to call this function | 40 // Returns the next response. It is an error to call this function |
| 39 // unless ResponseAvailable returns true. | 41 // unless ResponseAvailable returns true. |
| 40 FtpCtrlResponse PopResponse() { | 42 FtpCtrlResponse PopResponse(); |
| 41 FtpCtrlResponse result = responses_.front(); | |
| 42 responses_.pop(); | |
| 43 return result; | |
| 44 } | |
| 45 | 43 |
| 46 private: | 44 private: |
| 47 struct ParsedLine { | 45 struct ParsedLine { |
| 48 ParsedLine() | 46 ParsedLine(); |
| 49 : has_status_code(false), | |
| 50 is_multiline(false), | |
| 51 is_complete(false), | |
| 52 status_code(FtpCtrlResponse::kInvalidStatusCode) { | |
| 53 } | |
| 54 | 47 |
| 55 // Indicates that this line begins with a valid 3-digit status code. | 48 // Indicates that this line begins with a valid 3-digit status code. |
| 56 bool has_status_code; | 49 bool has_status_code; |
| 57 | 50 |
| 58 // Indicates that this line has the dash (-) after the code, which | 51 // Indicates that this line has the dash (-) after the code, which |
| 59 // means a multiline response. | 52 // means a multiline response. |
| 60 bool is_multiline; | 53 bool is_multiline; |
| 61 | 54 |
| 62 // Indicates that this line could be parsed as a complete and valid | 55 // Indicates that this line could be parsed as a complete and valid |
| 63 // response line, without taking into account preceding lines (which | 56 // response line, without taking into account preceding lines (which |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 | 89 |
| 97 // As we read full responses (possibly multiline), we add them to the queue. | 90 // As we read full responses (possibly multiline), we add them to the queue. |
| 98 std::queue<FtpCtrlResponse> responses_; | 91 std::queue<FtpCtrlResponse> responses_; |
| 99 | 92 |
| 100 DISALLOW_COPY_AND_ASSIGN(FtpCtrlResponseBuffer); | 93 DISALLOW_COPY_AND_ASSIGN(FtpCtrlResponseBuffer); |
| 101 }; | 94 }; |
| 102 | 95 |
| 103 } // namespace net | 96 } // namespace net |
| 104 | 97 |
| 105 #endif // NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ | 98 #endif // NET_FTP_FTP_CTRL_RESPONSE_BUFFER_H_ |
| OLD | NEW |