mirror of https://github.com/aria2/aria2
2010-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Inspect all xt in magnet to find urn:btih. * src/bittorrent_helper.cc * test/BittorrentHelperTest.ccpull/1/head
parent
542a06de6d
commit
7bbc5769a5
|
@ -1,3 +1,9 @@
|
||||||
|
2010-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Inspect all xt in magnet to find urn:btih.
|
||||||
|
* src/bittorrent_helper.cc
|
||||||
|
* test/BittorrentHelperTest.cc
|
||||||
|
|
||||||
2010-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2010-03-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Use global option for DHTSetup.
|
Use global option for DHTSetup.
|
||||||
|
|
|
@ -863,25 +863,29 @@ BDE parseMagnet(const std::string& magnet)
|
||||||
if(!r.containsKey("xt")) {
|
if(!r.containsKey("xt")) {
|
||||||
throw DL_ABORT_EX("Missing xt parameter in Magnet URI.");
|
throw DL_ABORT_EX("Missing xt parameter in Magnet URI.");
|
||||||
}
|
}
|
||||||
|
std::string infoHash;
|
||||||
const BDE& xts = r["xt"];
|
const BDE& xts = r["xt"];
|
||||||
if(xts.size() == 0 || !util::startsWith(xts[0].s(), "urn:btih:")) {
|
for(BDE::List::const_iterator xtiter = xts.listBegin(),
|
||||||
throw DL_ABORT_EX("Bad BitTorrent Magnet URI.");
|
eoi = xts.listEnd(); xtiter != eoi && infoHash.empty(); ++xtiter) {
|
||||||
|
if(util::startsWith((*xtiter).s(), "urn:btih:")) {
|
||||||
|
std::string xtarg = (*xtiter).s().substr(9);
|
||||||
|
size_t size = xtarg.size();
|
||||||
|
if(size == 32) {
|
||||||
|
std::string rawhash = base32::decode(xtarg);
|
||||||
|
if(rawhash.size() == 20) {
|
||||||
|
infoHash.swap(rawhash);
|
||||||
|
}
|
||||||
|
} else if(size == 40) {
|
||||||
|
std::string rawhash = util::fromHex(xtarg);
|
||||||
|
if(!rawhash.empty()) {
|
||||||
|
infoHash.swap(rawhash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
std::string infoHash = xts[0].s().substr(9);
|
if(infoHash.empty()) {
|
||||||
if(infoHash.size() == 32) {
|
throw DL_ABORT_EX("Bad BitTorrent Magnet URI. "
|
||||||
std::string rawhash = base32::decode(infoHash);
|
"No valid BitTorrent Info Hash found.");
|
||||||
if(rawhash.size() != 20) {
|
|
||||||
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 BitTorrent Info Hash.");
|
|
||||||
}
|
|
||||||
infoHash = rawhash;
|
|
||||||
} else {
|
|
||||||
throw DL_ABORT_EX("Invalid BitTorrent Info Hash.");
|
|
||||||
}
|
}
|
||||||
BDE announceList = BDE::list();
|
BDE announceList = BDE::list();
|
||||||
if(r.containsKey("tr")) {
|
if(r.containsKey("tr")) {
|
||||||
|
|
|
@ -729,6 +729,12 @@ void BittorrentHelperTest::testParseMagnet()
|
||||||
(std::string("[METADATA]248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
(std::string("[METADATA]248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
||||||
attrs[bittorrent::NAME].s());
|
attrs[bittorrent::NAME].s());
|
||||||
CPPUNIT_ASSERT(attrs[bittorrent::ANNOUNCE_LIST].size() == 0);
|
CPPUNIT_ASSERT(attrs[bittorrent::ANNOUNCE_LIST].size() == 0);
|
||||||
|
|
||||||
|
magnet = "magnet:?xt=urn:sha1:7899bdb90a026c746f3cbc10839dd9b2a2a3e985&"
|
||||||
|
"xt=urn:btih:248d0a1cd08284299de78d5c1ed359bb46717d8c";
|
||||||
|
attrs = bittorrent::parseMagnet(magnet);
|
||||||
|
CPPUNIT_ASSERT_EQUAL(std::string("248d0a1cd08284299de78d5c1ed359bb46717d8c"),
|
||||||
|
util::toHex(attrs[bittorrent::INFO_HASH].s()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void BittorrentHelperTest::testParseMagnet_base32()
|
void BittorrentHelperTest::testParseMagnet_base32()
|
||||||
|
|
Loading…
Reference in New Issue