diff --git a/ChangeLog b/ChangeLog index dd09edff7..27f01970a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -33,6 +33,10 @@ * added support for bitcomet padding files * improved support for sparse files on windows +release 0.14.4 + + * fixed magnet link parser to accept hex-encoded info-hashes + release 0.14.3 * added python binding for create_torrent diff --git a/include/libtorrent/peer_id.hpp b/include/libtorrent/peer_id.hpp index da04a52f7..a0395d089 100644 --- a/include/libtorrent/peer_id.hpp +++ b/include/libtorrent/peer_id.hpp @@ -72,6 +72,13 @@ namespace libtorrent std::memcpy(m_number, &s[0], sl); } + void assign(std::string const& s) + { + TORRENT_ASSERT(s.size() >= 20); + int sl = int(s.size()) < size ? int(s.size()) : size; + std::memcpy(m_number, &s[0], sl); + } + void assign(char const* str) { std::memcpy(m_number, str, size); diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index 78c29557c..b3e4db3db 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -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;