merged make_magnet_uri fix from RC_0_16

This commit is contained in:
Arvid Norberg 2013-04-27 21:11:12 +00:00
parent dc226eab80
commit a187d09bbf
2 changed files with 7 additions and 4 deletions

View File

@ -20,6 +20,7 @@
* fix uTP edge case where udp socket buffer fills up * fix uTP edge case where udp socket buffer fills up
* fix nagle implementation in uTP * fix nagle implementation in uTP
* fix crash in make_magnet_uri when generating links longer than 1024 characters
* fix hanging issue when closing files on windows (completing a download) * fix hanging issue when closing files on windows (completing a download)
* fix piece picking edge case that could cause torrents to get stuck at hash failure * fix piece picking edge case that could cause torrents to get stuck at hash failure
* try unencrypted connections first, and fall back to encryption if it fails (performance improvement) * try unencrypted connections first, and fall back to encryption if it fails (performance improvement)

View File

@ -44,7 +44,7 @@ namespace libtorrent
{ {
if (!handle.is_valid()) return ""; if (!handle.is_valid()) return "";
char ret[1024]; char ret[2048];
sha1_hash const& ih = handle.info_hash(); sha1_hash const& ih = handle.info_hash();
int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s" int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s"
, to_hex(ih.to_string()).c_str()); , to_hex(ih.to_string()).c_str());
@ -52,7 +52,7 @@ namespace libtorrent
torrent_status st = handle.status(torrent_handle::query_name); torrent_status st = handle.status(torrent_handle::query_name);
std::string name = st.name; std::string name = st.name;
if (!name.empty()) if (!name.empty() && sizeof(ret) - 5 > num_chars)
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s" num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s"
, escape_string(name.c_str(), name.length()).c_str()); , escape_string(name.c_str(), name.length()).c_str());
@ -60,6 +60,7 @@ namespace libtorrent
for (std::vector<announce_entry>::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i) for (std::vector<announce_entry>::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i)
{ {
if (num_chars >= sizeof(ret)) break;
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s" num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s"
, escape_string(i->url.c_str(), i->url.length()).c_str()); , escape_string(i->url.c_str(), i->url.length()).c_str());
} }
@ -69,20 +70,21 @@ namespace libtorrent
std::string make_magnet_uri(torrent_info const& info) std::string make_magnet_uri(torrent_info const& info)
{ {
char ret[1024]; char ret[2048];
sha1_hash const& ih = info.info_hash(); sha1_hash const& ih = info.info_hash();
int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s" int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s"
, to_hex(ih.to_string()).c_str()); , to_hex(ih.to_string()).c_str());
std::string const& name = info.name(); std::string const& name = info.name();
if (!name.empty()) if (!name.empty() && sizeof(ret) - 5 > num_chars)
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s" num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s"
, escape_string(name.c_str(), name.length()).c_str()); , escape_string(name.c_str(), name.length()).c_str());
std::vector<announce_entry> const& tr = info.trackers(); std::vector<announce_entry> const& tr = info.trackers();
for (std::vector<announce_entry>::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i) for (std::vector<announce_entry>::const_iterator i = tr.begin(), end(tr.end()); i != end; ++i)
{ {
if (num_chars >= sizeof(ret)) break;
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s" num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s"
, escape_string(i->url.c_str(), i->url.length()).c_str()); , escape_string(i->url.c_str(), i->url.length()).c_str());
} }