mirror of https://github.com/aria2/aria2
Refactor DownloadHandlerFactory
parent
ba3b823a66
commit
9e52483c04
|
@ -57,17 +57,13 @@ namespace aria2 {
|
||||||
|
|
||||||
BtPostDownloadHandler::BtPostDownloadHandler()
|
BtPostDownloadHandler::BtPostDownloadHandler()
|
||||||
{
|
{
|
||||||
std::shared_ptr<RequestGroupCriteria> cri
|
setCriteria(make_unique<ContentTypeRequestGroupCriteria>
|
||||||
(new ContentTypeRequestGroupCriteria
|
(getBtContentTypes(), getBtExtensions()));
|
||||||
(getBtContentTypes(), getBtExtensions()));
|
|
||||||
setCriteria(cri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BtPostDownloadHandler::~BtPostDownloadHandler() {}
|
|
||||||
|
|
||||||
void BtPostDownloadHandler::getNextRequestGroups
|
void BtPostDownloadHandler::getNextRequestGroups
|
||||||
(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
||||||
RequestGroup* requestGroup)
|
RequestGroup* requestGroup) const
|
||||||
{
|
{
|
||||||
A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
|
A2_LOG_INFO(fmt("Generating RequestGroups for Torrent file %s",
|
||||||
requestGroup->getFirstFilePath().c_str()));
|
requestGroup->getFirstFilePath().c_str()));
|
||||||
|
@ -100,13 +96,13 @@ void BtPostDownloadHandler::getNextRequestGroups
|
||||||
throw DL_ABORT_EX2("Could not parse BitTorrent metainfo",
|
throw DL_ABORT_EX2("Could not parse BitTorrent metainfo",
|
||||||
error_code::BENCODE_PARSE_ERROR);
|
error_code::BENCODE_PARSE_ERROR);
|
||||||
}
|
}
|
||||||
std::vector<std::shared_ptr<RequestGroup> > newRgs;
|
std::vector<std::shared_ptr<RequestGroup>> newRgs;
|
||||||
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
||||||
std::vector<std::string>(),
|
std::vector<std::string>(),
|
||||||
"",
|
"",
|
||||||
torrent.get());
|
torrent.get());
|
||||||
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
||||||
std::shared_ptr<MetadataInfo> mi =
|
auto mi =
|
||||||
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
|
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
|
||||||
requestGroup->getDownloadContext());
|
requestGroup->getDownloadContext());
|
||||||
if(mi) {
|
if(mi) {
|
||||||
|
|
|
@ -44,11 +44,9 @@ class BtPostDownloadHandler:public PostDownloadHandler
|
||||||
public:
|
public:
|
||||||
BtPostDownloadHandler();
|
BtPostDownloadHandler();
|
||||||
|
|
||||||
virtual ~BtPostDownloadHandler();
|
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
||||||
RequestGroup* requestGroup) CXX11_OVERRIDE;
|
RequestGroup* requestGroup) const CXX11_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -39,19 +39,15 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
DownloadHandler::DownloadHandler() {}
|
|
||||||
|
|
||||||
DownloadHandler::~DownloadHandler() {}
|
|
||||||
|
|
||||||
bool DownloadHandler::canHandle(const RequestGroup* requestGroup) const
|
bool DownloadHandler::canHandle(const RequestGroup* requestGroup) const
|
||||||
{
|
{
|
||||||
return criteria_ && criteria_->match(requestGroup);
|
return !criteria_ || criteria_->match(requestGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadHandler::setCriteria
|
void DownloadHandler::setCriteria
|
||||||
(const std::shared_ptr<RequestGroupCriteria>& criteria)
|
(std::unique_ptr<RequestGroupCriteria> criteria)
|
||||||
{
|
{
|
||||||
criteria_ = criteria;
|
criteria_ = std::move(criteria);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -47,16 +47,14 @@ class RequestGroupCriteria;
|
||||||
|
|
||||||
class DownloadHandler
|
class DownloadHandler
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
std::shared_ptr<RequestGroupCriteria> criteria_;
|
|
||||||
public:
|
public:
|
||||||
DownloadHandler();
|
virtual ~DownloadHandler() {}
|
||||||
|
|
||||||
virtual ~DownloadHandler();
|
|
||||||
|
|
||||||
bool canHandle(const RequestGroup* requestGroup) const;
|
bool canHandle(const RequestGroup* requestGroup) const;
|
||||||
|
|
||||||
void setCriteria(const std::shared_ptr<RequestGroupCriteria>& criteria);
|
void setCriteria(std::unique_ptr<RequestGroupCriteria> criteria);
|
||||||
|
private:
|
||||||
|
std::unique_ptr<RequestGroupCriteria> criteria_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -1,131 +0,0 @@
|
||||||
/* <!-- copyright */
|
|
||||||
/*
|
|
||||||
* aria2 - The high speed download utility
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give
|
|
||||||
* permission to link the code of portions of this program with the
|
|
||||||
* OpenSSL library under certain conditions as described in each
|
|
||||||
* individual source file, and distribute linked combinations
|
|
||||||
* including the two.
|
|
||||||
* You must obey the GNU General Public License in all respects
|
|
||||||
* for all of the code used other than OpenSSL. If you modify
|
|
||||||
* file(s) with this exception, you may extend this exception to your
|
|
||||||
* version of the file(s), but you are not obligated to do so. If you
|
|
||||||
* do not wish to do so, delete this exception statement from your
|
|
||||||
* version. If you delete this exception statement from all source
|
|
||||||
* files in the program, then also delete it here.
|
|
||||||
*/
|
|
||||||
/* copyright --> */
|
|
||||||
#include "DownloadHandlerFactory.h"
|
|
||||||
#include "MemoryBufferPreDownloadHandler.h"
|
|
||||||
#include "MetalinkPostDownloadHandler.h"
|
|
||||||
#include "BtPostDownloadHandler.h"
|
|
||||||
#include "DownloadHandlerConstants.h"
|
|
||||||
#include "ContentTypeRequestGroupCriteria.h"
|
|
||||||
#include "UTMetadataPostDownloadHandler.h"
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
#ifdef ENABLE_METALINK
|
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler>
|
|
||||||
DownloadHandlerFactory::metalinkPreDownloadHandler_;
|
|
||||||
|
|
||||||
std::shared_ptr<PostDownloadHandler>
|
|
||||||
DownloadHandlerFactory::metalinkPostDownloadHandler_;
|
|
||||||
|
|
||||||
#endif // ENABLE_METALINK
|
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler>
|
|
||||||
DownloadHandlerFactory::btPreDownloadHandler_;
|
|
||||||
|
|
||||||
std::shared_ptr<PostDownloadHandler>
|
|
||||||
DownloadHandlerFactory::btPostDownloadHandler_;
|
|
||||||
|
|
||||||
std::shared_ptr<PostDownloadHandler>
|
|
||||||
DownloadHandlerFactory::btMetadataPostDownloadHandler_;
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
|
|
||||||
#ifdef ENABLE_METALINK
|
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler>
|
|
||||||
DownloadHandlerFactory::getMetalinkPreDownloadHandler()
|
|
||||||
{
|
|
||||||
if(!metalinkPreDownloadHandler_) {
|
|
||||||
metalinkPreDownloadHandler_.reset(new MemoryBufferPreDownloadHandler());
|
|
||||||
|
|
||||||
std::shared_ptr<RequestGroupCriteria> criteria
|
|
||||||
(new ContentTypeRequestGroupCriteria
|
|
||||||
(getMetalinkContentTypes(), getMetalinkExtensions()));
|
|
||||||
metalinkPreDownloadHandler_->setCriteria(criteria);
|
|
||||||
}
|
|
||||||
return metalinkPreDownloadHandler_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<PostDownloadHandler>
|
|
||||||
DownloadHandlerFactory::getMetalinkPostDownloadHandler()
|
|
||||||
{
|
|
||||||
if(!metalinkPostDownloadHandler_) {
|
|
||||||
metalinkPostDownloadHandler_.reset(new MetalinkPostDownloadHandler());
|
|
||||||
}
|
|
||||||
return metalinkPostDownloadHandler_;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_METALINK
|
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler>
|
|
||||||
DownloadHandlerFactory::getBtPreDownloadHandler()
|
|
||||||
{
|
|
||||||
if(!btPreDownloadHandler_) {
|
|
||||||
btPreDownloadHandler_.reset
|
|
||||||
(new bittorrent::MemoryBencodePreDownloadHandler());
|
|
||||||
|
|
||||||
std::shared_ptr<RequestGroupCriteria> criteria
|
|
||||||
(new ContentTypeRequestGroupCriteria
|
|
||||||
(getBtContentTypes(), getBtExtensions()));
|
|
||||||
btPreDownloadHandler_->setCriteria(criteria);
|
|
||||||
}
|
|
||||||
return btPreDownloadHandler_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<PostDownloadHandler>
|
|
||||||
DownloadHandlerFactory::getBtPostDownloadHandler()
|
|
||||||
{
|
|
||||||
if(!btPostDownloadHandler_) {
|
|
||||||
btPostDownloadHandler_.reset(new BtPostDownloadHandler());
|
|
||||||
}
|
|
||||||
return btPostDownloadHandler_;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<PostDownloadHandler>
|
|
||||||
DownloadHandlerFactory::getUTMetadataPostDownloadHandler()
|
|
||||||
{
|
|
||||||
if(!btMetadataPostDownloadHandler_) {
|
|
||||||
btMetadataPostDownloadHandler_.reset(new UTMetadataPostDownloadHandler());
|
|
||||||
}
|
|
||||||
return btMetadataPostDownloadHandler_;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
|
@ -1,101 +0,0 @@
|
||||||
/* <!-- copyright */
|
|
||||||
/*
|
|
||||||
* aria2 - The high speed download utility
|
|
||||||
*
|
|
||||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
||||||
*
|
|
||||||
* In addition, as a special exception, the copyright holders give
|
|
||||||
* permission to link the code of portions of this program with the
|
|
||||||
* OpenSSL library under certain conditions as described in each
|
|
||||||
* individual source file, and distribute linked combinations
|
|
||||||
* including the two.
|
|
||||||
* You must obey the GNU General Public License in all respects
|
|
||||||
* for all of the code used other than OpenSSL. If you modify
|
|
||||||
* file(s) with this exception, you may extend this exception to your
|
|
||||||
* version of the file(s), but you are not obligated to do so. If you
|
|
||||||
* do not wish to do so, delete this exception statement from your
|
|
||||||
* version. If you delete this exception statement from all source
|
|
||||||
* files in the program, then also delete it here.
|
|
||||||
*/
|
|
||||||
/* copyright --> */
|
|
||||||
#ifndef D_DOWNLOAD_HANDLER_FACTORY_H
|
|
||||||
#define D_DOWNLOAD_HANDLER_FACTORY_H
|
|
||||||
|
|
||||||
#include "common.h"
|
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include "MemoryBufferPreDownloadHandler.h"
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
# include "MemoryBencodePreDownloadHandler.h"
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
|
|
||||||
namespace aria2 {
|
|
||||||
|
|
||||||
#ifdef ENABLE_METALINK
|
|
||||||
class MetalinkPostDownloadHandler;
|
|
||||||
#endif // ENABLE_METALINK
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
class BtPostDownloadHandler;
|
|
||||||
class UTMetadataPostDownloadHandler;
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
|
|
||||||
class DownloadHandlerFactory
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
#ifdef ENABLE_METALINK
|
|
||||||
static std::shared_ptr<PreDownloadHandler>
|
|
||||||
metalinkPreDownloadHandler_;
|
|
||||||
|
|
||||||
static std::shared_ptr<PostDownloadHandler>
|
|
||||||
metalinkPostDownloadHandler_;
|
|
||||||
#endif // ENABLE_METALINK
|
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
static std::shared_ptr<PreDownloadHandler>
|
|
||||||
btPreDownloadHandler_;
|
|
||||||
|
|
||||||
static std::shared_ptr<PostDownloadHandler>
|
|
||||||
btPostDownloadHandler_;
|
|
||||||
|
|
||||||
static std::shared_ptr<PostDownloadHandler>
|
|
||||||
btMetadataPostDownloadHandler_;
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
public:
|
|
||||||
#ifdef ENABLE_METALINK
|
|
||||||
static std::shared_ptr<PreDownloadHandler>
|
|
||||||
getMetalinkPreDownloadHandler();
|
|
||||||
|
|
||||||
static std::shared_ptr<PostDownloadHandler>
|
|
||||||
getMetalinkPostDownloadHandler();
|
|
||||||
#endif // ENABLE_METALINK
|
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
|
||||||
static std::shared_ptr<PreDownloadHandler>
|
|
||||||
getBtPreDownloadHandler();
|
|
||||||
|
|
||||||
static std::shared_ptr<PostDownloadHandler>
|
|
||||||
getBtPostDownloadHandler();
|
|
||||||
|
|
||||||
static std::shared_ptr<PostDownloadHandler>
|
|
||||||
getUTMetadataPostDownloadHandler();
|
|
||||||
#endif // ENABLE_BITTORRENT
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace aria2
|
|
||||||
|
|
||||||
#endif // D_DOWNLOAD_HANDLER_FACTORY_H
|
|
|
@ -115,7 +115,7 @@ SRCS = option_processing.cc\
|
||||||
ContentTypeRequestGroupCriteria.cc ContentTypeRequestGroupCriteria.h\
|
ContentTypeRequestGroupCriteria.cc ContentTypeRequestGroupCriteria.h\
|
||||||
DownloadHandler.cc DownloadHandler.h\
|
DownloadHandler.cc DownloadHandler.h\
|
||||||
DownloadHandlerConstants.cc DownloadHandlerConstants.h\
|
DownloadHandlerConstants.cc DownloadHandlerConstants.h\
|
||||||
DownloadHandlerFactory.cc DownloadHandlerFactory.h\
|
download_handlers.cc download_handlers.h\
|
||||||
MemoryPreDownloadHandler.h\
|
MemoryPreDownloadHandler.h\
|
||||||
MemoryBufferPreDownloadHandler.h\
|
MemoryBufferPreDownloadHandler.h\
|
||||||
HaveEraseCommand.cc HaveEraseCommand.h\
|
HaveEraseCommand.cc HaveEraseCommand.h\
|
||||||
|
|
|
@ -44,13 +44,9 @@ template<class DiskWriterFactoryType>
|
||||||
class MemoryPreDownloadHandler:public PreDownloadHandler
|
class MemoryPreDownloadHandler:public PreDownloadHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MemoryPreDownloadHandler() {}
|
virtual void execute(RequestGroup* requestGroup) const CXX11_OVERRIDE
|
||||||
|
|
||||||
virtual ~MemoryPreDownloadHandler() {}
|
|
||||||
|
|
||||||
virtual void execute(RequestGroup* requestGroup) CXX11_OVERRIDE
|
|
||||||
{
|
{
|
||||||
std::shared_ptr<DiskWriterFactory> dwf(new DiskWriterFactoryType());
|
auto dwf = std::make_shared<DiskWriterFactoryType>();
|
||||||
requestGroup->setDiskWriterFactory(dwf);
|
requestGroup->setDiskWriterFactory(dwf);
|
||||||
requestGroup->setFileAllocationEnabled(false);
|
requestGroup->setFileAllocationEnabled(false);
|
||||||
requestGroup->setPreLocalFileCheckEnabled(false);
|
requestGroup->setPreLocalFileCheckEnabled(false);
|
||||||
|
|
|
@ -47,7 +47,6 @@
|
||||||
#include "metalink_helper.h"
|
#include "metalink_helper.h"
|
||||||
#include "BinaryStream.h"
|
#include "BinaryStream.h"
|
||||||
#include "MemoryBufferPreDownloadHandler.h"
|
#include "MemoryBufferPreDownloadHandler.h"
|
||||||
#include "TrueRequestGroupCriteria.h"
|
|
||||||
#include "MetalinkEntry.h"
|
#include "MetalinkEntry.h"
|
||||||
#include "MetalinkResource.h"
|
#include "MetalinkResource.h"
|
||||||
#include "MetalinkMetaurl.h"
|
#include "MetalinkMetaurl.h"
|
||||||
|
@ -59,6 +58,8 @@
|
||||||
#include "SegList.h"
|
#include "SegList.h"
|
||||||
#include "DownloadFailureException.h"
|
#include "DownloadFailureException.h"
|
||||||
#include "Signature.h"
|
#include "Signature.h"
|
||||||
|
#include "download_handlers.h"
|
||||||
|
#include "RequestGroupCriteria.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "BtDependency.h"
|
# include "BtDependency.h"
|
||||||
# include "download_helper.h"
|
# include "download_helper.h"
|
||||||
|
@ -233,9 +234,8 @@ Metalink2RequestGroup::createRequestGroup
|
||||||
// tranparent metalink
|
// tranparent metalink
|
||||||
torrentRg->getDownloadContext()->setAcceptMetalink(false);
|
torrentRg->getDownloadContext()->setAcceptMetalink(false);
|
||||||
// make it in-memory download
|
// make it in-memory download
|
||||||
auto preh = std::make_shared<MemoryBufferPreDownloadHandler>();
|
torrentRg->addPreDownloadHandler
|
||||||
preh->setCriteria(std::make_shared<TrueRequestGroupCriteria>());
|
(download_handlers::getMemoryPreDownloadHandler());
|
||||||
torrentRg->addPreDownloadHandler(preh);
|
|
||||||
groups.push_back(torrentRg);
|
groups.push_back(torrentRg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,27 +56,22 @@ namespace aria2 {
|
||||||
|
|
||||||
MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
|
MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
|
||||||
{
|
{
|
||||||
std::shared_ptr<RequestGroupCriteria> cri
|
setCriteria(make_unique<ContentTypeRequestGroupCriteria>
|
||||||
(new ContentTypeRequestGroupCriteria
|
(getMetalinkContentTypes(), getMetalinkExtensions()));
|
||||||
(getMetalinkContentTypes(), getMetalinkExtensions()));
|
|
||||||
setCriteria(cri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MetalinkPostDownloadHandler::~MetalinkPostDownloadHandler() {}
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
const std::string& getBaseUri(RequestGroup* requestGroup)
|
const std::string& getBaseUri(RequestGroup* requestGroup)
|
||||||
{
|
{
|
||||||
const std::shared_ptr<DownloadContext>& dctx =
|
auto& dctx = requestGroup->getDownloadContext();
|
||||||
requestGroup->getDownloadContext();
|
|
||||||
if(dctx->getFileEntries().empty()) {
|
if(dctx->getFileEntries().empty()) {
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
} else {
|
} else {
|
||||||
// TODO Check download result for each URI
|
// TODO Check download result for each URI
|
||||||
const std::shared_ptr<FileEntry>& entry = dctx->getFirstFileEntry();
|
auto& entry = dctx->getFirstFileEntry();
|
||||||
const std::deque<std::string>& spentUris = entry->getSpentUris();
|
auto& spentUris = entry->getSpentUris();
|
||||||
if(spentUris.empty()) {
|
if(spentUris.empty()) {
|
||||||
const std::deque<std::string>& remainingUris = entry->getRemainingUris();
|
auto& remainingUris = entry->getRemainingUris();
|
||||||
if(remainingUris.empty()) {
|
if(remainingUris.empty()) {
|
||||||
return A2STR::NIL;
|
return A2STR::NIL;
|
||||||
} else {
|
} else {
|
||||||
|
@ -90,22 +85,21 @@ const std::string& getBaseUri(RequestGroup* requestGroup)
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void MetalinkPostDownloadHandler::getNextRequestGroups
|
void MetalinkPostDownloadHandler::getNextRequestGroups
|
||||||
(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
(std::vector<std::shared_ptr<RequestGroup>>& groups,
|
||||||
RequestGroup* requestGroup)
|
RequestGroup* requestGroup) const
|
||||||
{
|
{
|
||||||
A2_LOG_DEBUG(fmt("Generating RequestGroups for Metalink file %s",
|
A2_LOG_DEBUG(fmt("Generating RequestGroups for Metalink file %s",
|
||||||
requestGroup->getFirstFilePath().c_str()));
|
requestGroup->getFirstFilePath().c_str()));
|
||||||
std::shared_ptr<DiskAdaptor> diskAdaptor =
|
auto diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||||
requestGroup->getPieceStorage()->getDiskAdaptor();
|
|
||||||
try {
|
try {
|
||||||
diskAdaptor->openExistingFile();
|
diskAdaptor->openExistingFile();
|
||||||
//requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
|
//requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
|
||||||
const std::string& baseUri = getBaseUri(requestGroup);
|
const std::string& baseUri = getBaseUri(requestGroup);
|
||||||
std::vector<std::shared_ptr<RequestGroup> > newRgs;
|
std::vector<std::shared_ptr<RequestGroup>> newRgs;
|
||||||
Metalink2RequestGroup().generate(newRgs, diskAdaptor,
|
Metalink2RequestGroup().generate(newRgs, diskAdaptor,
|
||||||
requestGroup->getOption(), baseUri);
|
requestGroup->getOption(), baseUri);
|
||||||
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
||||||
std::shared_ptr<MetadataInfo> mi =
|
auto mi =
|
||||||
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
|
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
|
||||||
requestGroup->getDownloadContext());
|
requestGroup->getDownloadContext());
|
||||||
if(mi) {
|
if(mi) {
|
||||||
|
|
|
@ -44,11 +44,9 @@ class MetalinkPostDownloadHandler:public PostDownloadHandler
|
||||||
public:
|
public:
|
||||||
MetalinkPostDownloadHandler();
|
MetalinkPostDownloadHandler();
|
||||||
|
|
||||||
virtual ~MetalinkPostDownloadHandler();
|
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup>>& groups,
|
||||||
RequestGroup* requestGroup) CXX11_OVERRIDE;
|
RequestGroup* requestGroup) const CXX11_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -44,13 +44,11 @@ namespace aria2 {
|
||||||
class PostDownloadHandler:public DownloadHandler
|
class PostDownloadHandler:public DownloadHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PostDownloadHandler() {}
|
|
||||||
|
|
||||||
virtual ~PostDownloadHandler() {}
|
virtual ~PostDownloadHandler() {}
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup>>& groups,
|
||||||
RequestGroup* requestGroup) = 0;
|
RequestGroup* requestGroup) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
|
|
||||||
virtual ~PreDownloadHandler() {}
|
virtual ~PreDownloadHandler() {}
|
||||||
|
|
||||||
virtual void execute(RequestGroup* requestGroup) = 0;
|
virtual void execute(RequestGroup* requestGroup) const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -61,7 +61,7 @@
|
||||||
#include "RequestGroupMan.h"
|
#include "RequestGroupMan.h"
|
||||||
#include "DefaultBtProgressInfoFile.h"
|
#include "DefaultBtProgressInfoFile.h"
|
||||||
#include "DefaultPieceStorage.h"
|
#include "DefaultPieceStorage.h"
|
||||||
#include "DownloadHandlerFactory.h"
|
#include "download_handlers.h"
|
||||||
#include "MemoryBufferPreDownloadHandler.h"
|
#include "MemoryBufferPreDownloadHandler.h"
|
||||||
#include "DownloadHandlerConstants.h"
|
#include "DownloadHandlerConstants.h"
|
||||||
#include "Option.h"
|
#include "Option.h"
|
||||||
|
@ -78,6 +78,7 @@
|
||||||
#include "SimpleRandomizer.h"
|
#include "SimpleRandomizer.h"
|
||||||
#include "Segment.h"
|
#include "Segment.h"
|
||||||
#include "SocketRecvBuffer.h"
|
#include "SocketRecvBuffer.h"
|
||||||
|
#include "RequestGroupCriteria.h"
|
||||||
#ifdef ENABLE_MESSAGE_DIGEST
|
#ifdef ENABLE_MESSAGE_DIGEST
|
||||||
# include "CheckIntegrityCommand.h"
|
# include "CheckIntegrityCommand.h"
|
||||||
# include "ChecksumCheckIntegrityEntry.h"
|
# include "ChecksumCheckIntegrityEntry.h"
|
||||||
|
@ -1052,12 +1053,14 @@ void RequestGroup::initializePreDownloadHandler()
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(option_->get(PREF_FOLLOW_TORRENT) == V_MEM) {
|
if(option_->get(PREF_FOLLOW_TORRENT) == V_MEM) {
|
||||||
preDownloadHandlers_.push_back(DownloadHandlerFactory::getBtPreDownloadHandler());
|
preDownloadHandlers_.push_back
|
||||||
|
(download_handlers::getBtPreDownloadHandler());
|
||||||
}
|
}
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
if(option_->get(PREF_FOLLOW_METALINK) == V_MEM) {
|
if(option_->get(PREF_FOLLOW_METALINK) == V_MEM) {
|
||||||
preDownloadHandlers_.push_back(DownloadHandlerFactory::getMetalinkPreDownloadHandler());
|
preDownloadHandlers_.push_back
|
||||||
|
(download_handlers::getMetalinkPreDownloadHandler());
|
||||||
}
|
}
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
}
|
}
|
||||||
|
@ -1067,13 +1070,15 @@ void RequestGroup::initializePostDownloadHandler()
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(option_->getAsBool(PREF_FOLLOW_TORRENT) ||
|
if(option_->getAsBool(PREF_FOLLOW_TORRENT) ||
|
||||||
option_->get(PREF_FOLLOW_TORRENT) == V_MEM) {
|
option_->get(PREF_FOLLOW_TORRENT) == V_MEM) {
|
||||||
postDownloadHandlers_.push_back(DownloadHandlerFactory::getBtPostDownloadHandler());
|
postDownloadHandlers_.push_back
|
||||||
|
(download_handlers::getBtPostDownloadHandler());
|
||||||
}
|
}
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
if(option_->getAsBool(PREF_FOLLOW_METALINK) ||
|
if(option_->getAsBool(PREF_FOLLOW_METALINK) ||
|
||||||
option_->get(PREF_FOLLOW_METALINK) == V_MEM) {
|
option_->get(PREF_FOLLOW_METALINK) == V_MEM) {
|
||||||
postDownloadHandlers_.push_back(DownloadHandlerFactory::getMetalinkPostDownloadHandler());
|
postDownloadHandlers_.push_back
|
||||||
|
(download_handlers::getMetalinkPostDownloadHandler());
|
||||||
}
|
}
|
||||||
#endif // ENABLE_METALINK
|
#endif // ENABLE_METALINK
|
||||||
}
|
}
|
||||||
|
@ -1097,14 +1102,12 @@ void RequestGroup::setDiskWriterFactory(
|
||||||
diskWriterFactory_ = diskWriterFactory;
|
diskWriterFactory_ = diskWriterFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestGroup::addPostDownloadHandler
|
void RequestGroup::addPostDownloadHandler(const PostDownloadHandler* handler)
|
||||||
(const std::shared_ptr<PostDownloadHandler>& handler)
|
|
||||||
{
|
{
|
||||||
postDownloadHandlers_.push_back(handler);
|
postDownloadHandlers_.push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RequestGroup::addPreDownloadHandler(
|
void RequestGroup::addPreDownloadHandler(const PreDownloadHandler* handler)
|
||||||
const std::shared_ptr<PreDownloadHandler>& handler)
|
|
||||||
{
|
{
|
||||||
preDownloadHandlers_.push_back(handler);
|
preDownloadHandlers_.push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,9 +131,9 @@ private:
|
||||||
|
|
||||||
bool pauseRequested_;
|
bool pauseRequested_;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<PreDownloadHandler> > preDownloadHandlers_;
|
std::vector<const PreDownloadHandler*> preDownloadHandlers_;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<PostDownloadHandler> > postDownloadHandlers_;
|
std::vector<const PostDownloadHandler*> postDownloadHandlers_;
|
||||||
|
|
||||||
std::unique_ptr<URISelector> uriSelector_;
|
std::unique_ptr<URISelector> uriSelector_;
|
||||||
|
|
||||||
|
@ -375,13 +375,13 @@ public:
|
||||||
|
|
||||||
void postDownloadProcessing(std::vector<std::shared_ptr<RequestGroup> >& groups);
|
void postDownloadProcessing(std::vector<std::shared_ptr<RequestGroup> >& groups);
|
||||||
|
|
||||||
void addPostDownloadHandler(const std::shared_ptr<PostDownloadHandler>& handler);
|
void addPostDownloadHandler(const PostDownloadHandler* handler);
|
||||||
|
|
||||||
void clearPostDownloadHandler();
|
void clearPostDownloadHandler();
|
||||||
|
|
||||||
void preDownloadProcessing();
|
void preDownloadProcessing();
|
||||||
|
|
||||||
void addPreDownloadHandler(const std::shared_ptr<PreDownloadHandler>& handler);
|
void addPreDownloadHandler(const PreDownloadHandler* handler);
|
||||||
|
|
||||||
void clearPreDownloadHandler();
|
void clearPreDownloadHandler();
|
||||||
|
|
||||||
|
|
|
@ -53,29 +53,33 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
bool UTMetadataPostDownloadHandler::Criteria::match
|
namespace {
|
||||||
(const RequestGroup* requestGroup) const
|
class Criteria:public RequestGroupCriteria
|
||||||
{
|
{
|
||||||
const std::shared_ptr<DownloadContext>& dctx =
|
public:
|
||||||
requestGroup->getDownloadContext();
|
virtual bool match(const RequestGroup* requestGroup) const CXX11_OVERRIDE
|
||||||
if(dctx->hasAttribute(CTX_ATTR_BT)) {
|
{
|
||||||
if(bittorrent::getTorrentAttrs(dctx)->metadata.empty()) {
|
auto& dctx = requestGroup->getDownloadContext();
|
||||||
return true;
|
if(dctx->hasAttribute(CTX_ATTR_BT)) {
|
||||||
|
if(bittorrent::getTorrentAttrs(dctx)->metadata.empty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
};
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler()
|
UTMetadataPostDownloadHandler::UTMetadataPostDownloadHandler()
|
||||||
{
|
{
|
||||||
std::shared_ptr<Criteria> cri(new Criteria());
|
setCriteria(make_unique<Criteria>());
|
||||||
setCriteria(cri);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UTMetadataPostDownloadHandler::getNextRequestGroups
|
void UTMetadataPostDownloadHandler::getNextRequestGroups
|
||||||
(std::vector<std::shared_ptr<RequestGroup> >& groups, RequestGroup* requestGroup)
|
(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
||||||
|
RequestGroup* requestGroup) const
|
||||||
{
|
{
|
||||||
const std::shared_ptr<DownloadContext>& dctx =requestGroup->getDownloadContext();
|
auto& dctx =requestGroup->getDownloadContext();
|
||||||
auto attrs = bittorrent::getTorrentAttrs(dctx);
|
auto attrs = bittorrent::getTorrentAttrs(dctx);
|
||||||
std::string metadata =
|
std::string metadata =
|
||||||
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
util::toString(requestGroup->getPieceStorage()->getDiskAdaptor());
|
||||||
|
@ -92,7 +96,7 @@ void UTMetadataPostDownloadHandler::getNextRequestGroups
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(!requestGroup->getOption()->getAsBool(PREF_BT_METADATA_ONLY)) {
|
if(!requestGroup->getOption()->getAsBool(PREF_BT_METADATA_ONLY)) {
|
||||||
std::vector<std::shared_ptr<RequestGroup> > newRgs;
|
std::vector<std::shared_ptr<RequestGroup>> newRgs;
|
||||||
// Don't adjust announce URI because it has been done when
|
// Don't adjust announce URI because it has been done when
|
||||||
// RequestGroup is created with magnet URI.
|
// RequestGroup is created with magnet URI.
|
||||||
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
createRequestGroupForBitTorrent(newRgs, requestGroup->getOption(),
|
||||||
|
|
|
@ -43,17 +43,12 @@ namespace aria2 {
|
||||||
class UTMetadataPostDownloadHandler:public PostDownloadHandler
|
class UTMetadataPostDownloadHandler:public PostDownloadHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
class Criteria:public RequestGroupCriteria
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual bool match(const RequestGroup* requestGroup) const CXX11_OVERRIDE;
|
|
||||||
};
|
|
||||||
public:
|
public:
|
||||||
UTMetadataPostDownloadHandler();
|
UTMetadataPostDownloadHandler();
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
getNextRequestGroups(std::vector<std::shared_ptr<RequestGroup> >& groups,
|
||||||
RequestGroup* requestGroup) CXX11_OVERRIDE;
|
RequestGroup* requestGroup) const CXX11_OVERRIDE;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -0,0 +1,134 @@
|
||||||
|
/* <!-- copyright */
|
||||||
|
/*
|
||||||
|
* aria2 - The high speed download utility
|
||||||
|
*
|
||||||
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*
|
||||||
|
* In addition, as a special exception, the copyright holders give
|
||||||
|
* permission to link the code of portions of this program with the
|
||||||
|
* OpenSSL library under certain conditions as described in each
|
||||||
|
* individual source file, and distribute linked combinations
|
||||||
|
* including the two.
|
||||||
|
* You must obey the GNU General Public License in all respects
|
||||||
|
* for all of the code used other than OpenSSL. If you modify
|
||||||
|
* file(s) with this exception, you may extend this exception to your
|
||||||
|
* version of the file(s), but you are not obligated to do so. If you
|
||||||
|
* do not wish to do so, delete this exception statement from your
|
||||||
|
* version. If you delete this exception statement from all source
|
||||||
|
* files in the program, then also delete it here.
|
||||||
|
*/
|
||||||
|
/* copyright --> */
|
||||||
|
#include "download_handlers.h"
|
||||||
|
#include "DownloadHandlerConstants.h"
|
||||||
|
#include "ContentTypeRequestGroupCriteria.h"
|
||||||
|
#include "MemoryBufferPreDownloadHandler.h"
|
||||||
|
#include "a2functional.h"
|
||||||
|
#ifdef ENABLE_METALINK
|
||||||
|
# include "MetalinkPostDownloadHandler.h"
|
||||||
|
#endif // ENABLE_METALINK
|
||||||
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
# include "BtPostDownloadHandler.h"
|
||||||
|
# include "MemoryBencodePreDownloadHandler.h"
|
||||||
|
# include "UTMetadataPostDownloadHandler.h"
|
||||||
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
|
namespace aria2 {
|
||||||
|
|
||||||
|
namespace download_handlers {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::unique_ptr<PreDownloadHandler> memoryPreDownloadHandler;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
const PreDownloadHandler* getMemoryPreDownloadHandler()
|
||||||
|
{
|
||||||
|
if(!memoryPreDownloadHandler) {
|
||||||
|
memoryPreDownloadHandler = make_unique<MemoryBufferPreDownloadHandler>();
|
||||||
|
}
|
||||||
|
return memoryPreDownloadHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef ENABLE_METALINK
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::unique_ptr<PreDownloadHandler> metalinkPreDownloadHandler;
|
||||||
|
std::unique_ptr<PostDownloadHandler> metalinkPostDownloadHandler;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
const PreDownloadHandler* getMetalinkPreDownloadHandler()
|
||||||
|
{
|
||||||
|
if(!metalinkPreDownloadHandler) {
|
||||||
|
metalinkPreDownloadHandler = make_unique<MemoryBufferPreDownloadHandler>();
|
||||||
|
metalinkPreDownloadHandler->setCriteria
|
||||||
|
(make_unique<ContentTypeRequestGroupCriteria>(getMetalinkContentTypes(),
|
||||||
|
getMetalinkExtensions()));
|
||||||
|
}
|
||||||
|
return metalinkPreDownloadHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
const PostDownloadHandler* getMetalinkPostDownloadHandler()
|
||||||
|
{
|
||||||
|
if(!metalinkPostDownloadHandler) {
|
||||||
|
metalinkPostDownloadHandler = make_unique<MetalinkPostDownloadHandler>();
|
||||||
|
}
|
||||||
|
return metalinkPostDownloadHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_METALINK
|
||||||
|
|
||||||
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
std::unique_ptr<PreDownloadHandler> btPreDownloadHandler;
|
||||||
|
std::unique_ptr<PostDownloadHandler> btPostDownloadHandler;
|
||||||
|
std::unique_ptr<PostDownloadHandler> btMetadataPostDownloadHandler;
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
const PreDownloadHandler* getBtPreDownloadHandler()
|
||||||
|
{
|
||||||
|
if(!btPreDownloadHandler) {
|
||||||
|
btPreDownloadHandler =
|
||||||
|
make_unique<bittorrent::MemoryBencodePreDownloadHandler>();
|
||||||
|
btPreDownloadHandler->setCriteria
|
||||||
|
(make_unique<ContentTypeRequestGroupCriteria>(getBtContentTypes(),
|
||||||
|
getBtExtensions()));
|
||||||
|
}
|
||||||
|
return btPreDownloadHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
const PostDownloadHandler* getBtPostDownloadHandler()
|
||||||
|
{
|
||||||
|
if(!btPostDownloadHandler) {
|
||||||
|
btPostDownloadHandler = make_unique<BtPostDownloadHandler>();
|
||||||
|
}
|
||||||
|
return btPostDownloadHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
const PostDownloadHandler* getUTMetadataPostDownloadHandler()
|
||||||
|
{
|
||||||
|
if(!btMetadataPostDownloadHandler) {
|
||||||
|
btMetadataPostDownloadHandler =
|
||||||
|
make_unique<UTMetadataPostDownloadHandler>();
|
||||||
|
}
|
||||||
|
return btMetadataPostDownloadHandler.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
|
} // namespace download_handlers
|
||||||
|
|
||||||
|
} // namespace aria2
|
|
@ -32,26 +32,39 @@
|
||||||
* files in the program, then also delete it here.
|
* files in the program, then also delete it here.
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#ifndef D_TRUE_REQUEST_GROUP_CRITERIA_H
|
#ifndef D_DOWNLOAD_HANDLER_FACTORY_H
|
||||||
#define D_TRUE_REQUEST_GROUP_CRITERIA_H
|
#define D_DOWNLOAD_HANDLER_FACTORY_H
|
||||||
|
|
||||||
#include "RequestGroupCriteria.h"
|
#include "common.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class TrueRequestGroupCriteria:public RequestGroupCriteria
|
class PreDownloadHandler;
|
||||||
{
|
class PostDownloadHandler;
|
||||||
public:
|
|
||||||
TrueRequestGroupCriteria() {}
|
|
||||||
|
|
||||||
virtual ~TrueRequestGroupCriteria() {}
|
namespace download_handlers {
|
||||||
|
|
||||||
virtual bool match(const RequestGroup* requestGroup) const CXX11_OVERRIDE
|
const PreDownloadHandler* getMemoryPreDownloadHandler();
|
||||||
{
|
|
||||||
return true;
|
#ifdef ENABLE_METALINK
|
||||||
}
|
|
||||||
};
|
const PreDownloadHandler* getMetalinkPreDownloadHandler();
|
||||||
|
const PostDownloadHandler* getMetalinkPostDownloadHandler();
|
||||||
|
|
||||||
|
#endif // ENABLE_METALINK
|
||||||
|
|
||||||
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
|
||||||
|
const PreDownloadHandler* getBtPreDownloadHandler();
|
||||||
|
const PostDownloadHandler* getBtPostDownloadHandler();
|
||||||
|
const PostDownloadHandler* getUTMetadataPostDownloadHandler();
|
||||||
|
|
||||||
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
|
} // namespace download_handlers
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
||||||
#endif // D_TRUE_REQUEST_GROUP_CRITERIA_H
|
#endif // D_DOWNLOAD_HANDLER_FACTORY_H
|
|
@ -61,10 +61,10 @@
|
||||||
#include "MetadataInfo.h"
|
#include "MetadataInfo.h"
|
||||||
#include "OptionParser.h"
|
#include "OptionParser.h"
|
||||||
#include "SegList.h"
|
#include "SegList.h"
|
||||||
|
#include "download_handlers.h"
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
# include "bittorrent_helper.h"
|
# include "bittorrent_helper.h"
|
||||||
# include "BtConstants.h"
|
# include "BtConstants.h"
|
||||||
# include "UTMetadataPostDownloadHandler.h"
|
|
||||||
# include "ValueBaseBencodeParser.h"
|
# include "ValueBaseBencodeParser.h"
|
||||||
#endif // ENABLE_BITTORRENT
|
#endif // ENABLE_BITTORRENT
|
||||||
|
|
||||||
|
@ -244,9 +244,8 @@ createBtMagnetRequestGroup
|
||||||
dctx->getFirstFileEntry()->setPath(torrentAttrs->name);
|
dctx->getFirstFileEntry()->setPath(torrentAttrs->name);
|
||||||
rg->setDownloadContext(dctx);
|
rg->setDownloadContext(dctx);
|
||||||
rg->clearPostDownloadHandler();
|
rg->clearPostDownloadHandler();
|
||||||
auto utMetadataPostHandler =
|
rg->addPostDownloadHandler
|
||||||
std::make_shared<UTMetadataPostDownloadHandler>();
|
(download_handlers::getUTMetadataPostDownloadHandler());
|
||||||
rg->addPostDownloadHandler(utMetadataPostHandler);
|
|
||||||
rg->setDiskWriterFactory(std::make_shared<ByteArrayDiskWriterFactory>());
|
rg->setDiskWriterFactory(std::make_shared<ByteArrayDiskWriterFactory>());
|
||||||
rg->setMetadataInfo(createMetadataInfo(gid, magnetLink));
|
rg->setMetadataInfo(createMetadataInfo(gid, magnetLink));
|
||||||
rg->markInMemoryDownload();
|
rg->markInMemoryDownload();
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "bittorrent_helper.h"
|
#include "bittorrent_helper.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
|
#include "RequestGroupCriteria.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#include "DownloadHandlerFactory.h"
|
#include "download_handlers.h"
|
||||||
|
|
||||||
#include <cppunit/extensions/HelperMacros.h>
|
#include <cppunit/extensions/HelperMacros.h>
|
||||||
|
|
||||||
|
@ -7,12 +7,14 @@
|
||||||
#include "DownloadContext.h"
|
#include "DownloadContext.h"
|
||||||
#include "MemoryBufferPreDownloadHandler.h"
|
#include "MemoryBufferPreDownloadHandler.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
#include "RequestGroupCriteria.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class DownloadHandlerFactoryTest:public CppUnit::TestFixture {
|
class DownloadHandlersTest:public CppUnit::TestFixture {
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE(DownloadHandlerFactoryTest);
|
CPPUNIT_TEST_SUITE(DownloadHandlersTest);
|
||||||
|
CPPUNIT_TEST(testGetMemoryPreDownloadHandler);
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension);
|
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_extension);
|
||||||
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType);
|
CPPUNIT_TEST(testGetMetalinkPreDownloadHandler_contentType);
|
||||||
|
@ -29,8 +31,9 @@ private:
|
||||||
public:
|
public:
|
||||||
void setUp()
|
void setUp()
|
||||||
{
|
{
|
||||||
option_.reset(new Option());
|
option_ = std::make_shared<Option>();
|
||||||
}
|
}
|
||||||
|
void testGetMemoryPreDownloadHandler();
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
void testGetMetalinkPreDownloadHandler_extension();
|
void testGetMetalinkPreDownloadHandler_extension();
|
||||||
void testGetMetalinkPreDownloadHandler_contentType();
|
void testGetMetalinkPreDownloadHandler_contentType();
|
||||||
|
@ -44,17 +47,23 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlerFactoryTest );
|
CPPUNIT_TEST_SUITE_REGISTRATION( DownloadHandlersTest );
|
||||||
|
|
||||||
|
void DownloadHandlersTest::testGetMemoryPreDownloadHandler()
|
||||||
|
{
|
||||||
|
CPPUNIT_ASSERT(download_handlers::getMemoryPreDownloadHandler()
|
||||||
|
->canHandle(nullptr));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_METALINK
|
#ifdef ENABLE_METALINK
|
||||||
|
|
||||||
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
|
void DownloadHandlersTest::testGetMetalinkPreDownloadHandler_extension()
|
||||||
{
|
{
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext(0, 0, "test.metalink"));
|
auto dctx = std::make_shared<DownloadContext>(0, 0, "test.metalink");
|
||||||
RequestGroup rg(GroupId::create(), option_);
|
RequestGroup rg(GroupId::create(), option_);
|
||||||
rg.setDownloadContext(dctx);
|
rg.setDownloadContext(dctx);
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
|
auto handler = download_handlers::getMetalinkPreDownloadHandler();
|
||||||
|
|
||||||
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
||||||
|
|
||||||
|
@ -62,14 +71,14 @@ void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_extension()
|
||||||
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
|
void DownloadHandlersTest::testGetMetalinkPreDownloadHandler_contentType()
|
||||||
{
|
{
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
|
auto dctx = std::make_shared<DownloadContext>(0, 0, "test");
|
||||||
dctx->getFirstFileEntry()->setContentType("application/metalink+xml");
|
dctx->getFirstFileEntry()->setContentType("application/metalink+xml");
|
||||||
RequestGroup rg(GroupId::create(), option_);
|
RequestGroup rg(GroupId::create(), option_);
|
||||||
rg.setDownloadContext(dctx);
|
rg.setDownloadContext(dctx);
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler> handler = DownloadHandlerFactory::getMetalinkPreDownloadHandler();
|
auto handler = download_handlers::getMetalinkPreDownloadHandler();
|
||||||
|
|
||||||
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
||||||
|
|
||||||
|
@ -81,14 +90,14 @@ void DownloadHandlerFactoryTest::testGetMetalinkPreDownloadHandler_contentType()
|
||||||
|
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
|
|
||||||
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
|
void DownloadHandlersTest::testGetBtPreDownloadHandler_extension()
|
||||||
{
|
{
|
||||||
std::shared_ptr<DownloadContext> dctx
|
auto dctx = std::make_shared<DownloadContext>(0, 0,
|
||||||
(new DownloadContext(0, 0, A2_TEST_DIR"/test.torrent"));
|
A2_TEST_DIR"/test.torrent");
|
||||||
RequestGroup rg(GroupId::create(), option_);
|
RequestGroup rg(GroupId::create(), option_);
|
||||||
rg.setDownloadContext(dctx);
|
rg.setDownloadContext(dctx);
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
|
auto handler = download_handlers::getBtPreDownloadHandler();
|
||||||
|
|
||||||
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
||||||
|
|
||||||
|
@ -96,14 +105,14 @@ void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_extension()
|
||||||
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
CPPUNIT_ASSERT(!handler->canHandle(&rg));
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadHandlerFactoryTest::testGetBtPreDownloadHandler_contentType()
|
void DownloadHandlersTest::testGetBtPreDownloadHandler_contentType()
|
||||||
{
|
{
|
||||||
std::shared_ptr<DownloadContext> dctx(new DownloadContext(0, 0, "test"));
|
auto dctx = std::make_shared<DownloadContext>(0, 0, "test");
|
||||||
dctx->getFirstFileEntry()->setContentType("application/x-bittorrent");
|
dctx->getFirstFileEntry()->setContentType("application/x-bittorrent");
|
||||||
RequestGroup rg(GroupId::create(), option_);
|
RequestGroup rg(GroupId::create(), option_);
|
||||||
rg.setDownloadContext(dctx);
|
rg.setDownloadContext(dctx);
|
||||||
|
|
||||||
std::shared_ptr<PreDownloadHandler> handler = DownloadHandlerFactory::getBtPreDownloadHandler();
|
auto handler = download_handlers::getBtPreDownloadHandler();
|
||||||
|
|
||||||
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
CPPUNIT_ASSERT(handler->canHandle(&rg));
|
||||||
|
|
|
@ -42,7 +42,7 @@ aria2c_SOURCES = AllTest.cc\
|
||||||
ProtocolDetectorTest.cc\
|
ProtocolDetectorTest.cc\
|
||||||
ExceptionTest.cc\
|
ExceptionTest.cc\
|
||||||
FmtTest.cc\
|
FmtTest.cc\
|
||||||
DownloadHandlerFactoryTest.cc\
|
DownloadHandlersTest.cc\
|
||||||
SignatureTest.cc\
|
SignatureTest.cc\
|
||||||
ServerStatManTest.cc\
|
ServerStatManTest.cc\
|
||||||
FeedbackURISelectorTest.cc\
|
FeedbackURISelectorTest.cc\
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
#include "PieceStorage.h"
|
#include "PieceStorage.h"
|
||||||
#include "DiskAdaptor.h"
|
#include "DiskAdaptor.h"
|
||||||
|
#include "RequestGroupCriteria.h"
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue