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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-09-21 15:31:24 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2009-06-06 12:33:07 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2007-10-11 16:58:24 +00:00
|
|
|
#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"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2007-07-20 17:06:21 +00:00
|
|
|
#include "message.h"
|
2009-06-28 10:37:15 +00:00
|
|
|
#include "DownloadContext.h"
|
2011-02-05 14:21:06 +00:00
|
|
|
#include "metalink_helper.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"
|
2010-02-25 16:00:24 +00:00
|
|
|
#include "MetalinkMetaurl.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
#include "FileEntry.h"
|
2008-05-13 14:15:23 +00:00
|
|
|
#include "A2STR.h"
|
2009-06-06 12:33:07 +00:00
|
|
|
#include "a2functional.h"
|
2010-04-12 14:41:56 +00:00
|
|
|
#include "download_helper.h"
|
2010-11-20 08:21:36 +00:00
|
|
|
#include "fmt.h"
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
|
|
|
# include "BtDependency.h"
|
2009-11-28 09:21:12 +00:00
|
|
|
# include "download_helper.h"
|
2007-11-14 10:10:38 +00:00
|
|
|
#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
|
|
|
|
|
|
|
|
namespace aria2 {
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-11-20 08:21:36 +00:00
|
|
|
Metalink2RequestGroup::Metalink2RequestGroup() {}
|
2007-10-11 16:58:24 +00:00
|
|
|
|
2010-08-31 13:33:05 +00:00
|
|
|
namespace {
|
2010-03-07 10:36:42 +00:00
|
|
|
class AccumulateNonP2PUri {
|
2006-08-07 16:05:00 +00:00
|
|
|
private:
|
2010-03-07 10:36:42 +00:00
|
|
|
std::vector<std::string>& urisPtr;
|
2006-08-07 16:05:00 +00:00
|
|
|
public:
|
2010-03-07 10:36:42 +00:00
|
|
|
AccumulateNonP2PUri(std::vector<std::string>& urisPtr)
|
|
|
|
:urisPtr(urisPtr) {}
|
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:
|
2010-03-07 10:36:42 +00:00
|
|
|
urisPtr.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
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2010-10-30 14:53:40 +00:00
|
|
|
} // namespace
|
2006-08-07 16:05:00 +00:00
|
|
|
|
2010-08-31 13:33:05 +00:00
|
|
|
namespace {
|
2010-03-07 10:36:42 +00:00
|
|
|
class FindBitTorrentUri {
|
2006-08-07 16:05:00 +00:00
|
|
|
public:
|
2010-03-07 10:36:42 +00:00
|
|
|
FindBitTorrentUri() {}
|
2006-08-07 16:05:00 +00:00
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2010-10-30 14:53:40 +00:00
|
|
|
} // namespace
|
2006-08-07 16:05:00 +00:00
|
|
|
|
2008-05-11 13:59:27 +00:00
|
|
|
void
|
2010-02-28 12:30:11 +00:00
|
|
|
Metalink2RequestGroup::generate
|
|
|
|
(std::vector<SharedHandle<RequestGroup> >& groups,
|
|
|
|
const std::string& metalinkFile,
|
|
|
|
const SharedHandle<Option>& option)
|
2007-10-11 16:58:24 +00:00
|
|
|
{
|
2010-02-27 15:14:40 +00:00
|
|
|
std::vector<SharedHandle<MetalinkEntry> > entries;
|
2011-02-05 14:21:06 +00:00
|
|
|
metalink::parseAndQuery(entries, metalinkFile, option.get());
|
2010-04-08 12:54:14 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > tempgroups;
|
|
|
|
createRequestGroup(tempgroups, entries, option);
|
|
|
|
SharedHandle<MetadataInfo> mi;
|
2010-05-26 12:36:23 +00:00
|
|
|
if(metalinkFile == DEV_STDIN) {
|
2010-04-08 12:54:14 +00:00
|
|
|
mi.reset(new MetadataInfo());
|
|
|
|
} else {
|
|
|
|
mi.reset(new MetadataInfo(metalinkFile));
|
|
|
|
}
|
|
|
|
setMetadataInfo(tempgroups.begin(), tempgroups.end(), mi);
|
|
|
|
groups.insert(groups.end(), tempgroups.begin(), tempgroups.end());
|
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
|
2010-02-28 12:30:11 +00:00
|
|
|
Metalink2RequestGroup::generate
|
|
|
|
(std::vector<SharedHandle<RequestGroup> >& groups,
|
|
|
|
const SharedHandle<BinaryStream>& binaryStream,
|
|
|
|
const SharedHandle<Option>& option)
|
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
|
|
|
{
|
2010-02-27 15:14:40 +00:00
|
|
|
std::vector<SharedHandle<MetalinkEntry> > entries;
|
2011-02-05 14:21:06 +00:00
|
|
|
metalink::parseAndQuery(entries, binaryStream, option.get());
|
2010-04-08 12:54:14 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > tempgroups;
|
|
|
|
createRequestGroup(tempgroups, entries, option);
|
|
|
|
SharedHandle<MetadataInfo> mi(new MetadataInfo());
|
|
|
|
setMetadataInfo(tempgroups.begin(), tempgroups.end(), mi);
|
|
|
|
groups.insert(groups.end(), tempgroups.begin(), tempgroups.end());
|
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
|
2010-02-28 12:30:11 +00:00
|
|
|
(std::vector<SharedHandle<RequestGroup> >& groups,
|
2010-02-27 15:14:40 +00:00
|
|
|
const std::vector<SharedHandle<MetalinkEntry> >& entries,
|
2009-05-08 16:41:21 +00:00
|
|
|
const SharedHandle<Option>& option)
|
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
|
|
|
{
|
2010-02-26 15:37:08 +00:00
|
|
|
if(entries.empty()) {
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_NOTICE(EX_NO_RESULT_WITH_YOUR_PREFS);
|
2008-05-11 13:59:27 +00:00
|
|
|
return;
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<int32_t> selectIndexes =
|
2009-10-22 15:09:00 +00:00
|
|
|
util::parseIntRange(option->get(PREF_SELECT_FILE)).flush();
|
2010-02-26 15:37:08 +00:00
|
|
|
std::sort(selectIndexes.begin(), selectIndexes.end());
|
2010-02-27 15:14:40 +00:00
|
|
|
std::vector<std::string> locations;
|
2010-02-26 15:37:08 +00:00
|
|
|
if(option->defined(PREF_METALINK_LOCATION)) {
|
|
|
|
util::split(option->get(PREF_METALINK_LOCATION),
|
|
|
|
std::back_inserter(locations), ",", true);
|
|
|
|
std::transform
|
|
|
|
(locations.begin(), locations.end(), locations.begin(), util::toLower);
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
2010-02-26 15:37:08 +00:00
|
|
|
std::string preferredProtocol;
|
|
|
|
if(option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) {
|
|
|
|
preferredProtocol = option->get(PREF_METALINK_PREFERRED_PROTOCOL);
|
|
|
|
}
|
2010-02-28 16:04:52 +00:00
|
|
|
std::vector<SharedHandle<MetalinkEntry> > selectedEntries;
|
|
|
|
selectedEntries.reserve(entries.size());
|
2010-02-26 15:37:08 +00:00
|
|
|
{
|
|
|
|
int32_t count = 1;
|
2010-02-27 15:14:40 +00:00
|
|
|
for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
|
2010-02-28 16:04:52 +00:00
|
|
|
entries.begin(), eoi = entries.end(); i != eoi; ++i, ++count) {
|
2010-02-26 15:37:08 +00:00
|
|
|
(*i)->dropUnsupportedResource();
|
|
|
|
if((*i)->resources.empty() && (*i)->metaurls.empty()) {
|
2010-01-05 16:01:46 +00:00
|
|
|
continue;
|
2006-11-08 16:25:38 +00:00
|
|
|
}
|
2010-02-26 15:37:08 +00:00
|
|
|
(*i)->setLocationPriority
|
|
|
|
(locations, -MetalinkResource::getLowestPriority());
|
|
|
|
if(!preferredProtocol.empty()) {
|
|
|
|
(*i)->setProtocolPriority
|
|
|
|
(preferredProtocol, -MetalinkResource::getLowestPriority());
|
|
|
|
}
|
|
|
|
if(selectIndexes.empty() ||
|
|
|
|
std::binary_search(selectIndexes.begin(), selectIndexes.end(), count)){
|
|
|
|
selectedEntries.push_back(*i);
|
|
|
|
}
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
2010-02-26 15:37:08 +00:00
|
|
|
}
|
2010-02-27 15:04:48 +00:00
|
|
|
std::for_each(selectedEntries.begin(), selectedEntries.end(),
|
2010-02-26 15:37:08 +00:00
|
|
|
mem_fun_sh(&MetalinkEntry::reorderMetaurlsByPriority));
|
|
|
|
std::vector<std::pair<std::string,
|
|
|
|
std::vector<SharedHandle<MetalinkEntry> > > > entryGroups;
|
2011-02-05 14:21:06 +00:00
|
|
|
metalink::groupEntryByMetaurlName(entryGroups, selectedEntries);
|
2010-02-26 15:37:08 +00:00
|
|
|
for(std::vector<std::pair<std::string,
|
|
|
|
std::vector<SharedHandle<MetalinkEntry> > > >::const_iterator itr =
|
2010-02-28 16:04:52 +00:00
|
|
|
entryGroups.begin(), eoi = entryGroups.end(); itr != eoi; ++itr) {
|
2010-02-26 15:37:08 +00:00
|
|
|
const std::string& metaurl = (*itr).first;
|
|
|
|
const std::vector<SharedHandle<MetalinkEntry> >& mes = (*itr).second;
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_INFO(fmt("Processing metaurl group metaurl=%s", metaurl.c_str()));
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2008-04-20 00:50:22 +00:00
|
|
|
SharedHandle<RequestGroup> torrentRg;
|
2010-02-26 15:37:08 +00:00
|
|
|
if(!metaurl.empty()) {
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2010-02-26 15:37:08 +00:00
|
|
|
uris.push_back(metaurl);
|
2008-04-20 00:50:22 +00:00
|
|
|
{
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<SharedHandle<RequestGroup> > result;
|
2010-01-05 16:01:46 +00:00
|
|
|
createRequestGroupForUri(result, option, uris,
|
|
|
|
/* ignoreForceSequential = */true,
|
|
|
|
/* ignoreLocalPath = */true);
|
|
|
|
if(!uris.empty()) {
|
|
|
|
torrentRg = result[0];
|
|
|
|
}
|
2009-11-28 09:21:12 +00:00
|
|
|
}
|
2010-11-12 12:48:48 +00:00
|
|
|
if(torrentRg) {
|
2010-01-05 16:01:46 +00:00
|
|
|
torrentRg->setNumConcurrentCommand(1);
|
|
|
|
torrentRg->clearPreDownloadHandler();
|
|
|
|
torrentRg->clearPostDownloadHandler();
|
|
|
|
// remove "metalink" from Accept Type list to avoid loop in
|
|
|
|
// tranparent metalink
|
2010-04-01 15:41:53 +00:00
|
|
|
util::removeMetalinkContentTypes(torrentRg);
|
2010-01-05 16:01:46 +00:00
|
|
|
// make it in-memory download
|
|
|
|
SharedHandle<PreDownloadHandler> preh
|
|
|
|
(new MemoryBufferPreDownloadHandler());
|
|
|
|
SharedHandle<RequestGroupCriteria> cri(new TrueRequestGroupCriteria());
|
|
|
|
preh->setCriteria(cri);
|
|
|
|
torrentRg->addPreDownloadHandler(preh);
|
|
|
|
groups.push_back(torrentRg);
|
2008-04-20 00:50:22 +00:00
|
|
|
}
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_BITTORRENT
|
2009-06-29 08:42:58 +00:00
|
|
|
SharedHandle<RequestGroup> rg(new RequestGroup(option));
|
2010-02-26 15:37:08 +00:00
|
|
|
SharedHandle<DownloadContext> dctx;
|
|
|
|
if(mes.size() == 1) {
|
|
|
|
SharedHandle<MetalinkEntry> entry = mes[0];
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_INFO(fmt(MSG_METALINK_QUEUEING, entry->getPath().c_str()));
|
2010-02-26 15:37:08 +00:00
|
|
|
entry->reorderResourcesByPriority();
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2010-02-26 15:37:08 +00:00
|
|
|
std::for_each(entry->resources.begin(), entry->resources.end(),
|
2010-03-07 10:36:42 +00:00
|
|
|
AccumulateNonP2PUri(uris));
|
2010-02-26 15:37:08 +00:00
|
|
|
// If piece hash is specified in the metalink,
|
|
|
|
// make segment size equal to piece hash size.
|
|
|
|
size_t pieceLength;
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-11-12 12:48:48 +00:00
|
|
|
if(!entry->chunkChecksum) {
|
2010-02-26 15:37:08 +00:00
|
|
|
pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
|
|
|
|
} else {
|
|
|
|
pieceLength = entry->chunkChecksum->getChecksumLength();
|
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#else
|
2010-02-26 15:37:08 +00:00
|
|
|
pieceLength = option->getAsInt(PREF_SEGMENT_SIZE);
|
2007-11-14 10:10:38 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2010-02-26 15:37:08 +00:00
|
|
|
dctx.reset(new DownloadContext
|
|
|
|
(pieceLength,
|
|
|
|
entry->getLength(),
|
|
|
|
util::applyDir(option->get(PREF_DIR),
|
|
|
|
entry->file->getPath())));
|
|
|
|
dctx->getFirstFileEntry()->setUris(uris);
|
2010-11-14 08:36:41 +00:00
|
|
|
dctx->getFirstFileEntry()->setMaxConnectionPerServer
|
|
|
|
(option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER));
|
2010-02-26 15:37:08 +00:00
|
|
|
if(option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)) {
|
2010-07-14 11:39:05 +00:00
|
|
|
dctx->getFirstFileEntry()->setUniqueProtocol(true);
|
2010-02-26 15:37:08 +00:00
|
|
|
}
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-11-12 12:48:48 +00:00
|
|
|
if(entry->checksum) {
|
2010-05-14 15:18:59 +00:00
|
|
|
dctx->setChecksum(entry->checksum->getMessageDigest());
|
|
|
|
dctx->setChecksumHashAlgo(entry->checksum->getAlgo());
|
|
|
|
}
|
2010-11-12 12:48:48 +00:00
|
|
|
if(entry->chunkChecksum) {
|
2010-02-26 15:37:08 +00:00
|
|
|
dctx->setPieceHashes(entry->chunkChecksum->getChecksums().begin(),
|
|
|
|
entry->chunkChecksum->getChecksums().end());
|
|
|
|
dctx->setPieceHashAlgo(entry->chunkChecksum->getAlgo());
|
2007-11-12 11:28:16 +00:00
|
|
|
}
|
2010-02-26 15:37:08 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
dctx->setSignature(entry->getSignature());
|
|
|
|
rg->setNumConcurrentCommand
|
|
|
|
(entry->maxConnections < 0 ?
|
|
|
|
option->getAsInt(PREF_METALINK_SERVERS) :
|
|
|
|
std::min(option->getAsInt(PREF_METALINK_SERVERS),
|
|
|
|
static_cast<int32_t>(entry->maxConnections)));
|
2007-11-12 11:28:16 +00:00
|
|
|
} else {
|
2010-02-26 15:37:08 +00:00
|
|
|
dctx.reset(new DownloadContext());
|
|
|
|
// piece length is overridden by the one in torrent file.
|
|
|
|
dctx->setPieceLength(option->getAsInt(PREF_SEGMENT_SIZE));
|
|
|
|
std::vector<SharedHandle<FileEntry> > fileEntries;
|
|
|
|
off_t offset = 0;
|
2010-02-27 15:04:48 +00:00
|
|
|
for(std::vector<SharedHandle<MetalinkEntry> >::const_iterator i =
|
2010-02-28 16:04:52 +00:00
|
|
|
mes.begin(), eoi = mes.end(); i != eoi; ++i) {
|
2010-11-20 08:21:36 +00:00
|
|
|
A2_LOG_INFO(fmt("Metalink: Queueing %s for download as a member.",
|
|
|
|
(*i)->getPath().c_str()));
|
|
|
|
A2_LOG_DEBUG(fmt("originalName = %s", (*i)->metaurls[0]->name.c_str()));
|
2010-02-26 15:37:08 +00:00
|
|
|
(*i)->reorderResourcesByPriority();
|
2010-02-28 12:30:11 +00:00
|
|
|
std::vector<std::string> uris;
|
2010-02-26 15:37:08 +00:00
|
|
|
std::for_each((*i)->resources.begin(), (*i)->resources.end(),
|
2010-03-07 10:36:42 +00:00
|
|
|
AccumulateNonP2PUri(uris));
|
2010-02-26 15:37:08 +00:00
|
|
|
SharedHandle<FileEntry> fe
|
|
|
|
(new FileEntry
|
2010-05-06 14:18:29 +00:00
|
|
|
(util::applyDir(option->get(PREF_DIR), (*i)->file->getPath()),
|
2010-02-26 15:37:08 +00:00
|
|
|
(*i)->file->getLength(), offset, uris));
|
2010-11-14 08:36:41 +00:00
|
|
|
fe->setMaxConnectionPerServer
|
|
|
|
(option->getAsInt(PREF_MAX_CONNECTION_PER_SERVER));
|
2010-02-26 15:37:08 +00:00
|
|
|
if(option->getAsBool(PREF_METALINK_ENABLE_UNIQUE_PROTOCOL)) {
|
2010-07-14 11:39:05 +00:00
|
|
|
fe->setUniqueProtocol(true);
|
2010-02-26 15:37:08 +00:00
|
|
|
}
|
|
|
|
fe->setOriginalName((*i)->metaurls[0]->name);
|
|
|
|
fileEntries.push_back(fe);
|
|
|
|
offset += (*i)->file->getLength();
|
|
|
|
}
|
|
|
|
dctx->setFileEntries(fileEntries.begin(), fileEntries.end());
|
|
|
|
rg->setNumConcurrentCommand(option->getAsInt(PREF_METALINK_SERVERS));
|
2007-10-15 14:55:24 +00:00
|
|
|
}
|
|
|
|
rg->setDownloadContext(dctx);
|
2010-02-26 15:37:08 +00:00
|
|
|
// remove "metalink" from Accept Type list to avoid loop in
|
|
|
|
// tranparent metalink
|
2010-04-01 15:41:53 +00:00
|
|
|
util::removeMetalinkContentTypes(rg);
|
2007-11-14 10:10:38 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2010-02-26 15:37:08 +00:00
|
|
|
// Inject depenency between rg and torrentRg here if
|
2010-11-12 12:48:48 +00:00
|
|
|
// torrentRg is true
|
|
|
|
if(torrentRg) {
|
|
|
|
SharedHandle<Dependency> dep(new BtDependency(rg.get(), torrentRg));
|
2008-04-20 00:50:22 +00:00
|
|
|
rg->dependsOn(dep);
|
2009-12-20 09:49:43 +00:00
|
|
|
torrentRg->belongsTo(rg->getGID());
|
2010-07-18 15:14:50 +00:00
|
|
|
// metadata download may take very long time. If URIs are
|
|
|
|
// available, give up metadata download in at most 30 seconds.
|
|
|
|
const time_t btStopTimeout = 30;
|
|
|
|
time_t currentBtStopTimeout =
|
|
|
|
torrentRg->getOption()->getAsInt(PREF_BT_STOP_TIMEOUT);
|
|
|
|
if(currentBtStopTimeout == 0 || currentBtStopTimeout > btStopTimeout) {
|
|
|
|
std::vector<SharedHandle<FileEntry> >::const_iterator i;
|
|
|
|
std::vector<SharedHandle<FileEntry> >::const_iterator eoi
|
|
|
|
= dctx->getFileEntries().end();
|
|
|
|
for(i = dctx->getFileEntries().begin(); i != eoi; ++i) {
|
|
|
|
if((*i)->getRemainingUris().empty()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(i == dctx->getFileEntries().end()) {
|
|
|
|
torrentRg->getOption()->put
|
|
|
|
(PREF_BT_STOP_TIMEOUT, util::itos(btStopTimeout));
|
|
|
|
}
|
|
|
|
}
|
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
|