2008-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Fixed compile error without SSL/XML library.
	* src/DefaultBtProgressInfoFile.cc
	* src/DefaultBtProgressInfoFile.h
	* src/FileMetalinkParserState.cc
	* src/RequestGroup.h
	* src/SocketCore.cc
	* src/SocketCore.h
	* src/VerificationMetalinkParserState.cc
	* src/download_helper.h
	* src/main.cc
	* test/DefaultBtProgressInfoFileTest.cc
	* test/DownloadHelperTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2008-11-13 15:08:52 +00:00
parent eed0406484
commit 86478c49dd
12 changed files with 95 additions and 25 deletions

View File

@ -1,3 +1,18 @@
2008-11-14 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Fixed compile error without SSL/XML library.
* src/DefaultBtProgressInfoFile.cc
* src/DefaultBtProgressInfoFile.h
* src/FileMetalinkParserState.cc
* src/RequestGroup.h
* src/SocketCore.cc
* src/SocketCore.h
* src/VerificationMetalinkParserState.cc
* src/download_helper.h
* src/main.cc
* test/DefaultBtProgressInfoFileTest.cc
* test/DownloadHelperTest.cc
2008-11-13 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Rewritten URI handling functions. They are now provided as a testable

View File

@ -41,8 +41,10 @@
#include "BtContext.h"
#include "PieceStorage.h"
#include "Piece.h"
#ifdef ENABLE_BITTORRENT
#include "PeerStorage.h"
#include "BtRuntime.h"
#endif // ENABLE_BITTORRENT
#include "BitfieldMan.h"
#include "Option.h"
#include "TransferStat.h"
@ -87,7 +89,11 @@ void DefaultBtProgressInfoFile::updateFilename()
bool DefaultBtProgressInfoFile::isTorrentDownload()
{
#ifdef ENABLE_BITTORRENT
return !_btRuntime.isNull();
#else // !ENABLE_BITTORRENT
return false;
#endif // !ENABLE_BITTORRENT
}
// Since version 0001, Integers are saved in binary form, network byte order.
@ -138,10 +144,12 @@ void DefaultBtProgressInfoFile::save() {
sizeof(totalLengthNL));
// uploadLength: 64 bits
uint64_t uploadLengthNL = 0;
#ifdef ENABLE_BITTORRENT
if(torrentDownload) {
TransferStat stat = _peerStorage->calculateStat();
uploadLengthNL = hton64(stat.getAllTimeUploadLength());
}
#endif // ENABLE_BITTORRENT
o.write(reinterpret_cast<const char*>(&uploadLengthNL),
sizeof(uploadLengthNL));
// bitfieldLength: 32 bits
@ -266,10 +274,11 @@ void DefaultBtProgressInfoFile::load()
if(version >= 1) {
uploadLength = ntoh64(uploadLength);
}
#ifdef ENABLE_BITTORRENT
if(isTorrentDownload()) {
_btRuntime->setUploadLengthAtStartup(uploadLength);
}
#endif // ENABLE_BITTORRENT
// TODO implement the conversion mechanism between different piece length.
uint32_t bitfieldLength;
in.read(reinterpret_cast<char*>(&bitfieldLength), sizeof(bitfieldLength));
@ -400,6 +409,7 @@ bool DefaultBtProgressInfoFile::exists()
}
}
#ifdef ENABLE_BITTORRENT
void DefaultBtProgressInfoFile::setPeerStorage
(const SharedHandle<PeerStorage>& peerStorage)
{
@ -411,5 +421,6 @@ void DefaultBtProgressInfoFile::setBtRuntime
{
_btRuntime = btRuntime;
}
#endif // ENABLE_BITTORRENT
} // namespace aria2

View File

@ -50,9 +50,10 @@ class DefaultBtProgressInfoFile : public BtProgressInfoFile {
private:
SharedHandle<DownloadContext> _dctx;
SharedHandle<PieceStorage> _pieceStorage;
#ifdef ENABLE_BITTORRENT
SharedHandle<PeerStorage> _peerStorage;
SharedHandle<BtRuntime> _btRuntime;
#endif // ENABLE_BITTORRENT
const Option* _option;
Logger* _logger;
std::string _filename;
@ -81,10 +82,12 @@ public:
// re-set filename using current _dctx.
virtual void updateFilename();
#ifdef ENABLE_BITTORRENT
// for torrents
void setPeerStorage(const SharedHandle<PeerStorage>& peerStorage);
void setBtRuntime(const SharedHandle<BtRuntime>& btRuntime);
#endif // ENABLE_BITTORRENT
};
} // namespace aria2

View File

@ -65,10 +65,8 @@ void FileMetalinkParserState::beginElement(MetalinkParserStateMachine* stm,
stm->setLanguageState();
} else if(name == FileMetalinkParserState::OS) {
stm->setOSState();
#ifdef ENABLE_MESSAGE_DIGEST
} else if(name == FileMetalinkParserState::VERIFICATION) {
stm->setVerificationState();
#endif // ENABLE_MESSAGE_DIGEST
} else if(name == FileMetalinkParserState::RESOURCES) {
stm->setResourcesState();
int maxConnections;

View File

@ -126,9 +126,11 @@ private:
unsigned int _fileNotFoundCount;
#ifdef ENABLE_BITTORRENT
WeakHandle<BtRuntime> _btRuntime;
WeakHandle<PeerStorage> _peerStorage;
#endif // ENABLE_BITTORRENT
const Option* _option;

View File

@ -76,8 +76,15 @@
namespace aria2 {
#ifdef ENABLE_SSL
SharedHandle<TLSContext> SocketCore::_tlsContext;
void SocketCore::setTLSContext(const SharedHandle<TLSContext>& tlsContext)
{
_tlsContext = tlsContext;
}
#endif // ENABLE_SSL
SocketCore::SocketCore(int sockType):_sockType(sockType), sockfd(-1) {
init();
}
@ -1045,9 +1052,4 @@ bool SocketCore::wantWrite() const
return _wantWrite;
}
void SocketCore::setTLSContext(const SharedHandle<TLSContext>& tlsContext)
{
_tlsContext = tlsContext;
}
} // namespace aria2

View File

@ -61,7 +61,9 @@
namespace aria2 {
#ifdef ENABLE_SSL
class TLSContext;
#endif // ENABLE_SSL
class SocketCore {
friend bool operator==(const SocketCore& s1, const SocketCore& s2);
@ -90,7 +92,7 @@ private:
#if ENABLE_SSL
static SharedHandle<TLSContext> _tlsContext;
#endif
#endif // ENABLE_SSL
#ifdef HAVE_LIBSSL
// for SSL
@ -325,7 +327,9 @@ public:
*/
bool wantWrite() const;
#ifdef ENABLE_SSL
static void setTLSContext(const SharedHandle<TLSContext>& tlsContext);
#endif // ENABLE_SSL
};
} // namespace aria2

View File

@ -56,6 +56,7 @@ void VerificationMetalinkParserState::beginElement
const std::string& name,
const std::map<std::string, std::string>& attrs)
{
#ifdef ENABLE_MESSAGE_DIGEST
if(name == VerificationMetalinkParserState::HASH) {
stm->setHashState();
std::map<std::string, std::string>::const_iterator itr =
@ -96,7 +97,9 @@ void VerificationMetalinkParserState::beginElement
} catch(RecoverableException& e) {
stm->cancelChunkChecksumTransaction();
}
} else if(name == VerificationMetalinkParserState::SIGNATURE) {
} else
#endif // ENABLE_MESSAGE_DIGEST
if(name == VerificationMetalinkParserState::SIGNATURE) {
stm->setSignatureState();
std::map<std::string, std::string>::const_iterator itr =
attrs.find(VerificationMetalinkParserState::TYPE);

View File

@ -47,16 +47,20 @@ namespace aria2 {
class RequestGroup;
class Option;
#ifdef ENABLE_BITTORRENT
// Create RequestGroup object using torrent file specified by torrent-file
// option. In this function, force-sequential is ignored.
void createRequestGroupForBitTorrent
(std::deque<SharedHandle<RequestGroup> >& result, Option* op,
const std::deque<std::string>& uris);
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
// Create RequestGroup objects using Metalink file specified by metalink-file
// option.
void createRequestGroupForMetalink
(std::deque<SharedHandle<RequestGroup> >& result, Option* op);
#endif // ENABLE_METALINK
// Create RequestGroup objects from reading file specified by input-file option.
// If the value of input-file option is "-", stdin is used as a input source.

View File

@ -65,6 +65,7 @@
#include "ConsoleStatCalc.h"
#include "NullStatCalc.h"
#include "download_helper.h"
#include "Exception.h"
#ifdef ENABLE_METALINK
# include "MetalinkHelper.h"
# include "MetalinkEntry.h"

View File

@ -9,10 +9,10 @@
#include "Exception.h"
#ifdef ENABLE_BITTORRENT
#include "MockBtContext.h"
#endif // ENABLE_BITTORRENT
#include "MockPeerStorage.h"
#include "MockPieceStorage.h"
#include "BtRuntime.h"
#endif // ENABLE_BITTORRENT
#include "MockPieceStorage.h"
#include "prefs.h"
#include "SingleFileDownloadContext.h"
#include "Piece.h"
@ -71,9 +71,11 @@ public:
#endif // ENABLE_BITTORRENT
}
#ifdef ENABLE_BITTORRENT
void testSave();
void testLoad();
void testLoad_compat();
#endif // ENABLE_BITTORRENT
void testSave_nonBt();
void testLoad_nonBt();
void testLoad_nonBt_compat();
@ -318,8 +320,6 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_compat()
(new SingleFileDownloadContext(1024, 81920, "load-nonBt"));
DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
infoFile.setBtRuntime(_btRuntime);
infoFile.setPeerStorage(_peerStorage);
CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt.aria2"),
infoFile.getFilename());
@ -364,8 +364,7 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt()
(new SingleFileDownloadContext(1024, 81920, "load-nonBt-v0001"));
DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
infoFile.setBtRuntime(_btRuntime);
infoFile.setPeerStorage(_peerStorage);
CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt-v0001.aria2"),
infoFile.getFilename());
infoFile.load();
@ -410,8 +409,6 @@ void DefaultBtProgressInfoFileTest::testLoad_nonBt_pieceLengthShorter()
(new SingleFileDownloadContext(512, 81920, "load-nonBt-v0001"));
DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
infoFile.setBtRuntime(_btRuntime);
infoFile.setPeerStorage(_peerStorage);
CPPUNIT_ASSERT_EQUAL(std::string("./load-nonBt-v0001.aria2"),
infoFile.getFilename());
@ -448,7 +445,6 @@ void DefaultBtProgressInfoFileTest::testSave_nonBt()
_pieceStorage->addInFlightPiece(inFlightPieces);
DefaultBtProgressInfoFile infoFile(dctx, _pieceStorage, _option.get());
infoFile.setPeerStorage(_peerStorage);
CPPUNIT_ASSERT_EQUAL(std::string("./save-temp.aria2"),
infoFile.getFilename());
@ -545,8 +541,10 @@ void DefaultBtProgressInfoFileTest::testUpdateFilename()
(new SingleFileDownloadContext(1024, 81920, "file1"));
DefaultBtProgressInfoFile infoFile(dctx, SharedHandle<MockPieceStorage>(), 0);
#ifdef ENABLE_BITTORRENT
infoFile.setBtRuntime(_btRuntime);
infoFile.setPeerStorage(_peerStorage);
#endif // ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL(std::string("./file1.aria2"), infoFile.getFilename());

View File

@ -22,11 +22,18 @@ class DownloadHelperTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(DownloadHelperTest);
CPPUNIT_TEST(testCreateRequestGroupForUri);
CPPUNIT_TEST(testCreateRequestGroupForUri_parameterized);
CPPUNIT_TEST(testCreateRequestGroupForUri_BitTorrent);
CPPUNIT_TEST(testCreateRequestGroupForUri_Metalink);
CPPUNIT_TEST(testCreateRequestGroupForUriList);
#ifdef ENABLE_BITTORRENT
CPPUNIT_TEST(testCreateRequestGroupForUri_BitTorrent);
CPPUNIT_TEST(testCreateRequestGroupForBitTorrent);
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
CPPUNIT_TEST(testCreateRequestGroupForUri_Metalink);
CPPUNIT_TEST(testCreateRequestGroupForMetalink);
#endif // ENABLE_METALINK
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
@ -35,11 +42,17 @@ public:
void testCreateRequestGroupForUri();
void testCreateRequestGroupForUri_parameterized();
void testCreateRequestGroupForUri_BitTorrent();
void testCreateRequestGroupForUri_Metalink();
void testCreateRequestGroupForUriList();
#ifdef ENABLE_BITTORRENT
void testCreateRequestGroupForUri_BitTorrent();
void testCreateRequestGroupForBitTorrent();
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
void testCreateRequestGroupForUri_Metalink();
void testCreateRequestGroupForMetalink();
#endif // ENABLE_METALINK
};
@ -174,6 +187,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_parameterized()
}
}
#ifdef ENABLE_BITTORRENT
void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
{
std::string array[] = {
@ -220,7 +234,9 @@ void DownloadHelperTest::testCreateRequestGroupForUri_BitTorrent()
btctx->getActualBasePath());
}
}
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
{
std::string array[] = {
@ -242,7 +258,12 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
// group1: http://alpha/file, ...
// group2-7: 6 file entry in Metalink and 1 torrent file download
#ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)7, result.size());
#else // !ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)6, result.size());
#endif // !ENABLE_BITTORRENT
SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris;
group->getURIs(uris);
@ -270,6 +291,7 @@ void DownloadHelperTest::testCreateRequestGroupForUri_Metalink()
aria2051Group->getNumConcurrentCommand());
}
}
#endif // ENABLE_METALINK
void DownloadHelperTest::testCreateRequestGroupForUriList()
{
@ -304,6 +326,7 @@ void DownloadHelperTest::testCreateRequestGroupForUriList()
fileISOCtx->getActualBasePath());
}
#ifdef ENABLE_BITTORRENT
void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
{
std::string array[] = {
@ -347,7 +370,9 @@ void DownloadHelperTest::testCreateRequestGroupForBitTorrent()
CPPUNIT_ASSERT_EQUAL((size_t)1, result.size());
}
}
#endif // ENABLE_BITTORRENT
#ifdef ENABLE_METALINK
void DownloadHelperTest::testCreateRequestGroupForMetalink()
{
Option op;
@ -361,8 +386,11 @@ void DownloadHelperTest::testCreateRequestGroupForMetalink()
createRequestGroupForMetalink(result, &op);
#ifdef ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)6, result.size());
#else // !ENABLE_BITTORRENT
CPPUNIT_ASSERT_EQUAL((size_t)5, result.size());
#endif // !ENABLE_BITTORRENT
SharedHandle<RequestGroup> group = result[0];
std::deque<std::string> uris;
group->getURIs(uris);
@ -376,5 +404,6 @@ void DownloadHelperTest::testCreateRequestGroupForMetalink()
CPPUNIT_ASSERT_EQUAL((unsigned int)1, group->getNumConcurrentCommand());
}
}
#endif // ENABLE_METALINK
} // namespace aria2