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 "FtpInitiateConnectionCommand.h"
|
|
|
|
#include "FtpNegotiationCommand.h"
|
|
|
|
#include "HttpRequestCommand.h"
|
|
|
|
#include "FtpTunnelRequestCommand.h"
|
|
|
|
#include "DlAbortEx.h"
|
|
|
|
#include "message.h"
|
2006-02-21 14:00:58 +00:00
|
|
|
#include "prefs.h"
|
2006-08-11 12:29:55 +00:00
|
|
|
#include "Util.h"
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2006-08-11 12:29:55 +00:00
|
|
|
FtpInitiateConnectionCommand::FtpInitiateConnectionCommand(int cuid,
|
2006-10-18 14:57:00 +00:00
|
|
|
const RequestHandle req,
|
2006-08-11 12:29:55 +00:00
|
|
|
DownloadEngine* e)
|
|
|
|
:AbstractCommand(cuid, req, e)
|
|
|
|
{
|
2006-10-01 14:11:29 +00:00
|
|
|
setTimeout(e->option->getAsInt(PREF_DNS_TIMEOUT));
|
2006-08-11 12:29:55 +00:00
|
|
|
disableReadCheckSocket();
|
|
|
|
disableWriteCheckSocket();
|
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2006-08-11 12:29:55 +00:00
|
|
|
FtpInitiateConnectionCommand::~FtpInitiateConnectionCommand() {
|
2006-08-21 13:18:51 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2006-08-11 12:29:55 +00:00
|
|
|
disableNameResolverCheck(nameResolver);
|
2006-08-21 13:18:51 +00:00
|
|
|
#endif // ENABLE_ASYNC_DNS
|
2006-08-11 12:29:55 +00:00
|
|
|
}
|
2006-02-21 12:28:42 +00:00
|
|
|
|
2006-09-19 14:52:59 +00:00
|
|
|
bool FtpInitiateConnectionCommand::executeInternal(Segment& segment) {
|
2006-08-11 12:29:55 +00:00
|
|
|
string hostname;
|
|
|
|
if(useHttpProxy()) {
|
|
|
|
hostname = e->option->get(PREF_HTTP_PROXY_HOST);
|
|
|
|
} else {
|
|
|
|
hostname = req->getHost();
|
|
|
|
}
|
2006-08-21 13:18:51 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2006-08-11 12:29:55 +00:00
|
|
|
if(!Util::isNumbersAndDotsNotation(hostname)) {
|
|
|
|
if(resolveHostname(hostname, nameResolver)) {
|
|
|
|
hostname = nameResolver->getAddrString();
|
|
|
|
} else {
|
|
|
|
e->commands.push_back(this);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-08-21 13:18:51 +00:00
|
|
|
#endif // ENABLE_ASYNC_DNS
|
2006-02-21 12:28:42 +00:00
|
|
|
Command* command;
|
|
|
|
if(useHttpProxy()) {
|
2006-04-17 16:17:20 +00:00
|
|
|
logger->info(MSG_CONNECTING_TO_SERVER, cuid,
|
|
|
|
e->option->get(PREF_HTTP_PROXY_HOST).c_str(),
|
|
|
|
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
2006-08-11 12:29:55 +00:00
|
|
|
socket->establishConnection(hostname,
|
2006-02-21 14:00:58 +00:00
|
|
|
e->option->getAsInt(PREF_HTTP_PROXY_PORT));
|
2006-02-21 12:28:42 +00:00
|
|
|
|
|
|
|
if(useHttpProxyGet()) {
|
|
|
|
command = new HttpRequestCommand(cuid, req, e, socket);
|
|
|
|
} else if(useHttpProxyConnect()) {
|
|
|
|
command = new FtpTunnelRequestCommand(cuid, req, e, socket);
|
|
|
|
} else {
|
|
|
|
// TODO
|
|
|
|
throw new DlAbortEx("ERROR");
|
|
|
|
}
|
|
|
|
} else {
|
2006-04-17 16:17:20 +00:00
|
|
|
logger->info(MSG_CONNECTING_TO_SERVER, cuid, req->getHost().c_str(),
|
|
|
|
req->getPort());
|
2006-08-11 12:29:55 +00:00
|
|
|
socket->establishConnection(hostname, req->getPort());
|
2006-02-21 12:28:42 +00:00
|
|
|
command = new FtpNegotiationCommand(cuid, req, e, socket);
|
|
|
|
}
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(command);
|
2006-02-21 12:28:42 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpInitiateConnectionCommand::useHttpProxy() const {
|
2006-02-21 14:00:58 +00:00
|
|
|
return e->option->get(PREF_HTTP_PROXY_ENABLED) == V_TRUE;
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpInitiateConnectionCommand::useHttpProxyGet() const {
|
2006-02-21 14:00:58 +00:00
|
|
|
return useHttpProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_GET;
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FtpInitiateConnectionCommand::useHttpProxyConnect() const {
|
2006-02-21 14:00:58 +00:00
|
|
|
return useHttpProxy() && e->option->get(PREF_FTP_VIA_HTTP_PROXY) == V_TUNNEL;
|
2006-02-21 12:28:42 +00:00
|
|
|
}
|