fixed magnet link parser to accept hex encoded info-hashes

This commit is contained in:
Arvid Norberg
2009-05-02 18:36:51 +00:00
parent 76ce836fb9
commit b75648445e
3 changed files with 17 additions and 2 deletions

View File

@@ -116,7 +116,9 @@ namespace libtorrent
if (btih->compare(0, 9, "urn:btih:") != 0) return torrent_handle();
sha1_hash info_hash(base32decode(btih->substr(9)));
sha1_hash info_hash;
if (btih->size() == 40 + 9) from_hex(&(*btih)[9], 40, (char*)&info_hash[0]);
else info_hash.assign(base32decode(btih->substr(9)));
return ses.add_torrent(tracker.empty() ? 0 : tracker.c_str(), info_hash
, name.empty() ? 0 : name.c_str(), save_path, entry()
@@ -158,7 +160,9 @@ namespace libtorrent
return torrent_handle();
}
sha1_hash info_hash(base32decode(btih->substr(9)));
sha1_hash info_hash;
if (btih->size() == 40 + 9) from_hex(&(*btih)[9], 40, (char*)&info_hash[0]);
else info_hash.assign(base32decode(btih->substr(9)));
if (!tracker.empty()) p.tracker_url = tracker.c_str();
p.info_hash = info_hash;