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"
|
2007-01-08 00:13:25 +00:00
|
|
|
#include "Util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Option.h"
|
|
|
|
#include "Logger.h"
|
|
|
|
#include "Segment.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "SingleFileDownloadContext.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"
|
2007-12-12 13:53:33 +00:00
|
|
|
#include "ServerHost.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"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
FtpNegotiationCommand::FtpNegotiationCommand(int32_t cuid,
|
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
|
|
|
const RequestHandle& req,
|
2007-05-20 13:51:52 +00:00
|
|
|
RequestGroup* requestGroup,
|
2006-07-19 17:07:45 +00:00
|
|
|
DownloadEngine* e,
|
2008-05-09 14:44:28 +00:00
|
|
|
const SocketHandle& s,
|
2008-09-24 17:01:57 +00:00
|
|
|
Seq seq,
|
|
|
|
const std::string& baseWorkingDir):
|
2008-05-09 14:44:28 +00:00
|
|
|
AbstractCommand(cuid, req, requestGroup, e, s), sequence(seq),
|
2008-11-03 10:06:25 +00:00
|
|
|
ftp(new FtpConnection(cuid, socket, req,
|
|
|
|
e->getAuthConfigFactory()->createAuthConfig(req),
|
|
|
|
e->option))
|
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) {
|
|
|
|
setTimeout(e->option->getAsInt(PREF_CONNECT_TIMEOUT));
|
|
|
|
}
|
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 =
|
2008-05-09 14:44:28 +00:00
|
|
|
new FtpDownloadCommand(cuid, req, _requestGroup, ftp, e, dataSocket, socket);
|
2007-01-23 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add chunk checksum validation:
* src/MetalinkEntry.h
(MetalinkChunkChecksum.h): New include.
(chunkChecksum): New variable.
* src/Request.h
(method): New variable.
(setMethod): New function.
(getMethod): New function.
(METHOD_GET): New static constant.
(METHOD_HEAD): New static constant.
* src/Xml2MetalinkProcessor.h
(getPieceHash): New function.
* src/PieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/FileAllocator.h
(NullFileAllocationMonitor.h): New include.
(FileAllocator): Initialize fileAllocationMonitor with new
NullFileAllocationMonitor().
* src/MultiDiskAdaptor.h
(messageDigest.h): Remove include.
(ctx): Removed.
(hashUpdate): Added ctx.
(MultiDiskAdaptor): Removed ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/UrlRequestInfo.h
(HeadResult): New class.
(digestAlgo): New variable.
(chunkChecksumLength): New variable.
(chunkChecksums): New variable.
(getHeadResult): New function.
(UrlRequestInfo): Added digestAlgo, chunkChecksumLength.
(setDigestAlgo): New function.
(setChunkChecksumLength): New function.
(setChunkChecksums): New function.
* src/DefaultPieceStorage.cc
(DiskAdaptorWriter.h): New include.
(ChunkChecksumValidator.h): New include.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/DefaultBtContext.h
(getPieceHashes): New function.
* src/TorrentRequestInfo.cc
(execute): Try to validate chunk checksum if file already exists
and
.aria2 file doesn't there and user allows aria2 to overwrite it.
* src/messageDigest.h
(~MessageDigestContext): Added digestFree().
* src/MetalinkRequestInfo.cc
(execute): Set digestAlgo, chunkChecksum, chunkChecksums to
reqInfo.
* src/DiskAdaptor.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/DownloadCommand.h
(PeerStat.h): New include.
(maxDownloadSpeedLimit): New variable.
(startupIdleTime): New variable.
(lowestDownloadSpeedLimit): New variable.
(peerStat): New variable.
(setMaxDownloadSpeedLimit): New function.
(setStartupIdleTime): New function.
(setLowestDownloadSPeedLimit): New function.
* src/BtContext.h
(getPieceHashes): New function.
* src/main.cc
(main): Set PREF_REALTIME_CHUNK_CHECKSUM and
PREF_CHECK_INTEGRITY
option to true for testing purpose.
* src/BtPieceMessage.cc
(checkPieceHash): Use messageDigest
* src/DownloadEngine.cc
(SetDescriptor): Removed.
(AccumulateActiveCommand): Removed.
(waitData): Rewritten.
(updateFdSet): Rewritten.
* src/MultiDiskAdaptor.cc
(hashUpdate): Added ctx.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/BitfieldMan.h
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/ByteArrayDiskWriter.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ConsoleDownloadEngine.cc
(calculateStatistics): If nspeed < 0 then set nspeed to 0.
* src/DiskWriter.h
(messageDigest.h): New include.
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/ChunkChecksumValidator.h: New class.
* src/DiskAdaptorWriter.h: New class.
* src/prefs.h
(PREF_REALTIME_CHUNK_CHECKSUM): New definition.
(PREF_CHECK_INTEGRITY): New definition.
* src/HttpResponseCommand.cc
(handleDefaultEncoding): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
(handleOtherEncoding):
Added the call to
e->segmentMan->shouldCancelDownloadForSafety().
(createHttpDownloadCommand): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
* src/SegmentMan.h
(getSegmentEntryByIndex): New function.
(getSegmentEntryByCuid): New function.
(getSegmentEntryIteratorByCuid): New function.
(diskWriter): DiskWriter -> DiskWriterHandle
(pieceHashes): New variable.
(chunkHashLength): New variable.
(digestAlgo): New variable.
(FindPeerStat): Removed.
(getPeerStat): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(tryChunkChecksumValidation): New function.
(isChunkChecksumValidationReady): New function.
* src/BitfieldMan.cc
(BitfieldMan): Initialized bitfieldLength, blocks to 0.
(BitfieldMan): Initialized blockLength, totalLength,
bitfieldLength,
blocks to 0.
(isBitRangeSet): New function.
(unsetBitRange): New function.
* src/FtpNegotiateCommand.cc
(executeInternal): Set maxDownloadSpeedLimit,
startupIdleTime, lowestDownloadSpeedLimit to command.
(recvSize): Added method "HEAD" handling.
Removed the call to
e->segmentMan->shouldCancelDownloadForSafety().
* src/AbstractSingleDiskAdaptor.cc
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/AbstractSingleDiskAdaptor.h
(sha1Sum): Renamed as messageDigest.
(messageDigest): New function.
* src/Util.h
(indexRange): New function.
* src/MetalinkEntry.cc
(MetalinkEntry): Initialized chunkChecksum to 0.
* src/ShaVisitor.cc
(~ShaVisitor): Removed the call to ctx.digestFree().
* src/SegmentMan.cc
(ChunkChecksumValidator.h): New include.
(SegmentMan): Initialized chunkHashLength to 0. Initialized
digestAlgo
to DIGEST_ALGO_SHA1.
(~SegmentMan): Removed diskWriter.
(FindSegmentEntryByIndex): Removed.
(FindSegmentEntryByCuid): Removed.
(checkoutSegment): Rewritten.
(findSlowerSegmentEntry): Rewritten.
(getSegment): Rewritten.
(updateSegment): Rewritten.
(completeSegment): Rewritten.
(markAllPiecesDone): New function.
(checkIntegrity): New function.
(isChunkChecksumValidationReady): New function.
(tryChunkChecksumValidation): New function.
* src/Xml2MetalinkProcessor.cc
(getEntry): Get size and set it to entry.
Get chunk checksum and set it to entry.
(getPieceHash): New function.
* src/Util.cc
(sha1Sum): Removed ctx.digestFree()
(fileChecksum): Removed ctx.digestFree()
(indexRange): New function.
* src/Request.cc
(METHOD_GET): New variable.
(METHOD_HEAD): New variable.
(Request): Added method.
* src/UrlRequestInfo.cc
(FatalException.h): New include.
(message.h): New include.
(operator<<): Added operator<< for class HeadResult.
(getHeadResult): New function.
(execute): Get filename and size in separate download engine.
* src/ChunkChecksumValidator.cc: New class.
* src/DownloadCommand.cc:
(DownloadCommand): Added peerStat.
(executeInternal): Use maxDownloadSpeedLimit member instead of
getting
the value from Option.
The buffer size is now 16KB.
Use peerStat member instead of getting it from SegmentMan.
Use startupIdleTime member instead of gettingit from Option.
Added chunk checksum validation.
* src/AbstractDiskWriter.cc
(AbstractDiskWriter): Removed ctx.
(~AbstractDiskWriter): Removed ctx.digestFree()
(writeDataInternal): Returns the return value of write.
(readDataInternal): Returns the return value of read.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/AbstractDiwkWriter.h
(messageDigest.h): Removed include.
(ctx): Removed.
(sha1Sum): Renamed as messageDigest
(messageDigest): New function.
* src/DefaultPieceStorage.h
(markAllPiecesDone): New function.
(checkIntegrity): New function.
* src/NullFileAllocationMonitor.h: New class.
2007-01-24 15:55:34 +00:00
|
|
|
command->setMaxDownloadSpeedLimit(e->option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT));
|
|
|
|
command->setStartupIdleTime(e->option->getAsInt(PREF_STARTUP_IDLE_TIME));
|
|
|
|
command->setLowestDownloadSpeedLimit(e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT));
|
2007-12-12 13:53:33 +00:00
|
|
|
if(!_requestGroup->isSingleHostMultiConnectionEnabled()) {
|
2008-08-03 11:16:15 +00:00
|
|
|
SharedHandle<ServerHost> sv =
|
|
|
|
_requestGroup->searchServerHost(req->getHost());
|
|
|
|
if(!sv.isNull()) {
|
|
|
|
_requestGroup->removeURIWhoseHostnameIs(sv->getHostname());
|
|
|
|
}
|
2007-12-12 13:53:33 +00:00
|
|
|
}
|
2009-01-06 13:13:42 +00:00
|
|
|
_requestGroup->tuneDownloadCommand(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) {
|
2008-05-18 10:25:41 +00:00
|
|
|
if(e->option->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;
|
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() {
|
2008-09-14 14:31:19 +00:00
|
|
|
checkIfConnectionEstablished(socket);
|
2008-09-09 12:13:08 +00:00
|
|
|
setTimeout(e->option->getAsInt(PREF_TIMEOUT));
|
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) {
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(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:
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(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) {
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(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) {
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(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) {
|
|
|
|
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
|
|
|
|
}
|
|
|
|
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();
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2008-09-08 13:06:44 +00:00
|
|
|
if(e->option->getAsBool(PREF_REMOTE_TIME)) {
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
SingleFileDownloadContextHandle dctx =
|
|
|
|
dynamic_pointer_cast<SingleFileDownloadContext>(_requestGroup->getDownloadContext());
|
|
|
|
dctx->setTotalLength(totalLength);
|
|
|
|
dctx->setFilename(Util::urldecode(req->getFile()));
|
|
|
|
_requestGroup->preDownloadProcessing();
|
|
|
|
if(e->_requestGroupMan->isSameFileBeingDownloaded(_requestGroup)) {
|
|
|
|
throw DownloadFailureException
|
|
|
|
(StringFormat(EX_DUPLICATE_FILE_DOWNLOAD,
|
|
|
|
_requestGroup->getFilePath().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
|
|
|
|
2008-11-26 15:22:54 +00:00
|
|
|
if(e->option->getAsBool(PREF_FTP_PASV)) {
|
|
|
|
sequence = SEQ_SEND_PASV;
|
|
|
|
} else {
|
|
|
|
sequence = SEQ_PREPARE_SERVER_SOCKET;
|
|
|
|
}
|
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->initPieceStorage();
|
2008-11-26 15:22:54 +00:00
|
|
|
if(dctx->knowsTotalLength() &&
|
|
|
|
_requestGroup->downloadFinishedByFileLength()) {
|
|
|
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
|
|
|
|
|
|
|
poolConnection();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2008-06-24 14:31:23 +00:00
|
|
|
_requestGroup->shouldCancelDownloadForSafety();
|
|
|
|
_requestGroup->getPieceStorage()->getDiskAdaptor()->initAndOpenFile();
|
|
|
|
|
2008-11-26 15:22:54 +00:00
|
|
|
if(dctx->knowsTotalLength()) {
|
|
|
|
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 {
|
|
|
|
_requestGroup->initPieceStorage();
|
2007-05-20 13:51:52 +00:00
|
|
|
|
2008-04-20 00:50:22 +00:00
|
|
|
BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
|
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()) {
|
|
|
|
sequence = SEQ_DOWNLOAD_ALREADY_COMPLETED;
|
2008-06-24 14:31:23 +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) {
|
|
|
|
throw DlAbortEx
|
|
|
|
(StringFormat(EX_TOO_LARGE_FILE, Util::uitos(size, true).c_str()).str());
|
|
|
|
}
|
|
|
|
if(_requestGroup->getPieceStorage().isNull()) {
|
|
|
|
|
|
|
|
sequence = SEQ_FILE_PREPARATION;
|
|
|
|
return onFileSizeDetermined(size);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
_requestGroup->validateTotalLength(size);
|
|
|
|
}
|
|
|
|
|
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()) {
|
2008-11-26 15:22:54 +00:00
|
|
|
SingleFileDownloadContextHandle dctx =
|
|
|
|
dynamic_pointer_cast<SingleFileDownloadContext>
|
|
|
|
(_requestGroup->getDownloadContext());
|
|
|
|
dctx->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
|
|
|
}
|
2008-05-18 10:25:41 +00:00
|
|
|
if(e->option->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) {
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(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) {
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(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) {
|
|
|
|
throw DlAbortEx("FTP server doesn't support resuming.");
|
|
|
|
}
|
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();
|
2008-04-27 02:22:14 +00:00
|
|
|
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
2008-02-19 13:36:39 +00:00
|
|
|
if(e->option->getAsBool(PREF_FTP_PASV)) {
|
|
|
|
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());
|
2008-09-13 16:32:47 +00:00
|
|
|
//dataSocket->setBlockingMode();
|
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
|
|
|
|
{
|
2008-11-05 12:30:22 +00:00
|
|
|
if(e->option->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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|