fix tracker URL decoding when adding magnet links

This commit is contained in:
Arvid Norberg 2011-02-23 16:47:18 +00:00
parent 48a009f1c5
commit 5412c62b1f
2 changed files with 11 additions and 6 deletions

View File

@ -54,20 +54,20 @@ namespace libtorrent
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&dn=%s"
, escape_string(name.c_str(), name.length()).c_str());
char const* tracker = 0;
std::string tracker;
torrent_status st = handle.status();
if (!st.current_tracker.empty())
{
tracker = st.current_tracker.c_str();
tracker = st.current_tracker;
}
else
{
std::vector<announce_entry> const& tr = handle.trackers();
if (!tr.empty()) tracker = tr[0].url.c_str();
if (!tr.empty()) tracker = tr[0].url;
}
if (tracker)
if (!tracker.empty())
num_chars += snprintf(ret + num_chars, sizeof(ret) - num_chars, "&tr=%s"
, escape_string(tracker, strlen(tracker)).c_str());
, escape_string(tracker.c_str(), tracker.size()).c_str());
return ret;
}
@ -199,7 +199,10 @@ namespace libtorrent
pos = uri.find("&tr=", pos);
if (pos == std::string::npos) break;
pos += 4;
announce_entry ae(uri.substr(pos, uri.find('&', pos) - pos));
error_code ec;
std::string url = unescape_string(uri.substr(pos, uri.find('&', pos) - pos), ec);
if (ec) continue;
announce_entry ae(url);
ae.tier = tier++;
ret.add_tracker(ae);
}

View File

@ -325,6 +325,8 @@ namespace libtorrent
== p.blocks_in_piece(busy_block.piece_index));
#endif
TORRENT_ASSERT(p.is_requested(busy_block));
TORRENT_ASSERT(!p.is_downloaded(busy_block));
TORRENT_ASSERT(!p.is_finished(busy_block));
TORRENT_ASSERT(p.num_peers(busy_block) > 0);
c.add_request(busy_block, peer_connection::req_busy);