From 512be58217c32ddf8d5f711a83d6e1945e51d8b3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 24 Nov 2009 14:47:42 +0000 Subject: [PATCH] 2009-11-24 Tatsuhiro Tsujikawa Rewritten Magnet URI parser. * src/Makefile.am * src/ProtocolDetector.cc * src/bittorrent_helper.cc * src/bittorrent_helper.h * src/download_helper.cc * src/magnet.cc * src/magnet.h * test/BittorrentHelperTest.cc * test/MagnetTest.cc * test/Makefile.am * test/ProtocolDetectorTest.cc --- ChangeLog | 15 ++++++++ src/Makefile.am | 1 + src/Makefile.in | 17 +++++---- src/ProtocolDetector.cc | 15 ++++++-- src/bittorrent_helper.cc | 69 +++++++++++++++++------------------ src/bittorrent_helper.h | 17 +++++++-- src/download_helper.cc | 24 ++++++------- src/magnet.cc | 70 ++++++++++++++++++++++++++++++++++++ src/magnet.h | 56 +++++++++++++++++++++++++++++ test/BittorrentHelperTest.cc | 42 ++++++++++++---------- test/MagnetTest.cc | 40 +++++++++++++++++++++ test/Makefile.am | 1 + test/Makefile.in | 5 ++- test/ProtocolDetectorTest.cc | 6 ++-- 14 files changed, 294 insertions(+), 84 deletions(-) create mode 100644 src/magnet.cc create mode 100644 src/magnet.h create mode 100644 test/MagnetTest.cc diff --git a/ChangeLog b/ChangeLog index 25499fec..179b6c22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2009-11-24 Tatsuhiro Tsujikawa + + Rewritten Magnet URI parser. + * src/Makefile.am + * src/ProtocolDetector.cc + * src/bittorrent_helper.cc + * src/bittorrent_helper.h + * src/download_helper.cc + * src/magnet.cc + * src/magnet.h + * test/BittorrentHelperTest.cc + * test/MagnetTest.cc + * test/Makefile.am + * test/ProtocolDetectorTest.cc + 2009-11-24 Tatsuhiro Tsujikawa Use hton64 diff --git a/src/Makefile.am b/src/Makefile.am index 5e3c7ab8..926ed1da 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -355,6 +355,7 @@ SRCS += PeerAbstractCommand.cc PeerAbstractCommand.h\ UTMetadataRequestTracker.cc UTMetadataRequestTracker.h\ UTMetadataRequestFactory.cc UTMetadataRequestFactory.h\ UTMetadataPostDownloadHandler.cc UTMetadataPostDownloadHandler.h\ + magnet.cc magnet.h\ DHTNode.cc DHTNode.h\ DHTBucket.cc DHTBucket.h\ DHTRoutingTable.cc DHTRoutingTable.h\ diff --git a/src/Makefile.in b/src/Makefile.in index 7aaad03b..e9afd0a7 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -153,6 +153,7 @@ bin_PROGRAMS = aria2c$(EXEEXT) @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestTracker.cc UTMetadataRequestTracker.h\ @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestFactory.cc UTMetadataRequestFactory.h\ @ENABLE_BITTORRENT_TRUE@ UTMetadataPostDownloadHandler.cc UTMetadataPostDownloadHandler.h\ +@ENABLE_BITTORRENT_TRUE@ magnet.cc magnet.h\ @ENABLE_BITTORRENT_TRUE@ DHTNode.cc DHTNode.h\ @ENABLE_BITTORRENT_TRUE@ DHTBucket.cc DHTBucket.h\ @ENABLE_BITTORRENT_TRUE@ DHTRoutingTable.cc DHTRoutingTable.h\ @@ -508,12 +509,12 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \ UTMetadataDataExtensionMessage.h UTMetadataRequestTracker.cc \ UTMetadataRequestTracker.h UTMetadataRequestFactory.cc \ UTMetadataRequestFactory.h UTMetadataPostDownloadHandler.cc \ - UTMetadataPostDownloadHandler.h DHTNode.cc DHTNode.h \ - DHTBucket.cc DHTBucket.h DHTRoutingTable.cc DHTRoutingTable.h \ - DHTMessageEntry.cc DHTMessageEntry.h DHTMessageDispatcher.h \ - DHTMessageDispatcherImpl.cc DHTMessageDispatcherImpl.h \ - DHTMessageReceiver.cc DHTMessageReceiver.h \ - DHTMessageTracker.cc DHTMessageTracker.h \ + UTMetadataPostDownloadHandler.h magnet.cc magnet.h DHTNode.cc \ + DHTNode.h DHTBucket.cc DHTBucket.h DHTRoutingTable.cc \ + DHTRoutingTable.h DHTMessageEntry.cc DHTMessageEntry.h \ + DHTMessageDispatcher.h DHTMessageDispatcherImpl.cc \ + DHTMessageDispatcherImpl.h DHTMessageReceiver.cc \ + DHTMessageReceiver.h DHTMessageTracker.cc DHTMessageTracker.h \ DHTMessageTrackerEntry.cc DHTMessageTrackerEntry.h \ DHTMessage.cc DHTMessage.h DHTConnection.h \ DHTConnectionImpl.cc DHTConnectionImpl.h DHTAbstractMessage.cc \ @@ -670,7 +671,8 @@ am__objects_6 = @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestTracker.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestFactory.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ UTMetadataPostDownloadHandler.$(OBJEXT) \ -@ENABLE_BITTORRENT_TRUE@ DHTNode.$(OBJEXT) DHTBucket.$(OBJEXT) \ +@ENABLE_BITTORRENT_TRUE@ magnet.$(OBJEXT) DHTNode.$(OBJEXT) \ +@ENABLE_BITTORRENT_TRUE@ DHTBucket.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DHTRoutingTable.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DHTMessageEntry.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DHTMessageDispatcherImpl.$(OBJEXT) \ @@ -1573,6 +1575,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inet_aton.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgen.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/localtime_r.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/magnet.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/messageDigest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/option_processing.Po@am__quote@ diff --git a/src/ProtocolDetector.cc b/src/ProtocolDetector.cc index 5af33d8f..c620c5bf 100644 --- a/src/ProtocolDetector.cc +++ b/src/ProtocolDetector.cc @@ -41,6 +41,9 @@ #include "Request.h" #include "File.h" #include "util.h" +#ifdef ENABLE_BITTORRENT +# include "bittorrent_helper.h" +#endif // ENABLE_BITTORRENT namespace aria2 { @@ -70,8 +73,16 @@ bool ProtocolDetector::guessTorrentFile(const std::string& uri) const bool ProtocolDetector::guessTorrentMagnet(const std::string& uri) const { - return util::startsWith(uri, "magnet:?") && - uri.find("xt=urn:btih:") != std::string::npos; +#ifdef ENABLE_BITTORRENT + try { + bittorrent::parseMagnet(uri); + return true; + } catch(RecoverableException& e) { + return false; + } +#else // !ENABLE_BITTORRENT + return false; +#endif // !ENABLE_BITTORRENT } bool ProtocolDetector::guessMetalinkFile(const std::string& uri) const diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index 72d93eb7..6908f95b 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -53,6 +53,7 @@ #include "BtConstants.h" #include "bitfield.h" #include "base32.h" +#include "magnet.h" namespace aria2 { @@ -848,64 +849,58 @@ void generateRandomKey(unsigned char* key) MessageDigestHelper::digest(key, 20, MessageDigestContext::SHA1, bytes, sizeof(bytes)); } -void parseMagnetLink(const std::string& magnetLink, - const SharedHandle& dctx) +BDE parseMagnet(const std::string& magnet) { - // magnet:?xt=urn:btih:&dn=&tr= - // comes in 2 flavors: 40bytes hexadecimal ascii info hash, - // or 32bytes Base32 encoded info hash. - if(!util::startsWith(magnetLink, "magnet:?")) { - throw DL_ABORT_EX("Invalid magnet link."); + BDE result; + BDE r = magnet::parse(magnet); + if(r.isNone()) { + throw DL_ABORT_EX("Bad BitTorrent Magnet URI."); } - std::deque queries; - util::split(std::string(magnetLink.begin()+8, magnetLink.end()), - std::back_inserter(queries), "&"); - std::string infoHash; - std::string name; - BDE announceList = BDE::list(); - announceList << BDE::list(); - for(std::deque::const_iterator i = queries.begin(); - i != queries.end(); ++i) { - std::pair kv; - util::split(kv, *i, '='); - if(kv.first == "xt") { - if(!util::startsWith(kv.second, "urn:btih:")) { - throw DL_ABORT_EX("Bad BitTorrent Magnet Link."); - } - if(infoHash.empty()) { - infoHash = kv.second.substr(9); - } else { - throw DL_ABORT_EX("More than 1 info hash in magnet link."); - } - } else if(kv.first == "dn") { - name = kv.second; - } else if(kv.first == "tr") { - announceList[0] << kv.second; - } + if(!r.containsKey("xt")) { + throw DL_ABORT_EX("Missing xt parameter in Magnet URI."); } + const BDE& xts = r["xt"]; + if(xts.size() == 0 || !util::startsWith(xts[0].s(), "urn:btih:")) { + throw DL_ABORT_EX("Bad BitTorrent Magnet URI."); + } + std::string infoHash = xts[0].s().substr(9); if(infoHash.size() == 32) { std::string rawhash = base32::decode(infoHash); if(rawhash.size() != 20) { - throw DL_ABORT_EX("Invalid info hash"); + throw DL_ABORT_EX("Invalid BitTorrent Info Hash."); } infoHash = rawhash; } else if(infoHash.size() == 40) { std::string rawhash = util::fromHex(infoHash); if(rawhash.empty()) { - throw DL_ABORT_EX("Invalid info hash"); + throw DL_ABORT_EX("Invalid BitTorrent Info Hash."); } infoHash = rawhash; } else { - throw DL_ABORT_EX("Invalid magnet link."); + throw DL_ABORT_EX("Invalid BitTorrent Info Hash."); } - if(name.empty()) { - name = util::toHex(infoHash); + BDE announceList = BDE::list(); + if(r.containsKey("tr")) { + announceList << r["tr"]; + } + std::string name; + if(r.containsKey("dn") && r["dn"].size()) { + name = r["dn"][0].s(); + } else { + name = strconcat("[METADATA]", util::toHex(infoHash)); } BDE attrs = BDE::dict(); attrs[INFO_HASH] = infoHash; attrs[NAME] = name; attrs[ANNOUNCE_LIST] = announceList; + result = attrs; + return result; +} +void loadMagnet +(const std::string& magnet, const SharedHandle& dctx) +{ + BDE attrs = parseMagnet(magnet); dctx->setAttribute(BITTORRENT, attrs); } diff --git a/src/bittorrent_helper.h b/src/bittorrent_helper.h index 5e7a1fde..06d26058 100644 --- a/src/bittorrent_helper.h +++ b/src/bittorrent_helper.h @@ -119,10 +119,21 @@ void loadFromMemory(const std::string& context, const std::string& defaultName, const std::string& overrideName = ""); -// Parses BitTorrent magnet link. +// Parses BitTorrent Magnet URI and returns BDE::dict() which includes +// infoHash, name and announceList. If parsing operation failed, an +// RecoverableException will be thrown. infoHash and name are string +// and announceList is a list of list of announce URI. +// // magnet:?xt=urn:btih:&dn=&tr= -void parseMagnetLink(const std::string& magnetLink, - const SharedHandle& ctx); +// comes in 2 flavors: 40bytes hexadecimal ascii string, +// or 32bytes Base32 encoded string. +BDE parseMagnet(const std::string& magnet); + +// Parses BitTorrent Magnet URI and set them in ctx as a +// bittorrent::BITTORRENT attibute. If parsing operation failed, an +// RecoverableException will be thrown. +void loadMagnet +(const std::string& magnet, const SharedHandle& ctx); // Generates Peer ID. BitTorrent specification says Peer ID is 20-byte // length. This function uses peerIdPrefix as a Peer ID and it is diff --git a/src/download_helper.cc b/src/download_helper.cc index ee7c5bdf..84396a4d 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -242,7 +242,7 @@ createBtMagnetRequestGroup(const std::string& magnetLink, dctx->markTotalLengthIsUnknown(); rg->setFileAllocationEnabled(false); rg->setPreLocalFileCheckEnabled(false); - bittorrent::parseMagnetLink(magnetLink, dctx); + bittorrent::loadMagnet(magnetLink, dctx); dctx->getFirstFileEntry()->setPath (dctx->getAttribute(bittorrent::BITTORRENT)[bittorrent::NAME].s()); rg->setDownloadContext(dctx); @@ -327,16 +327,7 @@ public: _requestGroups.push_back(rg); } #ifdef ENABLE_BITTORRENT - else if(_detector.guessTorrentFile(uri)) { - try { - _requestGroups.push_back(createBtRequestGroup(uri, _option, - std::deque())); - } catch(RecoverableException& e) { - // error occurred while parsing torrent file. - // We simply ignore it. - LogFactory::getInstance()->error(EX_EXCEPTION_CAUGHT, e); - } - } else if(_detector.guessTorrentMagnet(uri)) { + else if(_detector.guessTorrentMagnet(uri)) { try { SharedHandle group = createBtMagnetRequestGroup(uri, _option, std::deque()); @@ -346,7 +337,16 @@ public: // We simply ignore it. LogFactory::getInstance()->error(EX_EXCEPTION_CAUGHT, e); } - } + } else if(_detector.guessTorrentFile(uri)) { + try { + _requestGroups.push_back(createBtRequestGroup(uri, _option, + std::deque())); + } catch(RecoverableException& e) { + // error occurred while parsing torrent file. + // We simply ignore it. + LogFactory::getInstance()->error(EX_EXCEPTION_CAUGHT, e); + } + } #endif // ENABLE_BITTORRENT #ifdef ENABLE_METALINK else if(_detector.guessMetalinkFile(uri)) { diff --git a/src/magnet.cc b/src/magnet.cc new file mode 100644 index 00000000..6c4f630e --- /dev/null +++ b/src/magnet.cc @@ -0,0 +1,70 @@ +/* */ +#include "magnet.h" +#include "util.h" + +namespace aria2 { + +namespace magnet { + +BDE parse(const std::string& magnet) +{ + BDE result; + if(!util::startsWith(magnet, "magnet:?")) { + return result; + } + std::deque queries; + util::split(std::string(magnet.begin()+8, magnet.end()), + std::back_inserter(queries), "&"); + BDE dict = BDE::dict(); + for(std::deque::const_iterator i = queries.begin(); + i != queries.end(); ++i) { + std::pair kv; + util::split(kv, *i, '='); + if(dict.containsKey(kv.first)) { + dict[kv.first] << kv.second; + } else { + BDE list = BDE::list(); + list << kv.second; + dict[kv.first] = list; + } + } + result = dict; + return result; +} + +} // namespace magnet + +} // namespace aria2 diff --git a/src/magnet.h b/src/magnet.h new file mode 100644 index 00000000..06468bfc --- /dev/null +++ b/src/magnet.h @@ -0,0 +1,56 @@ +/* */ +#ifndef _D_MAGNET_H_ +#define _D_MAGNET_H_ + +#include "common.h" +#include "BDE.h" + +namespace aria2 { + +namespace magnet { + +// Parses Magnet URI magnet and stores parameters in BDE::dict(). +// Because same parameter name can appear more than once, the value +// associated with a key is BDE::list(). A parameter value is stored +// in a list. If parsing operation failed, BDE::none is returned. +BDE parse(const std::string& magnet); + +} // namespace magnet + +} // namespace aria2 + + +#endif // _D_MAGNET_H_ diff --git a/test/BittorrentHelperTest.cc b/test/BittorrentHelperTest.cc index b4e5527d..73599a3c 100644 --- a/test/BittorrentHelperTest.cc +++ b/test/BittorrentHelperTest.cc @@ -59,8 +59,8 @@ class BittorrentHelperTest:public CppUnit::TestFixture { CPPUNIT_TEST(testCreatecompact); CPPUNIT_TEST(testCheckBitfield); CPPUNIT_TEST(testMetadata); - CPPUNIT_TEST(testParseMagnetLink); - CPPUNIT_TEST(testParseMagnetLink_base32); + CPPUNIT_TEST(testParseMagnet); + CPPUNIT_TEST(testParseMagnet_base32); CPPUNIT_TEST_SUITE_END(); public: void setUp() { @@ -100,8 +100,8 @@ public: void testCreatecompact(); void testCheckBitfield(); void testMetadata(); - void testParseMagnetLink(); - void testParseMagnetLink_base32(); + void testParseMagnet(); + void testParseMagnet_base32(); }; @@ -700,33 +700,37 @@ void BittorrentHelperTest::testMetadata() { (size_t)attrs[bittorrent::METADATA_SIZE].i()); } -void BittorrentHelperTest::testParseMagnetLink() +void BittorrentHelperTest::testParseMagnet() { - SharedHandle dctx(new DownloadContext()); std::string magnet = - "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2"; - bittorrent::parseMagnetLink(magnet, dctx); + "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2" + "&tr=http://tracker1&tr=http://tracker2"; + BDE attrs = bittorrent::parseMagnet(magnet); CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"), - bittorrent::getInfoHashString(dctx)); - BDE attrs = dctx->getAttribute(bittorrent::BITTORRENT); + util::toHex(attrs[bittorrent::INFO_HASH].s())); CPPUNIT_ASSERT_EQUAL(std::string("aria2"), attrs[bittorrent::NAME].s()); + CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"), + attrs[bittorrent::ANNOUNCE_LIST][0][0].s()); + CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"), + attrs[bittorrent::ANNOUNCE_LIST][0][1].s()); magnet = "magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"; - bittorrent::parseMagnetLink(magnet, dctx); - attrs = dctx->getAttribute(bittorrent::BITTORRENT); - CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"), - attrs[bittorrent::NAME].s()); + attrs = bittorrent::parseMagnet(magnet); + CPPUNIT_ASSERT_EQUAL + (std::string("[METADATA]248d0a1cd08284299de78d5c1ed359bb46717d8c"), + attrs[bittorrent::NAME].s()); + CPPUNIT_ASSERT(attrs[bittorrent::ANNOUNCE_LIST].size() == 0); } -void BittorrentHelperTest::testParseMagnetLink_base32() +void BittorrentHelperTest::testParseMagnet_base32() { std::string infoHash = "248d0a1cd08284299de78d5c1ed359bb46717d8c"; std::string base32InfoHash = base32::encode(util::fromHex(infoHash)); - SharedHandle dctx(new DownloadContext()); std::string magnet = "magnet:?xt=urn:btih:"+base32InfoHash+"&dn=aria2"; - bittorrent::parseMagnetLink(magnet, dctx); - CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"), - bittorrent::getInfoHashString(dctx)); + BDE attrs = bittorrent::parseMagnet(magnet); + CPPUNIT_ASSERT_EQUAL + (std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"), + util::toHex(attrs[bittorrent::INFO_HASH].s())); } } // namespace bittorrent diff --git a/test/MagnetTest.cc b/test/MagnetTest.cc new file mode 100644 index 00000000..dda40b22 --- /dev/null +++ b/test/MagnetTest.cc @@ -0,0 +1,40 @@ +#include "magnet.h" + +#include + +#include + +namespace aria2 { + +namespace magnet { + +class MagnetTest:public CppUnit::TestFixture { + + CPPUNIT_TEST_SUITE(MagnetTest); + CPPUNIT_TEST(testParse); + CPPUNIT_TEST_SUITE_END(); +public: + void testParse(); +}; + + +CPPUNIT_TEST_SUITE_REGISTRATION(MagnetTest); + +void MagnetTest::testParse() +{ + BDE r = parse + ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c&dn=aria2" + "&tr=http://tracker1&tr=http://tracker2"); + CPPUNIT_ASSERT_EQUAL + (std::string("urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c"), + r["xt"][0].s()); + CPPUNIT_ASSERT_EQUAL(std::string("aria2"), r["dn"][0].s()); + CPPUNIT_ASSERT_EQUAL(std::string("http://tracker1"), r["tr"][0].s()); + CPPUNIT_ASSERT_EQUAL(std::string("http://tracker2"), r["tr"][1].s()); + + CPPUNIT_ASSERT(parse("http://localhost").isNone()); +} + +} // namespace magnet + +} // namespace aria2 diff --git a/test/Makefile.am b/test/Makefile.am index 10bc398a..a85e0cea 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -143,6 +143,7 @@ aria2c_SOURCES += BtAllowedFastMessageTest.cc\ UTMetadataRequestTrackerTest.cc\ UTMetadataRequestFactoryTest.cc\ UTMetadataPostDownloadHandlerTest.cc\ + MagnetTest.cc\ DefaultBtMessageFactoryTest.cc\ DefaultExtensionMessageFactoryTest.cc\ DHTNodeTest.cc\ diff --git a/test/Makefile.in b/test/Makefile.in index 908dfca4..3f4735c5 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -92,6 +92,7 @@ check_PROGRAMS = $(am__EXEEXT_1) @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestTrackerTest.cc\ @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestFactoryTest.cc\ @ENABLE_BITTORRENT_TRUE@ UTMetadataPostDownloadHandlerTest.cc\ +@ENABLE_BITTORRENT_TRUE@ MagnetTest.cc\ @ENABLE_BITTORRENT_TRUE@ DefaultBtMessageFactoryTest.cc\ @ENABLE_BITTORRENT_TRUE@ DefaultExtensionMessageFactoryTest.cc\ @ENABLE_BITTORRENT_TRUE@ DHTNodeTest.cc\ @@ -236,7 +237,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \ UTMetadataRejectExtensionMessageTest.cc \ UTMetadataRequestTrackerTest.cc \ UTMetadataRequestFactoryTest.cc \ - UTMetadataPostDownloadHandlerTest.cc \ + UTMetadataPostDownloadHandlerTest.cc MagnetTest.cc \ DefaultBtMessageFactoryTest.cc \ DefaultExtensionMessageFactoryTest.cc DHTNodeTest.cc \ DHTBucketTest.cc DHTRoutingTableTest.cc \ @@ -315,6 +316,7 @@ am__aria2c_SOURCES_DIST = AllTest.cc TestUtil.cc TestUtil.h \ @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestTrackerTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ UTMetadataRequestFactoryTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ UTMetadataPostDownloadHandlerTest.$(OBJEXT) \ +@ENABLE_BITTORRENT_TRUE@ MagnetTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultBtMessageFactoryTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DefaultExtensionMessageFactoryTest.$(OBJEXT) \ @ENABLE_BITTORRENT_TRUE@ DHTNodeTest.$(OBJEXT) \ @@ -814,6 +816,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/IteratableChunkChecksumValidatorTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/LongestSequencePieceSelectorTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MSEHandshakeTest.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MagnetTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MessageDigestHelperTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/Metalink2RequestGroupTest.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/MetalinkEntryTest.Po@am__quote@ diff --git a/test/ProtocolDetectorTest.cc b/test/ProtocolDetectorTest.cc index 822bd3b8..0acdb1dc 100644 --- a/test/ProtocolDetectorTest.cc +++ b/test/ProtocolDetectorTest.cc @@ -47,9 +47,9 @@ void ProtocolDetectorTest::testGuessTorrentFile() void ProtocolDetectorTest::testGuessTorrentMagnet() { ProtocolDetector detector; - CPPUNIT_ASSERT(detector.guessTorrentMagnet("magnet:?xt=urn:btih:abcdef")); - CPPUNIT_ASSERT(detector.guessTorrentMagnet - ("magnet:?dn=name&xt=urn:btih:abcdef")); + CPPUNIT_ASSERT + (detector.guessTorrentMagnet + ("magnet:?xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c")); CPPUNIT_ASSERT(!detector.guessTorrentMagnet("magnet:?")); }