merged make_magnet_uri fix from RC_0_16
This commit is contained in:
parent
dc226eab80
commit
a187d09bbf
|
@ -20,6 +20,7 @@
|
|||
* fix uTP edge case where udp socket buffer fills up
|
||||
* 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 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)
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace libtorrent
|
|||
{
|
||||
if (!handle.is_valid()) return "";
|
||||
|
||||
char ret[1024];
|
||||
char ret[2048];
|
||||
sha1_hash const& ih = handle.info_hash();
|
||||
int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s"
|
||||
, to_hex(ih.to_string()).c_str());
|
||||
|
@ -52,7 +52,7 @@ namespace libtorrent
|
|||
torrent_status st = handle.status(torrent_handle::query_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"
|
||||
, 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)
|
||||
{
|
||||
if (num_chars >= sizeof(ret)) break;
|
||||
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s"
|
||||
, 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)
|
||||
{
|
||||
char ret[1024];
|
||||
char ret[2048];
|
||||
sha1_hash const& ih = info.info_hash();
|
||||
int num_chars = snprintf(ret, sizeof(ret), "magnet:?xt=urn:btih:%s"
|
||||
, to_hex(ih.to_string()).c_str());
|
||||
|
||||
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"
|
||||
, escape_string(name.c_str(), name.length()).c_str());
|
||||
|
||||
std::vector<announce_entry> const& tr = info.trackers();
|
||||
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"
|
||||
, escape_string(i->url.c_str(), i->url.length()).c_str());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue