2006-02-17 13:35:04 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-02-17 13:35:04 +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-17 13:35:04 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "AbstractCommand.h"
|
|
|
|
#include "DlAbortEx.h"
|
|
|
|
#include "DlRetryEx.h"
|
|
|
|
#include "InitiateConnectionCommandFactory.h"
|
|
|
|
#include "Util.h"
|
|
|
|
#include "message.h"
|
2006-02-18 05:13:21 +00:00
|
|
|
#include "SleepCommand.h"
|
2006-02-21 14:00:58 +00:00
|
|
|
#include "prefs.h"
|
2007-03-28 15:08:22 +00:00
|
|
|
#include "DNSCache.h"
|
2007-05-20 13:51:52 +00:00
|
|
|
#include "FatalException.h"
|
2006-02-17 13:35:04 +00:00
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
AbstractCommand::AbstractCommand(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-10-18 14:57:00 +00:00
|
|
|
DownloadEngine* e,
|
2006-07-19 17:07:45 +00:00
|
|
|
const SocketHandle& s):
|
2007-05-20 13:51:52 +00:00
|
|
|
Command(cuid), req(req), _requestGroup(requestGroup), e(e), socket(s),
|
2006-10-01 11:29:14 +00:00
|
|
|
checkSocketIsReadable(false), checkSocketIsWritable(false),
|
|
|
|
nameResolverCheck(false) {
|
2006-07-19 17:07:45 +00:00
|
|
|
|
|
|
|
setReadCheckSocket(socket);
|
2006-06-12 16:55:08 +00:00
|
|
|
timeout = this->e->option->getAsInt(PREF_TIMEOUT);
|
2007-05-20 13:51:52 +00:00
|
|
|
++_requestGroup->numConnection;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AbstractCommand::~AbstractCommand() {
|
2006-07-19 17:07:45 +00:00
|
|
|
disableReadCheckSocket();
|
|
|
|
disableWriteCheckSocket();
|
2007-05-20 13:51:52 +00:00
|
|
|
--_requestGroup->numConnection;
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AbstractCommand::execute() {
|
|
|
|
try {
|
2007-05-20 13:51:52 +00:00
|
|
|
if(_requestGroup->getSegmentMan()->finished()) {
|
2007-07-20 17:06:21 +00:00
|
|
|
//logger->debug("CUID#%d - finished.", cuid);
|
2006-09-21 06:56:54 +00:00
|
|
|
return true;
|
|
|
|
}
|
2007-05-20 13:51:52 +00:00
|
|
|
PeerStatHandle peerStat = _requestGroup->getSegmentMan()->getPeerStat(cuid);
|
2006-09-21 06:56:54 +00:00
|
|
|
if(peerStat.get()) {
|
|
|
|
if(peerStat->getStatus() == PeerStat::REQUEST_IDLE) {
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_ABORT_REQUESTED, cuid);
|
2006-09-21 06:56:54 +00:00
|
|
|
onAbort(0);
|
|
|
|
req->resetUrl();
|
|
|
|
tryReserved();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2006-05-18 17:08:29 +00:00
|
|
|
if(checkSocketIsReadable && readCheckTarget->isReadable(0) ||
|
|
|
|
checkSocketIsWritable && writeCheckTarget->isWritable(0) ||
|
2006-10-01 11:29:14 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
|
|
|
nameResolverCheck && nameResolveFinished() ||
|
|
|
|
#endif // ENABLE_ASYNC_DNS
|
|
|
|
!checkSocketIsReadable && !checkSocketIsWritable && !nameResolverCheck) {
|
2006-06-12 16:55:08 +00:00
|
|
|
checkPoint.reset();
|
2007-05-20 13:51:52 +00:00
|
|
|
if(_requestGroup->getSegmentMan()->downloadStarted) {
|
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
|
|
|
// TODO Segment::isNull(), Change method name, it is very confusing.
|
|
|
|
if(segment->isNull()) {
|
2007-05-20 13:51:52 +00:00
|
|
|
segment = _requestGroup->getSegmentMan()->getSegment(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
|
|
|
if(segment.isNull()) {
|
|
|
|
logger->info(MSG_NO_SEGMENT_AVAILABLE, cuid);
|
|
|
|
return prepareForRetry(1);
|
|
|
|
}
|
2006-05-18 17:08:29 +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
|
|
|
return executeInternal();
|
2006-05-18 17:08:29 +00:00
|
|
|
} else {
|
2006-09-21 06:56:54 +00:00
|
|
|
|
2006-06-12 16:55:08 +00:00
|
|
|
if(checkPoint.elapsed(timeout)) {
|
2006-02-17 13:35:04 +00:00
|
|
|
throw new DlRetryEx(EX_TIME_OUT);
|
|
|
|
}
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(this);
|
2006-02-17 13:35:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2007-05-20 13:51:52 +00:00
|
|
|
} catch(FatalException* err) {
|
2007-06-10 07:55:43 +00:00
|
|
|
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
|
2007-05-20 13:51:52 +00:00
|
|
|
onAbort(err);
|
|
|
|
delete(err);
|
|
|
|
req->resetUrl();
|
|
|
|
_requestGroup->getSegmentMan()->errors++;
|
|
|
|
return true;
|
2006-02-17 13:35:04 +00:00
|
|
|
} catch(DlAbortEx* err) {
|
2007-06-10 07:55:43 +00:00
|
|
|
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
|
2006-02-21 12:27:17 +00:00
|
|
|
onAbort(err);
|
2006-02-17 13:35:04 +00:00
|
|
|
delete(err);
|
|
|
|
req->resetUrl();
|
2007-05-20 13:51:52 +00:00
|
|
|
_requestGroup->getSegmentMan()->errors++;
|
2006-07-03 14:19:23 +00:00
|
|
|
tryReserved();
|
2006-02-17 13:35:04 +00:00
|
|
|
return true;
|
|
|
|
} catch(DlRetryEx* err) {
|
2007-06-10 07:55:43 +00:00
|
|
|
logger->info(MSG_RESTARTING_DOWNLOAD, err, cuid, req->getUrl().c_str());
|
2006-02-21 12:27:17 +00:00
|
|
|
req->addTryCount();
|
2006-03-01 02:26:29 +00:00
|
|
|
bool isAbort = e->option->getAsInt(PREF_MAX_TRIES) != 0 &&
|
|
|
|
req->getTryCount() >= e->option->getAsInt(PREF_MAX_TRIES);
|
|
|
|
if(isAbort) {
|
|
|
|
onAbort(err);
|
|
|
|
}
|
|
|
|
if(isAbort) {
|
2007-06-10 07:55:43 +00:00
|
|
|
logger->info(MSG_MAX_TRY, cuid, req->getTryCount());
|
|
|
|
logger->error(MSG_DOWNLOAD_ABORTED, err, cuid, req->getUrl().c_str());
|
|
|
|
delete(err);
|
2007-05-20 13:51:52 +00:00
|
|
|
_requestGroup->getSegmentMan()->errors++;
|
2006-07-03 14:19:23 +00:00
|
|
|
tryReserved();
|
2006-02-17 13:35:04 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2007-06-10 07:55:43 +00:00
|
|
|
delete(err);
|
2006-02-21 14:00:58 +00:00
|
|
|
return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-03 14:19:23 +00:00
|
|
|
void AbstractCommand::tryReserved() {
|
2007-06-03 14:24:37 +00:00
|
|
|
Commands commands = _requestGroup->createNextCommand(e, 1);
|
2007-05-20 13:51:52 +00:00
|
|
|
e->addCommand(commands);
|
2006-07-03 14:19:23 +00:00
|
|
|
}
|
|
|
|
|
2007-07-21 08:56:16 +00:00
|
|
|
bool AbstractCommand::prepareForRetry(int32_t wait) {
|
2007-05-20 13:51:52 +00:00
|
|
|
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
|
|
|
Command* command = InitiateConnectionCommandFactory::createInitiateConnectionCommand(cuid, req, _requestGroup, e);
|
2006-02-18 05:13:21 +00:00
|
|
|
if(wait == 0) {
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(command);
|
2006-02-18 05:13:21 +00:00
|
|
|
} else {
|
|
|
|
SleepCommand* scom = new SleepCommand(cuid, e, command, wait);
|
2006-05-09 15:54:14 +00:00
|
|
|
e->commands.push_back(scom);
|
2006-02-18 05:13:21 +00:00
|
|
|
}
|
2006-02-17 13:35:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-05-20 13:51:52 +00:00
|
|
|
void AbstractCommand::onAbort(Exception* ex) {
|
2006-04-17 16:17:20 +00:00
|
|
|
logger->debug(MSG_UNREGISTER_CUID, cuid);
|
2007-05-20 13:51:52 +00:00
|
|
|
//_segmentMan->unregisterId(cuid);
|
|
|
|
_requestGroup->getSegmentMan()->cancelSegment(cuid);
|
2006-02-21 12:27:17 +00:00
|
|
|
}
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
void AbstractCommand::disableReadCheckSocket() {
|
|
|
|
if(checkSocketIsReadable) {
|
2006-08-14 15:03:38 +00:00
|
|
|
e->deleteSocketForReadCheck(readCheckTarget, this);
|
2006-07-19 17:07:45 +00:00
|
|
|
checkSocketIsReadable = false;
|
|
|
|
readCheckTarget = SocketHandle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCommand::setReadCheckSocket(const SocketHandle& socket) {
|
|
|
|
if(!socket->isOpen()) {
|
|
|
|
disableReadCheckSocket();
|
2006-02-21 12:27:17 +00:00
|
|
|
} else {
|
|
|
|
if(checkSocketIsReadable) {
|
|
|
|
if(readCheckTarget != socket) {
|
2006-08-14 15:03:38 +00:00
|
|
|
e->deleteSocketForReadCheck(readCheckTarget, this);
|
|
|
|
e->addSocketForReadCheck(socket, this);
|
2006-02-21 12:27:17 +00:00
|
|
|
readCheckTarget = socket;
|
|
|
|
}
|
|
|
|
} else {
|
2006-08-14 15:03:38 +00:00
|
|
|
e->addSocketForReadCheck(socket, this);
|
2006-02-21 12:27:17 +00:00
|
|
|
checkSocketIsReadable = true;
|
|
|
|
readCheckTarget = socket;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-07-19 17:07:45 +00:00
|
|
|
void AbstractCommand::disableWriteCheckSocket() {
|
|
|
|
if(checkSocketIsWritable) {
|
2006-08-14 15:03:38 +00:00
|
|
|
e->deleteSocketForWriteCheck(writeCheckTarget, this);
|
2006-07-19 17:07:45 +00:00
|
|
|
checkSocketIsWritable = false;
|
|
|
|
writeCheckTarget = SocketHandle();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCommand::setWriteCheckSocket(const SocketHandle& socket) {
|
|
|
|
if(!socket->isOpen()) {
|
|
|
|
disableWriteCheckSocket();
|
2006-02-21 12:27:17 +00:00
|
|
|
} else {
|
|
|
|
if(checkSocketIsWritable) {
|
|
|
|
if(writeCheckTarget != socket) {
|
2006-08-14 15:03:38 +00:00
|
|
|
e->deleteSocketForWriteCheck(writeCheckTarget, this);
|
|
|
|
e->addSocketForWriteCheck(socket, this);
|
2006-02-21 12:27:17 +00:00
|
|
|
writeCheckTarget = socket;
|
|
|
|
}
|
|
|
|
} else {
|
2006-08-14 15:03:38 +00:00
|
|
|
e->addSocketForWriteCheck(socket, this);
|
2006-02-21 12:27:17 +00:00
|
|
|
checkSocketIsWritable = true;
|
|
|
|
writeCheckTarget = socket;
|
|
|
|
}
|
|
|
|
}
|
2006-02-17 13:35:04 +00:00
|
|
|
}
|
2006-08-11 12:29:55 +00:00
|
|
|
|
2007-03-28 15:08:22 +00:00
|
|
|
bool AbstractCommand::resolveHostname(const string& hostname,
|
|
|
|
const NameResolverHandle& resolver) {
|
|
|
|
string ipaddr = DNSCacheSingletonHolder::instance()->find(hostname);
|
|
|
|
if(ipaddr.empty()) {
|
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
|
|
|
switch(resolver->getStatus()) {
|
|
|
|
case NameResolver::STATUS_READY:
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_RESOLVING_HOSTNAME, cuid, hostname.c_str());
|
2007-03-28 15:08:22 +00:00
|
|
|
resolver->resolve(hostname);
|
|
|
|
setNameResolverCheck(resolver);
|
|
|
|
return false;
|
|
|
|
case NameResolver::STATUS_SUCCESS:
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_NAME_RESOLUTION_COMPLETE, cuid,
|
2007-03-28 15:08:22 +00:00
|
|
|
hostname.c_str(), resolver->getAddrString().c_str());
|
|
|
|
DNSCacheSingletonHolder::instance()->put(hostname, resolver->getAddrString());
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
case NameResolver::STATUS_ERROR:
|
2007-07-20 17:06:21 +00:00
|
|
|
throw new DlAbortEx(MSG_NAME_RESOLUTION_FAILED, cuid,
|
2007-03-28 15:08:22 +00:00
|
|
|
hostname.c_str(),
|
|
|
|
resolver->getError().c_str());
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#else
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_RESOLVING_HOSTNAME, cuid, hostname.c_str());
|
2007-03-28 15:08:22 +00:00
|
|
|
resolver->resolve(hostname);
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_NAME_RESOLUTION_COMPLETE, cuid,
|
2007-03-28 15:08:22 +00:00
|
|
|
hostname.c_str(), resolver->getAddrString().c_str());
|
|
|
|
DNSCacheSingletonHolder::instance()->put(hostname, resolver->getAddrString());
|
|
|
|
return true;
|
|
|
|
#endif // ENABLE_ASYNC_DNS
|
|
|
|
} else {
|
2007-07-20 17:06:21 +00:00
|
|
|
logger->info(MSG_DNS_CACHE_HIT, cuid,
|
2007-03-28 15:08:22 +00:00
|
|
|
hostname.c_str(), ipaddr.c_str());
|
|
|
|
resolver->setAddr(ipaddr);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-21 13:18:51 +00:00
|
|
|
#ifdef ENABLE_ASYNC_DNS
|
2006-08-11 12:29:55 +00:00
|
|
|
void AbstractCommand::setNameResolverCheck(const NameResolverHandle& resolver) {
|
2006-10-01 11:29:14 +00:00
|
|
|
nameResolverCheck = true;
|
2006-08-14 15:03:38 +00:00
|
|
|
e->addNameResolverCheck(resolver, this);
|
2006-08-11 12:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AbstractCommand::disableNameResolverCheck(const NameResolverHandle& resolver) {
|
2006-10-01 11:29:14 +00:00
|
|
|
nameResolverCheck = false;
|
2006-08-14 15:03:38 +00:00
|
|
|
e->deleteNameResolverCheck(resolver, this);
|
2006-08-11 12:29:55 +00:00
|
|
|
}
|
|
|
|
|
2006-10-01 11:29:14 +00:00
|
|
|
bool AbstractCommand::nameResolveFinished() const {
|
|
|
|
return false;
|
|
|
|
}
|
2006-08-21 13:18:51 +00:00
|
|
|
#endif // ENABLE_ASYNC_DNS
|