2007-12-04 11:12:56 +00:00
|
|
|
/* <!-- 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
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2007-12-04 11:12:56 +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.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "MetalinkParserController.h"
|
2009-03-04 15:56:56 +00:00
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
#include "Metalinker.h"
|
|
|
|
#include "MetalinkEntry.h"
|
|
|
|
#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"
|
|
|
|
#include "a2functional.h"
|
2008-05-13 14:15:23 +00:00
|
|
|
#include "A2STR.h"
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
# include "Checksum.h"
|
|
|
|
# include "ChunkChecksum.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
# include "messageDigest.h"
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2008-07-12 13:35:35 +00:00
|
|
|
#include "Signature.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
MetalinkParserController::MetalinkParserController():
|
2010-06-21 13:51:56 +00:00
|
|
|
metalinker_(new Metalinker())
|
2007-12-05 14:54:53 +00:00
|
|
|
{}
|
2007-12-04 11:12:56 +00:00
|
|
|
|
|
|
|
MetalinkParserController::~MetalinkParserController() {}
|
|
|
|
|
|
|
|
void MetalinkParserController::newEntryTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_.reset(new MetalinkEntry());
|
|
|
|
tResource_.reset();
|
|
|
|
tMetaurl_.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
tChecksum_.reset();
|
|
|
|
tChunkChecksumV4_.reset();
|
|
|
|
tChunkChecksum_.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setFileNameOfEntry(const std::string& filename)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_->file.isNull()) {
|
|
|
|
tEntry_->file.reset(new FileEntry(util::escapePath(filename), 0, 0));
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->file->setPath(util::escapePath(filename));
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserController::setFileLengthOfEntry(uint64_t length)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_->file.isNull()) {
|
2010-02-27 08:42:13 +00:00
|
|
|
return;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->file->setLength(length);
|
|
|
|
tEntry_->sizeKnown = true;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setVersionOfEntry(const std::string& version)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->version = version;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setLanguageOfEntry(const std::string& language)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->languages.push_back(language);
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setOSOfEntry(const std::string& os)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->oses.push_back(os);
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserController::setMaxConnectionsOfEntry(int maxConnections)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->maxConnections = maxConnections;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitEntryTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
commitResourceTransaction();
|
2010-03-01 17:20:41 +00:00
|
|
|
commitMetaurlTransaction();
|
2007-12-04 11:12:56 +00:00
|
|
|
commitChecksumTransaction();
|
2010-02-25 14:40:18 +00:00
|
|
|
commitChunkChecksumTransactionV4();
|
2007-12-04 11:12:56 +00:00
|
|
|
commitChunkChecksumTransaction();
|
2008-07-12 13:35:35 +00:00
|
|
|
commitSignatureTransaction();
|
2010-06-21 13:51:56 +00:00
|
|
|
metalinker_->addEntry(tEntry_);
|
|
|
|
tEntry_.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelEntryTransaction()
|
|
|
|
{
|
|
|
|
cancelResourceTransaction();
|
2010-03-01 17:20:41 +00:00
|
|
|
cancelMetaurlTransaction();
|
2007-12-04 11:12:56 +00:00
|
|
|
cancelChecksumTransaction();
|
2010-02-25 14:40:18 +00:00
|
|
|
cancelChunkChecksumTransactionV4();
|
2007-12-04 11:12:56 +00:00
|
|
|
cancelChunkChecksumTransaction();
|
2008-07-12 13:35:35 +00:00
|
|
|
cancelSignatureTransaction();
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::newResourceTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_.reset(new MetalinkResource());
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setURLOfResource(const std::string& url)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->url = url;
|
2010-02-25 14:40:18 +00:00
|
|
|
// Metalink4Spec
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_->type == MetalinkResource::TYPE_UNKNOWN) {
|
2010-02-25 14:40:18 +00:00
|
|
|
// guess from URI sheme
|
|
|
|
std::string::size_type pos = url.find("://");
|
|
|
|
if(pos != std::string::npos) {
|
|
|
|
setTypeOfResource(url.substr(0, pos));
|
|
|
|
}
|
|
|
|
}
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setTypeOfResource(const std::string& type)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-05-13 14:15:23 +00:00
|
|
|
if(type == MetalinkResource::FTP) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->type = MetalinkResource::TYPE_FTP;
|
2008-05-13 14:15:23 +00:00
|
|
|
} else if(type == MetalinkResource::HTTP) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->type = MetalinkResource::TYPE_HTTP;
|
2008-05-13 14:15:23 +00:00
|
|
|
} else if(type == MetalinkResource::HTTPS) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->type = MetalinkResource::TYPE_HTTPS;
|
2008-05-13 14:15:23 +00:00
|
|
|
} else if(type == MetalinkResource::BITTORRENT) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->type = MetalinkResource::TYPE_BITTORRENT;
|
2010-02-25 14:40:18 +00:00
|
|
|
} else if(type == MetalinkResource::TORRENT) { // Metalink4Spec
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->type = MetalinkResource::TYPE_BITTORRENT;
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->type = MetalinkResource::TYPE_NOT_SUPPORTED;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setLocationOfResource(const std::string& location)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->location = location;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void MetalinkParserController::setPriorityOfResource(int priority)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->priority = priority;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserController::setMaxConnectionsOfResource(int maxConnections)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_->maxConnections = maxConnections;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitResourceTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-02-25 16:00:24 +00:00
|
|
|
#ifdef ENABLE_BITTORRENT
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tResource_->type == MetalinkResource::TYPE_BITTORRENT) {
|
2010-02-25 16:00:24 +00:00
|
|
|
SharedHandle<MetalinkMetaurl> metaurl(new MetalinkMetaurl());
|
2010-06-21 13:51:56 +00:00
|
|
|
metaurl->url = tResource_->url;
|
|
|
|
metaurl->priority = tResource_->priority;
|
2010-02-25 16:00:24 +00:00
|
|
|
metaurl->mediatype = MetalinkMetaurl::MEDIATYPE_TORRENT;
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->metaurls.push_back(metaurl);
|
2010-02-25 16:00:24 +00:00
|
|
|
} else {
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->resources.push_back(tResource_);
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
#else // !ENABLE_BITTORRENT
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->resources.push_back(tResource_);
|
2010-02-25 16:00:24 +00:00
|
|
|
#endif // !ENABLE_BITTORRENT
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelResourceTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
tResource_.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::newChecksumTransaction()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tChecksum_.reset(new Checksum());
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setTypeOfChecksum(const std::string& type)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-14 14:11:56 +00:00
|
|
|
std::string calgo = MessageDigestContext::getCanonicalAlgo(type);
|
|
|
|
if(MessageDigestContext::supports(calgo)) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tChecksum_->setAlgo(calgo);
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
|
|
|
cancelChecksumTransaction();
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setHashOfChecksum(const std::string& md)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(MessageDigestContext::isValidHash(tChecksum_->getAlgo(), md)) {
|
|
|
|
tChecksum_->setMessageDigest(md);
|
2010-03-02 15:14:39 +00:00
|
|
|
} else {
|
|
|
|
cancelChecksumTransaction();
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitChecksumTransaction()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_->checksum.isNull() ||
|
|
|
|
MessageDigestContext::isStronger(tChecksum_->getAlgo(),
|
|
|
|
tEntry_->checksum->getAlgo())) {
|
|
|
|
tEntry_->checksum = tChecksum_;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tChecksum_.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelChecksumTransaction()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
tChecksum_.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
2010-02-25 14:40:18 +00:00
|
|
|
|
|
|
|
void MetalinkParserController::newChunkChecksumTransactionV4()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2010-02-25 14:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksumV4_.reset(new ChunkChecksum());
|
|
|
|
tempChunkChecksumsV4_.clear();
|
2010-02-25 14:40:18 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksumV4_.isNull()) {
|
2010-02-25 14:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-14 14:11:56 +00:00
|
|
|
std::string calgo = MessageDigestContext::getCanonicalAlgo(type);
|
|
|
|
if(MessageDigestContext::supports(calgo)) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksumV4_->setAlgo(calgo);
|
2010-02-25 14:40:18 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransactionV4();
|
|
|
|
}
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksumV4_.isNull()) {
|
2010-02-25 14:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(length > 0) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksumV4_->setChecksumLength(length);
|
2010-02-25 14:40:18 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransactionV4();
|
|
|
|
}
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksumV4_.isNull()) {
|
2010-02-25 14:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(MessageDigestContext::isValidHash(tChunkChecksumV4_->getAlgo(), md)) {
|
|
|
|
tempChunkChecksumsV4_.push_back(md);
|
2010-03-02 15:14:39 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransactionV4();
|
|
|
|
}
|
2010-02-25 14:40:18 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitChunkChecksumTransactionV4()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksumV4_.isNull()) {
|
2010-02-25 14:40:18 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_->chunkChecksum.isNull() ||
|
|
|
|
MessageDigestContext::isStronger(tChunkChecksumV4_->getAlgo(),
|
|
|
|
tEntry_->chunkChecksum->getAlgo())) {
|
|
|
|
std::vector<std::string> checksums(tempChunkChecksumsV4_.begin(),
|
|
|
|
tempChunkChecksumsV4_.end());
|
|
|
|
tChunkChecksumV4_->setChecksums(checksums);
|
|
|
|
tEntry_->chunkChecksum = tChunkChecksumV4_;
|
2010-02-25 14:40:18 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksumV4_.reset();
|
2010-02-25 14:40:18 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelChunkChecksumTransactionV4()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksumV4_.reset();
|
2010-02-25 14:40:18 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
void MetalinkParserController::newChunkChecksumTransaction()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksum_.reset(new ChunkChecksum());
|
|
|
|
tempChunkChecksums_.clear();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setTypeOfChunkChecksum(const std::string& type)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-05-14 14:11:56 +00:00
|
|
|
std::string calgo = MessageDigestContext::getCanonicalAlgo(type);
|
|
|
|
if(MessageDigestContext::supports(calgo)) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksum_->setAlgo(calgo);
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransaction();
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserController::setLengthOfChunkChecksum(size_t length)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(length > 0) {
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksum_->setChecksumLength(length);
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransaction();
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserController::addHashOfChunkChecksum(size_t order, const std::string& md)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(MessageDigestContext::isValidHash(tChunkChecksum_->getAlgo(), md)) {
|
|
|
|
tempChunkChecksums_.push_back(std::make_pair(order, md));
|
2010-03-02 15:14:39 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransaction();
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-03-09 12:24:01 +00:00
|
|
|
void MetalinkParserController::createNewHashOfChunkChecksum(size_t order)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tempHashPair_.first = order;
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setMessageDigestOfChunkChecksum(const std::string& md)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(MessageDigestContext::isValidHash(tChunkChecksum_->getAlgo(), md)) {
|
|
|
|
tempHashPair_.second = md;
|
2010-03-02 15:14:39 +00:00
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransaction();
|
|
|
|
}
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::addHashOfChunkChecksum()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tempChunkChecksums_.push_back(tempHashPair_);
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitChunkChecksumTransaction()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tChunkChecksum_.isNull()) {
|
2007-12-04 11:12:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_->chunkChecksum.isNull() ||
|
|
|
|
MessageDigestContext::isStronger(tChunkChecksum_->getAlgo(),
|
|
|
|
tEntry_->chunkChecksum->getAlgo())) {
|
|
|
|
std::sort(tempChunkChecksums_.begin(), tempChunkChecksums_.end(),
|
2010-02-27 14:24:15 +00:00
|
|
|
Ascend1st<std::pair<size_t, std::string> >());
|
2010-02-27 14:32:02 +00:00
|
|
|
std::vector<std::string> checksums;
|
2010-06-21 13:51:56 +00:00
|
|
|
std::transform(tempChunkChecksums_.begin(), tempChunkChecksums_.end(),
|
2010-02-27 14:24:15 +00:00
|
|
|
std::back_inserter(checksums),
|
|
|
|
select2nd<std::pair<size_t, std::string> >());
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksum_->setChecksums(checksums);
|
|
|
|
tEntry_->chunkChecksum = tChunkChecksum_;
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksum_.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelChunkChecksumTransaction()
|
|
|
|
{
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2010-06-21 13:51:56 +00:00
|
|
|
tChunkChecksum_.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
2008-07-12 13:35:35 +00:00
|
|
|
void MetalinkParserController::newSignatureTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2008-07-12 13:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tSignature_.reset(new Signature());
|
2008-07-12 13:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setTypeOfSignature(const std::string& type)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tSignature_.isNull()) {
|
2008-07-12 13:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tSignature_->setType(type);
|
2008-07-12 13:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setFileOfSignature(const std::string& file)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tSignature_.isNull()) {
|
2008-07-12 13:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tSignature_->setFile(file);
|
2008-07-12 13:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setBodyOfSignature(const std::string& body)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tSignature_.isNull()) {
|
2008-07-12 13:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tSignature_->setBody(body);
|
2008-07-12 13:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitSignatureTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tSignature_.isNull()) {
|
2008-07-12 13:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tEntry_->setSignature(tSignature_);
|
|
|
|
tSignature_.reset();
|
2008-07-12 13:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelSignatureTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
tSignature_.reset();
|
2008-07-12 13:35:35 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 16:00:24 +00:00
|
|
|
void MetalinkParserController::newMetaurlTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tEntry_.isNull()) {
|
2010-02-25 16:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_.reset(new MetalinkMetaurl());
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setURLOfMetaurl(const std::string& url)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tMetaurl_.isNull()) {
|
2010-02-25 16:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_->url = url;
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setMediatypeOfMetaurl
|
|
|
|
(const std::string& mediatype)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tMetaurl_.isNull()) {
|
2010-02-25 16:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_->mediatype = mediatype;
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setPriorityOfMetaurl(int priority)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tMetaurl_.isNull()) {
|
2010-02-25 16:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_->priority = priority;
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
2010-02-26 08:55:10 +00:00
|
|
|
void MetalinkParserController::setNameOfMetaurl(const std::string& name)
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tMetaurl_.isNull()) {
|
2010-02-26 08:55:10 +00:00
|
|
|
return;
|
|
|
|
}
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_->name = name;
|
2010-02-26 08:55:10 +00:00
|
|
|
}
|
|
|
|
|
2010-02-25 16:00:24 +00:00
|
|
|
void MetalinkParserController::commitMetaurlTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tMetaurl_.isNull()) {
|
2010-02-25 16:00:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#ifdef ENABLE_BITTORRENT
|
2010-06-21 13:51:56 +00:00
|
|
|
if(tMetaurl_->mediatype == MetalinkMetaurl::MEDIATYPE_TORRENT) {
|
|
|
|
tEntry_->metaurls.push_back(tMetaurl_);
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
#endif // ENABLE_BITTORRENT
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_.reset();
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelMetaurlTransaction()
|
|
|
|
{
|
2010-06-21 13:51:56 +00:00
|
|
|
tMetaurl_.reset();
|
2010-02-25 16:00:24 +00:00
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|