2006-08-07 16:05:00 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-08-07 16:05:00 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-08-07 16:05:00 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "Metalink2RequestGroup.h"
|
|
|
|
#include "RequestGroup.h"
|
|
|
|
#include "Option.h"
|
|
|
|
#include "LogFactory.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "Logger.h"
|
2006-08-07 16:05:00 +00:00
|
|
|
#include "prefs.h"
|
2007-06-30 09:52:39 +00:00
|
|
|
#include "Util.h"
|
2007-07-20 17:06:21 +00:00
|
|
|
#include "message.h"
|
2007-10-11 16:58:24 +00:00
|
|
|
#include "SingleFileDownloadContext.h"
|
2007-11-03 12:03:53 +00:00
|
|
|
#include "MetalinkHelper.h"
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
#include "BinaryStream.h"
|
|
|
|
#include "MemoryBufferPreDownloadHandler.h"
|
|
|
|
#include "TrueRequestGroupCriteria.h"
|
2007-12-04 11:12:56 +00:00
|
|
|
#include "MetalinkEntry.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "MetalinkResource.h"
|
|
|
|
#include "FileEntry.h"
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
# include "BtDependency.h"
|
|
|
|
#endif // ENABLE_BITTORRENT
|
2008-02-08 15:53:45 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
# include "Checksum.h"
|
|
|
|
# include "ChunkChecksum.h"
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
namespace aria2 {
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
Metalink2RequestGroup::Metalink2RequestGroup(const Option* option):
|
|
|
|
_option(option),
|
|
|
|
_logger(LogFactory::getInstance()) {}
|
2007-10-11 16:58:24 +00:00
|
|
|
|
|
|
|
Metalink2RequestGroup::~Metalink2RequestGroup() {}
|
2006-08-07 16:05:00 +00:00
|
|
|
|
|
|
|
class AccumulateNonP2PUrl {
|
|
|
|
private:
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string>& urlsPtr;
|
2006-08-07 16:05:00 +00:00
|
|
|
public:
|
2008-02-08 15:53:45 +00:00
|
|
|
AccumulateNonP2PUrl(std::deque<std::string>& urlsPtr)
|
2007-12-12 14:08:19 +00:00
|
|
|
:urlsPtr(urlsPtr) {}
|
2006-08-07 16:05:00 +00:00
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void operator()(const SharedHandle<MetalinkResource>& resource) {
|
2006-08-07 16:05:00 +00:00
|
|
|
switch(resource->type) {
|
|
|
|
case MetalinkResource::TYPE_HTTP:
|
|
|
|
case MetalinkResource::TYPE_HTTPS:
|
|
|
|
case MetalinkResource::TYPE_FTP:
|
2007-12-12 14:08:19 +00:00
|
|
|
urlsPtr.push_back(resource->url);
|
2006-08-07 16:05:00 +00:00
|
|
|
break;
|
2007-07-31 16:45:16 +00:00
|
|
|
default:
|
|
|
|
break;
|
2006-08-07 16:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class FindBitTorrentUrl {
|
|
|
|
public:
|
|
|
|
FindBitTorrentUrl() {}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
bool operator()(const SharedHandle<MetalinkResource>& resource) {
|
2006-08-07 16:05:00 +00:00
|
|
|
if(resource->type == MetalinkResource::TYPE_BITTORRENT) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2008-05-11 13:59:27 +00:00
|
|
|
void
|
|
|
|
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
|
|
|
const std::string& metalinkFile)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2008-05-12 11:39:34 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> > entries;
|
|
|
|
MetalinkHelper::parseAndQuery(entries, metalinkFile, _option);
|
2008-05-11 13:59:27 +00:00
|
|
|
createRequestGroup(groups, entries);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 13:59:27 +00:00
|
|
|
void
|
|
|
|
Metalink2RequestGroup::generate(std::deque<SharedHandle<RequestGroup> >& groups,
|
|
|
|
const SharedHandle<BinaryStream>& binaryStream)
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
{
|
2008-05-12 11:39:34 +00:00
|
|
|
std::deque<SharedHandle<MetalinkEntry> > entries;
|
|
|
|
MetalinkHelper::parseAndQuery(entries, binaryStream, _option);
|
2008-05-11 13:59:27 +00:00
|
|
|
createRequestGroup(groups, entries);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
}
|
|
|
|
|
2008-05-11 13:59:27 +00:00
|
|
|
void
|
|
|
|
Metalink2RequestGroup::createRequestGroup
|
|
|
|
(std::deque<SharedHandle<RequestGroup> >& groups,
|
|
|
|
std::deque<SharedHandle<MetalinkEntry> > entries)
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
{
|
2007-10-15 14:55:24 +00:00
|
|
|
if(entries.size() == 0) {
|
|
|
|
_logger->notice(EX_NO_RESULT_WITH_YOUR_PREFS);
|
2008-05-11 13:59:27 +00:00
|
|
|
return;
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<int32_t> selectIndexes = Util::parseIntRange(_option->get(PREF_SELECT_FILE)).flush();
|
2007-10-15 14:55:24 +00:00
|
|
|
bool useIndex;
|
|
|
|
if(selectIndexes.size()) {
|
|
|
|
useIndex = true;
|
|
|
|
} else {
|
|
|
|
useIndex = false;
|
|
|
|
}
|
2008-03-09 12:24:01 +00:00
|
|
|
unsigned int count = 0;
|
2008-02-08 15:53:45 +00:00
|
|
|
for(std::deque<SharedHandle<MetalinkEntry> >::iterator itr = entries.begin(); itr != entries.end();
|
2007-10-15 14:55:24 +00:00
|
|
|
itr++, ++count) {
|
2008-02-08 15:53:45 +00:00
|
|
|
SharedHandle<MetalinkEntry>& entry = *itr;
|
2007-10-15 14:55:24 +00:00
|
|
|
if(_option->defined(PREF_METALINK_LOCATION)) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> locations;
|
2007-11-13 13:49:10 +00:00
|
|
|
Util::slice(locations, _option->get(PREF_METALINK_LOCATION), ',', true);
|
|
|
|
entry->setLocationPreference(locations, 100);
|
2007-06-30 09:52:39 +00:00
|
|
|
}
|
2007-12-12 13:53:33 +00:00
|
|
|
if(_option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
|
|
|
|
entry->setProtocolPreference(_option->get(PREF_METALINK_PREFERRED_PROTOCOL), 100);
|
|
|
|
}
|
2007-10-15 14:55:24 +00:00
|
|
|
if(useIndex) {
|
2008-02-08 15:53:45 +00:00
|
|
|
if(std::find(selectIndexes.begin(), selectIndexes.end(), count+1) == selectIndexes.end()) {
|
2006-11-08 16:25:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
|
|
|
entry->dropUnsupportedResource();
|
|
|
|
if(entry->resources.size() == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
_logger->info(MSG_METALINK_QUEUEING, entry->getPath().c_str());
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<SharedHandle<MetalinkResource> >::iterator itr =
|
|
|
|
std::find_if(entry->resources.begin(), entry->resources.end(), FindBitTorrentUrl());
|
|
|
|
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<RequestGroup> torrentRg;
|
2007-10-15 14:55:24 +00:00
|
|
|
// there is torrent entry
|
|
|
|
if(itr != entry->resources.end()) {
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> uris;
|
2007-10-15 14:55:24 +00:00
|
|
|
uris.push_back((*itr)->url);
|
2008-04-20 00:50:22 +00:00
|
|
|
torrentRg.reset(new RequestGroup(_option, uris));
|
|
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
|
|
(new SingleFileDownloadContext(_option->getAsInt(PREF_SEGMENT_SIZE),
|
|
|
|
0,
|
|
|
|
""));
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
//dctx->setDir(_option->get(PREF_DIR));
|
2007-10-15 14:55:24 +00:00
|
|
|
torrentRg->setDownloadContext(dctx);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
torrentRg->clearPreDowloadHandler();
|
2007-10-15 14:55:24 +00:00
|
|
|
torrentRg->clearPostDowloadHandler();
|
2008-05-05 08:25:41 +00:00
|
|
|
// remove "metalink" from Accept Type list to avoid loop in tranparent
|
2008-04-25 17:44:03 +00:00
|
|
|
// metalink
|
2008-05-05 08:25:41 +00:00
|
|
|
torrentRg->removeAcceptType(RequestGroup::ACCEPT_METALINK);
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
// make it in-memory download
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<PreDownloadHandler> preh(new MemoryBufferPreDownloadHandler());
|
|
|
|
{
|
|
|
|
SharedHandle<RequestGroupCriteria> cri(new TrueRequestGroupCriteria());
|
|
|
|
preh->setCriteria(cri);
|
|
|
|
}
|
2007-11-27 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Rewritten to add content-type support.
* src/DownloadHandler.{h, cc}
* src/BtPostDownloadHandler.{h, cc}
* test/BtPostDownloadHandlerTest.cc
* src/MetalinkPostDownloadHandler.{h, cc}
* test/MetalinkPostDownloadHandlerTest.cc
* src/PostDownloadHandler.{h, cc}
* src/DownloadHandlerConstants.{h, cc}
* src/RequestGroup.cc
* src/HttpResponseCommand.cc
* src/FtpNegotiationCommand.cc
* src/SingleFileDownloadContext.{h, cc}
* src/RequestGroup.h
* src/RequestGroupCriteria.h
* src/ContentTypeRequestGroupCriteria.h
Added 'mem' option value for --follow-metalink,
--follow-torrent.
If it is give, metalink/torrent file is not written to the disk,
but
just is kept in memory. Parsing is occurred on memory.
* src/MetalinkHelper.{h, cc}
* src/MetalinkProcessor.h
* src/Xml2MetalinkProcessor.{h, cc}
* test/Xml2MetalinkProcessorTest.cc
* src/DownloadHandlerFactory.{h, cc}
* test/DownloadHandlerFactoryTest.cc
* src/PreDownloadHandler.{h, cc}
* src/OptionHandlerFactory.cc
* src/DefaultBtContext.{h, cc}
* test/DefaultBtContextTest.cc
* src/version_usage.cc
* src/Metalink2RequestGroup.{h, cc}
* src/RequestGroup.{h, cc}
* src/a2functional.h
* test/a2functionalTest.cc
* src/MemoryBufferPreDownloadHandler.{h, cc}
* src/OptionHandlerImpl.h
* src/prefs.h
* src/Util.{h, cc}
* test/UtilTest.cc
Keep DownloadResult rather than RequestGroup after downloads to
reduce
memory usage.
* src/RequestGroupMan.{h, cc}
* src/DownloadEngine.cc
* src/BtDependency.{h, cc}: Changed the type of dependee from
WeakHandle to SharedHandle because WeakHandle could be null.
* src/RequestGroup.{h, cc}
* src/DownloadEngineFactory.cc
* src/DownloadResult.h
Set totalLength after download finished
* src/UnknownLengthPieceStorage.{h, cc}
Keep torrent file specified in metalink in memory.
* src/Metalink2RequestGroup.cc
* src/BtDependency.cc
* src/TrueRequestGroupCriteria.h
Fixed the bug: seekg is used where seekp should be used.
* src/ByteArrayDiskWriter.cc
* test/ByteArraydiskWriterTest.cc
2007-11-27 12:27:10 +00:00
|
|
|
torrentRg->addPreDownloadHandler(preh);
|
2007-10-15 14:55:24 +00:00
|
|
|
groups.push_back(torrentRg);
|
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2007-10-15 14:55:24 +00:00
|
|
|
entry->reorderResourcesByPreference();
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> uris;
|
|
|
|
std::for_each(entry->resources.begin(), entry->resources.end(),
|
|
|
|
AccumulateNonP2PUrl(uris));
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<RequestGroup> rg(new RequestGroup(_option, uris));
|
2007-10-15 14:55:24 +00:00
|
|
|
// If piece hash is specified in the metalink,
|
|
|
|
// make segment size equal to piece hash size.
|
2008-03-09 12:24:01 +00:00
|
|
|
size_t pieceLength;
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-10-15 14:55:24 +00:00
|
|
|
if(entry->chunkChecksum.isNull()) {
|
|
|
|
pieceLength = _option->getAsInt(PREF_SEGMENT_SIZE);
|
|
|
|
} else {
|
|
|
|
pieceLength = entry->chunkChecksum->getChecksumLength();
|
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#else
|
|
|
|
pieceLength = _option->getAsInt(PREF_SEGMENT_SIZE);
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<SingleFileDownloadContext> dctx
|
|
|
|
(new SingleFileDownloadContext(pieceLength,
|
|
|
|
entry->getLength(),
|
|
|
|
"",
|
|
|
|
entry->file->getPath()));
|
2007-10-15 14:55:24 +00:00
|
|
|
dctx->setDir(_option->get(PREF_DIR));
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2007-11-12 11:28:16 +00:00
|
|
|
if(entry->chunkChecksum.isNull()) {
|
|
|
|
if(!entry->checksum.isNull()) {
|
|
|
|
dctx->setChecksum(entry->checksum->getMessageDigest());
|
|
|
|
dctx->setChecksumHashAlgo(entry->checksum->getAlgo());
|
|
|
|
}
|
|
|
|
} else {
|
2007-10-15 14:55:24 +00:00
|
|
|
dctx->setPieceHashes(entry->chunkChecksum->getChecksums());
|
|
|
|
dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo());
|
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-10-15 14:55:24 +00:00
|
|
|
rg->setDownloadContext(dctx);
|
|
|
|
rg->setNumConcurrentCommand(entry->maxConnections < 0 ?
|
|
|
|
_option->getAsInt(PREF_METALINK_SERVERS) :
|
2008-03-09 12:24:01 +00:00
|
|
|
std::min(_option->getAsInt(PREF_METALINK_SERVERS), entry->maxConnections));
|
2007-12-22 06:40:58 +00:00
|
|
|
// In metalink, multi connection to a single host is not allowed by default.
|
|
|
|
rg->setSingleHostMultiConnectionEnabled(!_option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL));
|
2008-05-05 08:25:41 +00:00
|
|
|
// remove "metalink" from Accept Type list to avoid loop in tranparent
|
2008-04-25 17:44:03 +00:00
|
|
|
// metalink
|
2008-05-05 08:25:41 +00:00
|
|
|
rg->removeAcceptType(RequestGroup::ACCEPT_METALINK);
|
2008-04-25 17:44:03 +00:00
|
|
|
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2007-10-15 14:55:24 +00:00
|
|
|
// Inject depenency between rg and torrentRg here if torrentRg.isNull() == false
|
|
|
|
if(!torrentRg.isNull()) {
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<Dependency> dep(new BtDependency(rg, torrentRg, _option));
|
|
|
|
rg->dependsOn(dep);
|
2006-08-07 16:05:00 +00:00
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2007-10-15 14:55:24 +00:00
|
|
|
groups.push_back(rg);
|
2006-08-07 16:05:00 +00:00
|
|
|
}
|
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
} // namespace aria2
|