From 5412c62b1ffab407a507df9d999937cb2e7e9e2b Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Wed, 23 Feb 2011 16:47:18 +0000 Subject: [PATCH] fix tracker URL decoding when adding magnet links --- src/magnet_uri.cpp | 15 +++++++++------ src/policy.cpp | 2 ++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/magnet_uri.cpp b/src/magnet_uri.cpp index a46b41cca..8f26f766a 100644 --- a/src/magnet_uri.cpp +++ b/src/magnet_uri.cpp @@ -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 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); } diff --git a/src/policy.cpp b/src/policy.cpp index c20fb2e99..179656104 100644 --- a/src/policy.cpp +++ b/src/policy.cpp @@ -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);