| 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 #include "net/ftp/ftp_ctrl_response_buffer.h" | 5 #include "net/ftp/ftp_ctrl_response_buffer.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 | 10 |
| 11 namespace { | |
| 12 | |
| 13 // TODO(phajdan.jr): Remove when http://crbug.com/18036 is diagnosed. | |
| 14 void LogResponse(const net::FtpCtrlResponse& response) { | |
| 15 DLOG(INFO) << "received response with code " << response.status_code; | |
| 16 for (std::vector<std::string>::const_iterator i = response.lines.begin(); | |
| 17 i != response.lines.end(); ++i) { | |
| 18 DLOG(INFO) << "line [" << *i << "]"; | |
| 19 } | |
| 20 } | |
| 21 | |
| 22 } // namespace | |
| 23 | |
| 24 namespace net { | 11 namespace net { |
| 25 | 12 |
| 26 // static | 13 // static |
| 27 const int FtpCtrlResponse::kInvalidStatusCode = -1; | 14 const int FtpCtrlResponse::kInvalidStatusCode = -1; |
| 28 | 15 |
| 29 int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) { | 16 int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) { |
| 30 buffer_.append(std::string(data, data_length)); | 17 buffer_.append(std::string(data, data_length)); |
| 31 ExtractFullLinesFromBuffer(); | 18 ExtractFullLinesFromBuffer(); |
| 32 | 19 |
| 33 while (!lines_.empty()) { | 20 while (!lines_.empty()) { |
| 34 ParsedLine line = lines_.front(); | 21 ParsedLine line = lines_.front(); |
| 35 lines_.pop(); | 22 lines_.pop(); |
| 36 | 23 |
| 37 if (line_buf_.empty()) { | 24 if (line_buf_.empty()) { |
| 38 if (!line.is_complete) | 25 if (!line.is_complete) |
| 39 return ERR_INVALID_RESPONSE; | 26 return ERR_INVALID_RESPONSE; |
| 40 | 27 |
| 41 if (line.is_multiline) { | 28 if (line.is_multiline) { |
| 42 line_buf_ = line.status_text; | 29 line_buf_ = line.status_text; |
| 43 response_buf_.status_code = line.status_code; | 30 response_buf_.status_code = line.status_code; |
| 44 } else { | 31 } else { |
| 45 response_buf_.status_code = line.status_code; | 32 response_buf_.status_code = line.status_code; |
| 46 response_buf_.lines.push_back(line.status_text); | 33 response_buf_.lines.push_back(line.status_text); |
| 47 LogResponse(response_buf_); | |
| 48 responses_.push(response_buf_); | 34 responses_.push(response_buf_); |
| 49 | 35 |
| 50 // Prepare to handle following lines. | 36 // Prepare to handle following lines. |
| 51 response_buf_ = FtpCtrlResponse(); | 37 response_buf_ = FtpCtrlResponse(); |
| 52 line_buf_.clear(); | 38 line_buf_.clear(); |
| 53 } | 39 } |
| 54 } else { | 40 } else { |
| 55 if (!line.is_complete || line.status_code != response_buf_.status_code) { | 41 if (!line.is_complete || line.status_code != response_buf_.status_code) { |
| 56 line_buf_.append(line.raw_text); | 42 line_buf_.append(line.raw_text); |
| 57 continue; | 43 continue; |
| 58 } | 44 } |
| 59 | 45 |
| 60 response_buf_.lines.push_back(line_buf_); | 46 response_buf_.lines.push_back(line_buf_); |
| 61 | 47 |
| 62 line_buf_ = line.status_text; | 48 line_buf_ = line.status_text; |
| 63 DCHECK_EQ(line.status_code, response_buf_.status_code); | 49 DCHECK_EQ(line.status_code, response_buf_.status_code); |
| 64 | 50 |
| 65 if (!line.is_multiline) { | 51 if (!line.is_multiline) { |
| 66 response_buf_.lines.push_back(line_buf_); | 52 response_buf_.lines.push_back(line_buf_); |
| 67 LogResponse(response_buf_); | |
| 68 responses_.push(response_buf_); | 53 responses_.push(response_buf_); |
| 69 | 54 |
| 70 // Prepare to handle following lines. | 55 // Prepare to handle following lines. |
| 71 response_buf_ = FtpCtrlResponse(); | 56 response_buf_ = FtpCtrlResponse(); |
| 72 line_buf_.clear(); | 57 line_buf_.clear(); |
| 73 } | 58 } |
| 74 } | 59 } |
| 75 } | 60 } |
| 76 | 61 |
| 77 return OK; | 62 return OK; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { | 98 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { |
| 114 lines_.push(ParseLine(line_buf.substr(0, line_buf.length() - 2))); | 99 lines_.push(ParseLine(line_buf.substr(0, line_buf.length() - 2))); |
| 115 cut_pos = i + 1; | 100 cut_pos = i + 1; |
| 116 line_buf.clear(); | 101 line_buf.clear(); |
| 117 } | 102 } |
| 118 } | 103 } |
| 119 buffer_.erase(0, cut_pos); | 104 buffer_.erase(0, cut_pos); |
| 120 } | 105 } |
| 121 | 106 |
| 122 } // namespace net | 107 } // namespace net |
| OLD | NEW |