mirror of https://github.com/aria2/aria2
2009-05-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Moved C_* constants from BtContext to DefaultBtContext. * src/BtContext.cc: Removed. * src/BtContext.h * src/DefaultBtContext.cc * src/DefaultBtContext.h * src/Makefile.ampull/1/head
parent
41df4b5e28
commit
fcf183cc84
|
@ -1,3 +1,12 @@
|
|||
2009-05-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Moved C_* constants from BtContext to DefaultBtContext.
|
||||
* src/BtContext.cc: Removed.
|
||||
* src/BtContext.h
|
||||
* src/DefaultBtContext.cc
|
||||
* src/DefaultBtContext.h
|
||||
* src/Makefile.am
|
||||
|
||||
2009-05-27 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Use name.utf-8 and path.utf-8 key in higher priority than name and
|
||||
|
|
|
@ -1,69 +0,0 @@
|
|||
/* <!-- 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
|
||||
* 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.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#include "BtContext.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string BtContext::C_NAME("name");
|
||||
|
||||
const std::string BtContext::C_NAME_UTF8("name.utf-8");
|
||||
|
||||
const std::string BtContext::C_FILES("files");
|
||||
|
||||
const std::string BtContext::C_LENGTH("length");
|
||||
|
||||
const std::string BtContext::C_PATH("path");
|
||||
|
||||
const std::string BtContext::C_PATH_UTF8("path.utf-8");
|
||||
|
||||
const std::string BtContext::C_INFO("info");
|
||||
|
||||
const std::string BtContext::C_PIECES("pieces");
|
||||
|
||||
const std::string BtContext::C_PIECE_LENGTH("piece length");
|
||||
|
||||
const std::string BtContext::C_PRIVATE("private");
|
||||
|
||||
const std::string BtContext::C_PRIVATE_ON("1");
|
||||
|
||||
const std::string BtContext::C_URL_LIST("url-list");
|
||||
|
||||
const std::string BtContext::C_ANNOUNCE("announce");
|
||||
|
||||
const std::string BtContext::C_ANNOUNCE_LIST("announce-list");
|
||||
|
||||
const std::string BtContext::C_NODES("nodes");
|
||||
|
||||
} // namespace aria2
|
|
@ -87,38 +87,6 @@ public:
|
|||
virtual const std::string& getName() const = 0;
|
||||
|
||||
virtual void setFileFilter(IntSequence seq) = 0;
|
||||
|
||||
static const std::string C_NAME;
|
||||
|
||||
static const std::string C_NAME_UTF8;
|
||||
|
||||
static const std::string C_FILES;
|
||||
|
||||
static const std::string C_LENGTH;
|
||||
|
||||
static const std::string C_PATH;
|
||||
|
||||
static const std::string C_PATH_UTF8;
|
||||
|
||||
static const std::string C_INFO;
|
||||
|
||||
static const std::string C_PIECES;
|
||||
|
||||
static const std::string C_PIECE_LENGTH;
|
||||
|
||||
static const std::string C_PRIVATE;
|
||||
|
||||
// This is just a string "1". Used as a value of "private" flag.
|
||||
static const std::string C_PRIVATE_ON;
|
||||
|
||||
static const std::string C_URL_LIST;
|
||||
|
||||
static const std::string C_ANNOUNCE;
|
||||
|
||||
static const std::string C_ANNOUNCE_LIST;
|
||||
|
||||
static const std::string C_NODES;
|
||||
|
||||
};
|
||||
|
||||
class BtContext;
|
||||
|
|
|
@ -57,6 +57,36 @@
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
const std::string DefaultBtContext::C_NAME("name");
|
||||
|
||||
const std::string DefaultBtContext::C_NAME_UTF8("name.utf-8");
|
||||
|
||||
const std::string DefaultBtContext::C_FILES("files");
|
||||
|
||||
const std::string DefaultBtContext::C_LENGTH("length");
|
||||
|
||||
const std::string DefaultBtContext::C_PATH("path");
|
||||
|
||||
const std::string DefaultBtContext::C_PATH_UTF8("path.utf-8");
|
||||
|
||||
const std::string DefaultBtContext::C_INFO("info");
|
||||
|
||||
const std::string DefaultBtContext::C_PIECES("pieces");
|
||||
|
||||
const std::string DefaultBtContext::C_PIECE_LENGTH("piece length");
|
||||
|
||||
const std::string DefaultBtContext::C_PRIVATE("private");
|
||||
|
||||
const std::string DefaultBtContext::C_PRIVATE_ON("1");
|
||||
|
||||
const std::string DefaultBtContext::C_URL_LIST("url-list");
|
||||
|
||||
const std::string DefaultBtContext::C_ANNOUNCE("announce");
|
||||
|
||||
const std::string DefaultBtContext::C_ANNOUNCE_LIST("announce-list");
|
||||
|
||||
const std::string DefaultBtContext::C_NODES("nodes");
|
||||
|
||||
const std::string DefaultBtContext::DEFAULT_PEER_ID_PREFIX("-aria2-");
|
||||
|
||||
DefaultBtContext::DefaultBtContext():_peerIdPrefix(DEFAULT_PEER_ID_PREFIX),
|
||||
|
@ -118,10 +148,10 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
|
|||
{
|
||||
if(overrideName.empty()) {
|
||||
std::string nameKey;
|
||||
if(infoDict.containsKey(BtContext::C_NAME_UTF8)) {
|
||||
nameKey = BtContext::C_NAME_UTF8;
|
||||
if(infoDict.containsKey(C_NAME_UTF8)) {
|
||||
nameKey = C_NAME_UTF8;
|
||||
} else {
|
||||
nameKey = BtContext::C_NAME;
|
||||
nameKey = C_NAME;
|
||||
}
|
||||
const BDE& nameData = infoDict[nameKey];
|
||||
if(nameData.isString()) {
|
||||
|
@ -132,7 +162,7 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
|
|||
} else {
|
||||
name = overrideName;
|
||||
}
|
||||
const BDE& filesList = infoDict[BtContext::C_FILES];
|
||||
const BDE& filesList = infoDict[C_FILES];
|
||||
if(filesList.isList()) {
|
||||
uint64_t length = 0;
|
||||
off_t offset = 0;
|
||||
|
@ -145,18 +175,18 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
|
|||
continue;
|
||||
}
|
||||
|
||||
const BDE& fileLengthData = fileDict[BtContext::C_LENGTH];
|
||||
const BDE& fileLengthData = fileDict[C_LENGTH];
|
||||
if(!fileLengthData.isInteger()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
||||
BtContext::C_LENGTH.c_str()).str());
|
||||
C_LENGTH.c_str()).str());
|
||||
}
|
||||
length += fileLengthData.i();
|
||||
|
||||
std::string pathKey;
|
||||
if(fileDict.containsKey(BtContext::C_PATH_UTF8)) {
|
||||
pathKey = BtContext::C_PATH_UTF8;
|
||||
if(fileDict.containsKey(C_PATH_UTF8)) {
|
||||
pathKey = C_PATH_UTF8;
|
||||
} else {
|
||||
pathKey = BtContext::C_PATH;
|
||||
pathKey = C_PATH;
|
||||
}
|
||||
const BDE& pathList = fileDict[pathKey];
|
||||
if(!pathList.isList() || pathList.empty()) {
|
||||
|
@ -186,10 +216,10 @@ void DefaultBtContext::extractFileEntries(const BDE& infoDict,
|
|||
} else {
|
||||
// single-file mode;
|
||||
fileMode = BtContext::SINGLE;
|
||||
const BDE& lengthData = infoDict[BtContext::C_LENGTH];
|
||||
const BDE& lengthData = infoDict[C_LENGTH];
|
||||
if(!lengthData.isInteger()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
||||
BtContext::C_LENGTH.c_str()).str());
|
||||
C_LENGTH.c_str()).str());
|
||||
}
|
||||
totalLength = lengthData.i();
|
||||
// Slice path by '/' just in case nasty ".." is included in name
|
||||
|
@ -249,11 +279,11 @@ void DefaultBtContext::extractAnnounceList(const BDE& announceList)
|
|||
|
||||
void DefaultBtContext::extractAnnounce(const BDE& rootDict)
|
||||
{
|
||||
const BDE& announceList = rootDict[BtContext::C_ANNOUNCE_LIST];
|
||||
const BDE& announceList = rootDict[C_ANNOUNCE_LIST];
|
||||
if(announceList.isList()) {
|
||||
extractAnnounceList(announceList);
|
||||
} else {
|
||||
const BDE& announce = rootDict[BtContext::C_ANNOUNCE];
|
||||
const BDE& announce = rootDict[C_ANNOUNCE];
|
||||
if(announce.isString()) {
|
||||
extractAnnounceURI(announce);
|
||||
}
|
||||
|
@ -324,10 +354,10 @@ void DefaultBtContext::processRootDictionary(const BDE& rootDict,
|
|||
if(!rootDict.isDict()) {
|
||||
throw DL_ABORT_EX("torrent file does not contain a root dictionary.");
|
||||
}
|
||||
const BDE& infoDict = rootDict[BtContext::C_INFO];
|
||||
const BDE& infoDict = rootDict[C_INFO];
|
||||
if(!infoDict.isDict()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
||||
BtContext::C_INFO.c_str()).str());
|
||||
C_INFO.c_str()).str());
|
||||
}
|
||||
// retrieve infoHash
|
||||
std::string encodedInfoDict = bencode::encode(infoDict);
|
||||
|
@ -337,10 +367,10 @@ void DefaultBtContext::processRootDictionary(const BDE& rootDict,
|
|||
encodedInfoDict.size());
|
||||
infoHashString = Util::toHex(infoHash, INFO_HASH_LENGTH);
|
||||
// calculate the number of pieces
|
||||
const BDE& piecesData = infoDict[BtContext::C_PIECES];
|
||||
const BDE& piecesData = infoDict[C_PIECES];
|
||||
if(!piecesData.isString()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
||||
BtContext::C_PIECES.c_str()).str());
|
||||
C_PIECES.c_str()).str());
|
||||
}
|
||||
if(piecesData.s().empty()) {
|
||||
throw DL_ABORT_EX("The length of piece hash is 0.");
|
||||
|
@ -350,16 +380,16 @@ void DefaultBtContext::processRootDictionary(const BDE& rootDict,
|
|||
throw DL_ABORT_EX("The number of pieces is 0.");
|
||||
}
|
||||
// retrieve piece length
|
||||
const BDE& pieceLengthData = infoDict[BtContext::C_PIECE_LENGTH];
|
||||
const BDE& pieceLengthData = infoDict[C_PIECE_LENGTH];
|
||||
if(!pieceLengthData.isInteger()) {
|
||||
throw DL_ABORT_EX(StringFormat(MSG_MISSING_BT_INFO,
|
||||
BtContext::C_PIECE_LENGTH.c_str()).str());
|
||||
C_PIECE_LENGTH.c_str()).str());
|
||||
}
|
||||
pieceLength = pieceLengthData.i();
|
||||
// retrieve piece hashes
|
||||
extractPieceHash(piecesData.s(), PIECE_HASH_LENGTH);
|
||||
// private flag
|
||||
const BDE& privateData = infoDict[BtContext::C_PRIVATE];
|
||||
const BDE& privateData = infoDict[C_PRIVATE];
|
||||
if(privateData.isInteger()) {
|
||||
_private = (privateData.i() == 1);
|
||||
}
|
||||
|
@ -367,7 +397,7 @@ void DefaultBtContext::processRootDictionary(const BDE& rootDict,
|
|||
// This implemantation obeys HTTP-Seeding specification:
|
||||
// see http://www.getright.com/seedtorrent.html
|
||||
std::deque<std::string> urlList;
|
||||
extractUrlList(urlList, rootDict[BtContext::C_URL_LIST]);
|
||||
extractUrlList(urlList, rootDict[C_URL_LIST]);
|
||||
|
||||
// retrieve file entries
|
||||
extractFileEntries(infoDict, defaultName, overrideName, urlList);
|
||||
|
@ -377,7 +407,7 @@ void DefaultBtContext::processRootDictionary(const BDE& rootDict,
|
|||
// retrieve announce
|
||||
extractAnnounce(rootDict);
|
||||
// retrieve nodes
|
||||
extractNodes(rootDict[BtContext::C_NODES]);
|
||||
extractNodes(rootDict[C_NODES]);
|
||||
}
|
||||
|
||||
const std::string& DefaultBtContext::getPieceHash(size_t index) const {
|
||||
|
|
|
@ -71,6 +71,37 @@ private:
|
|||
|
||||
Logger* _logger;
|
||||
|
||||
static const std::string C_NAME;
|
||||
|
||||
static const std::string C_NAME_UTF8;
|
||||
|
||||
static const std::string C_FILES;
|
||||
|
||||
static const std::string C_LENGTH;
|
||||
|
||||
static const std::string C_PATH;
|
||||
|
||||
static const std::string C_PATH_UTF8;
|
||||
|
||||
static const std::string C_INFO;
|
||||
|
||||
static const std::string C_PIECES;
|
||||
|
||||
static const std::string C_PIECE_LENGTH;
|
||||
|
||||
static const std::string C_PRIVATE;
|
||||
|
||||
// This is just a string "1". Used as a value of "private" flag.
|
||||
static const std::string C_PRIVATE_ON;
|
||||
|
||||
static const std::string C_URL_LIST;
|
||||
|
||||
static const std::string C_ANNOUNCE;
|
||||
|
||||
static const std::string C_ANNOUNCE_LIST;
|
||||
|
||||
static const std::string C_NODES;
|
||||
|
||||
void clear();
|
||||
void extractPieceHash(const std::string& hashData, size_t hashLength);
|
||||
void extractFileEntries(const BDE& infoDic,
|
||||
|
|
|
@ -295,7 +295,7 @@ SRCS += PeerMessageUtil.cc PeerMessageUtil.h\
|
|||
PeerListProcessor.h\
|
||||
AnnounceTier.h\
|
||||
AnnounceList.h AnnounceList.cc\
|
||||
BtContext.cc BtContext.h\
|
||||
BtContext.h\
|
||||
DefaultBtContext.cc DefaultBtContext.h\
|
||||
PeerStorage.h\
|
||||
DefaultPeerStorage.cc DefaultPeerStorage.h\
|
||||
|
|
|
@ -89,7 +89,7 @@ bin_PROGRAMS = aria2c$(EXEEXT)
|
|||
@ENABLE_BITTORRENT_TRUE@ PeerListProcessor.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ AnnounceTier.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ AnnounceList.h AnnounceList.cc\
|
||||
@ENABLE_BITTORRENT_TRUE@ BtContext.cc BtContext.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ BtContext.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.cc DefaultBtContext.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ PeerStorage.h\
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.cc DefaultPeerStorage.h\
|
||||
|
@ -465,7 +465,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
TimeSeedCriteria.h ShareRatioSeedCriteria.h \
|
||||
UnionSeedCriteria.h SeedCheckCommand.cc SeedCheckCommand.h \
|
||||
PeerListProcessor.h AnnounceTier.h AnnounceList.h \
|
||||
AnnounceList.cc BtContext.cc BtContext.h DefaultBtContext.cc \
|
||||
AnnounceList.cc BtContext.h DefaultBtContext.cc \
|
||||
DefaultBtContext.h PeerStorage.h DefaultPeerStorage.cc \
|
||||
DefaultPeerStorage.h BtAnnounce.cc BtAnnounce.h \
|
||||
DefaultBtAnnounce.cc DefaultBtAnnounce.h BtRuntime.h \
|
||||
|
@ -636,7 +636,6 @@ am__objects_6 =
|
|||
@ENABLE_BITTORRENT_TRUE@ PeerChokeCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ SeedCheckCommand.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ AnnounceList.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BtContext.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultBtContext.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ DefaultPeerStorage.$(OBJEXT) \
|
||||
@ENABLE_BITTORRENT_TRUE@ BtAnnounce.$(OBJEXT) \
|
||||
|
@ -1306,7 +1305,6 @@ distclean-compile:
|
|||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtCancelMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtCheckIntegrityEntry.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtChokeMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtContext.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtDependency.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtExtendedMessage.Po@am__quote@
|
||||
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/BtFileAllocationEntry.Po@am__quote@
|
||||
|
|
Loading…
Reference in New Issue