diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-06 16:49:51 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-06 16:49:51 +0000 |
commit | e0bb61938b9d8a296c2a62d2dd36725c005a30fd (patch) | |
tree | 14d799ed35791ac69747cebbf2e34ab38b8bc875 /net/ftp/ftp_network_transaction.h | |
parent | 181542fa4565273aac30f7f0ea9c4459ac9bcb02 (diff) | |
download | chromium_src-e0bb61938b9d8a296c2a62d2dd36725c005a30fd.zip chromium_src-e0bb61938b9d8a296c2a62d2dd36725c005a30fd.tar.gz chromium_src-e0bb61938b9d8a296c2a62d2dd36725c005a30fd.tar.bz2 |
Make new FtpNetworkTransaction handle short reads correctly.
The problem was that some functions were parsing response lines, but without checking that they have the entire line available.
This change will also make it easier to handle multi-line greeting (230 welcome messages). I plan to do that afterwards.
TEST=Covered by net_unittests.
http://crbug.com/15259
Review URL: http://codereview.chromium.org/149043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_network_transaction.h')
-rw-r--r-- | net/ftp/ftp_network_transaction.h | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h index 53f0b29..90c53e4 100644 --- a/net/ftp/ftp_network_transaction.h +++ b/net/ftp/ftp_network_transaction.h @@ -6,6 +6,8 @@ #define NET_FTP_FTP_NETWORK_TRANSACTION_H_ #include <string> +#include <queue> +#include <utility> #include "base/ref_counted.h" #include "base/scoped_ptr.h" @@ -70,11 +72,24 @@ class FtpNetworkTransaction : public FtpTransaction { // the requested action did not take place. }; + struct ResponseLine { + ResponseLine(int code, const std::string& text) : code(code), text(text) { + } + + int code; // Three-digit status code. + std::string text; // Text after the code, without ending CRLF. + }; + void DoCallback(int result); void OnIOComplete(int result); - int GetRespnseCode(); - int ProcessResponse(int response_code); - int ParsePasvResponse(); + + // Executes correct ProcessResponse + command_name function based on last + // issued command. Returns error code. + int ProcessCtrlResponses(); + + // Parses as much as possible from response_message_buf_. Puts index of the + // first unparsed character in cut_pos. Returns error code. + int ParseCtrlResponse(int* cut_pos); int SendFtpCommand(const std::string& command, Command cmd); @@ -99,31 +114,31 @@ class FtpNetworkTransaction : public FtpTransaction { int DoCtrlRead(); int DoCtrlReadComplete(int result); int DoCtrlWriteUSER(); - int ProcessResponseUSER(int response_code); + int ProcessResponseUSER(const ResponseLine& response); int DoCtrlWritePASS(); - int ProcessResponsePASS(int response_code); + int ProcessResponsePASS(const ResponseLine& response); int DoCtrlWriteACCT(); - int ProcessResponseACCT(int response_code); + int ProcessResponseACCT(const ResponseLine& response); int DoCtrlWriteSYST(); - int ProcessResponseSYST(int response_code); + int ProcessResponseSYST(const ResponseLine& response); int DoCtrlWritePWD(); - int ProcessResponsePWD(int response_code); + int ProcessResponsePWD(const ResponseLine& response); int DoCtrlWriteTYPE(); - int ProcessResponseTYPE(int response_code); + int ProcessResponseTYPE(const ResponseLine& response); int DoCtrlWritePASV(); - int ProcessResponsePASV(int response_code); + int ProcessResponsePASV(const ResponseLine& response); int DoCtrlWriteRETR(); - int ProcessResponseRETR(int response_code); + int ProcessResponseRETR(const ResponseLine& response); int DoCtrlWriteSIZE(); - int ProcessResponseSIZE(int response_code); + int ProcessResponseSIZE(const ResponseLine& response); int DoCtrlWriteCWD(); - int ProcessResponseCWD(int response_code); + int ProcessResponseCWD(const ResponseLine& response); int DoCtrlWriteLIST(); - int ProcessResponseLIST(int response_code); + int ProcessResponseLIST(const ResponseLine& response); int DoCtrlWriteMDTM(); - int ProcessResponseMDTM(int response_code); + int ProcessResponseMDTM(const ResponseLine& response); int DoCtrlWriteQUIT(); - int ProcessResponseQUIT(int response_code); + int ProcessResponseQUIT(const ResponseLine& response); int DoDataResolveHost(); int DoDataResolveHostComplete(int result); @@ -146,13 +161,17 @@ class FtpNetworkTransaction : public FtpTransaction { SingleRequestHostResolver resolver_; AddressList addresses_; - // User buffer and length passed to the Read method. - scoped_refptr<IOBuffer> read_ctrl_buf_; - int read_ctrl_buf_size_; + // As we read full response lines, we parse them and add to the queue. + std::queue<ResponseLine> ctrl_responses_; - scoped_refptr<IOBuffer> response_message_buf_; + // Buffer holding not-yet-parsed control socket responses. + scoped_refptr<IOBufferWithSize> response_message_buf_; int response_message_buf_len_; + // User buffer passed to the Read method. It actually writes to the + // response_message_buf_ at correct offset. + scoped_refptr<ReusedIOBuffer> read_ctrl_buf_; + scoped_refptr<IOBuffer> read_data_buf_; int read_data_buf_len_; int file_data_len_; |