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

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

Issue 149043: Make new FtpNetworkTransaction handle short reads correctly.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: updated Created 11 years, 5 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
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> 8 #include <string>
9 #include <queue>
10 #include <utility>
9 11
10 #include "base/ref_counted.h" 12 #include "base/ref_counted.h"
11 #include "base/scoped_ptr.h" 13 #include "base/scoped_ptr.h"
12 #include "net/base/address_list.h" 14 #include "net/base/address_list.h"
13 #include "net/base/host_resolver.h" 15 #include "net/base/host_resolver.h"
14 #include "net/ftp/ftp_response_info.h" 16 #include "net/ftp/ftp_response_info.h"
15 #include "net/ftp/ftp_transaction.h" 17 #include "net/ftp/ftp_transaction.h"
16 18
17 namespace net { 19 namespace net {
18 20
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 ERROR_CLASS_PENDING, // The command accepted, but the 65 ERROR_CLASS_PENDING, // The command accepted, but the
64 // request on hold. 66 // request on hold.
65 ERROR_CLASS_ERROR_RETRY, // The command was not accepted and the 67 ERROR_CLASS_ERROR_RETRY, // The command was not accepted and the
66 // requested action did not take place, 68 // requested action did not take place,
67 // but the error condition is temporary and the 69 // but the error condition is temporary and the
68 // action may be requested again. 70 // action may be requested again.
69 ERROR_CLASS_ERROR, // The command was not accepted and 71 ERROR_CLASS_ERROR, // The command was not accepted and
70 // the requested action did not take place. 72 // the requested action did not take place.
71 }; 73 };
72 74
75 struct ResponseLine {
76 ResponseLine(int code, const std::string& text) : code(code), text(text) {
77 }
78
79 int code; // Three-digit status code.
80 std::string text; // Text after the code, without ending CRLF.
81 };
82
73 void DoCallback(int result); 83 void DoCallback(int result);
74 void OnIOComplete(int result); 84 void OnIOComplete(int result);
75 int GetRespnseCode(); 85
76 int ProcessResponse(int response_code); 86 // Executes correct ProcessResponse + command_name function based on last
77 int ParsePasvResponse(); 87 // issued command. Returns error code.
88 int ProcessCtrlResponses();
89
90 // Parses as much as possible from response_message_buf_. Puts index of the
91 // first unparsed character in cut_pos. Returns error code.
92 int ParseCtrlResponse(int* cut_pos);
78 93
79 int SendFtpCommand(const std::string& command, Command cmd); 94 int SendFtpCommand(const std::string& command, Command cmd);
80 95
81 // TODO(ibrar): Use C++ static_cast. 96 // TODO(ibrar): Use C++ static_cast.
82 ErrorClass GetErrorClass(int response_code) { 97 ErrorClass GetErrorClass(int response_code) {
83 return (ErrorClass)(response_code / 100); 98 return (ErrorClass)(response_code / 100);
84 } 99 }
85 100
86 // Runs the state transition loop. 101 // Runs the state transition loop.
87 int DoLoop(int result); 102 int DoLoop(int result);
88 103
89 // Each of these methods corresponds to a State value. Those with an input 104 // Each of these methods corresponds to a State value. Those with an input
90 // argument receive the result from the previous state. If a method returns 105 // argument receive the result from the previous state. If a method returns
91 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the 106 // ERR_IO_PENDING, then the result from OnIOComplete will be passed to the
92 // next state method as the result arg. 107 // next state method as the result arg.
93 int DoCtrlInit(); 108 int DoCtrlInit();
94 int DoCtrlInitComplete(int result); 109 int DoCtrlInitComplete(int result);
95 int DoCtrlResolveHost(); 110 int DoCtrlResolveHost();
96 int DoCtrlResolveHostComplete(int result); 111 int DoCtrlResolveHostComplete(int result);
97 int DoCtrlConnect(); 112 int DoCtrlConnect();
98 int DoCtrlConnectComplete(int result); 113 int DoCtrlConnectComplete(int result);
99 int DoCtrlRead(); 114 int DoCtrlRead();
100 int DoCtrlReadComplete(int result); 115 int DoCtrlReadComplete(int result);
101 int DoCtrlWriteUSER(); 116 int DoCtrlWriteUSER();
102 int ProcessResponseUSER(int response_code); 117 int ProcessResponseUSER(const ResponseLine& response);
103 int DoCtrlWritePASS(); 118 int DoCtrlWritePASS();
104 int ProcessResponsePASS(int response_code); 119 int ProcessResponsePASS(const ResponseLine& response);
105 int DoCtrlWriteACCT(); 120 int DoCtrlWriteACCT();
106 int ProcessResponseACCT(int response_code); 121 int ProcessResponseACCT(const ResponseLine& response);
107 int DoCtrlWriteSYST(); 122 int DoCtrlWriteSYST();
108 int ProcessResponseSYST(int response_code); 123 int ProcessResponseSYST(const ResponseLine& response);
109 int DoCtrlWritePWD(); 124 int DoCtrlWritePWD();
110 int ProcessResponsePWD(int response_code); 125 int ProcessResponsePWD(const ResponseLine& response);
111 int DoCtrlWriteTYPE(); 126 int DoCtrlWriteTYPE();
112 int ProcessResponseTYPE(int response_code); 127 int ProcessResponseTYPE(const ResponseLine& response);
113 int DoCtrlWritePASV(); 128 int DoCtrlWritePASV();
114 int ProcessResponsePASV(int response_code); 129 int ProcessResponsePASV(const ResponseLine& response);
115 int DoCtrlWriteRETR(); 130 int DoCtrlWriteRETR();
116 int ProcessResponseRETR(int response_code); 131 int ProcessResponseRETR(const ResponseLine& response);
117 int DoCtrlWriteSIZE(); 132 int DoCtrlWriteSIZE();
118 int ProcessResponseSIZE(int response_code); 133 int ProcessResponseSIZE(const ResponseLine& response);
119 int DoCtrlWriteCWD(); 134 int DoCtrlWriteCWD();
120 int ProcessResponseCWD(int response_code); 135 int ProcessResponseCWD(const ResponseLine& response);
121 int DoCtrlWriteLIST(); 136 int DoCtrlWriteLIST();
122 int ProcessResponseLIST(int response_code); 137 int ProcessResponseLIST(const ResponseLine& response);
123 int DoCtrlWriteMDTM(); 138 int DoCtrlWriteMDTM();
124 int ProcessResponseMDTM(int response_code); 139 int ProcessResponseMDTM(const ResponseLine& response);
125 int DoCtrlWriteQUIT(); 140 int DoCtrlWriteQUIT();
126 int ProcessResponseQUIT(int response_code); 141 int ProcessResponseQUIT(const ResponseLine& response);
127 142
128 int DoDataResolveHost(); 143 int DoDataResolveHost();
129 int DoDataResolveHostComplete(int result); 144 int DoDataResolveHostComplete(int result);
130 int DoDataConnect(); 145 int DoDataConnect();
131 int DoDataConnectComplete(int result); 146 int DoDataConnectComplete(int result);
132 int DoDataRead(); 147 int DoDataRead();
133 int DoDataReadComplete(int result); 148 int DoDataReadComplete(int result);
134 149
135 Command command_sent_; 150 Command command_sent_;
136 151
137 CompletionCallbackImpl<FtpNetworkTransaction> io_callback_; 152 CompletionCallbackImpl<FtpNetworkTransaction> io_callback_;
138 CompletionCallback* user_callback_; 153 CompletionCallback* user_callback_;
139 154
140 scoped_refptr<FtpNetworkSession> session_; 155 scoped_refptr<FtpNetworkSession> session_;
141 156
142 const FtpRequestInfo* request_; 157 const FtpRequestInfo* request_;
143 FtpResponseInfo response_; 158 FtpResponseInfo response_;
144 159
145 // Cancels the outstanding request on destruction. 160 // Cancels the outstanding request on destruction.
146 SingleRequestHostResolver resolver_; 161 SingleRequestHostResolver resolver_;
147 AddressList addresses_; 162 AddressList addresses_;
148 163
149 // User buffer and length passed to the Read method. 164 // As we read full response lines, we parse them and add to the queue.
150 scoped_refptr<IOBuffer> read_ctrl_buf_; 165 std::queue<ResponseLine> ctrl_responses_;
151 int read_ctrl_buf_size_;
152 166
153 scoped_refptr<IOBuffer> response_message_buf_; 167 // Buffer holding not-yet-parsed control socket responses.
168 scoped_refptr<IOBufferWithSize> response_message_buf_;
154 int response_message_buf_len_; 169 int response_message_buf_len_;
155 170
171 // User buffer passed to the Read method. It actually writes to the
172 // response_message_buf_ at correct offset.
173 scoped_refptr<ReusedIOBuffer> read_ctrl_buf_;
174
156 scoped_refptr<IOBuffer> read_data_buf_; 175 scoped_refptr<IOBuffer> read_data_buf_;
157 int read_data_buf_len_; 176 int read_data_buf_len_;
158 int file_data_len_; 177 int file_data_len_;
159 178
160 scoped_refptr<IOBuffer> write_buf_; 179 scoped_refptr<IOBuffer> write_buf_;
161 180
162 int last_error_; 181 int last_error_;
163 182
164 bool is_anonymous_; 183 bool is_anonymous_;
165 bool retr_failed_; 184 bool retr_failed_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 STATE_DATA_READ, 222 STATE_DATA_READ,
204 STATE_DATA_READ_COMPLETE, 223 STATE_DATA_READ_COMPLETE,
205 STATE_NONE 224 STATE_NONE
206 }; 225 };
207 State next_state_; 226 State next_state_;
208 }; 227 };
209 228
210 } // namespace net 229 } // namespace net
211 230
212 #endif // NET_FTP_FTP_NETWORK_TRANSACTION_H_ 231 #endif // NET_FTP_FTP_NETWORK_TRANSACTION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698