From a5d131b1bbce8b10c49234bf23097d0dfc069d6b Mon Sep 17 00:00:00 2001 From: arvidn Date: Fri, 19 Feb 2016 18:56:26 -0500 Subject: [PATCH] post fastresume_reject_alerts when building with deprecated functions enabled --- include/libtorrent/add_torrent_params.hpp | 6 ++++++ src/session_handle.cpp | 22 +++++++--------------- src/torrent.cpp | 10 ++++++++++ 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/libtorrent/add_torrent_params.hpp b/include/libtorrent/add_torrent_params.hpp index 81cfec38a..2c8fa6016 100644 --- a/include/libtorrent/add_torrent_params.hpp +++ b/include/libtorrent/add_torrent_params.hpp @@ -492,6 +492,12 @@ namespace libtorrent // will be swapped into the running torrent instance with // ``std::vector::swap()``. std::vector resume_data; + + // to support the deprecated use case of reading the resume data into + // resume_data field and getting a reject alert, any parse failure is + // communicated forward into libtorrent via this field. If this is set, a + // fastresume_rejected_alert will be posted. + error_code internal_resume_data_error; #endif }; diff --git a/src/session_handle.cpp b/src/session_handle.cpp index 81d9b2335..2cd0e06a6 100644 --- a/src/session_handle.cpp +++ b/src/session_handle.cpp @@ -159,17 +159,18 @@ namespace libtorrent #ifndef TORRENT_NO_DEPRECATE namespace { - void handle_backwards_compatible_resume_data(add_torrent_params& atp - , error_code& ec) + void handle_backwards_compatible_resume_data(add_torrent_params& atp) { // if there's no resume data set, there's nothing to do. It's either // using the previous API without resume data, or the resume data has // already been parsed out into the add_torrent_params struct. if (atp.resume_data.empty()) return; + error_code ec; add_torrent_params resume_data = read_resume_data(&atp.resume_data[0], atp.resume_data.size(), ec); + resume_data.internal_resume_data_error = ec; if (ec) return; // now, merge resume_data into atp according to the merge flags @@ -279,14 +280,13 @@ namespace libtorrent #ifndef BOOST_NO_EXCEPTIONS torrent_handle session_handle::add_torrent(add_torrent_params const& params) { - error_code ec; #ifndef TORRENT_NO_DEPRECATE add_torrent_params p = params; - handle_backwards_compatible_resume_data(p, ec); - if (ec) throw libtorrent_exception(ec); + handle_backwards_compatible_resume_data(p); #else add_torrent_params const& p = params; #endif + error_code ec; torrent_handle r = TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, p, boost::ref(ec)); if (ec) throw libtorrent_exception(ec); return r; @@ -298,8 +298,7 @@ namespace libtorrent ec.clear(); #ifndef TORRENT_NO_DEPRECATE add_torrent_params p = params; - handle_backwards_compatible_resume_data(p, ec); - if (ec) return torrent_handle(); + handle_backwards_compatible_resume_data(p); #else add_torrent_params const& p = params; #endif @@ -311,14 +310,7 @@ namespace libtorrent add_torrent_params* p = new add_torrent_params(params); #ifndef TORRENT_NO_DEPRECATE - error_code ec; - handle_backwards_compatible_resume_data(*p, ec); -//TODO: 3 what should we do about error handling here? - if (ec) - { - delete p; - return; - } + handle_backwards_compatible_resume_data(*p); #endif TORRENT_ASYNC_CALL1(async_add_torrent, p); diff --git a/src/torrent.cpp b/src/torrent.cpp index f15c691a4..1e86a5faa 100644 --- a/src/torrent.cpp +++ b/src/torrent.cpp @@ -797,6 +797,16 @@ namespace libtorrent { TORRENT_ASSERT(is_single_thread()); +#ifndef TORRENT_NO_DEPRECATE + if (m_add_torrent_params + && m_add_torrent_params->internal_resume_data_error + && m_ses.alerts().should_post()) + { + m_ses.alerts().emplace_alert(get_handle() + , m_add_torrent_params->internal_resume_data_error, "", ""); + } +#endif + // TODO: 3 why isn't this done in the constructor? #ifndef TORRENT_DISABLE_LOGGING