| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request_new_ftp_job.h" | 5 #include "net/url_request/url_request_new_ftp_job.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/file_version_info.h" | 8 #include "base/file_version_info.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 read_in_progress_(false), | 70 read_in_progress_(false), |
| 71 context_(request->context()) { | 71 context_(request->context()) { |
| 72 } | 72 } |
| 73 | 73 |
| 74 URLRequestNewFtpJob::~URLRequestNewFtpJob() { | 74 URLRequestNewFtpJob::~URLRequestNewFtpJob() { |
| 75 } | 75 } |
| 76 | 76 |
| 77 // static | 77 // static |
| 78 URLRequestJob* URLRequestNewFtpJob::Factory(URLRequest* request, | 78 URLRequestJob* URLRequestNewFtpJob::Factory(URLRequest* request, |
| 79 const std::string& scheme) { | 79 const std::string& scheme) { |
| 80 DCHECK(scheme == "ftp"); | 80 DCHECK_EQ(scheme, "ftp"); |
| 81 | 81 |
| 82 if (request->url().has_port() && | 82 if (request->url().has_port() && |
| 83 !net::IsPortAllowedByFtp(request->url().IntPort())) | 83 !net::IsPortAllowedByFtp(request->url().IntPort())) |
| 84 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); | 84 return new URLRequestErrorJob(request, net::ERR_UNSAFE_PORT); |
| 85 | 85 |
| 86 DCHECK(request->context()); | 86 DCHECK(request->context()); |
| 87 DCHECK(request->context()->ftp_transaction_factory()); | 87 DCHECK(request->context()->ftp_transaction_factory()); |
| 88 return new URLRequestNewFtpJob(request); | 88 return new URLRequestNewFtpJob(request); |
| 89 } | 89 } |
| 90 | 90 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 // to FEAT command includes 'UTF8'). | 193 // to FEAT command includes 'UTF8'). |
| 194 // See http://wiki.filezilla-project.org/Character_Set | 194 // See http://wiki.filezilla-project.org/Character_Set |
| 195 if (encoding_.empty()) | 195 if (encoding_.empty()) |
| 196 encoding_ = DetectEncoding(buf->data(), bytes_read); | 196 encoding_ = DetectEncoding(buf->data(), bytes_read); |
| 197 | 197 |
| 198 int64 file_size; | 198 int64 file_size; |
| 199 std::istringstream iss(buf->data()); | 199 std::istringstream iss(buf->data()); |
| 200 while (getline(iss, line)) { | 200 while (getline(iss, line)) { |
| 201 struct net::ListState state; | 201 struct net::ListState state; |
| 202 struct net::ListResult result; | 202 struct net::ListResult result; |
| 203 base::Time::Exploded et; | |
| 204 std::replace(line.begin(), line.end(), '\r', '\0'); | 203 std::replace(line.begin(), line.end(), '\r', '\0'); |
| 205 net::LineType line_type = ParseFTPLine(line.c_str(), &state, &result); | 204 net::LineType line_type = ParseFTPLine(line.c_str(), &state, &result); |
| 206 switch (line_type) { | 205 switch (line_type) { |
| 207 case net::FTP_TYPE_DIRECTORY: | 206 case net::FTP_TYPE_DIRECTORY: |
| 208 // TODO(ibrar): There is some problem in ParseFTPLine function or | |
| 209 // in conversion between tm and base::Time::Exploded. | |
| 210 // It returns wrong date/time (Differnce is 1 day and 17 Hours). | |
| 211 memset(&et, 0, sizeof(base::Time::Exploded)); | |
| 212 et.second = result.fe_time.tm_sec; | |
| 213 et.minute = result.fe_time.tm_min; | |
| 214 et.hour = result.fe_time.tm_hour; | |
| 215 et.day_of_month = result.fe_time.tm_mday; | |
| 216 et.month = result.fe_time.tm_mon + 1; | |
| 217 et.year = result.fe_time.tm_year + 1900; | |
| 218 et.day_of_week = result.fe_time.tm_wday; | |
| 219 | |
| 220 file_entry.append(net::GetDirectoryListingEntry( | 207 file_entry.append(net::GetDirectoryListingEntry( |
| 221 RawByteSequenceToFilename(result.fe_fname, encoding_), | 208 RawByteSequenceToFilename(result.fe_fname, encoding_), |
| 222 result.fe_fname, true, 0, base::Time::FromLocalExploded(et))); | 209 result.fe_fname, true, 0, |
| 210 base::Time::FromLocalExploded(result.fe_time))); |
| 223 break; | 211 break; |
| 224 case net::FTP_TYPE_FILE: | 212 case net::FTP_TYPE_FILE: |
| 225 // TODO(ibrar): There should be a way to create a Time object based | |
| 226 // on "tm" structure. This will remove bunch of line of code to convert | |
| 227 // tm to Time object. | |
| 228 memset(&et, 0, sizeof(base::Time::Exploded)); | |
| 229 et.second = result.fe_time.tm_sec; | |
| 230 et.minute = result.fe_time.tm_min; | |
| 231 et.hour = result.fe_time.tm_hour; | |
| 232 et.day_of_month = result.fe_time.tm_mday; | |
| 233 et.month = result.fe_time.tm_mon + 1; | |
| 234 et.year = result.fe_time.tm_year + 1900; | |
| 235 et.day_of_week = result.fe_time.tm_wday; | |
| 236 // TODO(ibrar): There is some problem in ParseFTPLine function or | |
| 237 // in conversion between tm and base::Time::Exploded. | |
| 238 // It returns wrong date/time (Differnce is 1 day and 17 Hours). | |
| 239 if (StringToInt64(result.fe_size, &file_size)) | 213 if (StringToInt64(result.fe_size, &file_size)) |
| 240 file_entry.append(net::GetDirectoryListingEntry( | 214 file_entry.append(net::GetDirectoryListingEntry( |
| 241 RawByteSequenceToFilename(result.fe_fname, encoding_), | 215 RawByteSequenceToFilename(result.fe_fname, encoding_), |
| 242 result.fe_fname, false, file_size, | 216 result.fe_fname, false, file_size, |
| 243 base::Time::FromLocalExploded(et))); | 217 base::Time::FromLocalExploded(result.fe_time))); |
| 244 break; | 218 break; |
| 245 case net::FTP_TYPE_SYMLINK: | 219 case net::FTP_TYPE_SYMLINK: |
| 246 case net::FTP_TYPE_JUNK: | 220 case net::FTP_TYPE_JUNK: |
| 247 case net::FTP_TYPE_COMMENT: | 221 case net::FTP_TYPE_COMMENT: |
| 248 break; | 222 break; |
| 249 default: | 223 default: |
| 250 break; | 224 break; |
| 251 } | 225 } |
| 252 } | 226 } |
| 253 directory_html_.append(file_entry); | 227 directory_html_.append(file_entry); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( | 294 MessageLoop::current()->PostTask(FROM_HERE, NewRunnableMethod( |
| 321 this, &URLRequestNewFtpJob::OnStartCompleted, rv)); | 295 this, &URLRequestNewFtpJob::OnStartCompleted, rv)); |
| 322 } | 296 } |
| 323 | 297 |
| 324 void URLRequestNewFtpJob::DestroyTransaction() { | 298 void URLRequestNewFtpJob::DestroyTransaction() { |
| 325 DCHECK(transaction_.get()); | 299 DCHECK(transaction_.get()); |
| 326 | 300 |
| 327 transaction_.reset(); | 301 transaction_.reset(); |
| 328 response_info_ = NULL; | 302 response_info_ = NULL; |
| 329 } | 303 } |
| OLD | NEW |