mirror of https://github.com/aria2/aria2
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Code clean up * src/BtPostDownloadHandler.cc * src/ContentTypeRequestGroupCriteria.cc * src/ContentTypeRequestGroupCriteria.h * src/DownloadHandlerConstants.cc * src/DownloadHandlerConstants.h * src/DownloadHandlerFactory.cc * src/MetalinkPostDownloadHandler.ccpull/1/head
parent
5f1d8c7897
commit
967dade8b2
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Code clean up
|
||||||
|
* src/BtPostDownloadHandler.cc
|
||||||
|
* src/ContentTypeRequestGroupCriteria.cc
|
||||||
|
* src/ContentTypeRequestGroupCriteria.h
|
||||||
|
* src/DownloadHandlerConstants.cc
|
||||||
|
* src/DownloadHandlerConstants.h
|
||||||
|
* src/DownloadHandlerFactory.cc
|
||||||
|
* src/MetalinkPostDownloadHandler.cc
|
||||||
|
|
||||||
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-10-05 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Don't save control file when aria2 exists while checking piece
|
Don't save control file when aria2 exists while checking piece
|
||||||
|
|
|
@ -52,8 +52,11 @@ namespace aria2 {
|
||||||
BtPostDownloadHandler::BtPostDownloadHandler()
|
BtPostDownloadHandler::BtPostDownloadHandler()
|
||||||
{
|
{
|
||||||
SharedHandle<RequestGroupCriteria> cri
|
SharedHandle<RequestGroupCriteria> cri
|
||||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getBtContentTypes(),
|
(new ContentTypeRequestGroupCriteria
|
||||||
DownloadHandlerConstants::getBtExtensions()));
|
(DownloadHandlerConstants::getBtContentTypes().begin(),
|
||||||
|
DownloadHandlerConstants::getBtContentTypes().end(),
|
||||||
|
DownloadHandlerConstants::getBtExtensions().begin(),
|
||||||
|
DownloadHandlerConstants::getBtExtensions().end()));
|
||||||
setCriteria(cri);
|
setCriteria(cri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,8 +82,8 @@ void BtPostDownloadHandler::getNextRequestGroups
|
||||||
}
|
}
|
||||||
SharedHandle<DownloadContext> context(new DownloadContext());
|
SharedHandle<DownloadContext> context(new DownloadContext());
|
||||||
context->setDir(requestGroup->getDownloadContext()->getDir());
|
context->setDir(requestGroup->getDownloadContext()->getDir());
|
||||||
bittorrent::loadFromMemory(content, context,
|
bittorrent::loadFromMemory
|
||||||
File(requestGroup->getFirstFilePath()).getBasename());
|
(content, context, File(requestGroup->getFirstFilePath()).getBasename());
|
||||||
rg->setDownloadContext(context);
|
rg->setDownloadContext(context);
|
||||||
context->setOwnerRequestGroup(rg.get());
|
context->setOwnerRequestGroup(rg.get());
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
*/
|
*/
|
||||||
/* copyright --> */
|
/* copyright --> */
|
||||||
#include "ContentTypeRequestGroupCriteria.h"
|
#include "ContentTypeRequestGroupCriteria.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "RequestGroup.h"
|
#include "RequestGroup.h"
|
||||||
#include "Util.h"
|
#include "Util.h"
|
||||||
#include "FileEntry.h"
|
#include "FileEntry.h"
|
||||||
|
@ -40,45 +43,33 @@
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
ContentTypeRequestGroupCriteria::ContentTypeRequestGroupCriteria(const std::deque<std::string>& contentTypes,
|
template<typename InputIterator>
|
||||||
const std::deque<std::string>& extensions):
|
bool tailMatch
|
||||||
_contentTypes(contentTypes),
|
(InputIterator first, InputIterator last, const std::string& target)
|
||||||
_extensions(extensions) {}
|
{
|
||||||
|
for(; first != last; ++first) {
|
||||||
|
if(Util::endsWith(target, *first)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ContentTypeRequestGroupCriteria::~ContentTypeRequestGroupCriteria() {}
|
bool ContentTypeRequestGroupCriteria::match
|
||||||
|
(const RequestGroup* requestGroup) const
|
||||||
bool ContentTypeRequestGroupCriteria::match(const RequestGroup* requestGroup) const
|
|
||||||
{
|
{
|
||||||
if(requestGroup->getDownloadContext()->getFileEntries().size() != 1) {
|
if(requestGroup->getDownloadContext()->getFileEntries().size() != 1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(forwardMatch(requestGroup->getFirstFilePath(), _extensions)) {
|
if(tailMatch(_extensions.begin(), _extensions.end(),
|
||||||
|
requestGroup->getFirstFilePath())) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return exactMatch
|
return
|
||||||
(requestGroup->getDownloadContext()->getFirstFileEntry()->getContentType(),
|
std::find(_contentTypes.begin(), _contentTypes.end(),
|
||||||
_contentTypes);
|
requestGroup->getDownloadContext()->getFirstFileEntry()->
|
||||||
|
getContentType()) != _contentTypes.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ContentTypeRequestGroupCriteria::forwardMatch(const std::string& target, const std::deque<std::string>& candidates) const
|
|
||||||
{
|
|
||||||
for(std::deque<std::string>::const_iterator itr = candidates.begin(); itr != candidates.end(); ++itr) {
|
|
||||||
if(Util::endsWith(target, *itr)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ContentTypeRequestGroupCriteria::exactMatch(const std::string& target, const std::deque<std::string>& candidates) const
|
|
||||||
{
|
|
||||||
for(std::deque<std::string>::const_iterator itr = candidates.begin(); itr != candidates.end(); ++itr) {
|
|
||||||
if(target == *itr) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -37,25 +37,23 @@
|
||||||
|
|
||||||
#include "RequestGroupCriteria.h"
|
#include "RequestGroupCriteria.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <vector>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
class ContentTypeRequestGroupCriteria:public RequestGroupCriteria
|
class ContentTypeRequestGroupCriteria:public RequestGroupCriteria
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
std::deque<std::string> _contentTypes;
|
std::vector<std::string> _contentTypes;
|
||||||
std::deque<std::string> _extensions;
|
std::vector<std::string> _extensions;
|
||||||
|
|
||||||
bool forwardMatch(const std::string& target, const std::deque<std::string>& candidates) const;
|
|
||||||
|
|
||||||
bool exactMatch(const std::string& target, const std::deque<std::string>& candidates) const;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ContentTypeRequestGroupCriteria(const std::deque<std::string>& contentTypes,
|
template<typename InputIterator>
|
||||||
const std::deque<std::string>& extensions);
|
ContentTypeRequestGroupCriteria(InputIterator contentTypeFirst,
|
||||||
|
InputIterator contentTypeLast,
|
||||||
virtual ~ContentTypeRequestGroupCriteria();
|
InputIterator extensionFirst,
|
||||||
|
InputIterator extensionLast):
|
||||||
|
_contentTypes(contentTypeFirst, contentTypeLast),
|
||||||
|
_extensions(extensionFirst, extensionLast) {}
|
||||||
|
|
||||||
virtual bool match(const RequestGroup* requestGroup) const;
|
virtual bool match(const RequestGroup* requestGroup) const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -49,33 +49,35 @@ const char* DownloadHandlerConstants::BT_CONTENT_TYPES[] = {
|
||||||
"application/x-bittorrent"
|
"application/x-bittorrent"
|
||||||
};
|
};
|
||||||
|
|
||||||
const std::deque<std::string>& DownloadHandlerConstants::getMetalinkExtensions()
|
const std::vector<std::string>&
|
||||||
|
DownloadHandlerConstants::getMetalinkExtensions()
|
||||||
{
|
{
|
||||||
static const std::deque<std::string> l
|
static const std::vector<std::string> l
|
||||||
(&METALINK_EXTENSIONS[0],
|
(&METALINK_EXTENSIONS[0],
|
||||||
&METALINK_EXTENSIONS[arrayLength(METALINK_EXTENSIONS)]);
|
&METALINK_EXTENSIONS[arrayLength(METALINK_EXTENSIONS)]);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<std::string>& DownloadHandlerConstants::getMetalinkContentTypes()
|
const std::vector<std::string>&
|
||||||
|
DownloadHandlerConstants::getMetalinkContentTypes()
|
||||||
{
|
{
|
||||||
static const std::deque<std::string> l
|
static const std::vector<std::string> l
|
||||||
(&METALINK_CONTENT_TYPES[0],
|
(&METALINK_CONTENT_TYPES[0],
|
||||||
&METALINK_CONTENT_TYPES[arrayLength(METALINK_CONTENT_TYPES)]);
|
&METALINK_CONTENT_TYPES[arrayLength(METALINK_CONTENT_TYPES)]);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<std::string>& DownloadHandlerConstants::getBtExtensions()
|
const std::vector<std::string>& DownloadHandlerConstants::getBtExtensions()
|
||||||
{
|
{
|
||||||
static const std::deque<std::string> l
|
static const std::vector<std::string> l
|
||||||
(&BT_EXTENSIONS[0],
|
(&BT_EXTENSIONS[0],
|
||||||
&BT_EXTENSIONS[arrayLength(BT_EXTENSIONS)]);
|
&BT_EXTENSIONS[arrayLength(BT_EXTENSIONS)]);
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::deque<std::string>& DownloadHandlerConstants::getBtContentTypes()
|
const std::vector<std::string>& DownloadHandlerConstants::getBtContentTypes()
|
||||||
{
|
{
|
||||||
static const std::deque<std::string> l
|
static const std::vector<std::string> l
|
||||||
(&BT_CONTENT_TYPES[0],
|
(&BT_CONTENT_TYPES[0],
|
||||||
&BT_CONTENT_TYPES[arrayLength(BT_CONTENT_TYPES)]);
|
&BT_CONTENT_TYPES[arrayLength(BT_CONTENT_TYPES)]);
|
||||||
return l;
|
return l;
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <deque>
|
#include <vector>
|
||||||
|
|
||||||
namespace aria2 {
|
namespace aria2 {
|
||||||
|
|
||||||
|
@ -46,19 +46,19 @@ class DownloadHandlerConstants
|
||||||
public:
|
public:
|
||||||
static const char* METALINK_EXTENSIONS[];
|
static const char* METALINK_EXTENSIONS[];
|
||||||
|
|
||||||
static const std::deque<std::string>& getMetalinkExtensions();
|
static const std::vector<std::string>& getMetalinkExtensions();
|
||||||
|
|
||||||
static const char* METALINK_CONTENT_TYPES[];
|
static const char* METALINK_CONTENT_TYPES[];
|
||||||
|
|
||||||
static const std::deque<std::string>& getMetalinkContentTypes();
|
static const std::vector<std::string>& getMetalinkContentTypes();
|
||||||
|
|
||||||
static const char* BT_EXTENSIONS[];
|
static const char* BT_EXTENSIONS[];
|
||||||
|
|
||||||
static const std::deque<std::string>& getBtExtensions();
|
static const std::vector<std::string>& getBtExtensions();
|
||||||
|
|
||||||
static const char* BT_CONTENT_TYPES[];
|
static const char* BT_CONTENT_TYPES[];
|
||||||
|
|
||||||
static const std::deque<std::string>& getBtContentTypes();
|
static const std::vector<std::string>& getBtContentTypes();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace aria2
|
} // namespace aria2
|
||||||
|
|
|
@ -70,8 +70,11 @@ DownloadHandlerFactory::getMetalinkPreDownloadHandler()
|
||||||
_metalinkPreDownloadHandler.reset(new MemoryBufferPreDownloadHandler());
|
_metalinkPreDownloadHandler.reset(new MemoryBufferPreDownloadHandler());
|
||||||
|
|
||||||
RequestGroupCriteriaHandle criteria
|
RequestGroupCriteriaHandle criteria
|
||||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getMetalinkContentTypes(),
|
(new ContentTypeRequestGroupCriteria
|
||||||
DownloadHandlerConstants::getMetalinkExtensions()));
|
(DownloadHandlerConstants::getMetalinkContentTypes().begin(),
|
||||||
|
DownloadHandlerConstants::getMetalinkContentTypes().end(),
|
||||||
|
DownloadHandlerConstants::getMetalinkExtensions().begin(),
|
||||||
|
DownloadHandlerConstants::getMetalinkExtensions().end()));
|
||||||
_metalinkPreDownloadHandler->setCriteria(criteria);
|
_metalinkPreDownloadHandler->setCriteria(criteria);
|
||||||
}
|
}
|
||||||
return _metalinkPreDownloadHandler;
|
return _metalinkPreDownloadHandler;
|
||||||
|
@ -97,8 +100,11 @@ DownloadHandlerFactory::getBtPreDownloadHandler()
|
||||||
_btPreDownloadHandler.reset(new MemoryBufferPreDownloadHandler());
|
_btPreDownloadHandler.reset(new MemoryBufferPreDownloadHandler());
|
||||||
|
|
||||||
RequestGroupCriteriaHandle criteria
|
RequestGroupCriteriaHandle criteria
|
||||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getBtContentTypes(),
|
(new ContentTypeRequestGroupCriteria
|
||||||
DownloadHandlerConstants::getBtExtensions()));
|
(DownloadHandlerConstants::getBtContentTypes().begin(),
|
||||||
|
DownloadHandlerConstants::getBtContentTypes().end(),
|
||||||
|
DownloadHandlerConstants::getBtExtensions().begin(),
|
||||||
|
DownloadHandlerConstants::getBtExtensions().end()));
|
||||||
_btPreDownloadHandler->setCriteria(criteria);
|
_btPreDownloadHandler->setCriteria(criteria);
|
||||||
}
|
}
|
||||||
return _btPreDownloadHandler;
|
return _btPreDownloadHandler;
|
||||||
|
|
|
@ -50,8 +50,11 @@ namespace aria2 {
|
||||||
MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
|
MetalinkPostDownloadHandler::MetalinkPostDownloadHandler()
|
||||||
{
|
{
|
||||||
SharedHandle<RequestGroupCriteria> cri
|
SharedHandle<RequestGroupCriteria> cri
|
||||||
(new ContentTypeRequestGroupCriteria(DownloadHandlerConstants::getMetalinkContentTypes(),
|
(new ContentTypeRequestGroupCriteria
|
||||||
DownloadHandlerConstants::getMetalinkExtensions()));
|
(DownloadHandlerConstants::getMetalinkContentTypes().begin(),
|
||||||
|
DownloadHandlerConstants::getMetalinkContentTypes().end(),
|
||||||
|
DownloadHandlerConstants::getMetalinkExtensions().begin(),
|
||||||
|
DownloadHandlerConstants::getMetalinkExtensions().end()));
|
||||||
setCriteria(cri);
|
setCriteria(cri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +66,8 @@ void MetalinkPostDownloadHandler::getNextRequestGroups
|
||||||
{
|
{
|
||||||
_logger->debug("Generating RequestGroups for Metalink file %s",
|
_logger->debug("Generating RequestGroups for Metalink file %s",
|
||||||
requestGroup->getFirstFilePath().c_str());
|
requestGroup->getFirstFilePath().c_str());
|
||||||
SharedHandle<DiskAdaptor> diskAdaptor = requestGroup->getPieceStorage()->getDiskAdaptor();
|
SharedHandle<DiskAdaptor> diskAdaptor =
|
||||||
|
requestGroup->getPieceStorage()->getDiskAdaptor();
|
||||||
try {
|
try {
|
||||||
diskAdaptor->openExistingFile();
|
diskAdaptor->openExistingFile();
|
||||||
//requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
|
//requestOption.put(PREF_DIR, requestGroup->getDownloadContext()->getDir());
|
||||||
|
|
Loading…
Reference in New Issue