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 "base/bind.h" |
7 #include "base/logging.h" | 8 #include "base/logging.h" |
8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
9 #include "base/string_piece.h" | 10 #include "base/string_piece.h" |
10 //#include "base/string_util.h" | 11 #include "base/values.h" |
11 #include "net/base/net_errors.h" | 12 #include "net/base/net_errors.h" |
12 | 13 |
13 namespace net { | 14 namespace net { |
14 | 15 |
15 // static | 16 // static |
16 const int FtpCtrlResponse::kInvalidStatusCode = -1; | 17 const int FtpCtrlResponse::kInvalidStatusCode = -1; |
17 | 18 |
18 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} | 19 FtpCtrlResponse::FtpCtrlResponse() : status_code(kInvalidStatusCode) {} |
19 | 20 |
20 FtpCtrlResponse::~FtpCtrlResponse() {} | 21 FtpCtrlResponse::~FtpCtrlResponse() {} |
21 | 22 |
22 FtpCtrlResponseBuffer::FtpCtrlResponseBuffer() : multiline_(false) {} | 23 FtpCtrlResponseBuffer::FtpCtrlResponseBuffer(const BoundNetLog& net_log) |
| 24 : multiline_(false), |
| 25 net_log_(net_log) { |
| 26 } |
23 | 27 |
24 FtpCtrlResponseBuffer::~FtpCtrlResponseBuffer() {} | 28 FtpCtrlResponseBuffer::~FtpCtrlResponseBuffer() {} |
25 | 29 |
26 int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) { | 30 int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) { |
27 buffer_.append(data, data_length); | 31 buffer_.append(data, data_length); |
28 ExtractFullLinesFromBuffer(); | 32 ExtractFullLinesFromBuffer(); |
29 | 33 |
30 while (!lines_.empty()) { | 34 while (!lines_.empty()) { |
31 ParsedLine line = lines_.front(); | 35 ParsedLine line = lines_.front(); |
32 lines_.pop(); | 36 lines_.pop(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 // Prepare to handle following lines. | 70 // Prepare to handle following lines. |
67 response_buf_ = FtpCtrlResponse(); | 71 response_buf_ = FtpCtrlResponse(); |
68 line_buf_.clear(); | 72 line_buf_.clear(); |
69 } | 73 } |
70 } | 74 } |
71 } | 75 } |
72 | 76 |
73 return OK; | 77 return OK; |
74 } | 78 } |
75 | 79 |
| 80 namespace { |
| 81 |
| 82 Value* NetLogFtpCtrlResponseCallback(const FtpCtrlResponse* response, |
| 83 NetLog::LogLevel log_level) { |
| 84 ListValue* lines = new ListValue(); |
| 85 lines->AppendStrings(response->lines); |
| 86 |
| 87 DictionaryValue* dict = new DictionaryValue(); |
| 88 dict->SetInteger("status_code", response->status_code); |
| 89 dict->Set("lines", lines); |
| 90 return dict; |
| 91 } |
| 92 |
| 93 } // namespace |
| 94 |
76 FtpCtrlResponse FtpCtrlResponseBuffer::PopResponse() { | 95 FtpCtrlResponse FtpCtrlResponseBuffer::PopResponse() { |
77 FtpCtrlResponse result = responses_.front(); | 96 FtpCtrlResponse result = responses_.front(); |
78 responses_.pop(); | 97 responses_.pop(); |
| 98 |
| 99 net_log_.AddEvent(NetLog::TYPE_FTP_CONTROL_RESPONSE, |
| 100 base::Bind(&NetLogFtpCtrlResponseCallback, &result)); |
| 101 |
79 return result; | 102 return result; |
80 } | 103 } |
81 | 104 |
82 FtpCtrlResponseBuffer::ParsedLine::ParsedLine() | 105 FtpCtrlResponseBuffer::ParsedLine::ParsedLine() |
83 : has_status_code(false), | 106 : has_status_code(false), |
84 is_multiline(false), | 107 is_multiline(false), |
85 is_complete(false), | 108 is_complete(false), |
86 status_code(FtpCtrlResponse::kInvalidStatusCode) { | 109 status_code(FtpCtrlResponse::kInvalidStatusCode) { |
87 } | 110 } |
88 | 111 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 for (size_t i = 0; i < buffer_.length(); i++) { | 143 for (size_t i = 0; i < buffer_.length(); i++) { |
121 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { | 144 if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') { |
122 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); | 145 lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1))); |
123 cut_pos = i + 1; | 146 cut_pos = i + 1; |
124 } | 147 } |
125 } | 148 } |
126 buffer_.erase(0, cut_pos); | 149 buffer_.erase(0, cut_pos); |
127 } | 150 } |
128 | 151 |
129 } // namespace net | 152 } // namespace net |
OLD | NEW |