Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: net/ftp/ftp_network_transaction.h

Issue 115137: FTP Transaction code for new Portable FTP code.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Upload before checkin Created 11 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/ftp/ftp_network_layer.cc ('k') | net/ftp/ftp_network_transaction.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #ifndef NET_FTP_FTP_NETWORK_TRANSACTION_H_ 5 #ifndef NET_FTP_FTP_NETWORK_TRANSACTION_H_
6 #define NET_FTP_FTP_NETWORK_TRANSACTION_H_ 6 #define NET_FTP_FTP_NETWORK_TRANSACTION_H_
7 7
8 #include <string>
9
8 #include "base/ref_counted.h" 10 #include "base/ref_counted.h"
9 #include "base/scoped_ptr.h" 11 #include "base/scoped_ptr.h"
12 #include "net/base/address_list.h"
13 #include "net/base/host_resolver.h"
10 #include "net/ftp/ftp_response_info.h" 14 #include "net/ftp/ftp_response_info.h"
11 #include "net/ftp/ftp_transaction.h" 15 #include "net/ftp/ftp_transaction.h"
12 16
13 namespace net { 17 namespace net {
14 18
15 class ClientSocket; 19 class ClientSocket;
16 class ClientSocketFactory; 20 class ClientSocketFactory;
17 class FtpNetworkSession; 21 class FtpNetworkSession;
18 22
19 class FtpNetworkTransaction : public FtpTransaction { 23 class FtpNetworkTransaction : public FtpTransaction {
20 public: 24 public:
21 FtpNetworkTransaction( 25 FtpNetworkTransaction(FtpNetworkSession* session,
22 FtpNetworkSession* session, ClientSocketFactory* socket_factory); 26 ClientSocketFactory* socket_factory);
23 ~FtpNetworkTransaction(); 27 virtual ~FtpNetworkTransaction();
24 28
25 // FtpTransaction methods: 29 // FtpTransaction methods:
26 virtual void Destroy(); 30 virtual int Start(const FtpRequestInfo* request_info,
27 virtual int Start( 31 CompletionCallback* callback);
28 const FtpRequestInfo* request_info, CompletionCallback* callback); 32 virtual int Stop(int error);
29 virtual int RestartWithAuth( 33 virtual int RestartWithAuth(const std::wstring& username,
30 const std::wstring& username, const std::wstring& password, 34 const std::wstring& password,
31 CompletionCallback* callback); 35 CompletionCallback* callback);
32 virtual int Read(char* buf, int buf_len, CompletionCallback* callback); 36 virtual int RestartIgnoringLastError(CompletionCallback* callback);
37 virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback);
33 virtual const FtpResponseInfo* GetResponseInfo() const; 38 virtual const FtpResponseInfo* GetResponseInfo() const;
34 virtual LoadState GetLoadState() const; 39 virtual LoadState GetLoadState() const;
35 virtual uint64 GetUploadProgress() const; 40 virtual uint64 GetUploadProgress() const;
36 41
37 private: 42 private:
43 enum Command {
44 COMMAND_NONE,
45 COMMAND_USER,
46 COMMAND_PASS,
47 COMMAND_ACCT,
48 COMMAND_SYST,
49 COMMAND_TYPE,
50 COMMAND_PASV,
51 COMMAND_PWD,
52 COMMAND_SIZE,
53 COMMAND_RETR,
54 COMMAND_CWD,
55 COMMAND_LIST,
56 COMMAND_QUIT
57 };
58
59 enum ErrorClass {
60 ERROR_CLASS_INITIATED = 1, // The requested action was initiated.
61 ERROR_CLASS_OK, // The requested action successfully completed.
62 ERROR_CLASS_PENDING, // The command accepted, but the
63 // request on hold.
64 ERROR_CLASS_ERROR_RETRY, // The command was not accepted and the
65 // requested action did not take place,
66 // but the error condition is temporary and the
67 // action may be requested again.
68 ERROR_CLASS_ERROR, // The command was not accepted and
69 // the requested action did not take place.
70 };
71
38 void DoCallback(int result); 72 void DoCallback(int result);
39 void OnIOComplete(int result); 73 void OnIOComplete(int result);
74 int GetRespnseCode();
75 int ProcessResponse(int response_code);
76 int ParsePasvResponse();
77
78 int SendFtpCommand(const std::string& command, Command cmd);
79
80 // TODO(ibrar): Use C++ static_cast.
81 ErrorClass GetErrorClass(int response_code) {
82 return (ErrorClass)(response_code / 100);
83 }
40 84
41 // Runs the state transition loop. 85 // Runs the state transition loop.
42 int DoLoop(int result); 86 int DoLoop(int result);
43 87
44 // Each of these methods corresponds to a State value. Those with an input 88 // Each of these methods corresponds to a State value. Those with an input
45 // argument receive the result from the previous state. If a method returns 89 // argument receive the result from the previous state. If a method returns
46 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the 90 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the
47 // next state method as the result arg. 91 // next state method as the result arg.
48 int DoCtrlInit(); 92 int DoCtrlInit();
49 int DoCtrlInitComplete(int result); 93 int DoCtrlInitComplete(int result);
50 int DoCtrlResolveHost(); 94 int DoCtrlResolveHost();
51 int DoCtrlResolveHostComplete(int result); 95 int DoCtrlResolveHostComplete(int result);
52 int DoCtrlConnect(); 96 int DoCtrlConnect();
53 int DoCtrlConnectComplete(int result); 97 int DoCtrlConnectComplete(int result);
54 int DoCtrlWrite();
55 int DoCtrlWriteComplete(int result);
56 int DoCtrlRead(); 98 int DoCtrlRead();
57 int DoCtrlReadComplete(int result); 99 int DoCtrlReadComplete(int result);
100 int DoCtrlWriteUSER();
101 int ProcessResponseUSER(int response_code);
102 int DoCtrlWritePASS();
103 int ProcessResponsePASS(int response_code);
104 int DoCtrlWriteACCT();
105 int ProcessResponseACCT(int response_code);
106 int DoCtrlWriteSYST();
107 int ProcessResponseSYST(int response_code);
108 int DoCtrlWritePWD();
109 int ProcessResponsePWD(int response_code);
110 int DoCtrlWriteTYPE();
111 int ProcessResponseTYPE(int response_code);
112 int DoCtrlWritePASV();
113 int ProcessResponsePASV(int response_code);
114 int DoCtrlWriteRETR();
115 int ProcessResponseRETR(int response_code);
116 int DoCtrlWriteSIZE();
117 int ProcessResponseSIZE(int response_code);
118 int DoCtrlWriteCWD();
119 int ProcessResponseCWD(int response_code);
120 int DoCtrlWriteLIST();
121 int ProcessResponseLIST(int response_code);
122 int DoCtrlWriteQUIT();
123 int ProcessResponseQUIT(int response_code);
124
58 int DoDataConnect(); 125 int DoDataConnect();
59 int DoDataConnectComplete(int result); 126 int DoDataConnectComplete(int result);
60 int DoDataRead(); 127 int DoDataRead();
61 int DoDataReadComplete(int result); 128 int DoDataReadComplete(int result);
62 129
130 Command command_sent_;
131
63 CompletionCallbackImpl<FtpNetworkTransaction> io_callback_; 132 CompletionCallbackImpl<FtpNetworkTransaction> io_callback_;
64 CompletionCallback* user_callback_; 133 CompletionCallback* user_callback_;
65 134
66 scoped_refptr<FtpNetworkSession> session_; 135 scoped_refptr<FtpNetworkSession> session_;
67 136
68 const FtpRequestInfo* request_; 137 const FtpRequestInfo* request_;
69 FtpResponseInfo response_; 138 FtpResponseInfo response_;
70 139
140 HostResolver resolver_;
141 AddressList addresses_;
142
143 // User buffer and length passed to the Read method.
144 scoped_refptr<IOBuffer> read_ctrl_buf_;
145 int read_ctrl_buf_size_;
146
147 scoped_refptr<IOBuffer> response_message_buf_;
148 int response_message_buf_len_;
149
150 scoped_refptr<IOBuffer> read_data_buf_;
151 int read_data_buf_len_;
152 int file_data_len_;
153
154 scoped_refptr<IOBuffer> write_buf_;
155
156 int last_error_;
157
158 std::string data_connection_ip_;
159 int data_connection_port_;
160
71 ClientSocketFactory* socket_factory_; 161 ClientSocketFactory* socket_factory_;
162
72 scoped_ptr<ClientSocket> ctrl_socket_; 163 scoped_ptr<ClientSocket> ctrl_socket_;
73 scoped_ptr<ClientSocket> data_socket_; 164 scoped_ptr<ClientSocket> data_socket_;
74 165
75 enum State { 166 enum State {
76 // Control connection states: 167 // Control connection states:
77 STATE_CTRL_INIT, 168 STATE_CTRL_INIT,
78 STATE_CTRL_INIT_COMPLETE, 169 STATE_CTRL_INIT_COMPLETE,
79 STATE_CTRL_RESOLVE_HOST, 170 STATE_CTRL_RESOLVE_HOST,
80 STATE_CTRL_RESOLVE_HOST_COMPLETE, 171 STATE_CTRL_RESOLVE_HOST_COMPLETE,
81 STATE_CTRL_CONNECT, 172 STATE_CTRL_CONNECT,
82 STATE_CTRL_CONNECT_COMPLETE, 173 STATE_CTRL_CONNECT_COMPLETE,
83 STATE_CTRL_WRITE,
84 STATE_CTRL_WRITE_COMPLETE,
85 STATE_CTRL_READ, 174 STATE_CTRL_READ,
86 STATE_CTRL_READ_COMPLETE, 175 STATE_CTRL_READ_COMPLETE,
176 STATE_CTRL_WRITE_USER,
177 STATE_CTRL_WRITE_PASS,
178 STATE_CTRL_WRITE_ACCT,
179 STATE_CTRL_WRITE_SYST,
180 STATE_CTRL_WRITE_TYPE,
181 STATE_CTRL_WRITE_PASV,
182 STATE_CTRL_WRITE_PWD,
183 STATE_CTRL_WRITE_RETR,
184 STATE_CTRL_WRITE_SIZE,
185 STATE_CTRL_WRITE_CWD,
186 STATE_CTRL_WRITE_LIST,
187 STATE_CTRL_WRITE_QUIT,
87 // Data connection states: 188 // Data connection states:
88 STATE_DATA_CONNECT, 189 STATE_DATA_CONNECT,
89 STATE_DATA_CONNECT_COMPLETE, 190 STATE_DATA_CONNECT_COMPLETE,
90 STATE_DATA_READ, 191 STATE_DATA_READ,
91 STATE_DATA_READ_COMPLETE, 192 STATE_DATA_READ_COMPLETE,
92 STATE_NONE 193 STATE_NONE
93 }; 194 };
94 State next_state_; 195 State next_state_;
95 }; 196 };
96 197
97 } // namespace net 198 } // namespace net
98 199
99 #endif // NET_FTP_FTP_NETWORK_TRANSACTION_H_ 200 #endif // NET_FTP_FTP_NETWORK_TRANSACTION_H_
OLDNEW
« no previous file with comments | « net/ftp/ftp_network_layer.cc ('k') | net/ftp/ftp_network_transaction.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698