2006-02-21 12:28:42 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-21 12:28:42 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-02-21 12:28:42 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "FtpNegotiationCommand.h"
|
2008-11-03 10:06:25 +00:00
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <cassert>
|
|
|
|
#include <utility>
|
|
|
|
#include <map>
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Request.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "DownloadEngine.h"
|
|
|
|
#include "FtpConnection.h"
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "PieceStorage.h"
|
2006-02-21 12:28:42 +00:00
|
|
|
#include "FtpDownloadCommand.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2006-02-21 12:28:42 +00:00
|
|
|
#include "DlAbortEx.h"
|
|
|
|
#include "message.h"
|
2006-02-21 14:00:58 +00:00
|
|
|
#include "prefs.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Option.h"
|
|
|
|
#include "Logger.h"
|
|
|
|
#include "Segment.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2007-11-05 15:50:49 +00:00
|
|
|
#include "DefaultBtProgressInfoFile.h"
|
2007-11-13 11:46:58 +00:00
|
|
|
#include "RequestGroupMan.h"
|
|
|
|
#include "DownloadFailureException.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Socket.h"
|
2008-04-27 02:22:14 +00:00
|
|
|
#include "StringFormat.h"
|
2008-06-24 14:31:23 +00:00
|
|
|
#include "DiskAdaptor.h"
|
|
|
|
#include "SegmentMan.h"
|
2008-11-03 10:06:25 +00:00
|
|
|
#include "AuthConfigFactory.h"
|
|
|
|
#include "AuthConfig.h"
|
2009-06-06 12:33:07 +00:00
|
|
|
#include "a2functional.h"
|
2009-06-29 08:42:58 +00:00
|
|
|
#include "URISelector.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2009-06-23 15:35:45 +00:00
|
|
|
FtpNegotiationCommand::FtpNegotiationCommand
|
|
|
|
(int32_t cuid,
|
|
|
|
const RequestHandle& req,
|
|
|
|
const SharedHandle<FileEntry>& fileEntry,
|
|
|
|
RequestGroup* requestGroup,
|
|
|
|
DownloadEngine* e,
|
|
|
|
const SocketHandle& s,
|
|
|
|
Seq seq,
|
|
|
|
const std::string& baseWorkingDir):
|
|
|
|
AbstractCommand(cuid, req, fileEntry, requestGroup, e, s), sequence(seq),
|
2008-11-03 10:06:25 +00:00
|
|
|
ftp(new FtpConnection(cuid, socket, req,
|
2009-07-14 12:37:34 +00:00
|
|
|
e->getAuthConfigFactory()->createAuthConfig
|
|
|
|
(req, requestGroup->getOption().get()),
|
2009-05-08 16:41:21 +00:00
|
|
|
getOption().get()))
|
2006-02-21 12:28:42 +00:00
|
|
|
{
|
2008-09-24 17:01:57 +00:00
|
|
|
ftp->setBaseWorkingDir(baseWorkingDir);
|
2008-09-09 12:13:08 +00:00
|
|
|
if(seq == SEQ_RECV_GREETING) {
|
2009-05-08 16:41:21 +00:00
|
|
|
setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
|
2008-09-09 12:13:08 +00:00
|
|
|
}
|
2006-07-19 17:07:45 +00:00
|
|
|
disableReadCheckSocket();
|
2006-02-21 12:28:42 +00:00
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
|
|
|
|
2008-05-09 14:44:28 +00:00
|
|
|
FtpNegotiationCommand::~FtpNegotiationCommand() {}
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
bool FtpNegotiationCommand::executeInternal() {
|
2007-10-17 16:26:51 +00:00
|
|
|
while(processSequence(_segments.front()));
|
2006-02-21 12:28:42 +00:00
|
|
|
if(sequence == SEQ_RETRY) {
|
|
|
|
return prepareForRetry(0);
|
|
|
|
} else if(sequence == SEQ_NEGOTIATION_COMPLETED) {
|
2006-07-19 17:07:45 +00:00
|
|
|
FtpDownloadCommand* command =
|
2009-06-23 15:35:45 +00:00
|
|
|
new FtpDownloadCommand
|
|
|
|
(cuid, req, _fileEntry, _requestGroup, ftp, e, dataSocket, socket);
|
2009-05-08 16:41:21 +00:00
|
|
|
command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
|
|
|
|
command->setLowestDownloadSpeedLimit(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
2009-06-29 16:43:41 +00:00
|
|
|
if(!_fileEntry->isSingleHostMultiConnectionEnabled()) {
|
|
|
|
_fileEntry->removeURIWhoseHostnameIs(req->getHost());
|
2007-12-12 13:53:33 +00:00
|
|
|
}
|
2009-06-29 08:42:58 +00:00
|
|
|
_requestGroup->getURISelector()->tuneDownloadCommand
|
|
|
|
(_fileEntry->getRemainingUris(), command);
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(command);
|
2006-02-21 12:28:42 +00:00
|
|
|
return true;
|
2007-12-01 04:56:10 +00:00
|
|
|
} else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
|
2007-01-29 16:46:48 +00:00
|
|
|
return true;
|
2007-12-01 04:56:10 +00:00
|
|
|
} else if(sequence == SEQ_FILE_PREPARATION) {
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_FTP_PASV)) {
|
2007-12-01 04:56:10 +00:00
|
|
|
sequence = SEQ_SEND_PASV;
|
|
|
|
} else {
|
2008-09-13 16:32:47 +00:00
|
|
|
sequence = SEQ_PREPARE_SERVER_SOCKET;
|
2007-12-01 04:56:10 +00:00
|
|
|
}
|
|
|
|
return false;
|
2009-07-02 15:18:13 +00:00
|
|
|
} else if(sequence == SEQ_EXIT) {
|
|
|
|
return true;
|
2006-02-21 12:28:42 +00:00
|
|
|
} else {
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(this);
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvGreeting() {
|
2009-07-02 15:18:13 +00:00
|
|
|
if(!checkIfConnectionEstablished
|
|
|
|
(socket, _connectedHostname, _connectedAddr, _connectedPort)) {
|
|
|
|
sequence = SEQ_EXIT;
|
|
|
|
return false;
|
|
|
|
}
|
2009-02-01 02:55:44 +00:00
|
|
|
setTimeout(_requestGroup->getTimeout());
|
2008-09-13 16:32:47 +00:00
|
|
|
//socket->setBlockingMode();
|
2006-08-07 16:05:00 +00:00
|
|
|
disableWriteCheckSocket();
|
|
|
|
setReadCheckSocket(socket);
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 220) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(EX_CONNECTION_FAILED);
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
sequence = SEQ_SEND_USER;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendUser() {
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendUser()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_USER;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvUser() {
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
switch(status) {
|
|
|
|
case 0:
|
|
|
|
return false;
|
|
|
|
case 230:
|
|
|
|
sequence = SEQ_SEND_TYPE;
|
|
|
|
break;
|
|
|
|
case 331:
|
|
|
|
sequence = SEQ_SEND_PASS;
|
|
|
|
break;
|
|
|
|
default:
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendPass() {
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendPass()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_PASS;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvPass() {
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 230) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
sequence = SEQ_SEND_TYPE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendType() {
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendType()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_TYPE;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvType() {
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 200) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2008-09-24 17:01:57 +00:00
|
|
|
sequence = SEQ_SEND_PWD;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendPwd()
|
|
|
|
{
|
|
|
|
if(ftp->sendPwd()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_PWD;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvPwd()
|
|
|
|
{
|
|
|
|
std::string pwd;
|
|
|
|
unsigned int status = ftp->receivePwdResponse(pwd);
|
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 257) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2008-09-24 17:01:57 +00:00
|
|
|
}
|
|
|
|
ftp->setBaseWorkingDir(pwd);
|
|
|
|
logger->info("CUID#%d - base working directory is '%s'", cuid, pwd.c_str());
|
2006-02-21 12:28:42 +00:00
|
|
|
sequence = SEQ_SEND_CWD;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendCwd() {
|
2008-09-13 16:32:47 +00:00
|
|
|
// Calling setReadCheckSocket() is needed when the socket is reused,
|
|
|
|
setReadCheckSocket(socket);
|
|
|
|
if(ftp->sendCwd()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_CWD;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvCwd() {
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 250) {
|
2008-05-10 05:14:35 +00:00
|
|
|
poolConnection();
|
2008-09-10 14:56:44 +00:00
|
|
|
_requestGroup->increaseAndValidateFileNotFoundCount();
|
2009-01-12 12:27:34 +00:00
|
|
|
if (status == 550)
|
2009-06-29 08:42:58 +00:00
|
|
|
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
|
|
|
|
downloadresultcode::RESOURCE_NOT_FOUND);
|
2009-01-12 12:27:34 +00:00
|
|
|
else
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_REMOTE_TIME)) {
|
2008-09-08 13:06:44 +00:00
|
|
|
sequence = SEQ_SEND_MDTM;
|
|
|
|
} else {
|
|
|
|
sequence = SEQ_SEND_SIZE;
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-09-08 13:06:44 +00:00
|
|
|
bool FtpNegotiationCommand::sendMdtm()
|
|
|
|
{
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendMdtm()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_MDTM;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2008-09-08 13:06:44 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvMdtm()
|
|
|
|
{
|
2008-11-05 10:30:43 +00:00
|
|
|
Time lastModifiedTime = Time::null();
|
2008-09-08 13:06:44 +00:00
|
|
|
unsigned int status = ftp->receiveMdtmResponse(lastModifiedTime);
|
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status == 213) {
|
|
|
|
if(lastModifiedTime.good()) {
|
|
|
|
_requestGroup->updateLastModifiedTime(lastModifiedTime);
|
|
|
|
time_t t = lastModifiedTime.getTime();
|
|
|
|
struct tm* tms = gmtime(&t); // returned struct is statically allocated.
|
|
|
|
if(tms) {
|
|
|
|
logger->debug("MDTM result was parsed as: %s GMT", asctime(tms));
|
|
|
|
} else {
|
|
|
|
logger->debug("gmtime() failed for MDTM result.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger->debug("MDTM response was returned, but it seems not to be a time"
|
|
|
|
" value as in specified in RFC3659.");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
logger->info("CUID#%d - MDTM command failed.", cuid);
|
|
|
|
}
|
|
|
|
sequence = SEQ_SEND_SIZE;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-02-21 12:28:42 +00:00
|
|
|
bool FtpNegotiationCommand::sendSize() {
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendSize()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_SIZE;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-24 14:31:23 +00:00
|
|
|
bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
|
|
|
|
{
|
2009-06-23 15:35:45 +00:00
|
|
|
_fileEntry->setLength(totalLength);
|
2009-11-28 09:05:50 +00:00
|
|
|
if(_fileEntry->getPath().empty()) {
|
2009-06-28 10:37:15 +00:00
|
|
|
_fileEntry->setPath
|
|
|
|
(strconcat(getDownloadContext()->getDir(),
|
2009-10-22 15:09:00 +00:00
|
|
|
"/", util::urldecode(req->getFile())));
|
2009-06-28 10:37:15 +00:00
|
|
|
}
|
2008-06-24 14:31:23 +00:00
|
|
|
_requestGroup->preDownloadProcessing();
|
|
|
|
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DOWNLOAD_FAILURE_EXCEPTION
|
2008-06-24 14:31:23 +00:00
|
|
|
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
2009-06-28 10:37:15 +00:00
|
|
|
_requestGroup->getFirstFilePath().c_str()).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2008-06-24 14:31:23 +00:00
|
|
|
if(totalLength == 0) {
|
2007-11-13 11:46:58 +00:00
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_FTP_PASV)) {
|
2008-11-26 15:22:54 +00:00
|
|
|
sequence = SEQ_SEND_PASV;
|
|
|
|
} else {
|
|
|
|
sequence = SEQ_PREPARE_SERVER_SOCKET;
|
|
|
|
}
|
2009-05-07 03:49:27 +00:00
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_DRY_RUN)) {
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->initPieceStorage();
|
|
|
|
onDryRunFileFound();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(_requestGroup->downloadFinishedByFileLength()) {
|
|
|
|
_requestGroup->initPieceStorage();
|
|
|
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
2008-11-26 15:22:54 +00:00
|
|
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
|
|
|
|
2009-05-07 03:49:27 +00:00
|
|
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
|
|
|
_requestGroup->getGID(),
|
2009-06-28 10:37:15 +00:00
|
|
|
_requestGroup->getFirstFilePath().c_str());
|
2009-05-07 03:49:27 +00:00
|
|
|
|
2008-11-26 15:22:54 +00:00
|
|
|
poolConnection();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2009-05-07 03:49:27 +00:00
|
|
|
|
2008-06-24 14:31:23 +00:00
|
|
|
_requestGroup->shouldCancelDownloadForSafety();
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->initPieceStorage();
|
2008-06-24 14:31:23 +00:00
|
|
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
|
|
|
|
2009-06-28 10:37:15 +00:00
|
|
|
if(getDownloadContext()->knowsTotalLength()) {
|
2008-11-26 15:22:54 +00:00
|
|
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
|
|
|
poolConnection();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-08-27 15:00:00 +00:00
|
|
|
return true;
|
2008-06-24 14:31:23 +00:00
|
|
|
} else {
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->adjustFilename
|
|
|
|
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
|
|
|
|
(_requestGroup->getDownloadContext(),
|
|
|
|
SharedHandle<PieceStorage>(),
|
2009-05-08 16:41:21 +00:00
|
|
|
getOption().get())));
|
2008-06-24 14:31:23 +00:00
|
|
|
_requestGroup->initPieceStorage();
|
2007-05-20 13:51:52 +00:00
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_DRY_RUN)) {
|
2009-05-07 03:49:27 +00:00
|
|
|
onDryRunFileFound();
|
2009-03-08 10:20:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-05-08 16:41:21 +00:00
|
|
|
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
|
2009-05-07 03:49:27 +00:00
|
|
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
|
|
|
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
2008-06-24 14:31:23 +00:00
|
|
|
|
2009-05-07 03:49:27 +00:00
|
|
|
logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
|
|
|
|
_requestGroup->getGID(),
|
2009-06-28 10:37:15 +00:00
|
|
|
_requestGroup->getFirstFilePath().c_str());
|
2009-05-07 03:49:27 +00:00
|
|
|
|
2008-05-10 05:14:35 +00:00
|
|
|
poolConnection();
|
2008-06-24 14:31:23 +00:00
|
|
|
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
return false;
|
2007-05-20 13:51:52 +00:00
|
|
|
}
|
2007-11-10 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Don't connect server before checking file integrity at startup,
if
filesize and output file path are known.
* src/AbstractCommand.cc
* src/StreamFileAllocationEntry.cc
* src/Metalink2RequestGroup.cc
* src/RequestGroup.{h, cc}
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
Added DownloadFailureException. If it is thrown, RequestGroup
should
halt.
* src/AbstractCommand.cc
* src/DownloadFailureException.h
* src/RequestGroup.cc
Catch RecoverableException, instead of DlAbortEx.
* src/RequestGroupMan.cc
* src/FillRequestGroupCommand.cc
* src/MetaFileUtil.cc
* src/IteratableChunkChecksumValidator.cc
Now first parameter of MSG_DOWNLOAD_ABORTED is
gid(RequestGroup::
getGID())
* src/CheckIntegrityCommand.cc
* src/message.h
Print gid instead of idx.
* src/RequestGroupMan.cc
Removed exception throwers declaration.
* src/DirectDiskAdaptor.{h, cc}
* src/SocketCore.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpConnection.{h, cc}
* src/HttpResponse.{h, cc}
* src/DiskAdaptor.{h, cc}
* src/CopyDiskAdaptor.{h, cc}
* src/MultiDiskAdaptor.{h, cc}
* src/HttpHeaderProcessor.{h, cc}
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/Util.{h, cc}
* test/UtilTest.cc
* src/DefaultDiskWriter.{h, cc}
* src/FtpConnection.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Removed duplicate code.
* src/StreamCheckIntegrityEntry.cc
Removed unnecessary include.
* src/DiskWriter.h
Included Exception.h
* src/option_processing.cc
Included 2 files and added doc
* src/TrackerWatcherCommand.cc
* src/SocketCore.cc (writeData): Fixed send error with GnuTLS.
2007-11-09 18:01:12 +00:00
|
|
|
_requestGroup->loadAndOpenFile(infoFile);
|
2007-12-01 04:56:10 +00:00
|
|
|
|
2008-06-28 08:54:54 +00:00
|
|
|
prepareForNextAction(this);
|
|
|
|
|
2007-12-01 04:56:10 +00:00
|
|
|
disableReadCheckSocket();
|
2008-06-24 14:31:23 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2008-05-09 14:44:28 +00:00
|
|
|
|
2008-06-24 14:31:23 +00:00
|
|
|
bool FtpNegotiationCommand::recvSize() {
|
|
|
|
uint64_t size = 0;
|
|
|
|
unsigned int status = ftp->receiveSizeResponse(size);
|
|
|
|
if(status == 0) {
|
2007-05-20 13:51:52 +00:00
|
|
|
return false;
|
2008-06-24 14:31:23 +00:00
|
|
|
}
|
|
|
|
if(status == 213) {
|
|
|
|
|
|
|
|
if(size > INT64_MAX) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX
|
2009-10-22 15:09:00 +00:00
|
|
|
(StringFormat(EX_TOO_LARGE_FILE, util::uitos(size, true).c_str()).str());
|
2008-06-24 14:31:23 +00:00
|
|
|
}
|
|
|
|
if(_requestGroup->getPieceStorage().isNull()) {
|
|
|
|
|
|
|
|
sequence = SEQ_FILE_PREPARATION;
|
|
|
|
return onFileSizeDetermined(size);
|
|
|
|
|
|
|
|
} else {
|
2009-06-23 15:35:45 +00:00
|
|
|
_requestGroup->validateTotalLength(_fileEntry->getLength(), size);
|
2008-06-24 14:31:23 +00:00
|
|
|
}
|
|
|
|
|
2007-05-20 13:51:52 +00:00
|
|
|
} else {
|
2008-06-24 14:31:23 +00:00
|
|
|
|
|
|
|
logger->info("CUID#%d - The remote FTP Server doesn't recognize SIZE command. Continue.", cuid);
|
|
|
|
|
2008-06-28 08:54:54 +00:00
|
|
|
// Even if one of the other servers waiting in the queue supports SIZE
|
|
|
|
// command, resuming and segmented downloading are disabled when the first
|
|
|
|
// contacted FTP server doesn't support it.
|
|
|
|
if(_requestGroup->getPieceStorage().isNull()) {
|
2009-06-28 10:37:15 +00:00
|
|
|
getDownloadContext()->markTotalLengthIsUnknown();
|
2008-06-28 08:54:54 +00:00
|
|
|
return onFileSizeDetermined(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
// TODO Skipping RequestGroup::validateTotalLength(0) here will allow
|
|
|
|
// wrong file to be downloaded if user-specified URL is wrong.
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_FTP_PASV)) {
|
2006-02-21 12:28:42 +00:00
|
|
|
sequence = SEQ_SEND_PASV;
|
|
|
|
} else {
|
2008-09-13 16:32:47 +00:00
|
|
|
sequence = SEQ_PREPARE_SERVER_SOCKET;
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2008-02-19 13:36:39 +00:00
|
|
|
void FtpNegotiationCommand::afterFileAllocation()
|
|
|
|
{
|
|
|
|
setReadCheckSocket(socket);
|
|
|
|
}
|
|
|
|
|
2008-09-13 16:32:47 +00:00
|
|
|
bool FtpNegotiationCommand::prepareServerSocket()
|
|
|
|
{
|
|
|
|
serverSocket = ftp->createServerSocket();
|
|
|
|
sequence = SEQ_SEND_PORT;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-02-21 12:28:42 +00:00
|
|
|
bool FtpNegotiationCommand::sendPort() {
|
2008-02-19 13:36:39 +00:00
|
|
|
afterFileAllocation();
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendPort(serverSocket)) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_PORT;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvPort() {
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 200) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
sequence = SEQ_SEND_REST;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendPasv() {
|
2008-02-19 13:36:39 +00:00
|
|
|
afterFileAllocation();
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendPasv()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_PASV;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvPasv() {
|
2008-03-09 12:24:01 +00:00
|
|
|
std::pair<std::string, uint16_t> dest;
|
|
|
|
unsigned int status = ftp->receivePasvResponse(dest);
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if(status != 227) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
// make a data connection to the server.
|
2006-04-17 16:17:20 +00:00
|
|
|
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
|
|
|
dest.first.c_str(),
|
|
|
|
dest.second);
|
2008-04-20 00:50:22 +00:00
|
|
|
dataSocket.reset(new SocketCore());
|
2006-02-21 12:28:42 +00:00
|
|
|
dataSocket->establishConnection(dest.first, dest.second);
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
disableReadCheckSocket();
|
2006-02-21 12:28:42 +00:00
|
|
|
setWriteCheckSocket(dataSocket);
|
|
|
|
|
|
|
|
sequence = SEQ_SEND_REST_PASV;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
bool FtpNegotiationCommand::sendRestPasv(const SegmentHandle& segment) {
|
2008-09-13 16:32:47 +00:00
|
|
|
//dataSocket->setBlockingMode();
|
2006-02-21 12:28:42 +00:00
|
|
|
setReadCheckSocket(socket);
|
2006-07-19 17:07:45 +00:00
|
|
|
disableWriteCheckSocket();
|
2006-02-21 12:28:42 +00:00
|
|
|
return sendRest(segment);
|
|
|
|
}
|
|
|
|
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
bool FtpNegotiationCommand::sendRest(const SegmentHandle& segment) {
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendRest(segment)) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_REST;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-06-24 14:43:27 +00:00
|
|
|
bool FtpNegotiationCommand::recvRest(const SharedHandle<Segment>& segment) {
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-24 14:43:27 +00:00
|
|
|
// If we recieve negative response and requested file position is not 0,
|
|
|
|
// then throw exception here.
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status != 350) {
|
2008-06-24 14:43:27 +00:00
|
|
|
if(!segment.isNull() && segment->getPositionToWrite() != 0) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX("FTP server doesn't support resuming.");
|
2008-06-24 14:43:27 +00:00
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
sequence = SEQ_SEND_RETR;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::sendRetr() {
|
2008-09-13 16:32:47 +00:00
|
|
|
if(ftp->sendRetr()) {
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
sequence = SEQ_RECV_RETR;
|
|
|
|
} else {
|
|
|
|
setWriteCheckSocket(socket);
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpNegotiationCommand::recvRetr() {
|
2008-06-28 08:54:54 +00:00
|
|
|
unsigned int status = ftp->receiveResponse();
|
2006-02-21 12:28:42 +00:00
|
|
|
if(status == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-07 17:21:09 +00:00
|
|
|
if(status != 150 && status != 125) {
|
2008-09-10 14:56:44 +00:00
|
|
|
_requestGroup->increaseAndValidateFileNotFoundCount();
|
2009-01-12 12:27:34 +00:00
|
|
|
if (status == 550)
|
2009-06-29 08:42:58 +00:00
|
|
|
throw DL_ABORT_EX2(MSG_RESOURCE_NOT_FOUND,
|
|
|
|
downloadresultcode::RESOURCE_NOT_FOUND);
|
2009-01-12 12:27:34 +00:00
|
|
|
else
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_FTP_PASV)) {
|
2008-02-19 13:36:39 +00:00
|
|
|
sequence = SEQ_NEGOTIATION_COMPLETED;
|
|
|
|
return false;
|
|
|
|
} else {
|
|
|
|
disableReadCheckSocket();
|
|
|
|
setReadCheckSocket(serverSocket);
|
|
|
|
sequence = SEQ_WAIT_CONNECTION;
|
|
|
|
return false;
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2008-02-19 13:36:39 +00:00
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2008-02-19 13:36:39 +00:00
|
|
|
bool FtpNegotiationCommand::waitConnection()
|
|
|
|
{
|
|
|
|
disableReadCheckSocket();
|
|
|
|
setReadCheckSocket(socket);
|
2008-04-20 00:50:22 +00:00
|
|
|
dataSocket.reset(serverSocket->acceptConnection());
|
2009-03-28 13:19:47 +00:00
|
|
|
dataSocket->setNonBlockingMode();
|
2008-02-19 13:36:39 +00:00
|
|
|
sequence = SEQ_NEGOTIATION_COMPLETED;
|
2006-02-21 12:28:42 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-03-15 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To handle Segment as SegmentHandle:
* src/AbstractCommand.cc (execute): Rewritten.
* src/SegmentMan.h: Segment -> SegmentHandle
Introducded HttpResponse class, HttpRequest class to improve
code
extensiveness and make it clear:
* src/HttpDownloadCommand.cc: transfer encoders are now managed
by
HttpResponse class.
* src/HttpRequest.h, src/HttpRequest.cc: New class.
* src/HttpResponse.h, src/HttpResponse.cc: New class.
* src/HttpConnection.cc: Contruction of http request were moved
to
HttpRequest class.
* src/HttpResponseCommand.h, src/HttpResponseCommand.cc:
Refactored.
* src/HttpRequestCommand.cc (executeInternal): Rewritten.
* src/HttpAuthConfig.h: New class.
* src/Range.h: New class.
To make FtpTunnel{Request, Response}Command and
HttpProxy{Request, Response}Command derived from
AbstractProxy{Request, Response}Command:
* src/FtpTunnelResponseCommand.h,
src/FtpTunnelResponseCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/FtpTunnelRequestCommand.h, src/FtpTunnelRequestCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/HttpProxyRequestCommand.h, src/HttpProxyRequestCommand.cc:
Derived from AbstractProxyRequestCommand class.
* src/HttpProxyResponseCommand.h,
src/HttpProxyResponseCommand.cc:
Derived from AbstractProxyResponseCommand class.
* src/AbstractProxyRequestCommand.h,
src/AbstractProxyRequestCommand.cc
: New class.
* src/AbstractProxyResponseCommand.h,
src/AbstractProxyResponseCommand.cc: New class.
To add netrc support:
* src/Netrc.h, src/Netrc.cc: New class.
* src/Util.h, src/Util.cc (split): New function.
* src/HttpHeader.cc (getRange): Fixed so that it inspects
"Content-Range" header instead of "Range" header.
* src/HttpHeader.h
(getStatus): Removed.
(setStatus): Removed.
* src/Segment.h
(getPositionToWrite): New function.
2007-03-15 15:07:18 +00:00
|
|
|
bool FtpNegotiationCommand::processSequence(const SegmentHandle& segment) {
|
2006-02-21 12:28:42 +00:00
|
|
|
bool doNextSequence = true;
|
|
|
|
switch(sequence) {
|
|
|
|
case SEQ_RECV_GREETING:
|
|
|
|
return recvGreeting();
|
|
|
|
case SEQ_SEND_USER:
|
|
|
|
return sendUser();
|
|
|
|
case SEQ_RECV_USER:
|
|
|
|
return recvUser();
|
|
|
|
case SEQ_SEND_PASS:
|
|
|
|
return sendPass();
|
|
|
|
case SEQ_RECV_PASS:
|
|
|
|
return recvPass();
|
|
|
|
case SEQ_SEND_TYPE:
|
|
|
|
return sendType();
|
|
|
|
case SEQ_RECV_TYPE:
|
|
|
|
return recvType();
|
2008-09-24 17:01:57 +00:00
|
|
|
case SEQ_SEND_PWD:
|
|
|
|
return sendPwd();
|
|
|
|
case SEQ_RECV_PWD:
|
|
|
|
return recvPwd();
|
2006-02-21 12:28:42 +00:00
|
|
|
case SEQ_SEND_CWD:
|
|
|
|
return sendCwd();
|
|
|
|
case SEQ_RECV_CWD:
|
|
|
|
return recvCwd();
|
2008-09-08 13:06:44 +00:00
|
|
|
case SEQ_SEND_MDTM:
|
|
|
|
return sendMdtm();
|
|
|
|
case SEQ_RECV_MDTM:
|
|
|
|
return recvMdtm();
|
2006-02-21 12:28:42 +00:00
|
|
|
case SEQ_SEND_SIZE:
|
|
|
|
return sendSize();
|
|
|
|
case SEQ_RECV_SIZE:
|
|
|
|
return recvSize();
|
2008-09-13 16:32:47 +00:00
|
|
|
case SEQ_PREPARE_SERVER_SOCKET:
|
|
|
|
return prepareServerSocket();
|
2006-02-21 12:28:42 +00:00
|
|
|
case SEQ_SEND_PORT:
|
|
|
|
return sendPort();
|
|
|
|
case SEQ_RECV_PORT:
|
|
|
|
return recvPort();
|
|
|
|
case SEQ_SEND_PASV:
|
|
|
|
return sendPasv();
|
|
|
|
case SEQ_RECV_PASV:
|
|
|
|
return recvPasv();
|
|
|
|
case SEQ_SEND_REST_PASV:
|
|
|
|
return sendRestPasv(segment);
|
|
|
|
case SEQ_SEND_REST:
|
|
|
|
return sendRest(segment);
|
|
|
|
case SEQ_RECV_REST:
|
2008-06-24 14:43:27 +00:00
|
|
|
return recvRest(segment);
|
2006-02-21 12:28:42 +00:00
|
|
|
case SEQ_SEND_RETR:
|
|
|
|
return sendRetr();
|
|
|
|
case SEQ_RECV_RETR:
|
|
|
|
return recvRetr();
|
2008-02-19 13:36:39 +00:00
|
|
|
case SEQ_WAIT_CONNECTION:
|
|
|
|
return waitConnection();
|
2006-02-21 12:28:42 +00:00
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
return doNextSequence;
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
2008-05-10 05:14:35 +00:00
|
|
|
void FtpNegotiationCommand::poolConnection() const
|
|
|
|
{
|
2009-05-08 16:41:21 +00:00
|
|
|
if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
|
2008-09-24 17:01:57 +00:00
|
|
|
std::map<std::string, std::string> options;
|
|
|
|
options["baseWorkingDir"] = ftp->getBaseWorkingDir();
|
2008-11-05 12:30:22 +00:00
|
|
|
e->poolSocket(req, isProxyDefined(), socket, options);
|
2008-05-10 05:14:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-07 03:49:27 +00:00
|
|
|
void FtpNegotiationCommand::onDryRunFileFound()
|
|
|
|
{
|
|
|
|
_requestGroup->getPieceStorage()->markAllPiecesDone();
|
|
|
|
poolConnection();
|
|
|
|
sequence = SEQ_HEAD_OK;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|