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> 2007-12-04 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added XML2SAXMetalinkProcessor class, which is a lot faster than Added XML2SAXMetalinkProcessor class, which is a lot faster than

View File

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

View File

@ -39,7 +39,6 @@
#include "PieceStorage.h" #include "PieceStorage.h"
#include "FtpDownloadCommand.h" #include "FtpDownloadCommand.h"
#include "DlAbortEx.h" #include "DlAbortEx.h"
#include "DlRetryEx.h"
#include "message.h" #include "message.h"
#include "prefs.h" #include "prefs.h"
#include "Util.h" #include "Util.h"
@ -101,7 +100,7 @@ bool FtpNegotiationCommand::recvGreeting() {
return false; return false;
} }
if(status != 220) { if(status != 220) {
throw new DlRetryEx(EX_CONNECTION_FAILED); throw new DlAbortEx(EX_CONNECTION_FAILED);
} }
sequence = SEQ_SEND_USER; sequence = SEQ_SEND_USER;
@ -126,7 +125,7 @@ bool FtpNegotiationCommand::recvUser() {
sequence = SEQ_SEND_PASS; sequence = SEQ_SEND_PASS;
break; break;
default: default:
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
return true; return true;
} }
@ -143,7 +142,7 @@ bool FtpNegotiationCommand::recvPass() {
return false; return false;
} }
if(status != 230) { if(status != 230) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_TYPE; sequence = SEQ_SEND_TYPE;
return true; return true;
@ -161,7 +160,7 @@ bool FtpNegotiationCommand::recvType() {
return false; return false;
} }
if(status != 200) { if(status != 200) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_CWD; sequence = SEQ_SEND_CWD;
return true; return true;
@ -179,7 +178,7 @@ bool FtpNegotiationCommand::recvCwd() {
return false; return false;
} }
if(status != 250) { if(status != 250) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_SIZE; sequence = SEQ_SEND_SIZE;
return true; return true;
@ -197,16 +196,8 @@ bool FtpNegotiationCommand::recvSize() {
if(status == 0) { if(status == 0) {
return false; 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) { if(status != 213) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
if(size == INT64_MAX || size < 0) { if(size == INT64_MAX || size < 0) {
throw new DlAbortEx(EX_TOO_LARGE_FILE, Util::llitos(size, true).c_str()); throw new DlAbortEx(EX_TOO_LARGE_FILE, Util::llitos(size, true).c_str());
@ -267,7 +258,7 @@ bool FtpNegotiationCommand::recvPort() {
return false; return false;
} }
if(status != 200) { if(status != 200) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_REST; sequence = SEQ_SEND_REST;
return true; return true;
@ -286,7 +277,7 @@ bool FtpNegotiationCommand::recvPasv() {
return false; return false;
} }
if(status != 227) { if(status != 227) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
// make a data connection to the server. // make a data connection to the server.
logger->info(MSG_CONNECTING_TO_SERVER, cuid, 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. // TODO if we recieve negative response, then we set _requestGroup->getSegmentMan()->splittable = false, and continue.
if(status != 350) { if(status != 350) {
throw new DlRetryEx(EX_BAD_STATUS, status); throw new DlAbortEx(EX_BAD_STATUS, status);
} }
sequence = SEQ_SEND_RETR; sequence = SEQ_SEND_RETR;
return true; return true;
@ -339,7 +330,7 @@ bool FtpNegotiationCommand::recvRetr() {
return false; return false;
} }
if(status != 150 && status != 125) { 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) { if(e->option->get(PREF_FTP_PASV) != V_TRUE) {
assert(serverSocket->getSockfd() != -1); assert(serverSocket->getSockfd() != -1);

View File

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

View File

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