deprecated (undocumented) file:// urls, added torrent_file_path alternative
This commit is contained in:
parent
be0e54b637
commit
488c1a2dcf
|
@ -1,3 +1,4 @@
|
|||
* deprecated (undocumented) file:// urls, added torrent_file_path alternative
|
||||
* add limit for number of web seed connections
|
||||
* added support for retrieval of DHT live nodes
|
||||
* complete UNC path support
|
||||
|
|
|
@ -576,48 +576,6 @@ void signal_handler(int)
|
|||
// if non-empty, a peer that will be added to all torrents
|
||||
std::string peer;
|
||||
|
||||
std::string path_to_url(std::string f)
|
||||
{
|
||||
std::string ret = "file://"
|
||||
#ifdef TORRENT_WINDOWS
|
||||
"/"
|
||||
#endif
|
||||
;
|
||||
static char const hex_chars[] = "0123456789abcdef";
|
||||
static const char unreserved[] =
|
||||
"/-_!.~*()ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
||||
"0123456789";
|
||||
|
||||
// make sure the path is an absolute path
|
||||
if (!is_absolute_path(f))
|
||||
{
|
||||
char cwd[TORRENT_MAX_PATH];
|
||||
#if defined TORRENT_WINDOWS && !defined TORRENT_MINGW
|
||||
_getcwd(cwd, sizeof(cwd));
|
||||
#else
|
||||
char const* ret = getcwd(cwd, sizeof(cwd));
|
||||
(void)ret; // best effort
|
||||
#endif
|
||||
f = path_append(cwd, f);
|
||||
}
|
||||
|
||||
for (int i = 0; i < int(f.size()); ++i)
|
||||
{
|
||||
#ifdef TORRENT_WINDOWS
|
||||
if (f[i] == '\\') ret.push_back('/');
|
||||
else
|
||||
#endif
|
||||
if (std::strchr(unreserved, f[i]) != nullptr) ret.push_back(f[i]);
|
||||
else
|
||||
{
|
||||
ret.push_back('%');
|
||||
ret.push_back(hex_chars[std::uint8_t(f[i]) >> 4]);
|
||||
ret.push_back(hex_chars[std::uint8_t(f[i]) & 0xf]);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void print_settings(int const start, int const num
|
||||
, char const* const fmt)
|
||||
{
|
||||
|
@ -656,7 +614,7 @@ void add_torrent(libtorrent::session& ses
|
|||
if (disable_storage) p.storage = disabled_storage_constructor;
|
||||
if (share_mode) p.flags |= add_torrent_params::flag_share_mode;
|
||||
|
||||
p.url = path_to_url(torrent);
|
||||
p.torrent_file_path = torrent;
|
||||
p.save_path = save_path;
|
||||
p.storage_mode = (storage_mode_t)allocation_mode;
|
||||
p.flags &= ~add_torrent_params::flag_duplicate_is_error;
|
||||
|
|
|
@ -56,10 +56,12 @@ namespace libtorrent
|
|||
// The add_torrent_params is a parameter pack for adding torrents to a
|
||||
// session. The key fields when adding a torrent are:
|
||||
//
|
||||
// * ti - when you have a .torrent file
|
||||
// * ti - when you have loaded a .torrent file into a torrent_info object
|
||||
// * url - when you have a magnet link
|
||||
// * info_hash - when all you have is an info-hash (this is similar to a
|
||||
// magnet link)
|
||||
// * torrent_file_path - when you have the path to a .torrent file and want
|
||||
// libtorrent to load it. (This is especially useful with async_add_torrent)
|
||||
//
|
||||
// one of those fields must be set. Another mandatory field is
|
||||
// ``save_path``. The add_torrent_params object is passed into one of the
|
||||
|
@ -345,13 +347,23 @@ namespace libtorrent
|
|||
// instead of this.
|
||||
std::string trackerid;
|
||||
|
||||
// If you specify a ``url``, the torrent will be set in
|
||||
// ``downloading_metadata`` state until the .torrent file has been
|
||||
// downloaded. If there's any error while downloading, the torrent will
|
||||
// be stopped and the torrent error state (``torrent_status::error``)
|
||||
// will indicate what went wrong. The ``url`` may be set to a magnet link.
|
||||
// ``url`` can be set to a magnet link, in order to download the .torrent
|
||||
// file (also known as the metadata), specifically the info-dictionary,
|
||||
// from the bittorrent swarm. This may require access to the DHT, in case
|
||||
// the magnet link does not come with trackers.
|
||||
//
|
||||
// In earlier versions of libtorrent, the URL could be an HTTP or file://
|
||||
// url. These uses are deprecated and discouraged. When adding a torrent
|
||||
// by magnet link, it will be set to the ``downloading_metadata`` state
|
||||
// until the .torrent file has been downloaded. If there is any error
|
||||
// while downloading, the torrent will be stopped and the torrent error
|
||||
// state (``torrent_status::error``) will indicate what went wrong.
|
||||
std::string url;
|
||||
|
||||
// if you specify a ``torrent_file_path``, libtorrent will attempt to load
|
||||
// a .torrent file from the file at the given path.
|
||||
std::string torrent_file_path;
|
||||
|
||||
// flags controlling aspects of this torrent and how it's added. See
|
||||
// flags_t for details.
|
||||
//
|
||||
|
|
|
@ -64,8 +64,11 @@ namespace libtorrent
|
|||
// it will be encoded
|
||||
TORRENT_EXTRA_EXPORT std::string maybe_url_encode(std::string const& url);
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// deprecated in 1.2
|
||||
// convert a file://-URL to a proper path
|
||||
TORRENT_EXTRA_EXPORT std::string resolve_file_url(std::string const& url);
|
||||
#endif
|
||||
|
||||
// returns true if the given string (not 0-terminated) contains
|
||||
// characters that would need to be escaped if used in a URL
|
||||
|
|
|
@ -258,6 +258,7 @@ namespace libtorrent
|
|||
return msg;
|
||||
}
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
std::string resolve_file_url(std::string const& url)
|
||||
{
|
||||
TORRENT_ASSERT(url.substr(0, 7) == "file://");
|
||||
|
@ -283,6 +284,7 @@ namespace libtorrent
|
|||
|
||||
return unescaped;
|
||||
}
|
||||
#endif
|
||||
|
||||
std::string base64encode(const std::string& s)
|
||||
{
|
||||
|
|
|
@ -4605,7 +4605,15 @@ namespace aux {
|
|||
{
|
||||
std::unique_ptr<add_torrent_params> holder(params);
|
||||
|
||||
if (string_begins_no_case("file://", params->url.c_str()) && !params->ti)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (!params->ti && string_begins_no_case("file://", params->url.c_str()))
|
||||
{
|
||||
params->torrent_file_path = resolve_file_url(params->url);
|
||||
params->url.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!params->ti && !params->torrent_file_path.empty())
|
||||
{
|
||||
if (!m_torrent_load_thread)
|
||||
m_torrent_load_thread.reset(new work_thread_t());
|
||||
|
@ -4614,7 +4622,7 @@ namespace aux {
|
|||
{
|
||||
std::unique_ptr<add_torrent_params> holder2(params);
|
||||
error_code ec;
|
||||
params->ti = std::make_shared<torrent_info>(resolve_file_url(params->url), ec);
|
||||
params->ti = std::make_shared<torrent_info>(params->torrent_file_path, ec);
|
||||
this->m_io_service.post(std::bind(&session_impl::on_async_load_torrent
|
||||
, this, params, ec));
|
||||
holder2.release();
|
||||
|
@ -4783,9 +4791,7 @@ namespace aux {
|
|||
}
|
||||
|
||||
std::pair<std::shared_ptr<torrent>, bool>
|
||||
session_impl::add_torrent_impl(
|
||||
add_torrent_params& params
|
||||
, error_code& ec)
|
||||
session_impl::add_torrent_impl(add_torrent_params& params, error_code& ec)
|
||||
{
|
||||
TORRENT_ASSERT(!params.save_path.empty());
|
||||
|
||||
|
@ -4796,14 +4802,23 @@ namespace aux {
|
|||
parse_magnet_uri(params.url, params, ec);
|
||||
if (ec) return std::make_pair(ptr_t(), false);
|
||||
params.url.clear();
|
||||
params.torrent_file_path.clear();
|
||||
}
|
||||
|
||||
if (string_begins_no_case("file://", params.url.c_str()) && !params.ti)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
if (!params.ti && string_begins_no_case("file://", params.url.c_str()))
|
||||
{
|
||||
std::string const filename = resolve_file_url(params.url);
|
||||
auto t = std::make_shared<torrent_info>(filename, std::ref(ec), 0);
|
||||
params.torrent_file_path = resolve_file_url(params.url);
|
||||
params.url.clear();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!params.ti && !params.torrent_file_path.empty())
|
||||
{
|
||||
auto t = std::make_shared<torrent_info>(params.torrent_file_path, std::ref(ec), 0);
|
||||
if (ec) return std::make_pair(ptr_t(), false);
|
||||
params.url.clear();
|
||||
params.torrent_file_path.clear();
|
||||
params.ti = t;
|
||||
}
|
||||
|
||||
|
|
|
@ -261,6 +261,7 @@ TORRENT_TEST(path)
|
|||
convert_path_to_posix(path);
|
||||
TEST_EQUAL(path, "a/b/c");
|
||||
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
// resolve_file_url
|
||||
|
||||
#ifdef TORRENT_WINDOWS
|
||||
|
@ -274,6 +275,7 @@ TORRENT_TEST(path)
|
|||
TEST_EQUAL(resolve_file_url("file:///c/blah/foo/bar"), "/c/blah/foo/bar");
|
||||
TEST_EQUAL(resolve_file_url("file:///c/b%3fah/foo/bar"), "/c/b?ah/foo/bar");
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void test_parse_interface(char const* input
|
||||
|
|
|
@ -414,7 +414,8 @@ TORRENT_TEST(rename_file)
|
|||
TEST_EQUAL(info->files().file_path(file_index_t(0)), "tmp1");
|
||||
}
|
||||
|
||||
TORRENT_TEST(async_load)
|
||||
#ifndef TORRENT_NO_DEPRECATE
|
||||
TORRENT_TEST(async_load_deprecated)
|
||||
{
|
||||
settings_pack pack = settings();
|
||||
lt::session ses(pack);
|
||||
|
@ -437,6 +438,32 @@ TORRENT_TEST(async_load)
|
|||
TEST_CHECK(!ta->error);
|
||||
TEST_CHECK(ta->params.ti->name() == "temp");
|
||||
}
|
||||
#endif
|
||||
|
||||
TORRENT_TEST(async_load)
|
||||
{
|
||||
settings_pack pack = settings();
|
||||
lt::session ses(pack);
|
||||
|
||||
add_torrent_params p;
|
||||
p.flags &= ~add_torrent_params::flag_paused;
|
||||
p.flags &= ~add_torrent_params::flag_auto_managed;
|
||||
std::string dir = parent_path(current_working_directory());
|
||||
|
||||
p.torrent_file_path = combine_path(combine_path(dir, "test_torrents"), "base.torrent");
|
||||
p.save_path = ".";
|
||||
ses.async_add_torrent(p);
|
||||
|
||||
alert const* a = wait_for_alert(ses, add_torrent_alert::alert_type);
|
||||
TEST_CHECK(a);
|
||||
if (a == nullptr) return;
|
||||
auto const* ta = alert_cast<add_torrent_alert const>(a);
|
||||
TEST_CHECK(ta);
|
||||
if (ta == nullptr) return;
|
||||
TEST_CHECK(!ta->error);
|
||||
TEST_CHECK(ta->params.ti->name() == "temp");
|
||||
}
|
||||
|
||||
|
||||
TORRENT_TEST(torrent_status)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue