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>
|
2009-10-18 12:31:07 +00:00
|
|
|
#include <vector>
|
2009-03-04 15:56:56 +00:00
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
#include "Metalinker.h"
|
|
|
|
#include "MetalinkEntry.h"
|
|
|
|
#include "MetalinkResource.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
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
const std::string MetalinkParserController::SHA1("sha1");// Metalink3Spec
|
2008-05-14 13:07:04 +00:00
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
MetalinkParserController::MetalinkParserController():
|
2008-04-20 00:50:22 +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()
|
|
|
|
{
|
2008-04-20 00:50:22 +00:00
|
|
|
_tEntry.reset(new MetalinkEntry());
|
|
|
|
_tResource.reset();
|
2007-12-05 14:54:53 +00:00
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
2008-04-20 00:50:22 +00:00
|
|
|
_tChecksum.reset();
|
2010-02-25 14:40:18 +00:00
|
|
|
_tChunkChecksumV4.reset();
|
2008-04-20 00:50:22 +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-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setFileNameOfEntry(const std::string& filename)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2009-10-18 12:31:07 +00:00
|
|
|
std::vector<std::string> elements;
|
2009-10-22 15:09:00 +00:00
|
|
|
util::split(filename, std::back_inserter(elements), "/");
|
|
|
|
std::string path = util::joinPath(elements.begin(), elements.end());
|
2009-03-04 15:56:56 +00:00
|
|
|
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tEntry->file.isNull()) {
|
2009-03-04 15:56:56 +00:00
|
|
|
_tEntry->file.reset(new FileEntry(path, 0, 0));
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
2009-03-04 15:56:56 +00:00
|
|
|
_tEntry->file->setPath(path);
|
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
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(_tEntry->file.isNull()) {
|
2008-05-13 14:15:23 +00:00
|
|
|
_tEntry->file.reset(new FileEntry(A2STR::NIL, length, 0));
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
|
|
|
_tEntry->file->setLength(length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setVersionOfEntry(const std::string& version)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tEntry->version = version;
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setLanguageOfEntry(const std::string& language)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-25 14:40:18 +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
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-25 14:40:18 +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
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tEntry->maxConnections = maxConnections;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitEntryTransaction()
|
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
commitResourceTransaction();
|
|
|
|
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();
|
2007-12-04 11:12:56 +00:00
|
|
|
_metalinker->entries.push_back(_tEntry);
|
2008-04-20 00:50:22 +00:00
|
|
|
_tEntry.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelEntryTransaction()
|
|
|
|
{
|
|
|
|
cancelResourceTransaction();
|
|
|
|
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();
|
2008-04-20 00:50:22 +00:00
|
|
|
_tEntry.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::newResourceTransaction()
|
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-04-20 00:50:22 +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
|
|
|
{
|
|
|
|
if(_tResource.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tResource->url = url;
|
2010-02-25 14:40:18 +00:00
|
|
|
// Metalink4Spec
|
|
|
|
if(_tResource->type == MetalinkResource::TYPE_UNKNOWN) {
|
|
|
|
// 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
|
|
|
{
|
|
|
|
if(_tResource.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-05-13 14:15:23 +00:00
|
|
|
if(type == MetalinkResource::FTP) {
|
2007-12-04 11:12:56 +00:00
|
|
|
_tResource->type = MetalinkResource::TYPE_FTP;
|
2008-05-13 14:15:23 +00:00
|
|
|
} else if(type == MetalinkResource::HTTP) {
|
2007-12-04 11:12:56 +00:00
|
|
|
_tResource->type = MetalinkResource::TYPE_HTTP;
|
2008-05-13 14:15:23 +00:00
|
|
|
} else if(type == MetalinkResource::HTTPS) {
|
2007-12-04 11:12:56 +00:00
|
|
|
_tResource->type = MetalinkResource::TYPE_HTTPS;
|
2008-05-13 14:15:23 +00:00
|
|
|
} else if(type == MetalinkResource::BITTORRENT) {
|
2007-12-04 11:12:56 +00:00
|
|
|
_tResource->type = MetalinkResource::TYPE_BITTORRENT;
|
2010-02-25 14:40:18 +00:00
|
|
|
} else if(type == MetalinkResource::TORRENT) { // Metalink4Spec
|
|
|
|
_tResource->type = MetalinkResource::TYPE_BITTORRENT;
|
2007-12-04 11:12:56 +00:00
|
|
|
} else {
|
|
|
|
_tResource->type = MetalinkResource::TYPE_NOT_SUPPORTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
void MetalinkParserController::setLocationOfResource(const std::string& location)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
if(_tResource.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tResource->location = location;
|
|
|
|
}
|
|
|
|
|
2010-02-25 14:40:18 +00:00
|
|
|
void MetalinkParserController::setPriorityOfResource(int priority)
|
2007-12-04 11:12:56 +00:00
|
|
|
{
|
|
|
|
if(_tResource.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2010-02-25 14:40:18 +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
|
|
|
{
|
|
|
|
if(_tResource.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tResource->maxConnections = maxConnections;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitResourceTransaction()
|
|
|
|
{
|
|
|
|
if(_tResource.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tEntry->resources.push_back(_tResource);
|
2008-04-20 00:50:22 +00:00
|
|
|
_tResource.reset();
|
2007-12-04 11:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelResourceTransaction()
|
|
|
|
{
|
2008-04-20 00:50:22 +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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-04-20 00:50:22 +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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(MessageDigestContext::supports(type)) {
|
|
|
|
_tChecksum->setAlgo(type);
|
|
|
|
} 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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tChecksum->setMessageDigest(md);
|
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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-05-14 13:07:04 +00:00
|
|
|
if(_tEntry->checksum.isNull() ||
|
2010-02-25 14:40:18 +00:00
|
|
|
// Metalink3Spec
|
|
|
|
(_tEntry->checksum->getAlgo() != MetalinkParserController::SHA1 &&
|
|
|
|
// Metalink4Spec
|
|
|
|
_tEntry->checksum->getAlgo() != MessageDigestContext::SHA1)) {
|
2007-12-04 11:12:56 +00:00
|
|
|
_tEntry->checksum = _tChecksum;
|
|
|
|
}
|
2008-04-20 00:50:22 +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
|
2008-04-20 00:50:22 +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
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tChunkChecksumV4.reset(new ChunkChecksum());
|
|
|
|
_tempChunkChecksumsV4.clear();
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setTypeOfChunkChecksumV4(const std::string& type)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
if(_tChunkChecksumV4.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(MessageDigestContext::supports(type)) {
|
|
|
|
_tChunkChecksumV4->setAlgo(type);
|
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransactionV4();
|
|
|
|
}
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setLengthOfChunkChecksumV4(size_t length)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
if(_tChunkChecksumV4.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(length > 0) {
|
|
|
|
_tChunkChecksumV4->setChecksumLength(length);
|
|
|
|
} else {
|
|
|
|
cancelChunkChecksumTransactionV4();
|
|
|
|
}
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::addHashOfChunkChecksumV4(const std::string& md)
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
if(_tChunkChecksumV4.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tempChunkChecksumsV4.push_back(md);
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitChunkChecksumTransactionV4()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
if(_tChunkChecksumV4.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(_tEntry->chunkChecksum.isNull() ||
|
|
|
|
_tEntry->chunkChecksum->getAlgo() != MessageDigestContext::SHA1) {
|
|
|
|
std::deque<std::string> checksums(_tempChunkChecksumsV4.begin(),
|
|
|
|
_tempChunkChecksumsV4.end());
|
|
|
|
_tChunkChecksumV4->setChecksums(checksums);
|
|
|
|
_tEntry->chunkChecksum = _tChunkChecksumV4;
|
|
|
|
}
|
|
|
|
_tChunkChecksumV4.reset();
|
|
|
|
#endif // ENABLE_MESSAGE_DIGEST
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelChunkChecksumTransactionV4()
|
|
|
|
{
|
|
|
|
#ifdef ENABLE_MESSAGE_DIGEST
|
|
|
|
_tChunkChecksumV4.reset();
|
|
|
|
#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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-04-20 00:50:22 +00:00
|
|
|
_tChunkChecksum.reset(new ChunkChecksum());
|
2007-12-04 11:12:56 +00:00
|
|
|
_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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(MessageDigestContext::supports(type)) {
|
|
|
|
_tChunkChecksum->setAlgo(type);
|
|
|
|
} 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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(length > 0) {
|
|
|
|
_tChunkChecksum->setChecksumLength(length);
|
|
|
|
} 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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-03-09 12:24:01 +00:00
|
|
|
_tempChunkChecksums.push_back(std::pair<size_t, std::string>(order, md));
|
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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tempHashPair.second = md;
|
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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_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
|
2007-12-04 11:12:56 +00:00
|
|
|
if(_tChunkChecksum.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
2008-05-14 13:07:04 +00:00
|
|
|
if(_tEntry->chunkChecksum.isNull() ||
|
|
|
|
_tEntry->chunkChecksum->getAlgo() != MetalinkParserController::SHA1) {
|
2008-03-09 12:24:01 +00:00
|
|
|
std::sort(_tempChunkChecksums.begin(), _tempChunkChecksums.end(), Ascend1st<std::pair<size_t, std::string> >());
|
2008-02-08 15:53:45 +00:00
|
|
|
std::deque<std::string> checksums;
|
|
|
|
std::transform(_tempChunkChecksums.begin(), _tempChunkChecksums.end(),
|
2010-01-05 16:01:46 +00:00
|
|
|
std::back_inserter(checksums), select2nd<std::pair<size_t, std::string> >());
|
2007-12-04 11:12:56 +00:00
|
|
|
_tChunkChecksum->setChecksums(checksums);
|
|
|
|
_tEntry->chunkChecksum = _tChunkChecksum;
|
|
|
|
}
|
2008-04-20 00:50:22 +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
|
2008-04-20 00:50:22 +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()
|
|
|
|
{
|
|
|
|
if(_tEntry.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tSignature.reset(new Signature());
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setTypeOfSignature(const std::string& type)
|
|
|
|
{
|
|
|
|
if(_tSignature.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tSignature->setType(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setFileOfSignature(const std::string& file)
|
|
|
|
{
|
|
|
|
if(_tSignature.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tSignature->setFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::setBodyOfSignature(const std::string& body)
|
|
|
|
{
|
|
|
|
if(_tSignature.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tSignature->setBody(body);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::commitSignatureTransaction()
|
|
|
|
{
|
|
|
|
if(_tSignature.isNull()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_tEntry->setSignature(_tSignature);
|
|
|
|
_tSignature.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MetalinkParserController::cancelSignatureTransaction()
|
|
|
|
{
|
|
|
|
_tSignature.reset();
|
|
|
|
}
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|