Chromium Code Reviews| 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_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "base/string_piece.h" | |
| 9 //#include "base/string_util.h" | 10 //#include "base/string_util.h" |
| 10 #include "net/base/net_errors.h" | 11 #include "net/base/net_errors.h" |
| 11 | 12 |
| 13 using base::StringPiece; | |
| 14 | |
| 12 namespace net { | 15 namespace net { |
| 13 | 16 |
| 14 // static | 17 // static |
| 15 const int FtpCtrlResponse::kInvalidStatusCode = -1; | 18 const int FtpCtrlResponse::kInvalidStatusCode = -1; |
| 16 | 19 |
| 17 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} | 20 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} |
| 18 | 21 |
| 19 FtpCtrlResponse::~FtpCtrlResponse() {} | 22 FtpCtrlResponse::~FtpCtrlResponse() {} |
| 20 | 23 |
| 21 FtpCtrlResponseBuffer::FtpCtrlResponseBuffer() : multiline_(false) {} | 24 FtpCtrlResponseBuffer::FtpCtrlResponseBuffer() : multiline_(false) {} |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 is_complete(false), | 87 is_complete(false), |
| 85 status_code(FtpCtrlResponse::kInvalidStatusCode) { | 88 status_code(FtpCtrlResponse::kInvalidStatusCode) { |
| 86 } | 89 } |
| 87 | 90 |
| 88 // static | 91 // static |
| 89 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( | 92 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( |
| 90 const std::string& line) { | 93 const std::string& line) { |
| 91 ParsedLine result; | 94 ParsedLine result; |
| 92 | 95 |
| 93 if (line.length() >= 3) { | 96 if (line.length() >= 3) { |
| 94 if (base::StringToInt(line.begin(), line.begin() + 3, &result.status_code)) | 97 if (base::StringToInt(StringPiece(line.begin(), line.begin() + 3), |
|
cbentzel
2011/12/14 16:54:09
What would happen if you just passed in 3 here? Wo
| |
| 98 &result.status_code)) | |
| 95 result.has_status_code = (100 <= result.status_code && | 99 result.has_status_code = (100 <= result.status_code && |
| 96 result.status_code <= 599); | 100 result.status_code <= 599); |
| 97 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { | 101 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { |
| 98 result.is_complete = true; | 102 result.is_complete = true; |
| 99 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { | 103 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { |
| 100 result.is_complete = true; | 104 result.is_complete = true; |
| 101 result.is_multiline = true; | 105 result.is_multiline = true; |
| 102 } | 106 } |
| 103 } | 107 } |
| 104 | 108 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 118 for (size_t i = 0; i < buffer_.length(); i++) { | 122 for (size_t i = 0; i < buffer_.length(); i++) { |
| 119 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { | 123 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { |
| 120 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); | 124 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); |
| 121 cut_pos = i + 1; | 125 cut_pos = i + 1; |
| 122 } | 126 } |
| 123 } | 127 } |
| 124 buffer_.erase(0, cut_pos); | 128 buffer_.erase(0, cut_pos); |
| 125 } | 129 } |
| 126 | 130 |
| 127 } // namespace net | 131 } // namespace net |
| OLD | NEW |