summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/ftp/ftp_ctrl_response_buffer.cc10
-rw-r--r--net/ftp/ftp_ctrl_response_buffer.h5
-rw-r--r--net/ftp/ftp_network_transaction.cc50
-rw-r--r--net/ftp/ftp_network_transaction.h10
4 files changed, 34 insertions, 41 deletions
diff --git a/net/ftp/ftp_ctrl_response_buffer.cc b/net/ftp/ftp_ctrl_response_buffer.cc
index 02f9908..9441f4b 100644
--- a/net/ftp/ftp_ctrl_response_buffer.cc
+++ b/net/ftp/ftp_ctrl_response_buffer.cc
@@ -27,7 +27,7 @@ namespace net {
const int FtpCtrlResponse::kInvalidStatusCode = -1;
int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) {
- buffer_.append(std::string(data, data_length));
+ buffer_.append(data, data_length);
ExtractFullLinesFromBuffer();
while (!lines_.empty()) {
@@ -38,11 +38,10 @@ int FtpCtrlResponseBuffer::ConsumeData(const char* data, int data_length) {
if (!line.is_complete)
return ERR_INVALID_RESPONSE;
+ response_buf_.status_code = line.status_code;
if (line.is_multiline) {
line_buf_ = line.status_text;
- response_buf_.status_code = line.status_code;
} else {
- response_buf_.status_code = line.status_code;
response_buf_.lines.push_back(line.status_text);
LogResponse(response_buf_);
responses_.push(response_buf_);
@@ -106,14 +105,11 @@ FtpCtrlResponseBuffer::ParsedLine FtpCtrlResponseBuffer::ParseLine(
}
void FtpCtrlResponseBuffer::ExtractFullLinesFromBuffer() {
- std::string line_buf;
int cut_pos = 0;
for (size_t i = 0; i < buffer_.length(); i++) {
- line_buf.push_back(buffer_[i]);
if (i >= 1 && buffer_[i - 1] == '\r' && buffer_[i] == '\n') {
- lines_.push(ParseLine(line_buf.substr(0, line_buf.length() - 2)));
+ lines_.push(ParseLine(buffer_.substr(cut_pos, i - cut_pos - 1)));
cut_pos = i + 1;
- line_buf.clear();
}
}
buffer_.erase(0, cut_pos);
diff --git a/net/ftp/ftp_ctrl_response_buffer.h b/net/ftp/ftp_ctrl_response_buffer.h
index 33f04b9..66aae8b 100644
--- a/net/ftp/ftp_ctrl_response_buffer.h
+++ b/net/ftp/ftp_ctrl_response_buffer.h
@@ -16,8 +16,7 @@ namespace net {
struct FtpCtrlResponse {
static const int kInvalidStatusCode;
- FtpCtrlResponse() : status_code(kInvalidStatusCode) {
- }
+ FtpCtrlResponse() : status_code(kInvalidStatusCode) {}
int status_code; // Three-digit status code.
std::vector<std::string> lines; // Response lines, without CRLFs.
@@ -69,7 +68,7 @@ class FtpCtrlResponseBuffer {
// Part of response parsed as status text.
std::string status_text;
- // Text before parsing, without ending CRLF.
+ // Text before parsing, without terminating CRLF.
std::string raw_text;
};
diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc
index 95025e7..aac8b74 100644
--- a/net/ftp/ftp_network_transaction.cc
+++ b/net/ftp/ftp_network_transaction.cc
@@ -37,6 +37,7 @@ FtpNetworkTransaction::FtpNetworkTransaction(
read_ctrl_buf_(new IOBuffer(kCtrlBufLen)),
read_data_buf_len_(0),
file_data_len_(0),
+ write_command_buf_written_(0),
last_error_(OK),
is_anonymous_(false),
retr_failed_(false),
@@ -115,14 +116,14 @@ int FtpNetworkTransaction::SendFtpCommand(const std::string& command,
DLOG(INFO) << " >> " << command;
command_sent_ = cmd;
- write_buf_written_ = 0;
+
write_command_buf_ = new IOBufferWithSize(command.length() + 2);
write_buf_ = new ReusedIOBuffer(write_command_buf_,
write_command_buf_->size());
memcpy(write_command_buf_->data(), command.data(), command.length());
memcpy(write_command_buf_->data() + command.length(), kCRLF, 2);
- next_state_ = STATE_CTRL_WRITE_COMMAND;
+ next_state_ = STATE_CTRL_WRITE;
return OK;
}
@@ -239,12 +240,12 @@ int FtpNetworkTransaction::DoLoop(int result) {
case STATE_CTRL_READ_COMPLETE:
rv = DoCtrlReadComplete(rv);
break;
- case STATE_CTRL_WRITE_COMMAND:
+ case STATE_CTRL_WRITE:
DCHECK(rv == OK);
- rv = DoCtrlWriteCommand();
+ rv = DoCtrlWrite();
break;
- case STATE_CTRL_WRITE_COMMAND_COMPLETE:
- rv = DoCtrlWriteCommandComplete(rv);
+ case STATE_CTRL_WRITE_COMPLETE:
+ rv = DoCtrlWriteComplete(rv);
break;
case STATE_CTRL_WRITE_USER:
DCHECK(rv == OK);
@@ -376,12 +377,7 @@ int FtpNetworkTransaction::DoCtrlConnectComplete(int result) {
}
int FtpNetworkTransaction::DoCtrlRead() {
- // Clear the write buffer.
- write_command_buf_ = NULL;
- write_buf_ = NULL;
-
next_state_ = STATE_CTRL_READ_COMPLETE;
- read_ctrl_buf_->data()[0] = 0;
return ctrl_socket_->Read(
read_ctrl_buf_,
kCtrlBufLen,
@@ -403,28 +399,30 @@ int FtpNetworkTransaction::DoCtrlReadComplete(int result) {
return ProcessCtrlResponse();
}
-int FtpNetworkTransaction::DoCtrlWriteCommand() {
- write_buf_->SetOffset(write_buf_written_);
- int rv = ctrl_socket_->Write(write_buf_,
- write_command_buf_->size() - write_buf_written_,
- &io_callback_);
- if (rv == ERR_IO_PENDING) {
- next_state_ = STATE_CTRL_WRITE_COMMAND_COMPLETE;
- return rv;
- } else {
- return DoCtrlWriteCommandComplete(rv);
- }
+int FtpNetworkTransaction::DoCtrlWrite() {
+ next_state_ = STATE_CTRL_WRITE_COMPLETE;
+
+ write_buf_->SetOffset(write_command_buf_written_);
+ int bytes_to_write = write_command_buf_->size() - write_command_buf_written_;
+ return ctrl_socket_->Write(write_buf_,
+ bytes_to_write,
+ &io_callback_);
}
-int FtpNetworkTransaction::DoCtrlWriteCommandComplete(int result) {
+int FtpNetworkTransaction::DoCtrlWriteComplete(int result) {
if (result < 0)
return result;
- write_buf_written_ += result;
- if (write_buf_written_ == write_command_buf_->size()) {
+ write_command_buf_written_ += result;
+ if (write_command_buf_written_ == write_command_buf_->size()) {
+ // Clear the write buffer.
+ write_buf_ = NULL;
+ write_command_buf_ = NULL;
+ write_command_buf_written_ = 0;
+
next_state_ = STATE_CTRL_READ;
} else {
- next_state_ = STATE_CTRL_WRITE_COMMAND;
+ next_state_ = STATE_CTRL_WRITE;
}
return OK;
}
diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h
index 5ca098c..3f70bed 100644
--- a/net/ftp/ftp_network_transaction.h
+++ b/net/ftp/ftp_network_transaction.h
@@ -103,8 +103,8 @@ class FtpNetworkTransaction : public FtpTransaction {
int DoCtrlConnectComplete(int result);
int DoCtrlRead();
int DoCtrlReadComplete(int result);
- int DoCtrlWriteCommand();
- int DoCtrlWriteCommandComplete(int result);
+ int DoCtrlWrite();
+ int DoCtrlWriteComplete(int result);
int DoCtrlWriteUSER();
int ProcessResponseUSER(const FtpCtrlResponse& response);
int DoCtrlWritePASS();
@@ -171,7 +171,7 @@ class FtpNetworkTransaction : public FtpTransaction {
// Number of bytes from write_command_buf_ that we've already sent to the
// server.
- int write_buf_written_;
+ int write_command_buf_written_;
int last_error_;
@@ -196,8 +196,8 @@ class FtpNetworkTransaction : public FtpTransaction {
STATE_CTRL_CONNECT_COMPLETE,
STATE_CTRL_READ,
STATE_CTRL_READ_COMPLETE,
- STATE_CTRL_WRITE_COMMAND,
- STATE_CTRL_WRITE_COMMAND_COMPLETE,
+ STATE_CTRL_WRITE,
+ STATE_CTRL_WRITE_COMPLETE,
STATE_CTRL_WRITE_USER,
STATE_CTRL_WRITE_PASS,
STATE_CTRL_WRITE_ACCT,