OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // source code is governed by a BSD-style license that can be found in the |
3 // found in the 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" | |
10 //#include "base/string_util.h" | 9 //#include "base/string_util.h" |
11 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
12 | 11 |
13 namespace net { | 12 namespace net { |
14 | 13 |
15 // static | 14 // static |
16 const int FtpCtrlResponse::kInvalidStatusCode = -1; | 15 const int FtpCtrlResponse::kInvalidStatusCode = -1; |
17 | 16 |
18 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} | 17 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} |
19 | 18 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 is_complete(false), | 84 is_complete(false), |
86 status_code(FtpCtrlResponse::kInvalidStatusCode) { | 85 status_code(FtpCtrlResponse::kInvalidStatusCode) { |
87 } | 86 } |
88 | 87 |
89 // static | 88 // static |
90 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( | 89 FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine( |
91 const std::string& line) { | 90 const std::string& line) { |
92 ParsedLine result; | 91 ParsedLine result; |
93 | 92 |
94 if (line.length() >= 3) { | 93 if (line.length() >= 3) { |
95 if (base::StringToInt(base::StringPiece(line.begin(), line.begin() + 3), | 94 if (base::StringToInt(line.begin(), line.begin() + 3, &result.status_code)) |
96 &result.status_code)) | |
97 result.has_status_code = (100 <= result.status_code && | 95 result.has_status_code = (100 <= result.status_code && |
98 result.status_code <= 599); | 96 result.status_code <= 599); |
99 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { | 97 if (result.has_status_code && line.length() >= 4 && line[3] == ' ') { |
100 result.is_complete = true; | 98 result.is_complete = true; |
101 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { | 99 } else if (result.has_status_code && line.length() >= 4 && line[3] == '-') { |
102 result.is_complete = true; | 100 result.is_complete = true; |
103 result.is_multiline = true; | 101 result.is_multiline = true; |
104 } | 102 } |
105 } | 103 } |
106 | 104 |
(...skipping 13 matching lines...) Expand all Loading... |
120 for (size_t i = 0; i < buffer_.length(); i++) { | 118 for (size_t i = 0; i < buffer_.length(); i++) { |
121 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { | 119 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { |
122 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); | 120 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); |
123 cut_pos = i + 1; | 121 cut_pos = i + 1; |
124 } | 122 } |
125 } | 123 } |
126 buffer_.erase(0, cut_pos); | 124 buffer_.erase(0, cut_pos); |
127 } | 125 } |
128 | 126 |
129 } // namespace net | 127 } // namespace net |
OLD | NEW |