post fastresume_reject_alerts when building with deprecated functions enabled

This commit is contained in:
arvidn 2016-02-19 18:56:26 -05:00 committed by arvidn
parent b23cb76b6f
commit a5d131b1bb
3 changed files with 23 additions and 15 deletions

View File

@ -492,6 +492,12 @@ namespace libtorrent
// will be swapped into the running torrent instance with // will be swapped into the running torrent instance with
// ``std::vector::swap()``. // ``std::vector::swap()``.
std::vector<char> resume_data; std::vector<char> 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 #endif
}; };

View File

@ -159,17 +159,18 @@ namespace libtorrent
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
namespace namespace
{ {
void handle_backwards_compatible_resume_data(add_torrent_params& atp void handle_backwards_compatible_resume_data(add_torrent_params& atp)
, error_code& ec)
{ {
// if there's no resume data set, there's nothing to do. It's either // 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 // using the previous API without resume data, or the resume data has
// already been parsed out into the add_torrent_params struct. // already been parsed out into the add_torrent_params struct.
if (atp.resume_data.empty()) return; if (atp.resume_data.empty()) return;
error_code ec;
add_torrent_params resume_data add_torrent_params resume_data
= read_resume_data(&atp.resume_data[0], atp.resume_data.size(), ec); = read_resume_data(&atp.resume_data[0], atp.resume_data.size(), ec);
resume_data.internal_resume_data_error = ec;
if (ec) return; if (ec) return;
// now, merge resume_data into atp according to the merge flags // now, merge resume_data into atp according to the merge flags
@ -279,14 +280,13 @@ namespace libtorrent
#ifndef BOOST_NO_EXCEPTIONS #ifndef BOOST_NO_EXCEPTIONS
torrent_handle session_handle::add_torrent(add_torrent_params const& params) torrent_handle session_handle::add_torrent(add_torrent_params const& params)
{ {
error_code ec;
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
add_torrent_params p = params; add_torrent_params p = params;
handle_backwards_compatible_resume_data(p, ec); handle_backwards_compatible_resume_data(p);
if (ec) throw libtorrent_exception(ec);
#else #else
add_torrent_params const& p = params; add_torrent_params const& p = params;
#endif #endif
error_code ec;
torrent_handle r = TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, p, boost::ref(ec)); torrent_handle r = TORRENT_SYNC_CALL_RET2(torrent_handle, add_torrent, p, boost::ref(ec));
if (ec) throw libtorrent_exception(ec); if (ec) throw libtorrent_exception(ec);
return r; return r;
@ -298,8 +298,7 @@ namespace libtorrent
ec.clear(); ec.clear();
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
add_torrent_params p = params; add_torrent_params p = params;
handle_backwards_compatible_resume_data(p, ec); handle_backwards_compatible_resume_data(p);
if (ec) return torrent_handle();
#else #else
add_torrent_params const& p = params; add_torrent_params const& p = params;
#endif #endif
@ -311,14 +310,7 @@ namespace libtorrent
add_torrent_params* p = new add_torrent_params(params); add_torrent_params* p = new add_torrent_params(params);
#ifndef TORRENT_NO_DEPRECATE #ifndef TORRENT_NO_DEPRECATE
error_code ec; handle_backwards_compatible_resume_data(*p);
handle_backwards_compatible_resume_data(*p, ec);
//TODO: 3 what should we do about error handling here?
if (ec)
{
delete p;
return;
}
#endif #endif
TORRENT_ASYNC_CALL1(async_add_torrent, p); TORRENT_ASYNC_CALL1(async_add_torrent, p);

View File

@ -797,6 +797,16 @@ namespace libtorrent
{ {
TORRENT_ASSERT(is_single_thread()); 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<fastresume_rejected_alert>())
{
m_ses.alerts().emplace_alert<fastresume_rejected_alert>(get_handle()
, m_add_torrent_params->internal_resume_data_error, "", "");
}
#endif
// TODO: 3 why isn't this done in the constructor? // TODO: 3 why isn't this done in the constructor?
#ifndef TORRENT_DISABLE_LOGGING #ifndef TORRENT_DISABLE_LOGGING