| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "net/ftp/ftp_ctrl_response_buffer.h" | 5 #include "net/ftp/ftp_ctrl_response_buffer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "net/base/parse_number.h" |
| 12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 // static | 18 // static |
| 19 const int FtpCtrlResponse::kInvalidStatusCode = -1; | 19 const int FtpCtrlResponse::kInvalidStatusCode = -1; |
| 20 | 20 |
| 21 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} | 21 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 116 |
| 117 FtpCtrlResponseBuffer::ParsedLine::ParsedLine(const ParsedLine& other) = | 117 FtpCtrlResponseBuffer::ParsedLine::ParsedLine(const ParsedLine& other) = |
| 118 default; | 118 default; |
| 119 | 119 |
| 120 // static | 120 // static |
| 121 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( | 121 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( |
| 122 const std::string& line) { | 122 const std::string& line) { |
| 123 ParsedLine result; | 123 ParsedLine result; |
| 124 | 124 |
| 125 if (line.length() >= 3) { | 125 if (line.length() >= 3) { |
| 126 if (base::StringToInt(base::StringPiece(line.begin(), line.begin() + 3), | 126 if (ParseInt32(base::StringPiece(line.begin(), line.begin() + 3), |
| 127 &result.status_code)) | 127 ParseIntFormat::NON_NEGATIVE, &result.status_code)) { |
| 128 result.has_status_code = (100 <= result.status_code && | 128 result.has_status_code = |
| 129 result.status_code <= 599); | 129 (100 <= result.status_code && result.status_code <= 599); |
| 130 } |
| 130 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { | 131 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { |
| 131 result.is_complete = true; | 132 result.is_complete = true; |
| 132 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { | 133 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { |
| 133 result.is_complete = true; | 134 result.is_complete = true; |
| 134 result.is_multiline = true; | 135 result.is_multiline = true; |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 | 138 |
| 138 if (result.is_complete) { | 139 if (result.is_complete) { |
| 139 result.status_text = line.substr(4); | 140 result.status_text = line.substr(4); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 151 for (size_t i = 0; i < buffer_.length(); i++) { | 152 for (size_t i = 0; i < buffer_.length(); i++) { |
| 152 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { | 153 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { |
| 153 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); | 154 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); |
| 154 cut_pos = i + 1; | 155 cut_pos = i + 1; |
| 155 } | 156 } |
| 156 } | 157 } |
| 157 buffer_.erase(0, cut_pos); | 158 buffer_.erase(0, cut_pos); |
| 158 } | 159 } |
| 159 | 160 |
| 160 } // namespace net | 161 } // namespace net |
| OLD | NEW |