2007-12-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

Forced download abort when received negative response from 
http/ftp
	server.
	* src/HttpResponseCommand.cc
	* src/FtpNegotiationCommand.cc
	* src/HttpResponse.cc
	* src/FtpConnection.cc
pull/1/head
Tatsuhiro Tsujikawa 2007-12-04 11:38:06 +00:00
parent 936ce09b83
commit ed3ebb7c22
5 changed files with 24 additions and 25 deletions

View File

@ -1,3 +1,12 @@
2007-12-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Forced download abort when received negative response from http/ftp
server.
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/HttpResponse.cc
* src/FtpConnection.cc
2007-12-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added XML2SAXMetalinkProcessor class, which is a lot faster than

View File

@ -40,6 +40,7 @@
#include "AuthConfigFactory.h"
#include "AuthConfig.h"
#include "DlRetryEx.h"
#include "DlAbortEx.h"
FtpConnection::FtpConnection(int32_t cuid, const SocketHandle& socket,
const RequestHandle req, const Option* op)
@ -184,7 +185,7 @@ bool FtpConnection::bulkReceiveResponse(pair<int32_t, string>& response)
if(strbuf.size() >= 4) {
status = getStatus(strbuf);
if(status == 0) {
throw new DlRetryEx(EX_INVALID_RESPONSE);
throw new DlAbortEx(EX_INVALID_RESPONSE);
}
} else {
return false;

View File

@ -39,7 +39,6 @@
#include "PieceStorage.h"
#include "FtpDownloadCommand.h"
#include "DlAbortEx.h"
#include "DlRetryEx.h"
#include "message.h"
#include "prefs.h"
#include "Util.h"
@ -101,7 +100,7 @@ bool FtpNegotiationCommand::recvGreeting() {
return false;
}
if(status != 220) {
throw new DlRetryEx(EX_CONNECTION_FAILED);
throw new DlAbortEx(EX_CONNECTION_FAILED);
}
sequence = SEQ_SEND_USER;
@ -126,7 +125,7 @@ bool FtpNegotiationCommand::recvUser() {
sequence = SEQ_SEND_PASS;
break;
default:
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
return true;
}
@ -143,7 +142,7 @@ bool FtpNegotiationCommand::recvPass() {
return false;
}
if(status != 230) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
sequence = SEQ_SEND_TYPE;
return true;
@ -161,7 +160,7 @@ bool FtpNegotiationCommand::recvType() {
return false;
}
if(status != 200) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
sequence = SEQ_SEND_CWD;
return true;
@ -179,7 +178,7 @@ bool FtpNegotiationCommand::recvCwd() {
return false;
}
if(status != 250) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
sequence = SEQ_SEND_SIZE;
return true;
@ -197,16 +196,8 @@ bool FtpNegotiationCommand::recvSize() {
if(status == 0) {
return false;
}
if(status == 550) {
// If file is not found in a server, then SIZE command fails.
// TODO There exist ftp servers that don't support SIZE command...
// the message "MSG_RESOURCE_NOT_FOUND" may be a little bit confusing.
// Nevertheless, curretly aria2 doesn't support such ftp servers,
// I don't care that.
throw new DlAbortEx(MSG_RESOURCE_NOT_FOUND);
}
if(status != 213) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
if(size == INT64_MAX || size < 0) {
throw new DlAbortEx(EX_TOO_LARGE_FILE, Util::llitos(size, true).c_str());
@ -267,7 +258,7 @@ bool FtpNegotiationCommand::recvPort() {
return false;
}
if(status != 200) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
sequence = SEQ_SEND_REST;
return true;
@ -286,7 +277,7 @@ bool FtpNegotiationCommand::recvPasv() {
return false;
}
if(status != 227) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
// make a data connection to the server.
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
@ -321,7 +312,7 @@ bool FtpNegotiationCommand::recvRest() {
}
// TODO if we recieve negative response, then we set _requestGroup->getSegmentMan()->splittable = false, and continue.
if(status != 350) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
sequence = SEQ_SEND_RETR;
return true;
@ -339,7 +330,7 @@ bool FtpNegotiationCommand::recvRetr() {
return false;
}
if(status != 150 && status != 125) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
if(e->option->get(PREF_FTP_PASV) != V_TRUE) {
assert(serverSocket->getSockfd() != -1);

View File

@ -37,7 +37,6 @@
#include "Util.h"
#include "message.h"
#include "DlAbortEx.h"
#include "DlRetryEx.h"
void HttpResponse::validateResponse() const
{
@ -48,11 +47,11 @@ void HttpResponse::validateResponse() const
throw new DlAbortEx(MSG_RESOURCE_NOT_FOUND);
}
if(status >= 400) {
throw new DlRetryEx(EX_BAD_STATUS, status);
throw new DlAbortEx(EX_BAD_STATUS, status);
}
if(status >= 300) {
if(!httpHeader->defined("Location")) {
throw new DlRetryEx(EX_LOCATION_HEADER_REQUIRED,
throw new DlAbortEx(EX_LOCATION_HEADER_REQUIRED,
status);
}
} else {
@ -60,7 +59,7 @@ void HttpResponse::validateResponse() const
// compare the received range against the requested range
RangeHandle responseRange = httpHeader->getRange();
if(!httpRequest->isRangeSatisfied(responseRange)) {
throw new DlRetryEx(EX_INVALID_RANGE_HEADER,
throw new DlAbortEx(EX_INVALID_RANGE_HEADER,
Util::llitos(httpRequest->getStartByte(), true).c_str(),
Util::llitos(httpRequest->getEndByte(), true).c_str(),
Util::llitos(httpRequest->getEntityLength(), true).c_str(),

View File

@ -38,7 +38,6 @@
#include "HttpConnection.h"
#include "SegmentMan.h"
#include "DlAbortEx.h"
#include "DlRetryEx.h"
#include "HttpDownloadCommand.h"
#include "message.h"
#include "Util.h"