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

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

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

Powered by Google App Engine
This is Rietveld 408576698