summaryrefslogtreecommitdiffstats
path: root/net/ftp/ftp_network_transaction.h
diff options
context:
space:
mode:
authorwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 17:01:17 +0000
committerwtc@chromium.org <wtc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-11 17:01:17 +0000
commit581e0d06dc3599bec309d34203b6b5693446fe7f (patch)
treec8c11535827d0b5302d07b257c12d998f8a9edb3 /net/ftp/ftp_network_transaction.h
parenta63bd1137e938034873b318355731c656caf05fe (diff)
downloadchromium_src-581e0d06dc3599bec309d34203b6b5693446fe7f.zip
chromium_src-581e0d06dc3599bec309d34203b6b5693446fe7f.tar.gz
chromium_src-581e0d06dc3599bec309d34203b6b5693446fe7f.tar.bz2
FTP Transaction code for new Portable FTP code.
The patch is contributed by Ibrar Ahmed <ibrar.ahmad@gmail.com>. Original review: http://codereview.chromium.org/39130 R=wtc http://crbug.com/4965 TEST=None. Work in progress. Review URL: http://codereview.chromium.org/115137 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/ftp/ftp_network_transaction.h')
-rw-r--r--net/ftp/ftp_network_transaction.h129
1 files changed, 115 insertions, 14 deletions
diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h
index c7f59cd..67ddaeb 100644
--- a/net/ftp/ftp_network_transaction.h
+++ b/net/ftp/ftp_network_transaction.h
@@ -5,8 +5,12 @@
#ifndef NET_FTP_FTP_NETWORK_TRANSACTION_H_
#define NET_FTP_FTP_NETWORK_TRANSACTION_H_
+#include <string>
+
#include "base/ref_counted.h"
#include "base/scoped_ptr.h"
+#include "net/base/address_list.h"
+#include "net/base/host_resolver.h"
#include "net/ftp/ftp_response_info.h"
#include "net/ftp/ftp_transaction.h"
@@ -18,25 +22,65 @@ class FtpNetworkSession;
class FtpNetworkTransaction : public FtpTransaction {
public:
- FtpNetworkTransaction(
- FtpNetworkSession* session, ClientSocketFactory* socket_factory);
- ~FtpNetworkTransaction();
+ FtpNetworkTransaction(FtpNetworkSession* session,
+ ClientSocketFactory* socket_factory);
+ virtual ~FtpNetworkTransaction();
// FtpTransaction methods:
- virtual void Destroy();
- virtual int Start(
- const FtpRequestInfo* request_info, CompletionCallback* callback);
- virtual int RestartWithAuth(
- const std::wstring& username, const std::wstring& password,
- CompletionCallback* callback);
- virtual int Read(char* buf, int buf_len, CompletionCallback* callback);
+ virtual int Start(const FtpRequestInfo* request_info,
+ CompletionCallback* callback);
+ virtual int Stop(int error);
+ virtual int RestartWithAuth(const std::wstring& username,
+ const std::wstring& password,
+ CompletionCallback* callback);
+ virtual int RestartIgnoringLastError(CompletionCallback* callback);
+ virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
virtual const FtpResponseInfo* GetResponseInfo() const;
virtual LoadState GetLoadState() const;
virtual uint64 GetUploadProgress() const;
private:
+ enum Command {
+ COMMAND_NONE,
+ COMMAND_USER,
+ COMMAND_PASS,
+ COMMAND_ACCT,
+ COMMAND_SYST,
+ COMMAND_TYPE,
+ COMMAND_PASV,
+ COMMAND_PWD,
+ COMMAND_SIZE,
+ COMMAND_RETR,
+ COMMAND_CWD,
+ COMMAND_LIST,
+ COMMAND_QUIT
+ };
+
+ enum ErrorClass {
+ ERROR_CLASS_INITIATED = 1, // The requested action was initiated.
+ ERROR_CLASS_OK, // The requested action successfully completed.
+ ERROR_CLASS_PENDING, // The command accepted, but the
+ // request on hold.
+ ERROR_CLASS_ERROR_RETRY, // The command was not accepted and the
+ // requested action did not take place,
+ // but the error condition is temporary and the
+ // action may be requested again.
+ ERROR_CLASS_ERROR, // The command was not accepted and
+ // the requested action did not take place.
+ };
+
void DoCallback(int result);
void OnIOComplete(int result);
+ int GetRespnseCode();
+ int ProcessResponse(int response_code);
+ int ParsePasvResponse();
+
+ int SendFtpCommand(const std::string& command, Command cmd);
+
+ // TODO(ibrar): Use C++ static_cast.
+ ErrorClass GetErrorClass(int response_code) {
+ return (ErrorClass)(response_code / 100);
+ }
// Runs the state transition loop.
int DoLoop(int result);
@@ -51,15 +95,40 @@ class FtpNetworkTransaction : public FtpTransaction {
int DoCtrlResolveHostComplete(int result);
int DoCtrlConnect();
int DoCtrlConnectComplete(int result);
- int DoCtrlWrite();
- int DoCtrlWriteComplete(int result);
int DoCtrlRead();
int DoCtrlReadComplete(int result);
+ int DoCtrlWriteUSER();
+ int ProcessResponseUSER(int response_code);
+ int DoCtrlWritePASS();
+ int ProcessResponsePASS(int response_code);
+ int DoCtrlWriteACCT();
+ int ProcessResponseACCT(int response_code);
+ int DoCtrlWriteSYST();
+ int ProcessResponseSYST(int response_code);
+ int DoCtrlWritePWD();
+ int ProcessResponsePWD(int response_code);
+ int DoCtrlWriteTYPE();
+ int ProcessResponseTYPE(int response_code);
+ int DoCtrlWritePASV();
+ int ProcessResponsePASV(int response_code);
+ int DoCtrlWriteRETR();
+ int ProcessResponseRETR(int response_code);
+ int DoCtrlWriteSIZE();
+ int ProcessResponseSIZE(int response_code);
+ int DoCtrlWriteCWD();
+ int ProcessResponseCWD(int response_code);
+ int DoCtrlWriteLIST();
+ int ProcessResponseLIST(int response_code);
+ int DoCtrlWriteQUIT();
+ int ProcessResponseQUIT(int response_code);
+
int DoDataConnect();
int DoDataConnectComplete(int result);
int DoDataRead();
int DoDataReadComplete(int result);
+ Command command_sent_;
+
CompletionCallbackImpl<FtpNetworkTransaction> io_callback_;
CompletionCallback* user_callback_;
@@ -68,7 +137,29 @@ class FtpNetworkTransaction : public FtpTransaction {
const FtpRequestInfo* request_;
FtpResponseInfo response_;
+ HostResolver resolver_;
+ AddressList addresses_;
+
+ // User buffer and length passed to the Read method.
+ scoped_refptr<IOBuffer> read_ctrl_buf_;
+ int read_ctrl_buf_size_;
+
+ scoped_refptr<IOBuffer> response_message_buf_;
+ int response_message_buf_len_;
+
+ scoped_refptr<IOBuffer> read_data_buf_;
+ int read_data_buf_len_;
+ int file_data_len_;
+
+ scoped_refptr<IOBuffer> write_buf_;
+
+ int last_error_;
+
+ std::string data_connection_ip_;
+ int data_connection_port_;
+
ClientSocketFactory* socket_factory_;
+
scoped_ptr<ClientSocket> ctrl_socket_;
scoped_ptr<ClientSocket> data_socket_;
@@ -80,10 +171,20 @@ class FtpNetworkTransaction : public FtpTransaction {
STATE_CTRL_RESOLVE_HOST_COMPLETE,
STATE_CTRL_CONNECT,
STATE_CTRL_CONNECT_COMPLETE,
- STATE_CTRL_WRITE,
- STATE_CTRL_WRITE_COMPLETE,
STATE_CTRL_READ,
STATE_CTRL_READ_COMPLETE,
+ STATE_CTRL_WRITE_USER,
+ STATE_CTRL_WRITE_PASS,
+ STATE_CTRL_WRITE_ACCT,
+ STATE_CTRL_WRITE_SYST,
+ STATE_CTRL_WRITE_TYPE,
+ STATE_CTRL_WRITE_PASV,
+ STATE_CTRL_WRITE_PWD,
+ STATE_CTRL_WRITE_RETR,
+ STATE_CTRL_WRITE_SIZE,
+ STATE_CTRL_WRITE_CWD,
+ STATE_CTRL_WRITE_LIST,
+ STATE_CTRL_WRITE_QUIT,
// Data connection states:
STATE_DATA_CONNECT,
STATE_DATA_CONNECT_COMPLETE,