summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-05-08 16:41:21 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2009-05-08 16:41:21 +0000
commit4cb5468662394ddf588d2c5c5787d24c799524ab (patch)
tree49f7c078aacfc44e3eb65f333fb4f5d7c932b27d
parent08856691b3fa306483c199a1e88ab15bcf0eea85 (diff)
2009-05-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Now RequestGroup has its own copy of Option object. This will help to give custom option for each RequestGroup. addTorrentFile command now takes options. * src/AbstractCommand.cc * src/AbstractCommand.h * src/AbstractProxyRequestCommand.cc * src/ActivePeerConnectionCommand.cc * src/ActivePeerConnectionCommand.h * src/AdaptiveURISelector.cc * src/BtCheckIntegrityEntry.cc * src/BtDependency.cc * src/BtDependency.h * src/BtFileAllocationEntry.cc * src/BtPostDownloadHandler.cc * src/CheckIntegrityEntry.cc * src/DownloadCommand.cc * src/FtpDownloadCommand.cc * src/FtpFinishDownloadCommand.cc * src/FtpInitiateConnectionCommand.cc * src/FtpNegotiationCommand.cc * src/HttpInitiateConnectionCommand.cc * src/HttpRequestCommand.cc * src/HttpResponseCommand.cc * src/HttpSkipResponseCommand.cc * src/InitiateConnectionCommand.cc * src/InitiateConnectionCommandFactory.cc * src/InitiatorMSEHandshakeCommand.cc * src/InitiatorMSEHandshakeCommand.h * src/Metalink2RequestGroup.cc * src/Metalink2RequestGroup.h * src/MetalinkPostDownloadHandler.cc * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/PeerAbstractCommand.cc * src/PeerInteractionCommand.cc * src/PeerInteractionCommand.h * src/PeerReceiveHandshakeCommand.cc * src/PeerReceiveHandshakeCommand.h * src/RequestGroup.cc * src/RequestGroup.h * src/TrackerWatcherCommand.cc * src/TrackerWatcherCommand.h * src/XmlRpcMethod.cc * src/XmlRpcMethod.h * src/XmlRpcMethodImpl.cc * src/download_helper.cc * src/download_helper.h * src/main.cc * test/BtDependencyTest.cc * test/BtPostDownloadHandlerTest.cc * test/DefaultBtMessageDispatcherTest.cc * test/DownloadHandlerFactoryTest.cc * test/DownloadHelperTest.cc * test/Metalink2RequestGroupTest.cc * test/MetalinkPostDownloadHandlerTest.cc * test/RequestGroupManTest.cc * test/RequestGroupTest.cc
-rw-r--r--ChangeLog60
-rw-r--r--src/AbstractCommand.cc32
-rw-r--r--src/AbstractCommand.h3
-rw-r--r--src/AbstractProxyRequestCommand.cc6
-rw-r--r--src/ActivePeerConnectionCommand.cc6
-rw-r--r--src/ActivePeerConnectionCommand.h1
-rw-r--r--src/AdaptiveURISelector.cc12
-rw-r--r--src/BtCheckIntegrityEntry.cc2
-rw-r--r--src/BtDependency.cc9
-rw-r--r--src/BtDependency.h4
-rw-r--r--src/BtFileAllocationEntry.cc2
-rw-r--r--src/BtPostDownloadHandler.cc2
-rw-r--r--src/CheckIntegrityEntry.cc2
-rw-r--r--src/DownloadCommand.cc2
-rw-r--r--src/FtpDownloadCommand.cc2
-rw-r--r--src/FtpFinishDownloadCommand.cc2
-rw-r--r--src/FtpInitiateConnectionCommand.cc4
-rw-r--r--src/FtpNegotiationCommand.cc28
-rw-r--r--src/HttpInitiateConnectionCommand.cc6
-rw-r--r--src/HttpRequestCommand.cc10
-rw-r--r--src/HttpResponseCommand.cc16
-rw-r--r--src/HttpSkipResponseCommand.cc2
-rw-r--r--src/InitiateConnectionCommand.cc4
-rw-r--r--src/InitiateConnectionCommandFactory.cc4
-rw-r--r--src/InitiatorMSEHandshakeCommand.cc17
-rw-r--r--src/InitiatorMSEHandshakeCommand.h3
-rw-r--r--src/Metalink2RequestGroup.cc59
-rw-r--r--src/Metalink2RequestGroup.h12
-rw-r--r--src/MetalinkPostDownloadHandler.cc7
-rw-r--r--src/MultiUrlRequestInfo.cc6
-rw-r--r--src/MultiUrlRequestInfo.h4
-rw-r--r--src/PeerAbstractCommand.cc1
-rw-r--r--src/PeerInteractionCommand.cc17
-rw-r--r--src/PeerInteractionCommand.h3
-rw-r--r--src/PeerReceiveHandshakeCommand.cc10
-rw-r--r--src/PeerReceiveHandshakeCommand.h3
-rw-r--r--src/RequestGroup.cc27
-rw-r--r--src/RequestGroup.h9
-rw-r--r--src/TrackerWatcherCommand.cc9
-rw-r--r--src/TrackerWatcherCommand.h2
-rw-r--r--src/XmlRpcMethod.cc5
-rw-r--r--src/XmlRpcMethod.h2
-rw-r--r--src/XmlRpcMethodImpl.cc15
-rw-r--r--src/download_helper.cc145
-rw-r--r--src/download_helper.h23
-rw-r--r--src/main.cc52
-rw-r--r--test/BtDependencyTest.cc49
-rw-r--r--test/BtPostDownloadHandlerTest.cc16
-rw-r--r--test/DefaultBtMessageDispatcherTest.cc2
-rw-r--r--test/DownloadHandlerFactoryTest.cc24
-rw-r--r--test/DownloadHelperTest.cc100
-rw-r--r--test/Metalink2RequestGroupTest.cc6
-rw-r--r--test/MetalinkPostDownloadHandlerTest.cc16
-rw-r--r--test/RequestGroupManTest.cc21
-rw-r--r--test/RequestGroupTest.cc22
55 files changed, 484 insertions, 424 deletions
diff --git a/ChangeLog b/ChangeLog
index e8cd22bd..a206424d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,63 @@
+2009-05-09 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
+
+ Now RequestGroup has its own copy of Option object. This will help
+ to give custom option for each RequestGroup.
+ addTorrentFile command now takes options.
+ * src/AbstractCommand.cc
+ * src/AbstractCommand.h
+ * src/AbstractProxyRequestCommand.cc
+ * src/ActivePeerConnectionCommand.cc
+ * src/ActivePeerConnectionCommand.h
+ * src/AdaptiveURISelector.cc
+ * src/BtCheckIntegrityEntry.cc
+ * src/BtDependency.cc
+ * src/BtDependency.h
+ * src/BtFileAllocationEntry.cc
+ * src/BtPostDownloadHandler.cc
+ * src/CheckIntegrityEntry.cc
+ * src/DownloadCommand.cc
+ * src/FtpDownloadCommand.cc
+ * src/FtpFinishDownloadCommand.cc
+ * src/FtpInitiateConnectionCommand.cc
+ * src/FtpNegotiationCommand.cc
+ * src/HttpInitiateConnectionCommand.cc
+ * src/HttpRequestCommand.cc
+ * src/HttpResponseCommand.cc
+ * src/HttpSkipResponseCommand.cc
+ * src/InitiateConnectionCommand.cc
+ * src/InitiateConnectionCommandFactory.cc
+ * src/InitiatorMSEHandshakeCommand.cc
+ * src/InitiatorMSEHandshakeCommand.h
+ * src/Metalink2RequestGroup.cc
+ * src/Metalink2RequestGroup.h
+ * src/MetalinkPostDownloadHandler.cc
+ * src/MultiUrlRequestInfo.cc
+ * src/MultiUrlRequestInfo.h
+ * src/PeerAbstractCommand.cc
+ * src/PeerInteractionCommand.cc
+ * src/PeerInteractionCommand.h
+ * src/PeerReceiveHandshakeCommand.cc
+ * src/PeerReceiveHandshakeCommand.h
+ * src/RequestGroup.cc
+ * src/RequestGroup.h
+ * src/TrackerWatcherCommand.cc
+ * src/TrackerWatcherCommand.h
+ * src/XmlRpcMethod.cc
+ * src/XmlRpcMethod.h
+ * src/XmlRpcMethodImpl.cc
+ * src/download_helper.cc
+ * src/download_helper.h
+ * src/main.cc
+ * test/BtDependencyTest.cc
+ * test/BtPostDownloadHandlerTest.cc
+ * test/DefaultBtMessageDispatcherTest.cc
+ * test/DownloadHandlerFactoryTest.cc
+ * test/DownloadHelperTest.cc
+ * test/Metalink2RequestGroupTest.cc
+ * test/MetalinkPostDownloadHandlerTest.cc
+ * test/RequestGroupManTest.cc
+ * test/RequestGroupTest.cc
+
2009-05-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added tellActiveStatus xml-rpc command which reports download
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc
index a55e8d60..4799146c 100644
--- a/src/AbstractCommand.cc
+++ b/src/AbstractCommand.cc
@@ -179,7 +179,7 @@ bool AbstractCommand::execute() {
onAbort();
req->resetUrl();
} else {
- if(e->option->getAsBool(PREF_RESET_URI)) {
+ if(getOption()->getAsBool(PREF_RESET_URI)) {
req->resetUrl();
}
}
@@ -190,7 +190,7 @@ bool AbstractCommand::execute() {
tryReserved();
return true;
} else {
- return prepareForRetry(e->option->getAsInt(PREF_RETRY_WAIT));
+ return prepareForRetry(getOption()->getAsInt(PREF_RETRY_WAIT));
}
} catch(DownloadFailureException& err) {
logger->error(EX_EXCEPTION_CAUGHT, err);
@@ -310,7 +310,7 @@ void AbstractCommand::setWriteCheckSocketIf
}
static const std::string& getProxyStringFor(const std::string& proxyPref,
- const Option* option)
+ const SharedHandle<Option>& option)
{
if(option->defined(proxyPref)) {
return option->get(proxyPref);
@@ -320,7 +320,7 @@ static const std::string& getProxyStringFor(const std::string& proxyPref,
}
static bool isProxyUsed(const std::string& proxyPref,
- const Option* option)
+ const SharedHandle<Option>& option)
{
std::string proxy = getProxyStringFor(proxyPref, option);
if(proxy.empty()) {
@@ -330,7 +330,8 @@ static bool isProxyUsed(const std::string& proxyPref,
}
}
-static bool isProxyRequest(const std::string& protocol, const Option* option)
+static bool isProxyRequest(const std::string& protocol,
+ const SharedHandle<Option>& option)
{
return
(protocol == Request::PROTO_HTTP && isProxyUsed(PREF_HTTP_PROXY, option)) ||
@@ -369,12 +370,12 @@ static bool inNoProxy(const SharedHandle<Request>& req,
bool AbstractCommand::isProxyDefined() const
{
- return isProxyRequest(req->getProtocol(), e->option) &&
- !inNoProxy(req, e->option->get(PREF_NO_PROXY));
+ return isProxyRequest(req->getProtocol(), getOption()) &&
+ !inNoProxy(req, getOption()->get(PREF_NO_PROXY));
}
static const std::string& getProxyString(const SharedHandle<Request>& req,
- const Option* option)
+ const SharedHandle<Option>& option)
{
if(req->getProtocol() == Request::PROTO_HTTP) {
return getProxyStringFor(PREF_HTTP_PROXY, option);
@@ -390,10 +391,10 @@ static const std::string& getProxyString(const SharedHandle<Request>& req,
SharedHandle<Request> AbstractCommand::createProxyRequest() const
{
SharedHandle<Request> proxyRequest;
- if(inNoProxy(req, e->option->get(PREF_NO_PROXY))) {
+ if(inNoProxy(req, getOption()->get(PREF_NO_PROXY))) {
return proxyRequest;
}
- std::string proxy = getProxyString(req, e->option);
+ std::string proxy = getProxyString(req, getOption());
if(!proxy.empty()) {
proxyRequest.reset(new Request());
if(proxyRequest->setUrl(proxy)) {
@@ -427,7 +428,7 @@ bool AbstractCommand::asyncResolveHostname()
case AsyncNameResolver::STATUS_SUCCESS:
return true;
case AsyncNameResolver::STATUS_ERROR:
- if(!isProxyRequest(req->getProtocol(), e->option)) {
+ if(!isProxyRequest(req->getProtocol(), getOption())) {
e->_requestGroupMan->getOrCreateServerStat
(req->getHost(), req->getProtocol())->setError();
}
@@ -486,7 +487,7 @@ void AbstractCommand::checkIfConnectionEstablished
if(!error.empty()) {
// Don't set error if proxy server is used and its method is GET.
if(resolveProxyMethod(req->getProtocol()) != V_GET ||
- !isProxyRequest(req->getProtocol(), e->option)) {
+ !isProxyRequest(req->getProtocol(), getOption())) {
e->_requestGroupMan->getOrCreateServerStat
(req->getHost(), req->getProtocol())->setError();
}
@@ -499,7 +500,7 @@ void AbstractCommand::checkIfConnectionEstablished
const std::string& AbstractCommand::resolveProxyMethod
(const std::string& protocol) const
{
- if(e->option->get(PREF_PROXY_METHOD) == V_TUNNEL ||
+ if(getOption()->get(PREF_PROXY_METHOD) == V_TUNNEL ||
Request::PROTO_HTTPS == protocol) {
return V_TUNNEL;
} else {
@@ -507,4 +508,9 @@ const std::string& AbstractCommand::resolveProxyMethod
}
}
+const SharedHandle<Option>& AbstractCommand::getOption() const
+{
+ return _requestGroup->getOption();
+}
+
} // namespace aria2
diff --git a/src/AbstractCommand.h b/src/AbstractCommand.h
index c33ab841..fa3781f0 100644
--- a/src/AbstractCommand.h
+++ b/src/AbstractCommand.h
@@ -47,6 +47,7 @@ class RequestGroup;
class Segment;
class Exception;
class SocketCore;
+class Option;
#ifdef ENABLE_ASYNC_DNS
class AsyncNameResolver;
#endif // ENABLE_ASYNC_DNS
@@ -117,6 +118,8 @@ protected:
// Returns proxy method for given protocol. Either V_GET or V_TUNNEL
// is returned. For HTTPS, always returns V_TUNNEL.
const std::string& resolveProxyMethod(const std::string& protocol) const;
+
+ const SharedHandle<Option>& getOption() const;
private:
bool checkSocketIsReadable;
bool checkSocketIsWritable;
diff --git a/src/AbstractProxyRequestCommand.cc b/src/AbstractProxyRequestCommand.cc
index d7cfb51d..4fc3fadc 100644
--- a/src/AbstractProxyRequestCommand.cc
+++ b/src/AbstractProxyRequestCommand.cc
@@ -58,9 +58,9 @@ AbstractProxyRequestCommand::AbstractProxyRequestCommand
:
AbstractCommand(cuid, req, requestGroup, e, s),
_proxyRequest(proxyRequest),
- httpConnection(new HttpConnection(cuid, s, e->option))
+ httpConnection(new HttpConnection(cuid, s, getOption().get()))
{
- setTimeout(e->option->getAsInt(PREF_CONNECT_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
disableReadCheckSocket();
setWriteCheckSocket(socket);
}
@@ -71,7 +71,7 @@ bool AbstractProxyRequestCommand::executeInternal() {
//socket->setBlockingMode();
if(httpConnection->sendBufferIsEmpty()) {
HttpRequestHandle httpRequest(new HttpRequest());
- httpRequest->setUserAgent(e->option->get(PREF_USER_AGENT));
+ httpRequest->setUserAgent(getOption()->get(PREF_USER_AGENT));
httpRequest->setRequest(req);
httpRequest->setProxyRequest(_proxyRequest);
diff --git a/src/ActivePeerConnectionCommand.cc b/src/ActivePeerConnectionCommand.cc
index 828488e0..7c76ab4a 100644
--- a/src/ActivePeerConnectionCommand.cc
+++ b/src/ActivePeerConnectionCommand.cc
@@ -63,7 +63,6 @@ ActivePeerConnectionCommand::ActivePeerConnectionCommand
_btContext(btContext),
interval(interval),
e(e),
- _thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT)),
_numNewConnection(5)
{
_requestGroup->increaseNumCommand();
@@ -84,9 +83,10 @@ bool ActivePeerConnectionCommand::execute() {
const unsigned int maxDownloadLimit =
_requestGroup->getMaxDownloadSpeedLimit();
const unsigned int maxUploadLimit = _requestGroup->getMaxUploadSpeedLimit();
- unsigned int thresholdSpeed = _thresholdSpeed;
+ unsigned int thresholdSpeed =
+ _requestGroup->getOption()->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT);
if(maxDownloadLimit > 0) {
- thresholdSpeed = std::min(maxDownloadLimit, _thresholdSpeed);
+ thresholdSpeed = std::min(maxDownloadLimit, thresholdSpeed);
}
if(// for seeder state
(_pieceStorage->downloadFinished() && _btRuntime->lessThanMaxPeers() &&
diff --git a/src/ActivePeerConnectionCommand.h b/src/ActivePeerConnectionCommand.h
index f99f07ce..d8c7c452 100644
--- a/src/ActivePeerConnectionCommand.h
+++ b/src/ActivePeerConnectionCommand.h
@@ -62,7 +62,6 @@ private:
time_t interval; // UNIT: sec
DownloadEngine* e;
Time checkPoint;
- unsigned int _thresholdSpeed; // UNIT: byte/sec
unsigned int _numNewConnection; // the number of the connection to establish.
public:
ActivePeerConnectionCommand(int cuid,
diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc
index ff168625..a67ff259 100644
--- a/src/AdaptiveURISelector.cc
+++ b/src/AdaptiveURISelector.cc
@@ -64,11 +64,9 @@ AdaptiveURISelector::AdaptiveURISelector
(const SharedHandle<ServerStatMan>& serverStatMan, RequestGroup* requestGroup):
_serverStatMan(serverStatMan),
_requestGroup(requestGroup),
- _nbConnections(1),
_logger(LogFactory::getInstance())
{
- const Option* op = _requestGroup->getOption();
- _nbServerToEvaluate = op->getAsInt(PREF_METALINK_SERVERS) - 1;
+ resetCounters();
}
AdaptiveURISelector::~AdaptiveURISelector() {}
@@ -191,9 +189,9 @@ std::string AdaptiveURISelector::getBestMirror
void AdaptiveURISelector::resetCounters()
{
- const Option* op = _requestGroup->getOption();
_nbConnections = 1;
- _nbServerToEvaluate = op->getAsInt(PREF_METALINK_SERVERS) - 1;
+ _nbServerToEvaluate =
+ _requestGroup->getOption()->getAsInt(PREF_METALINK_SERVERS) - 1;
}
void AdaptiveURISelector::tuneDownloadCommand
@@ -205,8 +203,8 @@ void AdaptiveURISelector::tuneDownloadCommand
void AdaptiveURISelector::adjustLowestSpeedLimit
(const std::deque<std::string>& uris, DownloadCommand* command) const
{
- const Option* op = _requestGroup->getOption();
- unsigned int lowest = op->getAsInt(PREF_LOWEST_SPEED_LIMIT);
+ unsigned int lowest =
+ _requestGroup->getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT);
if (lowest > 0) {
unsigned int low_lowest = 4 * 1024;
unsigned int max = getMaxDownloadSpeed(uris);
diff --git a/src/BtCheckIntegrityEntry.cc b/src/BtCheckIntegrityEntry.cc
index 211467c2..3197e6c2 100644
--- a/src/BtCheckIntegrityEntry.cc
+++ b/src/BtCheckIntegrityEntry.cc
@@ -72,7 +72,7 @@ void BtCheckIntegrityEntry::onDownloadFinished(std::deque<Command*>& commands,
// are valid, then aira2 goes to seeding mode. Sometimes it is better
// to exit rather than doing seeding. So, it would be good to toggle this
// behavior.
- if(e->option->getAsBool(PREF_BT_HASH_CHECK_SEED)) {
+ if(_requestGroup->getOption()->getAsBool(PREF_BT_HASH_CHECK_SEED)) {
SharedHandle<BtFileAllocationEntry> entry
(new BtFileAllocationEntry(_requestGroup));
proceedFileAllocation(commands, entry, e);
diff --git a/src/BtDependency.cc b/src/BtDependency.cc
index 9ace82e6..0109f1de 100644
--- a/src/BtDependency.cc
+++ b/src/BtDependency.cc
@@ -49,11 +49,9 @@
namespace aria2 {
BtDependency::BtDependency(const RequestGroupWeakHandle& dependant,
- const RequestGroupHandle& dependee,
- const Option* option):
+ const RequestGroupHandle& dependee):
_dependant(dependant),
_dependee(dependee),
- _option(option),
_logger(LogFactory::getInstance()) {}
BtDependency::~BtDependency() {}
@@ -84,8 +82,9 @@ bool BtDependency::resolve()
btContext->loadFromMemory(content,
File(dependee->getFilePath()).getBasename(),
overrideName);
- if(_option->defined(PREF_PEER_ID_PREFIX)) {
- btContext->setPeerIdPrefix(_option->get(PREF_PEER_ID_PREFIX));
+ if(_dependant->getOption()->defined(PREF_PEER_ID_PREFIX)) {
+ btContext->setPeerIdPrefix
+ (_dependant->getOption()->get(PREF_PEER_ID_PREFIX));
}
} catch(RecoverableException& e) {
_logger->error(EX_EXCEPTION_CAUGHT, e);
diff --git a/src/BtDependency.h b/src/BtDependency.h
index 7edc8c15..8e61b408 100644
--- a/src/BtDependency.h
+++ b/src/BtDependency.h
@@ -48,12 +48,10 @@ class BtDependency : public Dependency
private:
WeakHandle<RequestGroup> _dependant;
SharedHandle<RequestGroup> _dependee;
- const Option* _option;
Logger* _logger;
public:
BtDependency(const WeakHandle<RequestGroup>& dependant,
- const SharedHandle<RequestGroup>& dependee,
- const Option* option);
+ const SharedHandle<RequestGroup>& dependee);
virtual ~BtDependency();
diff --git a/src/BtFileAllocationEntry.cc b/src/BtFileAllocationEntry.cc
index 1c9c1112..861a634e 100644
--- a/src/BtFileAllocationEntry.cc
+++ b/src/BtFileAllocationEntry.cc
@@ -52,7 +52,7 @@ BtFileAllocationEntry::~BtFileAllocationEntry() {}
void BtFileAllocationEntry::prepareForNextAction(std::deque<Command*>& commands,
DownloadEngine* e)
{
- BtSetup().setup(commands, _requestGroup, e, e->option);
+ BtSetup().setup(commands, _requestGroup, e, _requestGroup->getOption().get());
if(!_requestGroup->downloadFinished()) {
_requestGroup->getDownloadContext()->resetDownloadStartTime();
_requestGroup->createNextCommandWithAdj(commands, e, 0);
diff --git a/src/BtPostDownloadHandler.cc b/src/BtPostDownloadHandler.cc
index 320769d9..29685e6e 100644
--- a/src/BtPostDownloadHandler.cc
+++ b/src/BtPostDownloadHandler.cc
@@ -62,7 +62,7 @@ void BtPostDownloadHandler::getNextRequestGroups
(std::deque<SharedHandle<RequestGroup> >& groups,
RequestGroup* requestGroup)
{
- const Option* op = requestGroup->getOption();
+ const SharedHandle<Option>& op = requestGroup->getOption();
_logger->debug("Generating RequestGroups for Torrent file %s",
requestGroup->getFilePath().c_str());
RequestGroupHandle rg(new RequestGroup(op, std::deque<std::string>()));
diff --git a/src/CheckIntegrityEntry.cc b/src/CheckIntegrityEntry.cc
index 7d71b7f8..85b493b9 100644
--- a/src/CheckIntegrityEntry.cc
+++ b/src/CheckIntegrityEntry.cc
@@ -95,7 +95,7 @@ void CheckIntegrityEntry::proceedFileAllocation
entry->prepareForNextAction(commands, e);
}
// Disable directIO when fallocation() is going to be used.
- if(e->option->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
+ if(_requestGroup->getOption()->get(PREF_FILE_ALLOCATION) == V_FALLOC) {
entry->disableDirectIO();
}
}
diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc
index 14a31834..1e7d9850 100644
--- a/src/DownloadCommand.cc
+++ b/src/DownloadCommand.cc
@@ -76,7 +76,7 @@ DownloadCommand::DownloadCommand(int cuid,
{
#ifdef ENABLE_MESSAGE_DIGEST
{
- if(e->option->getAsBool(PREF_REALTIME_CHUNK_CHECKSUM)) {
+ if(getOption()->getAsBool(PREF_REALTIME_CHUNK_CHECKSUM)) {
std::string algo = _requestGroup->getDownloadContext()->getPieceHashAlgo();
if(MessageDigestContext::supports(algo)) {
_messageDigestContext.reset(new MessageDigestContext());
diff --git a/src/FtpDownloadCommand.cc b/src/FtpDownloadCommand.cc
index c505e190..64929662 100644
--- a/src/FtpDownloadCommand.cc
+++ b/src/FtpDownloadCommand.cc
@@ -63,7 +63,7 @@ FtpDownloadCommand::~FtpDownloadCommand() {}
bool FtpDownloadCommand::prepareForNextSegment()
{
- if(e->option->getAsBool(PREF_FTP_REUSE_CONNECTION) &&
+ if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION) &&
(uint64_t)_segments.front()->getPositionToWrite() == _requestGroup->getTotalLength()) {
Command* command = new FtpFinishDownloadCommand(cuid, req, _requestGroup, _ftpConnection, e, ctrlSocket);
e->commands.push_back(command);
diff --git a/src/FtpFinishDownloadCommand.cc b/src/FtpFinishDownloadCommand.cc
index 76c42244..a8c09dd8 100644
--- a/src/FtpFinishDownloadCommand.cc
+++ b/src/FtpFinishDownloadCommand.cc
@@ -84,7 +84,7 @@ bool FtpFinishDownloadCommand::execute()
if(status != 226) {
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
}
- if(e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
+ if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
std::map<std::string, std::string> options;
options["baseWorkingDir"] = _ftpConnection->getBaseWorkingDir();
e->poolSocket(req, isProxyDefined(), socket, options);
diff --git a/src/FtpInitiateConnectionCommand.cc b/src/FtpInitiateConnectionCommand.cc
index 6bf05a3f..6d46fad6 100644
--- a/src/FtpInitiateConnectionCommand.cc
+++ b/src/FtpInitiateConnectionCommand.cc
@@ -83,7 +83,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
// Use GET for FTP via HTTP proxy.
req->setMethod(Request::METHOD_GET);
SharedHandle<HttpConnection> hc
- (new HttpConnection(cuid, socket, e->option));
+ (new HttpConnection(cuid, socket, getOption().get()));
HttpRequestCommand* c =
new HttpRequestCommand(cuid, req, _requestGroup, hc, e, socket);
@@ -106,7 +106,7 @@ Command* FtpInitiateConnectionCommand::createNextCommand
// Use GET for FTP via HTTP proxy.
req->setMethod(Request::METHOD_GET);
SharedHandle<HttpConnection> hc
- (new HttpConnection(cuid, pooledSocket, e->option));
+ (new HttpConnection(cuid, pooledSocket, getOption().get()));
HttpRequestCommand* c =
new HttpRequestCommand(cuid, req, _requestGroup, hc, e, pooledSocket);
diff --git a/src/FtpNegotiationCommand.cc b/src/FtpNegotiationCommand.cc
index ea9e6314..c2ac51d8 100644
--- a/src/FtpNegotiationCommand.cc
+++ b/src/FtpNegotiationCommand.cc
@@ -77,11 +77,11 @@ FtpNegotiationCommand::FtpNegotiationCommand(int32_t cuid,
AbstractCommand(cuid, req, requestGroup, e, s), sequence(seq),
ftp(new FtpConnection(cuid, socket, req,
e->getAuthConfigFactory()->createAuthConfig(req),
- e->option))
+ getOption().get()))
{
ftp->setBaseWorkingDir(baseWorkingDir);
if(seq == SEQ_RECV_GREETING) {
- setTimeout(e->option->getAsInt(PREF_CONNECT_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
}
disableReadCheckSocket();
setWriteCheckSocket(socket);
@@ -96,8 +96,8 @@ bool FtpNegotiationCommand::executeInternal() {
} else if(sequence == SEQ_NEGOTIATION_COMPLETED) {
FtpDownloadCommand* command =
new FtpDownloadCommand(cuid, req, _requestGroup, ftp, e, dataSocket, socket);
- command->setStartupIdleTime(e->option->getAsInt(PREF_STARTUP_IDLE_TIME));
- command->setLowestDownloadSpeedLimit(e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT));
+ command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
+ command->setLowestDownloadSpeedLimit(getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
if(!_requestGroup->isSingleHostMultiConnectionEnabled()) {
SharedHandle<ServerHost> sv =
_requestGroup->searchServerHost(req->getHost());
@@ -111,7 +111,7 @@ bool FtpNegotiationCommand::executeInternal() {
} else if(sequence == SEQ_HEAD_OK || sequence == SEQ_DOWNLOAD_ALREADY_COMPLETED) {
return true;
} else if(sequence == SEQ_FILE_PREPARATION) {
- if(e->option->getAsBool(PREF_FTP_PASV)) {
+ if(getOption()->getAsBool(PREF_FTP_PASV)) {
sequence = SEQ_SEND_PASV;
} else {
sequence = SEQ_PREPARE_SERVER_SOCKET;
@@ -265,7 +265,7 @@ bool FtpNegotiationCommand::recvCwd() {
else
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
}
- if(e->option->getAsBool(PREF_REMOTE_TIME)) {
+ if(getOption()->getAsBool(PREF_REMOTE_TIME)) {
sequence = SEQ_SEND_MDTM;
} else {
sequence = SEQ_SEND_SIZE;
@@ -336,13 +336,13 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
}
if(totalLength == 0) {
- if(e->option->getAsBool(PREF_FTP_PASV)) {
+ if(getOption()->getAsBool(PREF_FTP_PASV)) {
sequence = SEQ_SEND_PASV;
} else {
sequence = SEQ_PREPARE_SERVER_SOCKET;
}
- if(e->option->getAsBool(PREF_DRY_RUN)) {
+ if(getOption()->getAsBool(PREF_DRY_RUN)) {
_requestGroup->initPieceStorage();
onDryRunFileFound();
return false;
@@ -378,15 +378,15 @@ bool FtpNegotiationCommand::onFileSizeDetermined(uint64_t totalLength)
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(_requestGroup->getDownloadContext(),
SharedHandle<PieceStorage>(),
- e->option)));
+ getOption().get())));
_requestGroup->initPieceStorage();
- if(e->option->getAsBool(PREF_DRY_RUN)) {
+ if(getOption()->getAsBool(PREF_DRY_RUN)) {
onDryRunFileFound();
return false;
}
- BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
+ BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
_requestGroup->getPieceStorage()->markAllPiecesDone();
@@ -448,7 +448,7 @@ bool FtpNegotiationCommand::recvSize() {
// TODO Skipping RequestGroup::validateTotalLength(0) here will allow
// wrong file to be downloaded if user-specified URL is wrong.
}
- if(e->option->getAsBool(PREF_FTP_PASV)) {
+ if(getOption()->getAsBool(PREF_FTP_PASV)) {
sequence = SEQ_SEND_PASV;
} else {
sequence = SEQ_PREPARE_SERVER_SOCKET;
@@ -580,7 +580,7 @@ bool FtpNegotiationCommand::recvRetr() {
else
throw DlAbortEx(StringFormat(EX_BAD_STATUS, status).str());
}
- if(e->option->getAsBool(PREF_FTP_PASV)) {
+ if(getOption()->getAsBool(PREF_FTP_PASV)) {
sequence = SEQ_NEGOTIATION_COMPLETED;
return false;
} else {
@@ -664,7 +664,7 @@ bool FtpNegotiationCommand::processSequence(const SegmentHandle& segment) {
void FtpNegotiationCommand::poolConnection() const
{
- if(e->option->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
+ if(getOption()->getAsBool(PREF_FTP_REUSE_CONNECTION)) {
std::map<std::string, std::string> options;
options["baseWorkingDir"] = ftp->getBaseWorkingDir();
e->poolSocket(req, isProxyDefined(), socket, options);
diff --git a/src/HttpInitiateConnectionCommand.cc b/src/HttpInitiateConnectionCommand.cc
index 35211c56..f36b227c 100644
--- a/src/HttpInitiateConnectionCommand.cc
+++ b/src/HttpInitiateConnectionCommand.cc
@@ -80,7 +80,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
proxyRequest, socket);
} else if(proxyMethod == V_GET) {
SharedHandle<HttpConnection> httpConnection
- (new HttpConnection(cuid, socket, e->option));
+ (new HttpConnection(cuid, socket, getOption().get()));
HttpRequestCommand* c = new HttpRequestCommand(cuid, req, _requestGroup,
httpConnection, e,
socket);
@@ -92,7 +92,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
}
} else {
SharedHandle<HttpConnection> httpConnection
- (new HttpConnection(cuid, pooledSocket, e->option));
+ (new HttpConnection(cuid, pooledSocket, getOption().get()));
HttpRequestCommand* c = new HttpRequestCommand(cuid, req, _requestGroup,
httpConnection, e,
pooledSocket);
@@ -112,7 +112,7 @@ Command* HttpInitiateConnectionCommand::createNextCommand
} else {
socket = pooledSocket;
}
- SharedHandle<HttpConnection> httpConnection(new HttpConnection(cuid, socket, e->option));
+ SharedHandle<HttpConnection> httpConnection(new HttpConnection(cuid, socket, getOption().get()));
command = new HttpRequestCommand(cuid, req, _requestGroup, httpConnection,
e, socket);
}
diff --git a/src/HttpRequestCommand.cc b/src/HttpRequestCommand.cc
index 872cf55d..bf3bf8f2 100644
--- a/src/HttpRequestCommand.cc
+++ b/src/HttpRequestCommand.cc
@@ -65,7 +65,7 @@ HttpRequestCommand::HttpRequestCommand
:AbstractCommand(cuid, req, requestGroup, e, s),
_httpConnection(httpConnection)
{
- setTimeout(e->option->getAsInt(PREF_CONNECT_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_CONNECT_TIMEOUT));
disableReadCheckSocket();
setWriteCheckSocket(socket);
}
@@ -76,7 +76,7 @@ static SharedHandle<HttpRequest>
createHttpRequest(const SharedHandle<Request>& req,
const SharedHandle<Segment>& segment,
uint64_t totalLength,
- const Option* option,
+ const SharedHandle<Option>& option,
const RequestGroup* rg,
const SharedHandle<CookieStorage>& cookieStorage,
const SharedHandle<AuthConfigFactory>& authConfigFactory,
@@ -121,7 +121,8 @@ bool HttpRequestCommand::executeInternal() {
if(_segments.empty()) {
HttpRequestHandle httpRequest
(createHttpRequest(req, SharedHandle<Segment>(),
- _requestGroup->getTotalLength(), e->option,
+ _requestGroup->getTotalLength(),
+ getOption(),
_requestGroup,
e->getCookieStorage(),
e->getAuthConfigFactory(),
@@ -133,7 +134,8 @@ bool HttpRequestCommand::executeInternal() {
if(!_httpConnection->isIssued(segment)) {
HttpRequestHandle httpRequest
(createHttpRequest(req, segment,
- _requestGroup->getTotalLength(), e->option,
+ _requestGroup->getTotalLength(),
+ getOption(),
_requestGroup,
e->getCookieStorage(),
e->getAuthConfigFactory(),
diff --git a/src/HttpResponseCommand.cc b/src/HttpResponseCommand.cc
index d33399a3..0c713f10 100644
--- a/src/HttpResponseCommand.cc
+++ b/src/HttpResponseCommand.cc
@@ -108,7 +108,7 @@ bool HttpResponseCommand::executeInternal()
req->supportsPersistentConnection
(httpResponse->supportsPersistentConnection());
if(req->isPipeliningEnabled()) {
- req->setMaxPipelinedRequest(e->option->getAsInt(PREF_MAX_HTTP_PIPELINING));
+ req->setMaxPipelinedRequest(getOption()->getAsInt(PREF_MAX_HTTP_PIPELINING));
}
if(httpResponse->getResponseStatus() >= HttpHeader::S300) {
@@ -187,7 +187,7 @@ bool HttpResponseCommand::executeInternal()
void HttpResponseCommand::updateLastModifiedTime(const Time& lastModified)
{
- if(e->option->getAsBool(PREF_REMOTE_TIME)) {
+ if(getOption()->getAsBool(PREF_REMOTE_TIME)) {
_requestGroup->updateLastModifiedTime(lastModified);
}
}
@@ -220,15 +220,15 @@ bool HttpResponseCommand::handleDefaultEncoding(const HttpResponseHandle& httpRe
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(_requestGroup->getDownloadContext(),
SharedHandle<PieceStorage>(),
- e->option)));
+ getOption().get())));
_requestGroup->initPieceStorage();
- if(e->option->getAsBool(PREF_DRY_RUN)) {
+ if(getOption()->getAsBool(PREF_DRY_RUN)) {
onDryRunFileFound();
return true;
}
- BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), e->option));
+ BtProgressInfoFileHandle infoFile(new DefaultBtProgressInfoFile(_requestGroup->getDownloadContext(), _requestGroup->getPieceStorage(), getOption().get()));
if(!infoFile->exists() && _requestGroup->downloadFinishedByFileLength()) {
_requestGroup->getPieceStorage()->markAllPiecesDone();
@@ -308,7 +308,7 @@ bool HttpResponseCommand::handleOtherEncoding(const HttpResponseHandle& httpResp
// We assume that RequestGroup::getTotalLength() == 0 here
HttpRequestHandle httpRequest = httpResponse->getHttpRequest();
- if(e->option->getAsBool(PREF_DRY_RUN)) {
+ if(getOption()->getAsBool(PREF_DRY_RUN)) {
_requestGroup->initPieceStorage();
onDryRunFileFound();
return true;
@@ -386,9 +386,9 @@ HttpDownloadCommand* HttpResponseCommand::createHttpDownloadCommand
HttpDownloadCommand* command =
new HttpDownloadCommand(cuid, req, _requestGroup,
httpResponse, httpConnection, e, socket);
- command->setStartupIdleTime(e->option->getAsInt(PREF_STARTUP_IDLE_TIME));
+ command->setStartupIdleTime(getOption()->getAsInt(PREF_STARTUP_IDLE_TIME));
command->setLowestDownloadSpeedLimit
- (e->option->getAsInt(PREF_LOWEST_SPEED_LIMIT));
+ (getOption()->getAsInt(PREF_LOWEST_SPEED_LIMIT));
command->setTransferEncodingDecoder(transferEncodingDecoder);
if(!contentEncodingDecoder.isNull()) {
diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc
index f62be69c..9fa1d614 100644
--- a/src/HttpSkipResponseCommand.cc
+++ b/src/HttpSkipResponseCommand.cc
@@ -159,7 +159,7 @@ bool HttpSkipResponseCommand::processResponse()
return prepareForRetry(_httpResponse->getRetryAfter());
} else if(_httpResponse->getResponseStatus() >= HttpHeader::S400) {
if(_httpResponse->getResponseStatus() == HttpHeader::S401) {
- if(e->option->getAsBool(PREF_HTTP_AUTH_CHALLENGE) &&
+ if(getOption()->getAsBool(PREF_HTTP_AUTH_CHALLENGE) &&
!_httpResponse->getHttpRequest()->authenticationUsed() &&
e->getAuthConfigFactory()->activateBasicCred
(req->getHost(), req->getDir())) {
diff --git a/src/InitiateConnectionCommand.cc b/src/InitiateConnectionCommand.cc
index 512da0b1..936f1ca5 100644
--- a/src/InitiateConnectionCommand.cc
+++ b/src/InitiateConnectionCommand.cc
@@ -52,7 +52,7 @@ InitiateConnectionCommand::InitiateConnectionCommand
DownloadEngine* e):
AbstractCommand(cuid, req, requestGroup, e)
{
- setTimeout(e->option->getAsInt(PREF_DNS_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_DNS_TIMEOUT));
setStatus(Command::STATUS_ONESHOT_REALTIME);
disableReadCheckSocket();
disableWriteCheckSocket();
@@ -72,7 +72,7 @@ bool InitiateConnectionCommand::executeInternal() {
std::string ipaddr = e->findCachedIPAddress(hostname);
if(ipaddr.empty()) {
#ifdef ENABLE_ASYNC_DNS
- if(e->option->getAsBool(PREF_ASYNC_DNS)) {
+ if(getOption()->getAsBool(PREF_ASYNC_DNS)) {
if(!isAsyncNameResolverInitialized()) {
initAsyncNameResolver(hostname);
}
diff --git a/src/InitiateConnectionCommandFactory.cc b/src/InitiateConnectionCommandFactory.cc
index b38cd18f..504dc494 100644
--- a/src/InitiateConnectionCommandFactory.cc
+++ b/src/InitiateConnectionCommandFactory.cc
@@ -55,10 +55,10 @@ InitiateConnectionCommandFactory::createInitiateConnectionCommand(int32_t cuid,
#endif // ENABLE_SSL
) {
- if(e->option->getAsBool(PREF_ENABLE_HTTP_KEEP_ALIVE)) {
+ if(requestGroup->getOption()->getAsBool(PREF_ENABLE_HTTP_KEEP_ALIVE)) {
req->setKeepAliveHint(true);
}
- if(e->option->getAsBool(PREF_ENABLE_HTTP_PIPELINING)) {
+ if(requestGroup->getOption()->getAsBool(PREF_ENABLE_HTTP_PIPELINING)) {
req->setPipeliningHint(true);
}
diff --git a/src/InitiatorMSEHandshakeCommand.cc b/src/InitiatorMSEHandshakeCommand.cc
index e669b918..8fbd1bd2 100644
--- a/src/InitiatorMSEHandshakeCommand.cc
+++ b/src/InitiatorMSEHandshakeCommand.cc
@@ -69,11 +69,11 @@ InitiatorMSEHandshakeCommand::InitiatorMSEHandshakeCommand
_btContext(btContext),
_btRuntime(btRuntime),
_sequence(INITIATOR_SEND_KEY),
- _mseHandshake(new MSEHandshake(cuid, socket, e->option))
+ _mseHandshake(new MSEHandshake(cuid, socket, getOption().get()))
{
disableReadCheckSocket();
setWriteCheckSocket(socket);
- setTimeout(e->option->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
_btRuntime->increaseConnections();
_requestGroup->increaseNumCommand();
@@ -96,7 +96,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
disableWriteCheckSocket();
setReadCheckSocket(socket);
//socket->setBlockingMode();
- setTimeout(e->option->getAsInt(PREF_BT_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_BT_TIMEOUT));
_mseHandshake->initEncryptionFacility(true);
if(_mseHandshake->sendPublicKey()) {
_sequence = INITIATOR_WAIT_KEY;
@@ -145,7 +145,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
case INITIATOR_RECEIVE_PAD_D: {
if(_mseHandshake->receivePad()) {
SharedHandle<PeerConnection> peerConnection
- (new PeerConnection(cuid, socket, e->option));
+ (new PeerConnection(cuid, socket, getOption().get()));
if(_mseHandshake->getNegotiatedCryptoType() == MSEHandshake::CRYPTO_ARC4) {
peerConnection->enableEncryption(_mseHandshake->getEncryptor(),
_mseHandshake->getDecryptor());
@@ -169,7 +169,7 @@ bool InitiatorMSEHandshakeCommand::executeInternal() {
bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
{
- if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
+ if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
logger->info("CUID#%d - Establishing connection using legacy BitTorrent handshake is disabled by preference.", cuid);
if(_peerStorage->isPeerAvailable() && _btRuntime->lessThanEqMinPeers()) {
SharedHandle<Peer> peer = _peerStorage->getUnusedPeer();
@@ -197,7 +197,7 @@ bool InitiatorMSEHandshakeCommand::prepareForNextPeer(time_t wait)
void InitiatorMSEHandshakeCommand::onAbort()
{
- if(e->option->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
+ if(getOption()->getAsBool(PREF_BT_REQUIRE_CRYPTO)) {
_peerStorage->returnPeer(peer);
}
}
@@ -219,4 +219,9 @@ void InitiatorMSEHandshakeCommand::setPieceStorage
_pieceStorage = pieceStorage;
}
+const SharedHandle<Option>& InitiatorMSEHandshakeCommand::getOption() const
+{
+ return _requestGroup->getOption();
+}
+
} // namespace aria2
diff --git a/src/InitiatorMSEHandshakeCommand.h b/src/InitiatorMSEHandshakeCommand.h
index 799382eb..46cbedf0 100644
--- a/src/InitiatorMSEHandshakeCommand.h
+++ b/src/InitiatorMSEHandshakeCommand.h
@@ -45,6 +45,7 @@ class PeerStorage;
class PieceStorage;
class BtRuntime;
class MSEHandshake;
+class Option;
class InitiatorMSEHandshakeCommand : public PeerAbstractCommand {
public:
@@ -70,6 +71,8 @@ private:
Seq _sequence;
MSEHandshake* _mseHandshake;
+
+ const SharedHandle<Option>& getOption() const;
protected:
virtual bool executeInternal();
virtual bool prepareForNextPeer(time_t wait);
diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc
index dd70c8d6..eeef248b 100644
--- a/src/Metalink2RequestGroup.cc
+++ b/src/Metalink2RequestGroup.cc
@@ -60,12 +60,9 @@
namespace aria2 {
-Metalink2RequestGroup::Metalink2RequestGroup(const Option* option):
- _option(option),
+Metalink2RequestGroup::Metalink2RequestGroup():
_logger(LogFactory::getInstance()) {}
-Metalink2RequestGroup::~Metalink2RequestGroup() {}
-
class AccumulateNonP2PUrl {
private:
std::deque<std::string>& urlsPtr;
@@ -102,35 +99,35 @@ public:
void
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
const std::string& metalinkFile,
- const Option& requestOption)
+ const SharedHandle<Option>& option)
{
std::deque<SharedHandle<MetalinkEntry> > entries;
- MetalinkHelper::parseAndQuery(entries, metalinkFile, _option);
- createRequestGroup(groups, entries, requestOption);
+ MetalinkHelper::parseAndQuery(entries, metalinkFile, option.get());
+ createRequestGroup(groups, entries, option);
}
void
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
const SharedHandle<BinaryStream>& binaryStream,
- const Option& requestOption)
+ const SharedHandle<Option>& option)
{
std::deque<SharedHandle<MetalinkEntry> > entries;
- MetalinkHelper::parseAndQuery(entries, binaryStream, _option);
- createRequestGroup(groups, entries, requestOption);
+ MetalinkHelper::parseAndQuery(entries, binaryStream, option.get());
+ createRequestGroup(groups, entries, option);
}
void
Metalink2RequestGroup::createRequestGroup
(std::deque<SharedHandle<RequestGroup> >& groups,
std::deque<SharedHandle<MetalinkEntry> > entries,
- const Option& requestOption)
+ const SharedHandle<Option>& option)
{
if(entries.size() == 0) {
_logger->notice(EX_NO_RESULT_WITH_YOUR_PREFS);
return;
}
std::deque<int32_t> selectIndexes =
- Util::parseIntRange(_option->get(PREF_SELECT_FILE)).flush();
+ Util::parseIntRange(option->get(PREF_SELECT_FILE)).flush();
bool useIndex;
if(selectIndexes.size()) {
useIndex = true;
@@ -141,13 +138,13 @@ Metalink2RequestGroup::createRequestGroup
for(std::deque<SharedHandle<MetalinkEntry> >::iterator itr = entries.begin(); itr != entries.end();
itr++, ++count) {
SharedHandle<MetalinkEntry>& entry = *itr;
- if(_option->defined(PREF_METALINK_LOCATION)) {
+ if(option->defined(PREF_METALINK_LOCATION)) {
std::deque<std::string> locations;
- Util::slice(locations, _option->get(PREF_METALINK_LOCATION), ',', true);
+ Util::slice(locations, option->get(PREF_METALINK_LOCATION), ',', true);
entry->setLocationPreference(locations, 100);
}
- if(_option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
- entry->setProtocolPreference(_option->get(PREF_METALINK_PREFERRED_PROTOCOL), 100);
+ if(option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
+ entry->setProtocolPreference(option->get(PREF_METALINK_PREFERRED_PROTOCOL), 100);
}
if(useIndex) {
if(std::find(selectIndexes.begin(), selectIndexes.end(), count+1) ==
@@ -169,9 +166,9 @@ Metalink2RequestGroup::createRequestGroup
if(itr != entry->resources.end()) {
std::deque<std::string> uris;
uris.push_back((*itr)->url);
- torrentRg.reset(new RequestGroup(_option, uris));
+ torrentRg.reset(new RequestGroup(option, uris));
SharedHandle<SingleFileDownloadContext> dctx
- (new SingleFileDownloadContext(_option->getAsInt(PREF_SEGMENT_SIZE),
+ (new SingleFileDownloadContext(option->getAsInt(PREF_SEGMENT_SIZE),
0,
A2STR::NIL));
//dctx->setDir(_option->get(PREF_DIR));
@@ -195,26 +192,26 @@ Metalink2RequestGroup::createRequestGroup
std::deque<std::string> uris;
std::for_each(entry->resources.begin(), entry->resources.end(),
AccumulateNonP2PUrl(uris));
- SharedHandle<RequestGroup> rg(new RequestGroup(_option, uris));
+ SharedHandle<RequestGroup> rg(new RequestGroup(option, uris));
// If piece hash is specified in the metalink,
// make segment size equal to piece hash size.
size_t pieceLength;
#ifdef ENABLE_MESSAGE_DIGEST
if(entry->chunkChecksum.isNull()) {
- pieceLength = _option->getAsInt(PREF_SEGMENT_SIZE);
+ pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
} else {
pieceLength = entry->chunkChecksum->getChecksumLength();
}
#else
- pieceLength = _option->getAsInt(PREF_SEGMENT_SIZE);
+ pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
#endif // ENABLE_MESSAGE_DIGEST
SharedHandle<SingleFileDownloadContext> dctx
- (new SingleFileDownloadContext(pieceLength,
- entry->getLength(),
- A2STR::NIL,
- requestOption.get(PREF_DIR)+"/"+
- entry->file->getPath()));
- dctx->setDir(requestOption.get(PREF_DIR));
+ (new SingleFileDownloadContext
+ (pieceLength,
+ entry->getLength(),
+ A2STR::NIL,
+ option->get(PREF_DIR)+"/"+entry->file->getPath()));
+ dctx->setDir(option->get(PREF_DIR));
#ifdef ENABLE_MESSAGE_DIGEST
if(entry->chunkChecksum.isNull()) {
if(!entry->checksum.isNull()) {
@@ -230,11 +227,11 @@ Metalink2RequestGroup::createRequestGroup
rg->setDownloadContext(dctx);
rg->setNumConcurrentCommand
(entry->maxConnections < 0 ?
- _option->getAsInt(PREF_METALINK_SERVERS) :
- std::min(_option->getAsInt(PREF_METALINK_SERVERS),
+ option->getAsInt(PREF_METALINK_SERVERS) :
+ std::min(option->getAsInt(PREF_METALINK_SERVERS),
static_cast<int32_t>(entry->maxConnections)));
// In metalink, multi connection to a single host is not allowed by default.
- rg->setSingleHostMultiConnectionEnabled(!_option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL));
+ rg->setSingleHostMultiConnectionEnabled(!option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL));
// remove "metalink" from Accept Type list to avoid loop in tranparent
// metalink
rg->removeAcceptType(RequestGroup::ACCEPT_METALINK);
@@ -242,7 +239,7 @@ Metalink2RequestGroup::createRequestGroup
#ifdef ENABLE_BITTORRENT
// Inject depenency between rg and torrentRg here if torrentRg.isNull() == false
if(!torrentRg.isNull()) {
- SharedHandle<Dependency> dep(new BtDependency(rg, torrentRg, _option));
+ SharedHandle<Dependency> dep(new BtDependency(rg, torrentRg));
rg->dependsOn(dep);
}
#endif // ENABLE_BITTORRENT
diff --git a/src/Metalink2RequestGroup.h b/src/Metalink2RequestGroup.h
index 748d7bb7..4836d85a 100644
--- a/src/Metalink2RequestGroup.h
+++ b/src/Metalink2RequestGroup.h
@@ -50,26 +50,22 @@ class MetalinkEntry;
class Metalink2RequestGroup {
private:
- const Option* _option;
-
Logger* _logger;
void
createRequestGroup(std::deque<SharedHandle<RequestGroup> >& groups,
std::deque<SharedHandle<MetalinkEntry> > entries,
- const Option& requestOption);
+ const SharedHandle<Option>& option);
public:
- Metalink2RequestGroup(const Option* option);
-
- ~Metalink2RequestGroup();
+ Metalink2RequestGroup();
void generate(std::deque<SharedHandle<RequestGroup> >& groups,
const std::string& metalinkFile,
- const Option& requestOption);
+ const SharedHandle<Option>& option);
void generate(std::deque<SharedHandle<RequestGroup> >& groups,
const SharedHandle<BinaryStream>& binaryStream,
- const Option& requestOption);
+ const SharedHandle<Option>& option);
};
} // namespace aria2
diff --git a/src/MetalinkPostDownloadHandler.cc b/src/MetalinkPostDownloadHandler.cc
index a662751e..7623f1e8 100644
--- a/src/MetalinkPostDownloadHandler.cc
+++ b/src/MetalinkPostDownloadHandler.cc
@@ -61,16 +61,15 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
(std::deque<SharedHandle<RequestGroup> >& groups,
RequestGroup* requestGroup)
{
- const Option* op = requestGroup->getOption();
_logger->debug("Generating RequestGroups for Metalink file %s",
requestGroup->getFilePath().c_str());
SharedHandle<DiskAdaptor> diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
try {
diskAdaptor->openExistingFile();
- Option requestOption;
- requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
+ //requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
- Metalink2RequestGroup(op).generate(groups, diskAdaptor, requestOption);
+ Metalink2RequestGroup().generate(groups, diskAdaptor,
+ requestGroup->getOption());
diskAdaptor->closeFile();
} catch(Exception& e) {
diskAdaptor->closeFile();
diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc
index 192eb128..d0ffe5ed 100644
--- a/src/MultiUrlRequestInfo.cc
+++ b/src/MultiUrlRequestInfo.cc
@@ -77,7 +77,7 @@ static void handler(int signal) {
MultiUrlRequestInfo::MultiUrlRequestInfo
(const RequestGroups& requestGroups,
- Option* op,
+ const SharedHandle<Option>& op,
const SharedHandle<StatCalc>& statCalc,
std::ostream& summaryOut)
:
@@ -104,7 +104,7 @@ DownloadResult::RESULT MultiUrlRequestInfo::execute()
DownloadResult::RESULT returnValue = DownloadResult::FINISHED;
try {
DownloadEngineHandle e =
- DownloadEngineFactory().newDownloadEngine(_option, _requestGroups);
+ DownloadEngineFactory().newDownloadEngine(_option.get(), _requestGroups);
try {
if(!_option->blank(PREF_LOAD_COOKIES)) {
@@ -121,7 +121,7 @@ DownloadResult::RESULT MultiUrlRequestInfo::execute()
}
SharedHandle<AuthConfigFactory> authConfigFactory
- (new AuthConfigFactory(_option));
+ (new AuthConfigFactory(_option.get()));
File netrccf(_option->get(PREF_NETRC_PATH));
if(!_option->getAsBool(PREF_NO_NETRC) && netrccf.isFile()) {
mode_t mode = netrccf.mode();
diff --git a/src/MultiUrlRequestInfo.h b/src/MultiUrlRequestInfo.h
index 25742034..aaa9b05f 100644
--- a/src/MultiUrlRequestInfo.h
+++ b/src/MultiUrlRequestInfo.h
@@ -54,7 +54,7 @@ class MultiUrlRequestInfo {
private:
std::deque<SharedHandle<RequestGroup> > _requestGroups;
- Option* _option;
+ SharedHandle<Option> _option;
SharedHandle<StatCalc> _statCalc;
@@ -67,7 +67,7 @@ private:
public:
MultiUrlRequestInfo
(const std::deque<SharedHandle<RequestGroup> >& requestGroups,
- Option* op,
+ const SharedHandle<Option>& op,
const SharedHandle<StatCalc>& statCalc,
std::ostream& summaryOut);
diff --git a/src/PeerAbstractCommand.cc b/src/PeerAbstractCommand.cc
index ab73ef8c..caf4f140 100644
--- a/src/PeerAbstractCommand.cc
+++ b/src/PeerAbstractCommand.cc
@@ -61,6 +61,7 @@ PeerAbstractCommand::PeerAbstractCommand(int32_t cuid,
if(!socket.isNull() && socket->isOpen()) {
setReadCheckSocket(socket);
}
+ // TODO referring global option
timeout = e->option->getAsInt(PREF_BT_TIMEOUT);
}
diff --git a/src/PeerInteractionCommand.cc b/src/PeerInteractionCommand.cc
index 556a0fef..291d3f3c 100644
--- a/src/PeerInteractionCommand.cc
+++ b/src/PeerInteractionCommand.cc
@@ -95,7 +95,7 @@ PeerInteractionCommand::PeerInteractionCommand
if(sequence == INITIATOR_SEND_HANDSHAKE) {
disableReadCheckSocket();
setWriteCheckSocket(socket);
- setTimeout(e->option->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_PEER_CONNECTION_TIMEOUT));
}
SharedHandle<BtRegistry> btRegistry = e->getBtRegistry();
@@ -123,7 +123,7 @@ PeerInteractionCommand::PeerInteractionCommand
PeerConnectionHandle peerConnection;
if(passedPeerConnection.isNull()) {
- peerConnection.reset(new PeerConnection(cuid, socket, e->option));
+ peerConnection.reset(new PeerConnection(cuid, socket, getOption().get()));
} else {
peerConnection = passedPeerConnection;
}
@@ -135,7 +135,7 @@ PeerInteractionCommand::PeerInteractionCommand
dispatcher->setBtContext(_btContext);
dispatcher->setPieceStorage(pieceStorage);
dispatcher->setPeerStorage(peerStorage);
- dispatcher->setRequestTimeout(e->option->getAsInt(PREF_BT_REQUEST_TIMEOUT));
+ dispatcher->setRequestTimeout(getOption()->getAsInt(PREF_BT_REQUEST_TIMEOUT));
dispatcher->setBtMessageFactory(factory);
dispatcher->setRequestGroupMan(e->_requestGroupMan);
@@ -169,11 +169,11 @@ PeerInteractionCommand::PeerInteractionCommand
btInteractive->setExtensionMessageFactory(extensionMessageFactory);
btInteractive->setExtensionMessageRegistry(exMsgRegistry);
btInteractive->setKeepAliveInterval
- (e->option->getAsInt(PREF_BT_KEEP_ALIVE_INTERVAL));
+ (getOption()->getAsInt(PREF_BT_KEEP_ALIVE_INTERVAL));
btInteractive->setRequestGroupMan(e->_requestGroupMan);
btInteractive->setBtMessageFactory(factory);
if(!_btContext->isPrivate()) {
- if(e->option->getAsBool(PREF_ENABLE_PEER_EXCHANGE)) {
+ if(getOption()->getAsBool(PREF_ENABLE_PEER_EXCHANGE)) {
btInteractive->setUTPexEnabled(true);
}
if(DHTSetup::initialized()) {
@@ -220,7 +220,7 @@ bool PeerInteractionCommand::executeInternal() {
disableWriteCheckSocket();
setReadCheckSocket(socket);
//socket->setBlockingMode();
- setTimeout(e->option->getAsInt(PREF_BT_TIMEOUT));
+ setTimeout(getOption()->getAsInt(PREF_BT_TIMEOUT));
btInteractive->initiateHandshake();
sequence = INITIATOR_WAIT_HANDSHAKE;
break;
@@ -324,4 +324,9 @@ void PeerInteractionCommand::setPeerStorage
_peerStorage = peerStorage;
}
+const SharedHandle<Option>& PeerInteractionCommand::getOption() const
+{
+ return _requestGroup->getOption();
+}
+
} // namespace aria2
diff --git a/src/PeerInteractionCommand.h b/src/PeerInteractionCommand.h
index d90f9ce6..a8ed8514 100644
--- a/src/PeerInteractionCommand.h
+++ b/src/PeerInteractionCommand.h
@@ -46,6 +46,7 @@ class PeerConnection;
class BtRuntime;
class PeerStorage;
class PieceStorage;
+class Option;
class PeerInteractionCommand : public PeerAbstractCommand {
public:
@@ -67,6 +68,8 @@ private:
Seq sequence;
SharedHandle<BtInteractive> btInteractive;
+
+ const SharedHandle<Option>& getOption() const;
protected:
virtual bool executeInternal();
virtual bool prepareForNextPeer(time_t wait);
diff --git a/src/PeerReceiveHandshakeCommand.cc b/src/PeerReceiveHandshakeCommand.cc
index e5bf415a..c77dd843 100644
--- a/src/PeerReceiveHandshakeCommand.cc
+++ b/src/PeerReceiveHandshakeCommand.cc
@@ -67,10 +67,10 @@ PeerReceiveHandshakeCommand::PeerReceiveHandshakeCommand
const SharedHandle<PeerConnection>& peerConnection)
:
PeerAbstractCommand(cuid, peer, e, s),
- _peerConnection(peerConnection),
- _thresholdSpeed(e->option->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT))
+ _peerConnection(peerConnection)
{
if(_peerConnection.isNull()) {
+ // TODO referring global option
_peerConnection.reset(new PeerConnection(cuid, socket, e->option));
}
}
@@ -109,9 +109,11 @@ bool PeerReceiveHandshakeCommand::executeInternal()
TransferStat tstat = btContext->getOwnerRequestGroup()->calculateStat();
const unsigned int maxDownloadLimit =
btContext->getOwnerRequestGroup()->getMaxDownloadSpeedLimit();
- unsigned int thresholdSpeed = _thresholdSpeed;
+ unsigned int thresholdSpeed =
+ btContext->getOwnerRequestGroup()->
+ getOption()->getAsInt(PREF_BT_REQUEST_PEER_SPEED_LIMIT);
if(maxDownloadLimit > 0) {
- thresholdSpeed = std::min(maxDownloadLimit, _thresholdSpeed);
+ thresholdSpeed = std::min(maxDownloadLimit, thresholdSpeed);
}
if((!pieceStorage->downloadFinished() &&
diff --git a/src/PeerReceiveHandshakeCommand.h b/src/PeerReceiveHandshakeCommand.h
index d63bcdec..afeb8bdc 100644
--- a/src/PeerReceiveHandshakeCommand.h
+++ b/src/PeerReceiveHandshakeCommand.h
@@ -47,9 +47,6 @@ class PeerReceiveHandshakeCommand:public PeerAbstractCommand
{
private:
SharedHandle<PeerConnection> _peerConnection;
-
- unsigned int _thresholdSpeed;
-
protected:
virtual bool executeInternal();
virtual bool exitBeforeExecute();
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index 6bab311d..981e56a2 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -110,14 +110,15 @@ int32_t RequestGroup::_gidCounter = 0;
const std::string RequestGroup::ACCEPT_METALINK = "application/metalink+xml";
-RequestGroup::RequestGroup(const Option* option,
+RequestGroup::RequestGroup(const SharedHandle<Option>& option,
const std::deque<std::string>& uris):
_gid(++_gidCounter),
+ _option(new Option(*option.get())),
_uris(uris),
_numConcurrentCommand(option->getAsInt(PREF_SPLIT)),
_numStreamConnection(0),
_numCommand(0),
- _segmentManFactory(new DefaultSegmentManFactory(option)),
+ _segmentManFactory(new DefaultSegmentManFactory(_option.get())),
_progressInfoFile(new NullProgressInfoFile()),
_preLocalFileCheckEnabled(true),
_haltRequested(false),
@@ -131,7 +132,6 @@ RequestGroup::RequestGroup(const Option* option,
_inMemoryDownload(false),
_maxDownloadSpeedLimit(option->getAsInt(PREF_MAX_DOWNLOAD_LIMIT)),
_maxUploadSpeedLimit(option->getAsInt(PREF_MAX_UPLOAD_LIMIT)),
- _option(option),
_logger(LogFactory::getInstance())
{
_fileAllocationEnabled = _option->get(PREF_FILE_ALLOCATION) != V_NONE;
@@ -237,7 +237,7 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
SharedHandle<DefaultBtProgressInfoFile>
progressInfoFile(new DefaultBtProgressInfoFile(_downloadContext,
_pieceStorage,
- _option));
+ _option.get()));
btRegistry->registerBtContext(btContext->getInfoHashAsString(),
btContext);
@@ -256,7 +256,7 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
progressInfoFile->setBtRuntime(btRuntime);
SharedHandle<DefaultPeerStorage> peerStorage
- (new DefaultPeerStorage(btContext, _option));
+ (new DefaultPeerStorage(btContext, _option.get()));
peerStorage->setBtRuntime(btRuntime);
peerStorage->setPieceStorage(_pieceStorage);
btRegistry->registerPeerStorage(btContext->getInfoHashAsString(),
@@ -265,7 +265,7 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
progressInfoFile->setPeerStorage(peerStorage);
SharedHandle<DefaultBtAnnounce> btAnnounce
- (new DefaultBtAnnounce(btContext, _option));
+ (new DefaultBtAnnounce(btContext, _option.get()));
btAnnounce->setBtRuntime(btRuntime);
btAnnounce->setPieceStorage(_pieceStorage);
btAnnounce->setPeerStorage(peerStorage);
@@ -326,7 +326,7 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
if(!btContext->isPrivate() && _option->getAsBool(PREF_ENABLE_DHT)) {
std::deque<Command*> commands;
- DHTSetup().setup(commands, e, _option);
+ DHTSetup().setup(commands, e, _option.get());
e->addCommand(commands);
if(!btContext->getNodes().empty() && DHTSetup::initialized()) {
DHTEntryPointNameResolveCommand* command =
@@ -367,10 +367,11 @@ void RequestGroup::createInitialCommand(std::deque<Command*>& commands,
(SharedHandle<BtProgressInfoFile>(new DefaultBtProgressInfoFile
(_downloadContext,
SharedHandle<PieceStorage>(),
- _option)));
+ _option.get())));
initPieceStorage();
BtProgressInfoFileHandle infoFile
- (new DefaultBtProgressInfoFile(_downloadContext, _pieceStorage, _option));
+ (new DefaultBtProgressInfoFile(_downloadContext, _pieceStorage,
+ _option.get()));
if(!infoFile->exists() && downloadFinishedByFileLength()) {
_pieceStorage->markAllPiecesDone();
_logger->notice(MSG_DOWNLOAD_ALREADY_COMPLETED,
@@ -389,7 +390,7 @@ void RequestGroup::processCheckIntegrityEntry(std::deque<Command*>& commands,
DownloadEngine* e)
{
#ifdef ENABLE_MESSAGE_DIGEST
- if(e->option->getAsBool(PREF_CHECK_INTEGRITY) &&
+ if(_option->getAsBool(PREF_CHECK_INTEGRITY) &&
entry->isValidationReady()) {
entry->initValidator();
entry->cutTrailingGarbage();
@@ -406,7 +407,7 @@ void RequestGroup::initPieceStorage()
if(_downloadContext->knowsTotalLength()) {
#ifdef ENABLE_BITTORRENT
SharedHandle<DefaultPieceStorage> ps
- (new DefaultPieceStorage(_downloadContext, _option));
+ (new DefaultPieceStorage(_downloadContext, _option.get()));
// Use LongestSequencePieceSelector when HTTP/FTP/BitTorrent integrated
// downloads. Currently multi-file integrated download is not supported.
if(!_uris.empty() &&
@@ -418,7 +419,7 @@ void RequestGroup::initPieceStorage()
}
#else // !ENABLE_BITTORRENT
SharedHandle<DefaultPieceStorage> ps
- (new DefaultPieceStorage(_downloadContext, _option));
+ (new DefaultPieceStorage(_downloadContext, _option.get()));
#endif // !ENABLE_BITTORRENT
if(!_diskWriterFactory.isNull()) {
ps->setDiskWriterFactory(_diskWriterFactory);
@@ -426,7 +427,7 @@ void RequestGroup::initPieceStorage()
_pieceStorage = ps;
} else {
UnknownLengthPieceStorageHandle ps
- (new UnknownLengthPieceStorage(_downloadContext, _option));
+ (new UnknownLengthPieceStorage(_downloadContext, _option.get()));
if(!_diskWriterFactory.isNull()) {
ps->setDiskWriterFactory(_diskWriterFactory);
}
diff --git a/src/RequestGroup.h b/src/RequestGroup.h
index c3e678b8..c110664e 100644
--- a/src/RequestGroup.h
+++ b/src/RequestGroup.h
@@ -79,6 +79,8 @@ private:
int32_t _gid;
+ SharedHandle<Option> _option;
+
std::deque<std::string> _uris;
std::deque<std::string> _spentUris;
@@ -154,8 +156,6 @@ private:
unsigned int _maxUploadSpeedLimit;
- const Option* _option;
-
Logger* _logger;
void validateFilename(const std::string& expectedFilename,
@@ -177,7 +177,8 @@ private:
// Otherwise returns DownloadResult::UNKNOWN_ERROR.
DownloadResult::RESULT downloadResult() const;
public:
- RequestGroup(const Option* option, const std::deque<std::string>& uris);
+ RequestGroup(const SharedHandle<Option>& option,
+ const std::deque<std::string>& uris);
~RequestGroup();
/**
@@ -375,7 +376,7 @@ public:
SharedHandle<DownloadResult> createDownloadResult() const;
- const Option* getOption() const
+ const SharedHandle<Option>& getOption() const
{
return _option;
}
diff --git a/src/TrackerWatcherCommand.cc b/src/TrackerWatcherCommand.cc
index b4a05117..910696b6 100644
--- a/src/TrackerWatcherCommand.cc
+++ b/src/TrackerWatcherCommand.cc
@@ -205,7 +205,7 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
{
std::deque<std::string> uris;
uris.push_back(uri);
- RequestGroupHandle rg(new RequestGroup(e->option, uris));
+ RequestGroupHandle rg(new RequestGroup(getOption(), uris));
// If backup tracker is available, only try 2 times for each tracker
// and if they all fails, then try next one.
if(backupTrackerIsAvailable(_btContext->getAnnounceTiers())) {
@@ -218,7 +218,7 @@ TrackerWatcherCommand::createRequestGroup(const std::string& uri)
static const std::string TRACKER_ANNOUNCE_FILE("[tracker.announce]");
SingleFileDownloadContextHandle dctx
- (new SingleFileDownloadContext(e->option->getAsInt(PREF_SEGMENT_SIZE),
+ (new SingleFileDownloadContext(getOption()->getAsInt(PREF_SEGMENT_SIZE),
0,
A2STR::NIL,
TRACKER_ANNOUNCE_FILE));
@@ -256,4 +256,9 @@ void TrackerWatcherCommand::setBtAnnounce
_btAnnounce = btAnnounce;
}
+const SharedHandle<Option>& TrackerWatcherCommand::getOption() const
+{
+ return _requestGroup->getOption();
+}
+
} // namespace aria2
diff --git a/src/TrackerWatcherCommand.h b/src/TrackerWatcherCommand.h
index a98f33a4..9c7c2417 100644
--- a/src/TrackerWatcherCommand.h
+++ b/src/TrackerWatcherCommand.h
@@ -47,6 +47,7 @@ class PeerStorage;
class PieceStorage;
class BtRuntime;
class BtAnnounce;
+class Option;
class TrackerWatcherCommand : public Command
{
@@ -76,6 +77,7 @@ private:
void processTrackerResponse(const std::string& response);
+ const SharedHandle<Option>& getOption() const;
public:
TrackerWatcherCommand(int32_t cuid,
RequestGroup* requestGroup,
diff --git a/src/XmlRpcMethod.cc b/src/XmlRpcMethod.cc
index 46faacab..f626286a 100644
--- a/src/XmlRpcMethod.cc
+++ b/src/XmlRpcMethod.cc
@@ -140,7 +140,7 @@ std::string XmlRpcMethod::execute(const XmlRpcRequest& req, DownloadEngine* e)
}
void XmlRpcMethod::gatherRequestOption
-(Option& requestOption, const Option& option, const BDE& optionsDict)
+(const SharedHandle<Option>& option, const BDE& optionsDict)
{
for(std::vector<std::string>::const_iterator i = listRequestOptions().begin();
i != listRequestOptions().end(); ++i) {
@@ -148,11 +148,10 @@ void XmlRpcMethod::gatherRequestOption
const BDE& value = optionsDict[*i];
if(value.isString()) {
_optionParser->findByName(*i)->parse
- (requestOption, value.s());
+ (*option.get(), value.s());
}
}
}
- completeRequestOption(requestOption, option);
}
} // namespace xmlrpc
diff --git a/src/XmlRpcMethod.h b/src/XmlRpcMethod.h
index 52b59a61..02118d33 100644
--- a/src/XmlRpcMethod.h
+++ b/src/XmlRpcMethod.h
@@ -61,7 +61,7 @@ protected:
virtual BDE process(const XmlRpcRequest& req, DownloadEngine* e) = 0;
- void gatherRequestOption(Option& requestOption, const Option& option,
+ void gatherRequestOption(const SharedHandle<Option>& option,
const BDE& optionsDict);
public:
XmlRpcMethod();
diff --git a/src/XmlRpcMethodImpl.cc b/src/XmlRpcMethodImpl.cc
index 78b9914f..ebad520d 100644
--- a/src/XmlRpcMethodImpl.cc
+++ b/src/XmlRpcMethodImpl.cc
@@ -87,12 +87,12 @@ BDE AddURIXmlRpcMethod::process(const XmlRpcRequest& req, DownloadEngine* e)
}
}
- Option requestOption;
+ SharedHandle<Option> requestOption(new Option(*e->option));
if(params.size() > 1 && params[1].isDict()) {
- gatherRequestOption(requestOption, *e->option, params[1]);
+ gatherRequestOption(requestOption, params[1]);
}
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, *e->option, uris, requestOption,
+ createRequestGroupForUri(result, requestOption, uris,
/* ignoreForceSeq = */ true,
/* ignoreNonURI = */ true);
@@ -113,9 +113,14 @@ BDE AddTorrentFileXmlRpcMethod::process
throw DlAbortEx("Torrent data is not provided.");
}
- // TODO should accect uris from xml rpc request
+ // TODO should accept uris from xml rpc request
+
+ SharedHandle<Option> requestOption(new Option(*e->option));
+ if(params.size() > 2 && params[2].isDict()) {
+ gatherRequestOption(requestOption, params[2]);
+ }
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForBitTorrent(result, *e->option,
+ createRequestGroupForBitTorrent(result, requestOption,
std::deque<std::string>(),
params[0].s());
diff --git a/src/download_helper.cc b/src/download_helper.cc
index 588b3742..3d906c8a 100644
--- a/src/download_helper.cc
+++ b/src/download_helper.cc
@@ -108,19 +108,19 @@ static void splitURI(std::deque<std::string>& result,
}
static SharedHandle<RequestGroup> createRequestGroup
-(const Option& op, const std::deque<std::string>& uris,
- const Option& requestOption,
+(const SharedHandle<Option>& option, const std::deque<std::string>& uris,
bool useOutOption = false)
{
- SharedHandle<RequestGroup> rg(new RequestGroup(&op, uris));
+ SharedHandle<RequestGroup> rg(new RequestGroup(option, uris));
SharedHandle<SingleFileDownloadContext> dctx
- (new SingleFileDownloadContext(op.getAsInt(PREF_SEGMENT_SIZE),
- 0,
- A2STR::NIL,
- useOutOption&&!requestOption.blank(PREF_OUT)?
- requestOption.get(PREF_DIR)+"/"+requestOption.get(PREF_OUT):A2STR::NIL));
+ (new SingleFileDownloadContext
+ (option->getAsInt(PREF_SEGMENT_SIZE),
+ 0,
+ A2STR::NIL,
+ useOutOption&&!option->blank(PREF_OUT)?
+ option->get(PREF_DIR)+"/"+option->get(PREF_OUT):A2STR::NIL));
- dctx->setDir(requestOption.get(PREF_DIR));
+ dctx->setDir(option->get(PREF_DIR));
rg->setDownloadContext(dctx);
return rg;
}
@@ -130,25 +130,24 @@ static SharedHandle<RequestGroup> createRequestGroup
static
SharedHandle<RequestGroup>
createBtRequestGroup(const std::string& torrentFilePath,
- const Option& op,
+ const SharedHandle<Option>& option,
const std::deque<std::string>& auxUris,
- const Option& requestOption,
const std::string& torrentData = "")
{
- SharedHandle<RequestGroup> rg(new RequestGroup(&op, auxUris));
+ SharedHandle<RequestGroup> rg(new RequestGroup(option, auxUris));
SharedHandle<DefaultBtContext> btContext(new DefaultBtContext());
- btContext->setDir(requestOption.get(PREF_DIR));
+ btContext->setDir(option->get(PREF_DIR));
if(torrentData.empty()) {
btContext->load(torrentFilePath);// may throw exception
} else {
btContext->loadFromMemory(torrentData, "default"); // may throw exception
}
- if(op.defined(PREF_PEER_ID_PREFIX)) {
- btContext->setPeerIdPrefix(op.get(PREF_PEER_ID_PREFIX));
+ if(option->defined(PREF_PEER_ID_PREFIX)) {
+ btContext->setPeerIdPrefix(option->get(PREF_PEER_ID_PREFIX));
}
btContext->setFileFilter
- (Util::parseIntRange(requestOption.get(PREF_SELECT_FILE)));
- std::istringstream indexOutIn(requestOption.get(PREF_INDEX_OUT));
+ (Util::parseIntRange(option->get(PREF_SELECT_FILE)));
+ std::istringstream indexOutIn(option->get(PREF_INDEX_OUT));
std::map<size_t, std::string> indexPathMap =
Util::createIndexPathMap(indexOutIn);
for(std::map<size_t, std::string>::const_iterator i = indexPathMap.begin();
@@ -162,22 +161,23 @@ createBtRequestGroup(const std::string& torrentFilePath,
}
void createRequestGroupForBitTorrent
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option,
const std::deque<std::string>& uris,
const std::string& torrentData)
{
std::deque<std::string> nargs;
- if(op.get(PREF_PARAMETERIZED_URI) == V_TRUE) {
+ if(option->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
unfoldURI(nargs, uris);
} else {
nargs = uris;
}
// we ignore -Z option here
- size_t numSplit = op.getAsInt(PREF_SPLIT);
+ size_t numSplit = option->getAsInt(PREF_SPLIT);
std::deque<std::string> auxUris;
splitURI(auxUris, nargs.begin(), nargs.end(), numSplit);
SharedHandle<RequestGroup> rg =
- createBtRequestGroup(op.get(PREF_TORRENT_FILE), op, auxUris, op,
+ createBtRequestGroup(option->get(PREF_TORRENT_FILE), option, auxUris,
torrentData);
rg->setNumConcurrentCommand(numSplit);
result.push_back(rg);
@@ -187,9 +187,12 @@ void createRequestGroupForBitTorrent
#ifdef ENABLE_METALINK
void createRequestGroupForMetalink
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op)
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option)
{
- Metalink2RequestGroup(&op).generate(result, op.get(PREF_METALINK_FILE), op);
+ Metalink2RequestGroup().generate(result,
+ option->get(PREF_METALINK_FILE),
+ option);
if(result.empty()) {
throw FatalException(MSG_NO_FILES_TO_DOWNLOAD);
}
@@ -200,34 +203,31 @@ class AccRequestGroup {
private:
std::deque<SharedHandle<RequestGroup> >& _requestGroups;
ProtocolDetector _detector;
- const Option& _op;
- const Option& _requestOption;
+ SharedHandle<Option> _option;
public:
AccRequestGroup(std::deque<SharedHandle<RequestGroup> >& requestGroups,
- const Option& op,
- const Option& requestOption):
- _requestGroups(requestGroups), _op(op), _requestOption(requestOption) {}
+ const SharedHandle<Option>& option):
+ _requestGroups(requestGroups), _option(option) {}
void
operator()(const std::string& uri)
{
if(_detector.isStreamProtocol(uri)) {
std::deque<std::string> streamURIs;
- size_t numSplit = _op.getAsInt(PREF_SPLIT);
+ size_t numSplit = _option->getAsInt(PREF_SPLIT);
for(size_t i = 0; i < numSplit; ++i) {
streamURIs.push_back(uri);
}
SharedHandle<RequestGroup> rg =
- createRequestGroup(_op, streamURIs, _requestOption);
+ createRequestGroup(_option, streamURIs);
rg->setNumConcurrentCommand(numSplit);
_requestGroups.push_back(rg);
}
#ifdef ENABLE_BITTORRENT
else if(_detector.guessTorrentFile(uri)) {
try {
- _requestGroups.push_back(createBtRequestGroup(uri, _op,
- std::deque<std::string>(),
- _requestOption));
+ _requestGroups.push_back(createBtRequestGroup(uri, _option,
+ std::deque<std::string>()));
} catch(RecoverableException& e) {
// error occurred while parsing torrent file.
// We simply ignore it.
@@ -238,8 +238,7 @@ public:
#ifdef ENABLE_METALINK
else if(_detector.guessMetalinkFile(uri)) {
try {
- Metalink2RequestGroup(&_op).generate(_requestGroups, uri,
- _requestOption);
+ Metalink2RequestGroup().generate(_requestGroups, uri, _option);
} catch(RecoverableException& e) {
// error occurred while parsing metalink file.
// We simply ignore it.
@@ -262,104 +261,76 @@ public:
}
};
-static void copyIfndef(Option& dest, const Option& src, const std::string& name)
-{
- if(!dest.defined(name)) {
- dest.put(name, src.get(name));
- }
-}
-
void createRequestGroupForUri
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
- const std::deque<std::string>& uris, const Option& requestOption,
- bool ignoreForceSequential, bool ignoreNonURI)
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option,
+ const std::deque<std::string>& uris,
+ bool ignoreForceSequential,
+ bool ignoreNonURI)
{
std::deque<std::string> nargs;
- if(op.get(PREF_PARAMETERIZED_URI) == V_TRUE) {
+ if(option->get(PREF_PARAMETERIZED_URI) == V_TRUE) {
unfoldURI(nargs, uris);
} else {
nargs = uris;
}
- if(!ignoreForceSequential && op.get(PREF_FORCE_SEQUENTIAL) == V_TRUE) {
+ if(!ignoreForceSequential && option->get(PREF_FORCE_SEQUENTIAL) == V_TRUE) {
std::for_each(nargs.begin(), nargs.end(),
- AccRequestGroup(result, op, requestOption));
+ AccRequestGroup(result, option));
} else {
std::deque<std::string>::iterator strmProtoEnd =
std::stable_partition(nargs.begin(), nargs.end(), StreamProtocolFilter());
// let's process http/ftp protocols first.
if(nargs.begin() != strmProtoEnd) {
- size_t numSplit = op.getAsInt(PREF_SPLIT);
+ size_t numSplit = option->getAsInt(PREF_SPLIT);
std::deque<std::string> streamURIs;
splitURI(streamURIs, nargs.begin(), strmProtoEnd,
numSplit);
SharedHandle<RequestGroup> rg =
- createRequestGroup(op, streamURIs, requestOption, true);
+ createRequestGroup(option, streamURIs, true);
rg->setNumConcurrentCommand(numSplit);
result.push_back(rg);
}
if(!ignoreNonURI) {
// process remaining URIs(local metalink, BitTorrent files)
std::for_each(strmProtoEnd, nargs.end(),
- AccRequestGroup(result, op, requestOption));
+ AccRequestGroup(result, option));
}
}
}
-void createRequestGroupForUri
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
- const std::deque<std::string>& uris)
-{
- createRequestGroupForUri(result, op, uris, op);
-}
-
-template<typename InputIterator>
-static void foreachCopyIfndef(InputIterator first, InputIterator last,
- Option& dest, const Option& src)
-{
- for(; first != last; ++first) {
- copyIfndef(dest, src, *first);
- }
-}
-
static void createRequestGroupForUriList
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option,
std::istream& in)
{
UriListParser p(in);
while(p.hasNext()) {
std::deque<std::string> uris;
- Option requestOption;
- p.parseNext(uris, requestOption);
+ SharedHandle<Option> requestOption(new Option(*option.get()));
+ p.parseNext(uris, *requestOption.get());
if(uris.empty()) {
continue;
}
- completeRequestOption(requestOption, op);
-
- createRequestGroupForUri(result, op, uris, requestOption);
+ createRequestGroupForUri(result, requestOption, uris);
}
}
void createRequestGroupForUriList
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op)
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option)
{
- if(op.get(PREF_INPUT_FILE) == "-") {
- createRequestGroupForUriList(result, op, std::cin);
+ if(option->get(PREF_INPUT_FILE) == "-") {
+ createRequestGroupForUriList(result, option, std::cin);
} else {
- if(!File(op.get(PREF_INPUT_FILE)).isFile()) {
+ if(!File(option->get(PREF_INPUT_FILE)).isFile()) {
throw FatalException
- (StringFormat(EX_FILE_OPEN, op.get(PREF_INPUT_FILE).c_str(),
+ (StringFormat(EX_FILE_OPEN, option->get(PREF_INPUT_FILE).c_str(),
"No such file").str());
}
- std::ifstream f(op.get(PREF_INPUT_FILE).c_str(), std::ios::binary);
- createRequestGroupForUriList(result, op, f);
+ std::ifstream f(option->get(PREF_INPUT_FILE).c_str(), std::ios::binary);
+ createRequestGroupForUriList(result, option, f);
}
}
-void completeRequestOption(Option& requestOption, const Option& option)
-{
- foreachCopyIfndef(listRequestOptions().begin(),
- listRequestOptions().end(),
- requestOption, option);
-}
-
} // namespace aria2
diff --git a/src/download_helper.h b/src/download_helper.h
index 3921441b..8bc1597b 100644
--- a/src/download_helper.h
+++ b/src/download_helper.h
@@ -56,7 +56,8 @@ const std::vector<std::string>& listRequestOptions();
// as a content of torrent file in stead. In this function,
// force-sequential is ignored.
void createRequestGroupForBitTorrent
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option,
const std::deque<std::string>& uris,
const std::string& torrentData = "");
#endif // ENABLE_BITTORRENT
@@ -65,7 +66,8 @@ void createRequestGroupForBitTorrent
// Create RequestGroup objects using Metalink file specified by metalink-file
// option.
void createRequestGroupForMetalink
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op);
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option);
#endif // ENABLE_METALINK
// Create RequestGroup objects from reading file specified by input-file option.
@@ -74,19 +76,16 @@ void createRequestGroupForMetalink
// The additional out and dir options can be specified after each line of URIs.
// This optional line must start with white space(s).
void createRequestGroupForUriList
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op);
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option);
// Create RequestGroup object using provided uris.
void createRequestGroupForUri
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
- const std::deque<std::string>& uris);
-
-void createRequestGroupForUri
-(std::deque<SharedHandle<RequestGroup> >& result, const Option& op,
- const std::deque<std::string>& uris, const Option& requestOption,
- bool ignoreForceSequential = false, bool ignoreNonURI = false);
-
-void completeRequestOption(Option& requestOption, const Option& option);
+(std::deque<SharedHandle<RequestGroup> >& result,
+ const SharedHandle<Option>& option,
+ const std::deque<std::string>& uris,
+ bool ignoreForceSequential = false,
+ bool ignoreNonURI = false);
} // namespace aria2
diff --git a/src/main.cc b/src/main.cc
index 9ccb624e..e7a58896 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -85,7 +85,7 @@ namespace aria2 {
// output stream to /dev/null
std::ofstream nullout(DEV_NULL);
-SharedHandle<StatCalc> getStatCalc(const Option* op)
+SharedHandle<StatCalc> getStatCalc(const SharedHandle<Option>& op)
{
SharedHandle<StatCalc> statCalc;
if(op->getAsBool(PREF_QUIET)) {
@@ -96,7 +96,7 @@ SharedHandle<StatCalc> getStatCalc(const Option* op)
return statCalc;
}
-std::ostream& getSummaryOut(const Option* op)
+std::ostream& getSummaryOut(const SharedHandle<Option>& op)
{
if(op->getAsBool(PREF_QUIET)) {
return nullout;
@@ -115,10 +115,11 @@ static void showTorrentFile(const std::string& uri)
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
-static void showMetalinkFile(const std::string& uri, const Option& op)
+static void showMetalinkFile
+(const std::string& uri, const SharedHandle<Option>& op)
{
std::deque<SharedHandle<MetalinkEntry> > metalinkEntries;
- MetalinkHelper::parseAndQuery(metalinkEntries, uri, &op);
+ MetalinkHelper::parseAndQuery(metalinkEntries, uri, op.get());
std::deque<SharedHandle<FileEntry> > fileEntries;
MetalinkEntry::toFileEntry(fileEntries, metalinkEntries);
Util::toStream(std::cout, fileEntries);
@@ -127,7 +128,8 @@ static void showMetalinkFile(const std::string& uri, const Option& op)
#endif // ENABLE_METALINK
#if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
-static void showFiles(const std::deque<std::string>& uris, const Option& op)
+static void showFiles
+(const std::deque<std::string>& uris, const SharedHandle<Option>& op)
{
ProtocolDetector dt;
for(std::deque<std::string>::const_iterator i = uris.begin();
@@ -163,28 +165,28 @@ extern void option_processing(Option& option, std::deque<std::string>& uris,
DownloadResult::RESULT main(int argc, char* argv[])
{
std::deque<std::string> args;
- Option op;
- option_processing(op, args, argc, argv);
+ SharedHandle<Option> op(new Option());
+ option_processing(*op.get(), args, argc, argv);
SimpleRandomizer::init();
BitfieldManFactory::setDefaultRandomizer(SimpleRandomizer::getInstance());
- if(op.get(PREF_LOG) == "-") {
+ if(op->get(PREF_LOG) == "-") {
LogFactory::setLogFile(DEV_STDOUT);
- } else if(!op.get(PREF_LOG).empty()) {
- LogFactory::setLogFile(op.get(PREF_LOG));
+ } else if(!op->get(PREF_LOG).empty()) {
+ LogFactory::setLogFile(op->get(PREF_LOG));
} else {
LogFactory::setLogFile(DEV_NULL);
}
- LogFactory::setLogLevel(op.get(PREF_LOG_LEVEL));
- if(op.getAsBool(PREF_QUIET)) {
+ LogFactory::setLogLevel(op->get(PREF_LOG_LEVEL));
+ if(op->getAsBool(PREF_QUIET)) {
LogFactory::setConsoleOutput(false);
}
#ifdef HAVE_EPOLL
- if(op.get(PREF_EVENT_POLL) == V_EPOLL) {
+ if(op->get(PREF_EVENT_POLL) == V_EPOLL) {
SocketCore::useEpoll();
} else
#endif // HAVE_EPOLL
- if(op.get(PREF_EVENT_POLL) == V_SELECT) {
+ if(op->get(PREF_EVENT_POLL) == V_SELECT) {
SocketCore::useSelect();
}
DownloadResult::RESULT exitStatus = DownloadResult::FINISHED;
@@ -205,9 +207,9 @@ DownloadResult::RESULT main(int argc, char* argv[])
#endif
std::deque<SharedHandle<RequestGroup> > requestGroups;
#ifdef ENABLE_BITTORRENT
- if(!op.blank(PREF_TORRENT_FILE)) {
- if(op.get(PREF_SHOW_FILES) == V_TRUE) {
- showTorrentFile(op.get(PREF_TORRENT_FILE));
+ if(!op->blank(PREF_TORRENT_FILE)) {
+ if(op->get(PREF_SHOW_FILES) == V_TRUE) {
+ showTorrentFile(op->get(PREF_TORRENT_FILE));
return exitStatus;
} else {
createRequestGroupForBitTorrent(requestGroups, op, args);
@@ -216,9 +218,9 @@ DownloadResult::RESULT main(int argc, char* argv[])
else
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
- if(!op.blank(PREF_METALINK_FILE)) {
- if(op.get(PREF_SHOW_FILES) == V_TRUE) {
- showMetalinkFile(op.get(PREF_METALINK_FILE), op);
+ if(!op->blank(PREF_METALINK_FILE)) {
+ if(op->get(PREF_SHOW_FILES) == V_TRUE) {
+ showMetalinkFile(op->get(PREF_METALINK_FILE), op);
return exitStatus;
} else {
createRequestGroupForMetalink(requestGroups, op);
@@ -226,10 +228,10 @@ DownloadResult::RESULT main(int argc, char* argv[])
}
else
#endif // ENABLE_METALINK
- if(!op.blank(PREF_INPUT_FILE)) {
+ if(!op->blank(PREF_INPUT_FILE)) {
createRequestGroupForUriList(requestGroups, op);
#if defined ENABLE_BITTORRENT || defined ENABLE_METALINK
- } else if(op.get(PREF_SHOW_FILES) == V_TRUE) {
+ } else if(op->get(PREF_SHOW_FILES) == V_TRUE) {
showFiles(args, op);
#endif // ENABLE_METALINK || ENABLE_METALINK
} else {
@@ -238,13 +240,13 @@ DownloadResult::RESULT main(int argc, char* argv[])
if(
#ifdef ENABLE_XML_RPC
- !op.getAsBool(PREF_ENABLE_HTTP_SERVER) &&
+ !op->getAsBool(PREF_ENABLE_HTTP_SERVER) &&
#endif // ENABLE_XML_RPC
requestGroups.empty()) {
std::cout << MSG_NO_FILES_TO_DOWNLOAD << std::endl;
} else {
- exitStatus = MultiUrlRequestInfo(requestGroups, &op, getStatCalc(&op),
- getSummaryOut(&op)).execute();
+ exitStatus = MultiUrlRequestInfo(requestGroups, op, getStatCalc(op),
+ getSummaryOut(op)).execute();
}
} catch(Exception& ex) {
std::cerr << EX_EXCEPTION_CAUGHT << "\n" << ex.stackTrace() << std::endl;
diff --git a/test/BtDependencyTest.cc b/test/BtDependencyTest.cc
index 3e5efd51..5d37f30f 100644
--- a/test/BtDependencyTest.cc
+++ b/test/BtDependencyTest.cc
@@ -25,9 +25,10 @@ class BtDependencyTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testResolve_dependeeInProgress);
CPPUNIT_TEST_SUITE_END();
- SharedHandle<RequestGroup> createDependant(const Option* option)
+ SharedHandle<RequestGroup> createDependant(const SharedHandle<Option>& option)
{
- SharedHandle<RequestGroup> dependant(new RequestGroup(option, std::deque<std::string>()));
+ SharedHandle<RequestGroup> dependant
+ (new RequestGroup(option, std::deque<std::string>()));
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "/tmp/outfile.path"));
dctx->setDir("/tmp");
@@ -36,7 +37,10 @@ class BtDependencyTest:public CppUnit::TestFixture {
}
SharedHandle<RequestGroup>
- createDependee(const Option* option, const std::string& torrentFile, int64_t length)
+ createDependee
+ (const SharedHandle<Option>& option,
+ const std::string& torrentFile,
+ int64_t length)
{
SharedHandle<RequestGroup> dependee
(new RequestGroup(option, std::deque<std::string>()));
@@ -44,15 +48,19 @@ class BtDependencyTest:public CppUnit::TestFixture {
(new SingleFileDownloadContext(1024*1024, length, torrentFile));
dctx->setDir(".");
dependee->setDownloadContext(dctx);
- DefaultPieceStorageHandle ps(new DefaultPieceStorage(dctx, option));
+ DefaultPieceStorageHandle ps(new DefaultPieceStorage(dctx, option.get()));
dependee->setPieceStorage(ps);
ps->initStorage();
dependee->initSegmentMan();
return dependee;
}
+ SharedHandle<Option> _option;
public:
- void setUp() {}
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
void testResolve();
void testResolve_loadError();
@@ -66,12 +74,12 @@ CPPUNIT_TEST_SUITE_REGISTRATION( BtDependencyTest );
void BtDependencyTest::testResolve()
{
std::string filename = "test.torrent";
- Option option;
- SharedHandle<RequestGroup> dependant = createDependant(&option);
- SharedHandle<RequestGroup> dependee = createDependee(&option, filename, File(filename).size());
+ SharedHandle<RequestGroup> dependant = createDependant(_option);
+ SharedHandle<RequestGroup> dependee =
+ createDependee(_option, filename, File(filename).size());
dependee->getPieceStorage()->markAllPiecesDone();
- BtDependency dep(dependant, dependee, &option);
+ BtDependency dep(dependant, dependee);
CPPUNIT_ASSERT(dep.resolve());
SharedHandle<BtContext> btContext
@@ -84,12 +92,12 @@ void BtDependencyTest::testResolve()
void BtDependencyTest::testResolve_loadError()
{
try {
- Option option;
- SharedHandle<RequestGroup> dependant = createDependant(&option);
- SharedHandle<RequestGroup> dependee = createDependee(&option, "notExist", 40);
+ SharedHandle<RequestGroup> dependant = createDependant(_option);
+ SharedHandle<RequestGroup> dependee =
+ createDependee(_option, "notExist", 40);
dependee->getPieceStorage()->markAllPiecesDone();
- BtDependency dep(dependant, dependee, &option);
+ BtDependency dep(dependant, dependee);
CPPUNIT_ASSERT(dep.resolve());
SharedHandle<SingleFileDownloadContext> dctx
@@ -106,11 +114,10 @@ void BtDependencyTest::testResolve_loadError()
void BtDependencyTest::testResolve_dependeeFailure()
{
- Option option;
- SharedHandle<RequestGroup> dependant = createDependant(&option);
- SharedHandle<RequestGroup> dependee = createDependee(&option, "notExist", 40);
+ SharedHandle<RequestGroup> dependant = createDependant(_option);
+ SharedHandle<RequestGroup> dependee = createDependee(_option, "notExist", 40);
- BtDependency dep(dependant, dependee, &option);
+ BtDependency dep(dependant, dependee);
CPPUNIT_ASSERT(dep.resolve());
SharedHandle<SingleFileDownloadContext> dctx
@@ -124,12 +131,12 @@ void BtDependencyTest::testResolve_dependeeFailure()
void BtDependencyTest::testResolve_dependeeInProgress()
{
std::string filename = "test.torrent";
- Option option;
- SharedHandle<RequestGroup> dependant = createDependant(&option);
- SharedHandle<RequestGroup> dependee = createDependee(&option, filename, File(filename).size());
+ SharedHandle<RequestGroup> dependant = createDependant(_option);
+ SharedHandle<RequestGroup> dependee =
+ createDependee(_option, filename, File(filename).size());
dependee->increaseNumCommand();
- BtDependency dep(dependant, dependee, &option);
+ BtDependency dep(dependant, dependee);
CPPUNIT_ASSERT(!dep.resolve());
}
diff --git a/test/BtPostDownloadHandlerTest.cc b/test/BtPostDownloadHandlerTest.cc
index f3b25dfb..4d67d5ab 100644
--- a/test/BtPostDownloadHandlerTest.cc
+++ b/test/BtPostDownloadHandlerTest.cc
@@ -16,9 +16,12 @@ class BtPostDownloadHandlerTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testGetNextRequestGroups);
CPPUNIT_TEST_SUITE_END();
private:
-
+ SharedHandle<Option> _option;
public:
- void setUp() {}
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
void testCanHandle_extension();
void testCanHandle_contentType();
@@ -30,10 +33,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION( BtPostDownloadHandlerTest );
void BtPostDownloadHandlerTest::testCanHandle_extension()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test.torrent"));
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
BtPostDownloadHandler handler;
@@ -46,11 +48,10 @@ void BtPostDownloadHandlerTest::testCanHandle_extension()
void BtPostDownloadHandlerTest::testCanHandle_contentType()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test"));
dctx->setContentType("application/x-bittorrent");
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
BtPostDownloadHandler handler;
@@ -63,10 +64,9 @@ void BtPostDownloadHandlerTest::testCanHandle_contentType()
void BtPostDownloadHandlerTest::testGetNextRequestGroups()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(1024, 0, "test.torrent"));
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
rg.initPieceStorage();
diff --git a/test/DefaultBtMessageDispatcherTest.cc b/test/DefaultBtMessageDispatcherTest.cc
index 7927fb45..073ae542 100644
--- a/test/DefaultBtMessageDispatcherTest.cc
+++ b/test/DefaultBtMessageDispatcherTest.cc
@@ -136,7 +136,7 @@ public:
void setUp() {
_option.reset(new Option());
- _rg.reset(new RequestGroup(_option.get(), std::deque<std::string>()));
+ _rg.reset(new RequestGroup(_option, std::deque<std::string>()));
btContext.reset(new DefaultBtContext());
btContext->load("test.torrent");
diff --git a/test/DownloadHandlerFactoryTest.cc b/test/DownloadHandlerFactoryTest.cc
index 004578d8..67cc6581 100644
--- a/test/DownloadHandlerFactoryTest.cc
+++ b/test/DownloadHandlerFactoryTest.cc
@@ -1,10 +1,12 @@
#include "DownloadHandlerFactory.h"
+
+#include <cppunit/extensions/HelperMacros.h>
+
#include "RequestGroup.h"
#include "Option.h"
#include "SingleFileDownloadContext.h"
#include "MemoryBufferPreDownloadHandler.h"
#include "FileEntry.h"
-#include <cppunit/extensions/HelperMacros.h>
namespace aria2 {
@@ -23,10 +25,12 @@ class DownloadHandlerFactoryTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE_END();
private:
-
+ SharedHandle<Option> _option;
public:
- void setUp() {}
-
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
#ifdef ENABLE_METALINK
void testGetMetalinkPreDownloadHandler_extension();
void testGetMetalinkPreDownloadHandler_contentType();
@@ -46,10 +50,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test.metalink"));
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
@@ -62,11 +65,10 @@ void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test"));
dctx->setContentType("application/metalink+xml");
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
@@ -83,10 +85,9 @@ void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test.torrent"));
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
@@ -99,11 +100,10 @@ void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test"));
dctx->setContentType("application/x-bittorrent");
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
SharedHandle<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
diff --git a/test/DownloadHelperTest.cc b/test/DownloadHelperTest.cc
index 070b281d..99969634 100644
--- a/test/DownloadHelperTest.cc
+++ b/test/DownloadHelperTest.cc
@@ -35,8 +35,13 @@ class DownloadHelperTest:public CppUnit::TestFixture {
#endif // ENABLE_METALINK
CPPUNIT_TEST_SUITE_END();
+private:
+ SharedHandle<Option> _option;
public:
- void setUp() {}
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
void tearDown() {}
@@ -66,14 +71,13 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
"http://charlie/file"
};
std::deque<std::string> uris(&array[0], &array[arrayLength(array)]);
- Option op;
- op.put(PREF_SPLIT, "3");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
+ _option->put(PREF_SPLIT, "3");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0];
@@ -89,11 +93,11 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/file.out"),
ctx->getActualBasePath());
}
- op.put(PREF_SPLIT, "5");
+ _option->put(PREF_SPLIT, "5");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0];
@@ -108,11 +112,11 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
}
CPPUNIT_ASSERT_EQUAL((unsigned int)5, group->getNumConcurrentCommand());
}
- op.put(PREF_SPLIT, "2");
+ _option->put(PREF_SPLIT, "2");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0];
@@ -124,11 +128,11 @@ void DownloadHelperTest::testCreateRequestGroupForUri()
}
CPPUNIT_ASSERT_EQUAL((unsigned int)2, group->getNumConcurrentCommand());
}
- op.put(PREF_FORCE_SEQUENTIAL, V_TRUE);
+ _option->put(PREF_FORCE_SEQUENTIAL, V_TRUE);
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
CPPUNIT_ASSERT_EQUAL((size_t)3, result.size());
@@ -156,15 +160,14 @@ void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
"http://charlie/file"
};
std::deque<std::string> uris(&array[0], &array[arrayLength(array)]);
- Option op;
- op.put(PREF_SPLIT, "3");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
- op.put(PREF_PARAMETERIZED_URI, V_TRUE);
+ _option->put(PREF_SPLIT, "3");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
+ _option->put(PREF_PARAMETERIZED_URI, V_TRUE);
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0];
@@ -194,14 +197,13 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
"http://charlie/file"
};
std::deque<std::string> uris(&array[0], &array[arrayLength(array)]);
- Option op;
- op.put(PREF_SPLIT, "3");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
+ _option->put(PREF_SPLIT, "3");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
CPPUNIT_ASSERT_EQUAL((size_t)2, result.size());
SharedHandle<RequestGroup> group = result[0];
@@ -243,15 +245,14 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
"test.xml"
};
std::deque<std::string> uris(&array[0], &array[arrayLength(array)]);
- Option op;
- op.put(PREF_SPLIT, "3");
- op.put(PREF_METALINK_SERVERS, "2");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
+ _option->put(PREF_SPLIT, "3");
+ _option->put(PREF_METALINK_SERVERS, "2");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUri(result, op, uris);
+ createRequestGroupForUri(result, _option, uris);
// group1: http://alpha/file, ...
// group2-7: 6 file entry in Metalink and 1 torrent file download
@@ -292,15 +293,14 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
void DownloadHelperTest::testCreateRequestGroupForUriList()
{
- Option op;
- op.put(PREF_SPLIT, "3");
- op.put(PREF_INPUT_FILE, "input_uris.txt");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
+ _option->put(PREF_SPLIT, "3");
+ _option->put(PREF_INPUT_FILE, "input_uris.txt");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForUriList(result, op);
+ createRequestGroupForUriList(result, _option);
CPPUNIT_ASSERT_EQUAL((size_t)2, result.size());
@@ -333,15 +333,14 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
};
std::deque<std::string> auxURIs(&array[0], &array[arrayLength(array)]);
- Option op;
- op.put(PREF_SPLIT, "5");
- op.put(PREF_TORRENT_FILE, "test.torrent");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
+ _option->put(PREF_SPLIT, "5");
+ _option->put(PREF_TORRENT_FILE, "test.torrent");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForBitTorrent(result, op, auxURIs);
+ createRequestGroupForBitTorrent(result, _option, auxURIs);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
@@ -361,7 +360,7 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
// no URIs are given
std::deque<SharedHandle<RequestGroup> > result;
std::deque<std::string> emptyURIs;
- createRequestGroupForBitTorrent(result, op, emptyURIs);
+ createRequestGroupForBitTorrent(result, _option, emptyURIs);
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
SharedHandle<RequestGroup> group = result[0];
@@ -369,11 +368,11 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
group->getURIs(uris);
CPPUNIT_ASSERT_EQUAL((size_t)0, uris.size());
}
- op.put(PREF_FORCE_SEQUENTIAL, V_TRUE);
+ _option->put(PREF_FORCE_SEQUENTIAL, V_TRUE);
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForBitTorrent(result, op, auxURIs);
+ createRequestGroupForBitTorrent(result, _option, auxURIs);
// See --force-requencial is ignored
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
@@ -384,16 +383,15 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
#ifdef ENABLE_METALINK
void DownloadHelperTest::testCreateRequestGroupForMetalink()
{
- Option op;
- op.put(PREF_SPLIT, "3");
- op.put(PREF_METALINK_FILE, "test.xml");
- op.put(PREF_METALINK_SERVERS, "5");
- op.put(PREF_DIR, "/tmp");
- op.put(PREF_OUT, "file.out");
+ _option->put(PREF_SPLIT, "3");
+ _option->put(PREF_METALINK_FILE, "test.xml");
+ _option->put(PREF_METALINK_SERVERS, "5");
+ _option->put(PREF_DIR, "/tmp");
+ _option->put(PREF_OUT, "file.out");
{
std::deque<SharedHandle<RequestGroup> > result;
- createRequestGroupForMetalink(result, op);
+ createRequestGroupForMetalink(result, _option);
#ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)6, result.size());
diff --git a/test/Metalink2RequestGroupTest.cc b/test/Metalink2RequestGroupTest.cc
index f8c00a86..1aab6af8 100644
--- a/test/Metalink2RequestGroupTest.cc
+++ b/test/Metalink2RequestGroupTest.cc
@@ -33,10 +33,8 @@ CPPUNIT_TEST_SUITE_REGISTRATION( Metalink2RequestGroupTest );
void Metalink2RequestGroupTest::testGenerate()
{
std::deque<SharedHandle<RequestGroup> > groups;
- Option requestOption;
- requestOption.put(PREF_DIR, "/tmp");
- Metalink2RequestGroup(_option.get()).generate(groups, "test.xml",
- requestOption);
+ _option->put(PREF_DIR, "/tmp");
+ Metalink2RequestGroup().generate(groups, "test.xml", _option);
// first file
{
SharedHandle<RequestGroup> rg = groups[0];
diff --git a/test/MetalinkPostDownloadHandlerTest.cc b/test/MetalinkPostDownloadHandlerTest.cc
index 00409673..15ec8f71 100644
--- a/test/MetalinkPostDownloadHandlerTest.cc
+++ b/test/MetalinkPostDownloadHandlerTest.cc
@@ -15,9 +15,12 @@ class MetalinkPostDownloadHandlerTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testGetNextRequestGroups);
CPPUNIT_TEST_SUITE_END();
private:
-
+ SharedHandle<Option> _option;
public:
- void setUp() {}
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
void testCanHandle_extension();
void testCanHandle_contentType();
@@ -29,10 +32,9 @@ CPPUNIT_TEST_SUITE_REGISTRATION( MetalinkPostDownloadHandlerTest );
void MetalinkPostDownloadHandlerTest::testCanHandle_extension()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test.metalink"));
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
MetalinkPostDownloadHandler handler;
@@ -45,11 +47,10 @@ void MetalinkPostDownloadHandlerTest::testCanHandle_extension()
void MetalinkPostDownloadHandlerTest::testCanHandle_contentType()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(0, 0, "test"));
dctx->setContentType("application/metalink+xml");
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
MetalinkPostDownloadHandler handler;
@@ -62,10 +63,9 @@ void MetalinkPostDownloadHandlerTest::testCanHandle_contentType()
void MetalinkPostDownloadHandlerTest::testGetNextRequestGroups()
{
- Option op;
SharedHandle<SingleFileDownloadContext> dctx
(new SingleFileDownloadContext(1024, 0, "test.xml"));
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
rg.setDownloadContext(dctx);
rg.initPieceStorage();
diff --git a/test/RequestGroupManTest.cc b/test/RequestGroupManTest.cc
index e3e67153..d55c0364 100644
--- a/test/RequestGroupManTest.cc
+++ b/test/RequestGroupManTest.cc
@@ -25,8 +25,13 @@ class RequestGroupManTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testSaveServerStat);
CPPUNIT_TEST_SUITE_END();
private:
-
+ SharedHandle<Option> _option;
public:
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
+
void testIsSameFileBeingDownloaded();
void testGetInitialCommands();
void testLoadServerStat();
@@ -38,12 +43,10 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupManTest );
void RequestGroupManTest::testIsSameFileBeingDownloaded()
{
- Option option;
-
std::deque<std::string> uris;
uris.push_back("http://localhost/aria2.tar.bz2");
- SharedHandle<RequestGroup> rg1(new RequestGroup(&option, uris));
- SharedHandle<RequestGroup> rg2(new RequestGroup(&option, uris));
+ SharedHandle<RequestGroup> rg1(new RequestGroup(_option, uris));
+ SharedHandle<RequestGroup> rg2(new RequestGroup(_option, uris));
SharedHandle<SingleFileDownloadContext> dctx1
(new SingleFileDownloadContext(0, 0, "aria2.tar.bz2"));
@@ -57,7 +60,7 @@ void RequestGroupManTest::testIsSameFileBeingDownloaded()
rgs.push_back(rg1);
rgs.push_back(rg2);
- RequestGroupMan gm(rgs, 1, &option);
+ RequestGroupMan gm(rgs, 1, _option.get());
CPPUNIT_ASSERT(gm.isSameFileBeingDownloaded(rg1.get()));
@@ -74,8 +77,7 @@ void RequestGroupManTest::testGetInitialCommands()
void RequestGroupManTest::testSaveServerStat()
{
- Option option;
- RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(), 0, &option);
+ RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(),0,_option.get());
SharedHandle<ServerStat> ss_localhost(new ServerStat("localhost", "http"));
rm.addServerStat(ss_localhost);
File f("/tmp/aria2_RequestGroupManTest_testSaveServerStat");
@@ -98,8 +100,7 @@ void RequestGroupManTest::testLoadServerStat()
<< "status=OK";
o.close();
- Option option;
- RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(), 0, &option);
+ RequestGroupMan rm(std::deque<SharedHandle<RequestGroup> >(),0,_option.get());
std::cerr << "testLoadServerStat" << std::endl;
CPPUNIT_ASSERT(rm.loadServerStat(f.getPath()));
SharedHandle<ServerStat> ss_localhost = rm.findServerStat("localhost",
diff --git a/test/RequestGroupTest.cc b/test/RequestGroupTest.cc
index b8558dad..27c1f0e2 100644
--- a/test/RequestGroupTest.cc
+++ b/test/RequestGroupTest.cc
@@ -20,9 +20,12 @@ class RequestGroupTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testExtractURIResult);
CPPUNIT_TEST_SUITE_END();
private:
-
+ SharedHandle<Option> _option;
public:
- void setUp() {}
+ void setUp()
+ {
+ _option.reset(new Option());
+ }
void testRegisterSearchRemove();
void testRemoveURIWhoseHostnameIs();
@@ -36,8 +39,7 @@ CPPUNIT_TEST_SUITE_REGISTRATION( RequestGroupTest );
void RequestGroupTest::testRegisterSearchRemove()
{
- Option op;
- RequestGroup rg(&op, std::deque<std::string>());
+ RequestGroup rg(_option, std::deque<std::string>());
SharedHandle<ServerHost> sv1(new ServerHost(1, "localhost1"));
SharedHandle<ServerHost> sv2(new ServerHost(2, "localhost2"));
SharedHandle<ServerHost> sv3(new ServerHost(3, "localhost3"));
@@ -72,8 +74,7 @@ void RequestGroupTest::testRemoveURIWhoseHostnameIs()
const char* uris[] = { "http://localhost/aria2.zip",
"ftp://localhost/aria2.zip",
"http://mirror/aria2.zip" };
- Option op;
- RequestGroup rg(&op, std::deque<std::string>(&uris[0], &uris[3]));
+ RequestGroup rg(_option, std::deque<std::string>(&uris[0], &uris[3]));
rg.removeURIWhoseHostnameIs("localhost");
CPPUNIT_ASSERT_EQUAL((size_t)1, rg.getRemainingUris().size());
CPPUNIT_ASSERT_EQUAL(std::string("http://mirror/aria2.zip"),
@@ -84,10 +85,9 @@ void RequestGroupTest::testGetFilePath()
{
SharedHandle<SingleFileDownloadContext> ctx
(new SingleFileDownloadContext(1024, 1024, "/tmp/myfile"));
- Option op;
std::deque<std::string> uris;
- RequestGroup group(&op, uris);
+ RequestGroup group(_option, uris);
group.setDownloadContext(ctx);
CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), group.getFilePath());
@@ -102,12 +102,11 @@ void RequestGroupTest::testCreateDownloadResult()
SharedHandle<SingleFileDownloadContext> ctx
(new SingleFileDownloadContext(1024, 1024*1024, "/tmp/myfile"));
//ctx->setDir("/tmp");
- Option op;
std::deque<std::string> uris;
uris.push_back("http://first/file");
uris.push_back("http://second/file");
- RequestGroup group(&op, uris);
+ RequestGroup group(_option, uris);
group.setDownloadContext(ctx);
group.initPieceStorage();
{
@@ -142,8 +141,7 @@ void RequestGroupTest::testCreateDownloadResult()
void RequestGroupTest::testExtractURIResult()
{
- Option op;
- RequestGroup group(&op, std::deque<std::string>());
+ RequestGroup group(_option, std::deque<std::string>());
group.addURIResult("http://timeout/file", DownloadResult::TIME_OUT);
group.addURIResult("http://finished/file", DownloadResult::FINISHED);
group.addURIResult("http://timeout/file2", DownloadResult::TIME_OUT);