mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-10-09 07:39:21 +00:00
Compare commits
33 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 109a20c09c | |||
| ac1b2685d5 | |||
| d7b2cfe4f2 | |||
| dcfbf82a38 | |||
| 3ae91b6536 | |||
| af6d8a10ad | |||
| 9066afc063 | |||
| a2fabb10de | |||
| 13e073d9ff | |||
| d73f245692 | |||
| 7db356cae4 | |||
| 8378c0a83a | |||
| 4c6f7afdc7 | |||
| 385e149ccc | |||
| 58e627f2be | |||
| 9ff0cd28d5 | |||
| 5e7dd98c67 | |||
| b24db0eaa5 | |||
| 6fa139f7bf | |||
| 68904ba005 | |||
| b401068246 | |||
| 946a4b5c83 | |||
| a075001a73 | |||
| 781520fef8 | |||
| 224f06fdc2 | |||
| 324811d6f0 | |||
| e51fad5bd2 | |||
| 44bb2d691f | |||
| 161a36dedd | |||
| a69e44a096 | |||
| 4dd8b1fd7e | |||
| b5f6bb5652 | |||
| 3ae6bbc394 |
+6
-4
@@ -1,6 +1,6 @@
|
||||
m4_pattern_allow([PKG_CHECK_EXISTS])
|
||||
|
||||
AC_INIT([rtorrent],[0.16.20],[sundell.software@gmail.com])
|
||||
AC_INIT([rtorrent],[0.16.21],[sundell.software@gmail.com])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
AC_CONFIG_MACRO_DIRS([scripts])
|
||||
@@ -14,7 +14,7 @@ AX_CXX_COMPILE_STDCXX(20, noext, mandatory)
|
||||
|
||||
PKG_PROG_PKG_CONFIG
|
||||
|
||||
AC_DEFINE([API_VERSION], [25], [api version])
|
||||
AC_DEFINE([API_VERSION], [26], [api version])
|
||||
|
||||
RAK_CHECK_CFLAGS
|
||||
RAK_CHECK_CXXFLAGS
|
||||
@@ -22,6 +22,8 @@ RAK_ENABLE_DEBUG
|
||||
RAK_ENABLE_EXTRA_DEBUG
|
||||
RAK_ENABLE_WERROR
|
||||
|
||||
TORRENT_CHECK_ATOMIC
|
||||
|
||||
AC_ARG_ENABLE(execinfo,
|
||||
AS_HELP_STRING([--disable-execinfo],
|
||||
[disable libexecinfo [[default=enable]]]),
|
||||
@@ -47,7 +49,7 @@ fi
|
||||
|
||||
PKG_CHECK_MODULES([CPPUNIT], [cppunit],, [no_cppunit="yes"])
|
||||
PKG_CHECK_MODULES([ZLIB], [zlib])
|
||||
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.20])
|
||||
PKG_CHECK_MODULES([DEPENDENCIES], [libtorrent >= 0.16.21])
|
||||
|
||||
AC_LANG_PUSH(C++)
|
||||
TORRENT_WITH_XMLRPC_C
|
||||
@@ -68,7 +70,7 @@ AC_DEFINE(USER_AGENT, [std::string(PACKAGE "/" VERSION)], Http user agent)
|
||||
|
||||
dnl Only update global build variables immediately before generating the output,
|
||||
dnl to avoid affecting the global build environment for other autoconf checks.
|
||||
LIBS="$PTHREAD_LIBS $CURSES_LIB $CURSES_LIBS $ZLIB_LIBS $DEPENDENCIES_LIBS $LIBS"
|
||||
LIBS="$ATOMIC_LIBS $PTHREAD_LIBS $CURSES_LIB $CURSES_LIBS $ZLIB_LIBS $DEPENDENCIES_LIBS $LIBS"
|
||||
CFLAGS="$CFLAGS $PTHREAD_CFLAGS $CURSES_CFLAGS $ZLIB_CFLAGS $DEPENDENCIES_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS $CURSES_CFLAGS $ZLIB_CFLAGS $DEPENDENCIES_CFLAGS"
|
||||
|
||||
|
||||
+10
-2
@@ -63,6 +63,14 @@
|
||||
#network.local_address.set = 127.0.0.1
|
||||
#network.local_address.set = rakshasa.no
|
||||
|
||||
# The port reported to the tracker, separate for ipv4/ipv6. A value of 0
|
||||
# (the default) falls back to reporting the listening port. network.local_port.set
|
||||
# sets both the ipv4 and ipv6 ports at once.
|
||||
#
|
||||
#network.local_port.set = 6881
|
||||
#network.local_port.ipv4.set = 6881
|
||||
#network.local_port.ipv6.set = 6882
|
||||
|
||||
# The IP address the listening socket and outgoing connections is
|
||||
# bound to.
|
||||
#
|
||||
@@ -71,11 +79,11 @@
|
||||
|
||||
# Port range to use for listening.
|
||||
#
|
||||
#network.port_range.set = 6890-6999
|
||||
#network.listen.port.range.set = 6890-6999
|
||||
|
||||
# Start opening ports at a random position within the port range.
|
||||
#
|
||||
#network.port_random.set = no
|
||||
#network.listen.port.random.set = no
|
||||
|
||||
# Set RPC type
|
||||
#network.rpc.use_xmlrpc.set = true
|
||||
|
||||
@@ -23,8 +23,8 @@ execute.throw = sh, -c, (cat,\
|
||||
"\"",(cfg.watch),"/start\" ")
|
||||
|
||||
# Listening port for incoming peer traffic (fixed; you can also randomize it)
|
||||
network.port_range.set = 50000-50000
|
||||
network.port_random.set = no
|
||||
network.listen.port.range.set = 50000-50000
|
||||
network.listen.port.random.set = no
|
||||
|
||||
# Tracker-less torrent and UDP tracker support
|
||||
# (conservative settings for 'private' trackers, change for 'public')
|
||||
|
||||
@@ -53,8 +53,8 @@ rc.execute.throw(
|
||||
cfg.watch..'/start'}))
|
||||
|
||||
-- Listening port for incoming peer traffic (fixed; you can also randomize it)
|
||||
rc.network.port_range = '50000-50000'
|
||||
rc.network.port_random = false
|
||||
rc.network.listen.port.range = '50000-50000'
|
||||
rc.network.listen.port.random = false
|
||||
|
||||
-- Tracker-less torrent and UDP tracker support
|
||||
-- (conservative settings for 'private' trackers, change for 'public')
|
||||
|
||||
+29
-7
@@ -51,7 +51,7 @@ apply_on_ratio(const torrent::Object& rawArgs) {
|
||||
!(max_ratio > 0 && total_upload * 100 > total_done * max_ratio))
|
||||
continue;
|
||||
|
||||
downloads.push_back(*itr);
|
||||
downloads.push_back(itr->get());
|
||||
}
|
||||
|
||||
auto ratio_command = "group." + group_name + ".ratio.command";
|
||||
@@ -128,7 +128,7 @@ apply_remove_untied() {
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_schedule(const torrent::Object::list_type& args) {
|
||||
apply_schedule(const torrent::Object::list_type& args, bool if_absent) {
|
||||
if (args.size() != 4)
|
||||
throw torrent::input_error("Wrong number of arguments.");
|
||||
|
||||
@@ -138,6 +138,9 @@ apply_schedule(const torrent::Object::list_type& args) {
|
||||
auto& arg2 = (itr++)->as_string();
|
||||
auto& arg3 = (itr++)->as_string();
|
||||
|
||||
if (if_absent && control->command_scheduler()->find(arg1) != control->command_scheduler()->end())
|
||||
return torrent::Object();
|
||||
|
||||
control->command_scheduler()->parse(arg1, arg2, arg3, *itr);
|
||||
|
||||
return torrent::Object();
|
||||
@@ -170,7 +173,7 @@ apply_close_low_diskspace(int64_t arg, uint32_t skip_priority) {
|
||||
|
||||
torrent::FileList::cache_list cache;
|
||||
|
||||
for (auto download : *control->core()->download_list()) {
|
||||
for (const auto& download : *control->core()->download_list()) {
|
||||
if (!download->is_downloading())
|
||||
continue;
|
||||
if (download->priority() >= skip_priority)
|
||||
@@ -237,15 +240,25 @@ d_multicall(const torrent::Object::list_type& args) {
|
||||
|
||||
// Add some pre-parsing of the commands, so we don't spend time
|
||||
// parsing and searching command map for every single call.
|
||||
std::vector<core::Download*> dlist((*view_itr)->begin_visible(), (*view_itr)->end_visible());
|
||||
// Hold a reference to each download so a command that erases one does not
|
||||
// leave the rest of the loop dispatching on freed memory.
|
||||
core::View::base_type dlist((*view_itr)->begin_visible(), (*view_itr)->end_visible());
|
||||
|
||||
torrent::Object resultRaw = torrent::Object::create_list();
|
||||
torrent::Object::list_type& result = resultRaw.as_list();
|
||||
|
||||
for (auto download : dlist) {
|
||||
for (const auto& download : dlist) {
|
||||
if (download.use_count() == 1)
|
||||
continue;
|
||||
|
||||
torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list();
|
||||
|
||||
for (torrent::Object::list_const_iterator cItr = ++args.begin(); cItr != args.end(); cItr++) {
|
||||
// A command may erase this download, which destroys the torrent object it
|
||||
// wraps; the list dropping its reference is what tells us.
|
||||
if (download.use_count() == 1)
|
||||
break;
|
||||
|
||||
auto& cmd = cItr->as_string();
|
||||
row.push_back(rpc::parse_command(rpc::make_target(download), cmd.c_str(), cmd.c_str() + cmd.size()).first);
|
||||
}
|
||||
@@ -268,10 +281,12 @@ d_multicall_filtered(const torrent::Object::list_type& args) {
|
||||
if (view_itr == viewManager->end())
|
||||
throw torrent::input_error("Could not find view '" + arg->as_string() + "'.");
|
||||
|
||||
// Make a filtered copy of the current item list
|
||||
// Make a filtered copy of the current item list, holding a reference to each
|
||||
// download so a command that erases one cannot free it under us.
|
||||
core::View::base_type dlist;
|
||||
(*view_itr)->filter_by(*++arg, dlist);
|
||||
|
||||
|
||||
// Generate result by iterating over all items
|
||||
auto resultRaw = torrent::Object::create_list();
|
||||
auto& result = resultRaw.as_list();
|
||||
@@ -279,11 +294,17 @@ d_multicall_filtered(const torrent::Object::list_type& args) {
|
||||
++arg; // skip to first command
|
||||
|
||||
for (const auto& item : dlist) {
|
||||
if (item.use_count() == 1)
|
||||
continue;
|
||||
|
||||
// Add empty row to result
|
||||
torrent::Object::list_type& row = result.insert(result.end(), torrent::Object::create_list())->as_list();
|
||||
|
||||
// Call the provided commands and assemble their results
|
||||
for (torrent::Object::list_const_iterator command = arg; command != args.end(); command++) {
|
||||
if (item.use_count() == 1)
|
||||
break;
|
||||
|
||||
auto& cmdstr = command->as_string();
|
||||
row.push_back(rpc::parse_command(rpc::make_target(item), cmdstr.c_str(), cmdstr.c_str() + cmdstr.size()).first);
|
||||
}
|
||||
@@ -340,7 +361,8 @@ initialize_command_events() {
|
||||
CMD2_ANY ("close_untied", [](auto, auto) { return apply_close_untied(); });
|
||||
CMD2_ANY ("remove_untied", [](auto, auto) { return apply_remove_untied(); });
|
||||
|
||||
CMD2_ANY_LIST ("schedule", [](auto, auto& args) { return apply_schedule(args); });
|
||||
CMD2_ANY_LIST ("schedule", [](auto, auto& args) { return apply_schedule(args, false); });
|
||||
CMD2_ANY_LIST ("schedule.if_absent", [](auto, auto& args) { return apply_schedule(args, true); });
|
||||
CMD2_ANY_STRING_V("schedule.remove", [](auto, auto& str) { return control->command_scheduler()->erase_str(str); });
|
||||
|
||||
CMD2_ANY_STRING_V("import", [](auto, auto& str) { return apply_import(str); });
|
||||
|
||||
+11
-9
@@ -1,5 +1,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <torrent/download/resource_manager.h>
|
||||
#include <torrent/download/choke_group.h>
|
||||
#include <torrent/download/choke_queue.h>
|
||||
@@ -111,7 +113,7 @@ apply_cg_all_update_balance(bool is_up) {
|
||||
//
|
||||
#else
|
||||
|
||||
std::vector<torrent::choke_group*> cg_list_hack;
|
||||
std::vector<std::unique_ptr<torrent::choke_group>> cg_list_hack;
|
||||
|
||||
int64_t
|
||||
cg_get_index(const torrent::Object& raw_args) {
|
||||
@@ -121,7 +123,7 @@ cg_get_index(const torrent::Object& raw_args) {
|
||||
|
||||
if (arg.is_string()) {
|
||||
if (!rpc::parse_whole_value_nothrow(arg.as_string().c_str(), &index)) {
|
||||
auto itr = std::find_if(cg_list_hack.begin(), cg_list_hack.end(), [&arg](torrent::choke_group* cg) { return arg.as_string() == cg->name(); });
|
||||
auto itr = std::find_if(cg_list_hack.begin(), cg_list_hack.end(), [&arg](const auto& cg) { return arg.as_string() == cg->name(); });
|
||||
|
||||
if (itr == cg_list_hack.end())
|
||||
throw torrent::input_error("Choke group not found.");
|
||||
@@ -149,7 +151,7 @@ cg_get_group(const torrent::Object& raw_args) {
|
||||
if ((size_t)index >= cg_list_hack.size())
|
||||
throw torrent::input_error("Choke group not found.");
|
||||
|
||||
return cg_list_hack.at(index);
|
||||
return cg_list_hack.at(index).get();
|
||||
}
|
||||
|
||||
int64_t cg_d_group(core::Download* download) { return download->group(); }
|
||||
@@ -162,7 +164,7 @@ torrent::Object
|
||||
apply_cg_list() {
|
||||
torrent::Object::list_type result;
|
||||
|
||||
for (auto itr : cg_list_hack)
|
||||
for (const auto& itr : cg_list_hack)
|
||||
result.push_back(itr->name());
|
||||
|
||||
return torrent::Object::from_list(result);
|
||||
@@ -180,10 +182,10 @@ apply_cg_insert(const std::string& arg) {
|
||||
if (rpc::parse_whole_value_nothrow(arg.c_str(), &dummy))
|
||||
throw torrent::input_error("Cannot use a value string as choke group name.");
|
||||
|
||||
if (arg.empty() || std::any_of(cg_list_hack.begin(), cg_list_hack.end(), [&arg](auto cg) { return arg == cg->name(); }))
|
||||
if (arg.empty() || std::any_of(cg_list_hack.begin(), cg_list_hack.end(), [&arg](const auto& cg) { return arg == cg->name(); }))
|
||||
throw torrent::input_error("Duplicate name for choke group.");
|
||||
|
||||
cg_list_hack.push_back(new torrent::choke_group());
|
||||
cg_list_hack.push_back(std::make_unique<torrent::choke_group>());
|
||||
cg_list_hack.back()->set_name(arg);
|
||||
|
||||
cg_list_hack.back()->up_queue()->set_heuristics(torrent::HEURISTICS_UPLOAD_LEECH);
|
||||
@@ -194,7 +196,7 @@ apply_cg_insert(const std::string& arg) {
|
||||
|
||||
torrent::Object
|
||||
apply_cg_index_of(const std::string& arg) {
|
||||
auto itr = std::find_if(cg_list_hack.begin(), cg_list_hack.end(), [&arg](torrent::choke_group* cg) { return arg == cg->name(); });
|
||||
auto itr = std::find_if(cg_list_hack.begin(), cg_list_hack.end(), [&arg](const auto& cg) { return arg == cg->name(); });
|
||||
|
||||
if (itr == cg_list_hack.end())
|
||||
throw torrent::input_error("Choke group not found.");
|
||||
@@ -206,7 +208,7 @@ torrent::Object
|
||||
apply_cg_all_update_balance(bool is_up) {
|
||||
LT_LOG_SUBSYSTEM("apply update balance: hack is_up:%i", (int)is_up);
|
||||
|
||||
for (auto itr : cg_list_hack) {
|
||||
for (const auto& itr : cg_list_hack) {
|
||||
if (is_up)
|
||||
itr->up_queue()->balance();
|
||||
else
|
||||
@@ -346,7 +348,7 @@ initialize_command_groups() {
|
||||
#else
|
||||
apply_cg_insert("default");
|
||||
|
||||
CMD_ANY ("choke_group.size", std::bind(&std::vector<torrent::choke_group*>::size, cg_list_hack));
|
||||
CMD_ANY ("choke_group.size", [](auto, auto) { return (int64_t)cg_list_hack.size(); });
|
||||
CMD_ANY_STRING ("choke_group.index_of", std::bind(&apply_cg_index_of, std::placeholders::_2));
|
||||
#endif
|
||||
|
||||
|
||||
+19
-3
@@ -3,6 +3,7 @@
|
||||
#include <cerrno>
|
||||
#include <fcntl.h>
|
||||
#include <functional>
|
||||
#include <limits>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
@@ -185,6 +186,14 @@ cmd_file_append(const torrent::Object::list_type& args) {
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
checked_socket_value(int64_t value, const char* label) {
|
||||
if (value < 0 || value > std::numeric_limits<uint32_t>::max())
|
||||
throw torrent::input_error(std::string("Invalid ") + label + " value.");
|
||||
|
||||
return static_cast<uint32_t>(value);
|
||||
}
|
||||
|
||||
void
|
||||
initialize_command_local() {
|
||||
core::DownloadList* dList = control->core()->download_list();
|
||||
@@ -241,7 +250,7 @@ initialize_command_local() {
|
||||
|
||||
CMD_ANY ("system.sockets.size", [](auto, auto) { return torrent::runtime::socket_manager()->size(); });
|
||||
CMD_ANY ("system.sockets.max_size", [](auto, auto) { return torrent::runtime::socket_manager()->max_size(); });
|
||||
CMD_ANY_VALUE_V ("system.sockets.max_size.set", [](auto, auto& value) { return torrent::runtime::socket_manager()->set_max_size_and_adjust(value); });
|
||||
CMD_ANY_VALUE_V ("system.sockets.max_size.set", [](auto, auto& value) { return torrent::runtime::socket_manager()->set_max_size_and_adjust(checked_socket_value(value, "socket max size")); });
|
||||
CMD_ANY_V ("system.sockets.adjust_alloc", [](auto, auto) { torrent::runtime::socket_manager()->adjust_allocation(); });
|
||||
CMD_ANY ("system.sockets.reserved_alloc", [](auto, auto) { return torrent::runtime::socket_manager()->reserved_allocation(); });
|
||||
CMD_ANY ("system.sockets.available_alloc", [](auto, auto) { return torrent::runtime::socket_manager()->available_allocation(); });
|
||||
@@ -258,10 +267,12 @@ initialize_command_local() {
|
||||
continue;
|
||||
}
|
||||
|
||||
CMD_ANY (category_name + ".max_alloc.limit", [category](auto, auto) { return torrent::runtime::socket_manager()->category_alloc_limit(category); });
|
||||
CMD_ANY (category_name + ".min_alloc.limit", [category](auto, auto) { return torrent::runtime::socket_manager()->category_alloc_minimum(category); });
|
||||
CMD_ANY (category_name + ".min_alloc", [category](auto, auto) { return torrent::runtime::socket_manager()->category_min_allocation(category); });
|
||||
CMD_ANY (category_name + ".max_alloc", [category](auto, auto) { return torrent::runtime::socket_manager()->category_max_allocation(category); });
|
||||
CMD_ANY_VALUE_V(category_name + ".min_alloc.set", [category](auto, auto& value) { torrent::runtime::socket_manager()->set_category_min_allocation(category, value); });
|
||||
CMD_ANY_VALUE_V(category_name + ".max_alloc.set", [category](auto, auto& value) { torrent::runtime::socket_manager()->set_category_max_allocation(category, value); });
|
||||
CMD_ANY_VALUE_V(category_name + ".min_alloc.set", [category](auto, auto& value) { torrent::runtime::socket_manager()->set_category_min_allocation(category, checked_socket_value(value, "socket min alloc")); });
|
||||
CMD_ANY_VALUE_V(category_name + ".max_alloc.set", [category](auto, auto& value) { torrent::runtime::socket_manager()->set_category_max_allocation(category, checked_socket_value(value, "socket max alloc")); });
|
||||
}
|
||||
|
||||
CMD_ANY ("pieces.sync.always_safe", [](auto, auto) { return torrent::runtime::memory_manager()->safe_sync(); });
|
||||
@@ -350,6 +361,9 @@ initialize_command_local() {
|
||||
rpc::rpc.mark_safe("system.api_version");
|
||||
rpc::rpc.mark_safe("system.client_version");
|
||||
rpc::rpc.mark_safe("system.library_version");
|
||||
rpc::rpc.mark_safe("system.time");
|
||||
rpc::rpc.mark_safe("system.time_seconds");
|
||||
rpc::rpc.mark_safe("system.time_usec");
|
||||
rpc::rpc.mark_safe("system.file.max_size");
|
||||
rpc::rpc.mark_safe("system.file.split_size");
|
||||
rpc::rpc.mark_safe("system.file.split_suffix");
|
||||
@@ -370,6 +384,8 @@ initialize_command_local() {
|
||||
continue;
|
||||
}
|
||||
|
||||
rpc::rpc.mark_safe(category_name + ".max_alloc.limit");
|
||||
rpc::rpc.mark_safe(category_name + ".min_alloc.limit");
|
||||
rpc::rpc.mark_safe(category_name + ".min_alloc");
|
||||
rpc::rpc.mark_safe(category_name + ".max_alloc");
|
||||
}
|
||||
|
||||
@@ -54,6 +54,14 @@ set_listen_port_range(const std::string& arg) {
|
||||
torrent::runtime::client_config()->set_listen_port_range(port_first, port_last);
|
||||
}
|
||||
|
||||
uint16_t
|
||||
checked_local_port_value(int64_t value, const char* label) {
|
||||
if (value < 0 || value > 65535)
|
||||
throw torrent::input_error(std::string("Invalid ") + label + " port number.");
|
||||
|
||||
return static_cast<uint16_t>(value);
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
get_encryption() {
|
||||
auto encryption_modes = torrent::runtime::network_config()->encryption_modes();
|
||||
@@ -379,6 +387,13 @@ initialize_command_network() {
|
||||
CMD_ANY ("network.local_address.ipv6", [nw_config](auto, auto) { return nw_config->local_inet6_address_str(); });
|
||||
CMD_ANY_STRING_V("network.local_address.ipv6.set", [nw_config](auto, auto& str) { return nw_config->set_local_inet6_address_str(str); });
|
||||
|
||||
CMD_ANY ("network.local_port", [nw_config](auto, auto) { return nw_config->local_port_best_match(); });
|
||||
CMD_ANY_VALUE_V ("network.local_port.set", [nw_config](auto, auto& value) { return nw_config->set_local_port(checked_local_port_value(value, "local")); });
|
||||
CMD_ANY ("network.local_port.ipv4", [nw_config](auto, auto) { return nw_config->local_inet_port(); });
|
||||
CMD_ANY_VALUE_V ("network.local_port.ipv4.set", [nw_config](auto, auto& value) { return nw_config->set_local_inet_port(checked_local_port_value(value, "local ipv4")); });
|
||||
CMD_ANY ("network.local_port.ipv6", [nw_config](auto, auto) { return nw_config->local_inet6_port(); });
|
||||
CMD_ANY_VALUE_V ("network.local_port.ipv6.set", [nw_config](auto, auto& value) { return nw_config->set_local_inet6_port(checked_local_port_value(value, "local ipv6")); });
|
||||
|
||||
CMD_ANY ("network.proxy.global", [](auto, auto) { return torrent::runtime::proxy_manager()->proxy_url(); });
|
||||
CMD_ANY_STRING_V("network.proxy.global.set", [](auto, auto& str) { return torrent::runtime::proxy_manager()->set_proxy_url(str); });
|
||||
CMD_ANY ("network.proxy.http", [](auto, auto) { return torrent::runtime::proxy_manager()->http_proxy_url(); });
|
||||
@@ -437,6 +452,9 @@ initialize_command_network() {
|
||||
rpc::rpc.mark_safe("network.receive_buffer.size");
|
||||
rpc::rpc.mark_safe("network.bind_address");
|
||||
rpc::rpc.mark_safe("network.local_address");
|
||||
rpc::rpc.mark_safe("network.local_port");
|
||||
rpc::rpc.mark_safe("network.local_port.ipv4");
|
||||
rpc::rpc.mark_safe("network.local_port.ipv6");
|
||||
rpc::rpc.mark_safe("network.xmlrpc.size_limit");
|
||||
rpc::rpc.mark_safe("network.open_sockets");
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
|
||||
namespace {
|
||||
|
||||
constexpr int64_t max_string_pad_size = 1 << 14;
|
||||
|
||||
const std::string whitespace_characters = " \t\n\r\f\v";
|
||||
|
||||
// The byte offset of every utf-8 character in 'text', terminated by the offset
|
||||
@@ -249,10 +251,14 @@ apply_string_pad(const char* name, const torrent::Object::list_type& args, bool
|
||||
if (pad_size <= text_length || padding.empty())
|
||||
return text;
|
||||
|
||||
if (pad_size - text_length > max_string_pad_size)
|
||||
throw torrent::input_error(std::string(name) + ": padding is too large.");
|
||||
|
||||
auto padding_offsets = utf8_offsets(padding);
|
||||
auto padding_length = static_cast<int64_t>(padding_offsets.size() - 1);
|
||||
|
||||
std::string result;
|
||||
result.reserve(pad_size - text_length);
|
||||
|
||||
for (int64_t i = 0; i < pad_size - text_length; i++) {
|
||||
auto index = static_cast<size_t>(i % padding_length);
|
||||
|
||||
@@ -68,11 +68,11 @@ apply_dht_add_node(const std::string& arg) {
|
||||
torrent::Object
|
||||
apply_enable_trackers(int64_t arg) {
|
||||
if (arg == 0) {
|
||||
for (auto download : *control->core()->download_list())
|
||||
for (const auto& download : *control->core()->download_list())
|
||||
download->tracker_controller().for_each([](auto& tracker) { tracker.disable(); });
|
||||
|
||||
} else {
|
||||
for (auto download : *control->core()->download_list())
|
||||
for (const auto& download : *control->core()->download_list())
|
||||
download->tracker_controller().for_each([](auto& tracker) { tracker.enable(); });
|
||||
}
|
||||
|
||||
|
||||
+11
-3
@@ -3,6 +3,7 @@
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <ctime>
|
||||
#include <limits>
|
||||
#include <regex>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
@@ -407,8 +408,9 @@ apply_to_time(const torrent::Object& rawArgs, int flags) {
|
||||
torrent::Object
|
||||
apply_to_elapsed_time(const torrent::Object& rawArgs) {
|
||||
auto cached_seconds = torrent::this_thread::cached_seconds().count();
|
||||
auto value = rawArgs.as_value();
|
||||
|
||||
uint64_t arg = cached_seconds - rawArgs.as_value();
|
||||
uint64_t arg = value >= 0 && value <= cached_seconds ? cached_seconds - value : 0;
|
||||
|
||||
char buffer[48];
|
||||
snprintf(buffer, 48, "%2d:%02d:%02d", (int)(arg / 3600), (int)((arg / 60) % 60), (int)(arg % 60));
|
||||
@@ -674,8 +676,13 @@ apply_math_basic(const char* name, Comp op, const torrent::Object::list_type& ar
|
||||
throw torrent::input_error(std::string(name) + ": Wrong argument type");
|
||||
}
|
||||
|
||||
if (divides && !rhs && itr != args.begin())
|
||||
throw torrent::input_error(std::string(name) + ": Division by zero!");
|
||||
if (divides && itr != args.begin()) {
|
||||
if (rhs == 0)
|
||||
throw torrent::input_error(std::string(name) + ": Division by zero!");
|
||||
|
||||
if (val == std::numeric_limits<int64_t>::min() && rhs == -1)
|
||||
throw torrent::input_error(std::string(name) + ": Division overflow!");
|
||||
}
|
||||
|
||||
val = itr == args.begin() ? rhs : op(val, rhs);
|
||||
|
||||
@@ -916,6 +923,7 @@ initialize_command_ui() {
|
||||
|
||||
rpc::rpc.mark_safe("view.set_visible");
|
||||
rpc::rpc.mark_safe("view.set_not_visible");
|
||||
rpc::rpc.mark_safe("view.list");
|
||||
|
||||
rpc::rpc.mark_safe("cat");
|
||||
rpc::rpc.mark_safe("if");
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef RTORRENT_CORE_DOWNLOAD_H
|
||||
#define RTORRENT_CORE_DOWNLOAD_H
|
||||
|
||||
#include <memory>
|
||||
#include <torrent/common.h>
|
||||
#include <torrent/download.h>
|
||||
#include <torrent/download_info.h>
|
||||
|
||||
@@ -35,8 +35,10 @@ is_network_uri(const std::string& uri) {
|
||||
std::strncmp(uri.c_str(), "ftp://", 6) == 0;
|
||||
}
|
||||
|
||||
static constexpr const char* session_invalid_message = "Session data is invalid, ignoring it";
|
||||
|
||||
static std::unique_ptr<torrent::Object>
|
||||
download_factory_load_stream(const char* filename) {
|
||||
download_factory_load_stream(const char* filename, bool* is_invalid) {
|
||||
std::fstream stream(filename, std::ios::in | std::ios::binary);
|
||||
|
||||
if (!stream.is_open())
|
||||
@@ -45,8 +47,10 @@ download_factory_load_stream(const char* filename) {
|
||||
auto obj = std::make_unique<torrent::Object>();
|
||||
stream >> *obj;
|
||||
|
||||
if (!stream.good())
|
||||
if (!stream.good() || !obj->is_map()) {
|
||||
*is_invalid = true;
|
||||
return std::unique_ptr<torrent::Object>();
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
@@ -161,8 +165,13 @@ DownloadFactory::receive_commit() {
|
||||
|
||||
void
|
||||
DownloadFactory::receive_success() {
|
||||
auto rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str());
|
||||
auto libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str());
|
||||
bool session_invalid = false;
|
||||
|
||||
auto rtorrent_object = download_factory_load_stream((expand_path(m_uri) + ".rtorrent").c_str(), &session_invalid);
|
||||
auto libtorrent_resume_object = download_factory_load_stream((expand_path(m_uri) + ".libtorrent_resume").c_str(), &session_invalid);
|
||||
|
||||
if (session_invalid)
|
||||
lt_log_print(torrent::LOG_ERROR, "%s: %s", session_invalid_message, m_uri.c_str());
|
||||
|
||||
uint32_t tracker_key;
|
||||
|
||||
@@ -184,6 +193,14 @@ DownloadFactory::receive_success() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (session_invalid) {
|
||||
download->set_hash_failed(true);
|
||||
download->set_message(session_invalid_message);
|
||||
|
||||
if (m_printLog)
|
||||
m_manager->push_log_std(std::string(session_invalid_message) + ": \"" + m_uri + "\"");
|
||||
}
|
||||
|
||||
torrent::Object* root = download->bencode();
|
||||
|
||||
if (download->download()->info()->is_meta_download()) {
|
||||
@@ -274,9 +291,22 @@ DownloadFactory::receive_success() {
|
||||
|
||||
rpc::call_command("d.peer_exchange.set", torrent::runtime::client_config()->is_pex_enabled(), rpc::make_target(download));
|
||||
|
||||
torrent::resume_load_addresses(*download->download(), resumeObject);
|
||||
torrent::resume_load_file_priorities(*download->download(), resumeObject);
|
||||
torrent::resume_load_tracker_settings(*download->download(), resumeObject);
|
||||
try {
|
||||
torrent::resume_load_addresses(*download->download(), resumeObject);
|
||||
torrent::resume_load_file_priorities(*download->download(), resumeObject);
|
||||
torrent::resume_load_tracker_settings(*download->download(), resumeObject);
|
||||
|
||||
} catch (const torrent::input_error& e) {
|
||||
std::string msg = std::string(session_invalid_message) + ": " + e.what();
|
||||
|
||||
lt_log_print(torrent::LOG_ERROR, "%s: %s", msg.c_str(), m_uri.c_str());
|
||||
|
||||
if (m_printLog)
|
||||
m_manager->push_log_std(msg + ": \"" + m_uri + "\"");
|
||||
|
||||
download->set_hash_failed(true);
|
||||
download->set_message(msg);
|
||||
}
|
||||
|
||||
// The action of inserting might cause the torrent to be
|
||||
// opened/started or such. Figure out a nicer way of handling this.
|
||||
|
||||
+10
-12
@@ -37,7 +37,7 @@ namespace core {
|
||||
inline void
|
||||
DownloadList::check_contains([[maybe_unused]] Download* d) {
|
||||
#ifdef USE_EXTRA_DEBUG
|
||||
if (std::find(begin(), end(), d) == end())
|
||||
if (std::find_if(begin(), end(), [d](const auto& entry) { return entry.get() == d; }) == end())
|
||||
throw torrent::internal_error("DownloadList::check_contains(...) failed.");
|
||||
#endif
|
||||
}
|
||||
@@ -54,7 +54,6 @@ DownloadList::clear() {
|
||||
base_type::pop_back();
|
||||
|
||||
torrent::download_remove(*download->download());
|
||||
delete download;
|
||||
|
||||
} catch (torrent::internal_error& e) {
|
||||
lt_log_print(torrent::LOG_ERROR, "DownloadList::clear() failed to close or remove download: %s", e.what());
|
||||
@@ -70,7 +69,7 @@ DownloadList::clear() {
|
||||
void
|
||||
DownloadList::session_save() {
|
||||
for (auto& download : *this)
|
||||
session_thread::manager()->save_resume_download(download);
|
||||
session_thread::manager()->save_resume_download(download.get());
|
||||
|
||||
control->dht_manager()->save_dht_cache();
|
||||
control->ui()->save_input_history();
|
||||
@@ -78,7 +77,7 @@ DownloadList::session_save() {
|
||||
|
||||
DownloadList::iterator
|
||||
DownloadList::find(const torrent::HashString& hash) {
|
||||
return std::find_if(begin(), end(), [hash](Download* d) { return hash == d->info()->hash(); });
|
||||
return std::find_if(begin(), end(), [hash](const auto& d) { return hash == d->info()->hash(); });
|
||||
}
|
||||
|
||||
DownloadList::iterator
|
||||
@@ -91,14 +90,14 @@ DownloadList::find_hex(const char* hash) {
|
||||
if (torrent::utils::transform_from_hex(hash, hash + 40, key) != key.end())
|
||||
return end();
|
||||
|
||||
return std::find_if(begin(), end(), [key](Download* d) { return key == d->info()->hash(); });
|
||||
return std::find_if(begin(), end(), [key](const auto& d) { return key == d->info()->hash(); });
|
||||
}
|
||||
|
||||
Download*
|
||||
DownloadList::find_hex_ptr(const char* hash) {
|
||||
iterator itr = find_hex(hash);
|
||||
|
||||
return itr != end() ? *itr : NULL;
|
||||
return itr != end() ? itr->get() : NULL;
|
||||
}
|
||||
|
||||
Download*
|
||||
@@ -159,7 +158,7 @@ DownloadList::create(std::istream* str, uint32_t tracker_key, bool printLog) {
|
||||
|
||||
DownloadList::iterator
|
||||
DownloadList::insert(Download* download) {
|
||||
iterator itr = base_type::insert(end(), download);
|
||||
iterator itr = base_type::insert(end(), std::shared_ptr<Download>(download));
|
||||
|
||||
lt_log_print_info(torrent::LOG_TORRENT_INFO, download->info(), "download_list", "Inserting download.");
|
||||
|
||||
@@ -170,7 +169,7 @@ DownloadList::insert(Download* download) {
|
||||
// This needs to be separated into two different calls to ensure
|
||||
// the download remains in the view.
|
||||
for (auto v : *control->view_manager())
|
||||
v->insert(download);
|
||||
v->insert(*itr);
|
||||
for (auto v : *control->view_manager())
|
||||
v->filter_download(download);
|
||||
|
||||
@@ -187,7 +186,7 @@ DownloadList::insert(Download* download) {
|
||||
|
||||
void
|
||||
DownloadList::erase_ptr(Download* download) {
|
||||
erase(std::find(begin(), end(), download));
|
||||
erase(std::find_if(begin(), end(), [download](const auto& entry) { return entry.get() == download; }));
|
||||
}
|
||||
|
||||
DownloadList::iterator
|
||||
@@ -201,15 +200,14 @@ DownloadList::erase(iterator itr) {
|
||||
(*itr)->set_hash_failed(true);
|
||||
|
||||
close(*itr);
|
||||
session_thread::manager()->remove_download(*itr);
|
||||
session_thread::manager()->remove_download(itr->get());
|
||||
|
||||
DL_TRIGGER_EVENT(*itr, "event.download.erased");
|
||||
|
||||
for (auto v : *control->view_manager())
|
||||
v->erase(*itr);
|
||||
v->erase(itr->get());
|
||||
|
||||
torrent::download_remove(*(*itr)->download());
|
||||
delete *itr;
|
||||
|
||||
return base_type::erase(itr);
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <iosfwd>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace torrent {
|
||||
@@ -20,9 +21,9 @@ class Download;
|
||||
//
|
||||
// Fix apply_on_ratio if the base_type is changed.
|
||||
|
||||
class DownloadList : private std::list<Download*> {
|
||||
class DownloadList : private std::list<std::shared_ptr<Download>> {
|
||||
public:
|
||||
typedef std::list<Download*> base_type;
|
||||
typedef std::list<std::shared_ptr<Download>> base_type;
|
||||
|
||||
using base_type::iterator;
|
||||
using base_type::const_iterator;
|
||||
@@ -64,6 +65,14 @@ public:
|
||||
bool open(Download* d);
|
||||
void open_throw(Download* d);
|
||||
|
||||
// Overloads for the list's own entries, so callers iterating it do not need
|
||||
// to unwrap.
|
||||
bool open(const value_type& d) { return open(d.get()); }
|
||||
void close(const value_type& d) { close(d.get()); }
|
||||
void close_quick(const value_type& d) { close_quick(d.get()); }
|
||||
void pause(const value_type& d) { pause(d.get()); }
|
||||
void resume(const value_type& d) { resume(d.get()); }
|
||||
|
||||
void close(Download* d);
|
||||
void close_directly(Download* d);
|
||||
void close_quick(Download* d);
|
||||
|
||||
+4
-4
@@ -154,10 +154,10 @@ Manager::cleanup() {
|
||||
void
|
||||
Manager::shutdown(bool force) {
|
||||
if (!force) {
|
||||
for (auto d : *m_download_list)
|
||||
m_download_list->pause_default(d);
|
||||
for (const auto& d : *m_download_list)
|
||||
m_download_list->pause_default(d.get());
|
||||
} else {
|
||||
for (auto d : *m_download_list)
|
||||
for (const auto& d : *m_download_list)
|
||||
m_download_list->close_quick(d);
|
||||
}
|
||||
}
|
||||
@@ -405,7 +405,7 @@ Manager::receive_hashing_changed() {
|
||||
continue;
|
||||
|
||||
try {
|
||||
m_download_list->open_throw(*itr);
|
||||
m_download_list->open_throw(itr->get());
|
||||
|
||||
// Since the bitfield is allocated on loading of resume load or
|
||||
// hash start, and unallocated on close, we know that if it it
|
||||
|
||||
+40
-16
@@ -16,10 +16,20 @@
|
||||
namespace core {
|
||||
|
||||
// Also add focus thingie here?
|
||||
// Matches the list entry that owns a given download.
|
||||
inline auto
|
||||
entry_is(Download* download) {
|
||||
return [download](const std::shared_ptr<Download>& entry) { return entry.get() == download; };
|
||||
}
|
||||
|
||||
struct view_downloads_compare {
|
||||
view_downloads_compare(const torrent::Object& cmd) :
|
||||
m_command(cmd) {}
|
||||
|
||||
bool operator()(const std::shared_ptr<Download>& d1, const std::shared_ptr<Download>& d2) const {
|
||||
return (*this)(d1.get(), d2.get());
|
||||
}
|
||||
|
||||
bool operator()(Download* d1, Download* d2) const {
|
||||
try {
|
||||
if (m_command.is_empty())
|
||||
@@ -54,6 +64,10 @@ struct view_downloads_filter {
|
||||
view_downloads_filter(const torrent::Object& cmd, const torrent::Object& cmd2) :
|
||||
m_command(cmd), m_command2(cmd2) {}
|
||||
|
||||
bool operator()(const std::shared_ptr<Download>& d1) const {
|
||||
return (*this)(d1.get());
|
||||
}
|
||||
|
||||
bool operator()(Download* d1) const {
|
||||
return this->evalCmd(m_command, d1) && this->evalCmd(m_command2, d1);
|
||||
}
|
||||
@@ -152,7 +166,7 @@ View::initialize(const std::string& name) {
|
||||
|
||||
void
|
||||
View::erase(Download* download) {
|
||||
iterator itr = std::find(base_type::begin(), base_type::end(), download);
|
||||
iterator itr = std::find_if(base_type::begin(), base_type::end(), entry_is(download));
|
||||
|
||||
if (itr >= end_visible()) {
|
||||
erase_internal(itr);
|
||||
@@ -165,22 +179,24 @@ View::erase(Download* download) {
|
||||
|
||||
void
|
||||
View::set_visible(Download* download) {
|
||||
iterator itr = std::find(begin_filtered(), end_filtered(), download);
|
||||
iterator itr = std::find_if(begin_filtered(), end_filtered(), entry_is(download));
|
||||
|
||||
if (itr == end_filtered())
|
||||
return;
|
||||
|
||||
// Don't optimize erase since we want to keep the order of the
|
||||
// non-visible elements.
|
||||
auto entry = *itr;
|
||||
|
||||
base_type::erase(itr);
|
||||
insert_visible(download);
|
||||
insert_visible(entry);
|
||||
|
||||
rpc::call_object_nothrow(m_event_added, rpc::make_target(download));
|
||||
}
|
||||
|
||||
void
|
||||
View::set_not_visible(Download* download) {
|
||||
iterator itr = std::find(begin_visible(), end_visible(), download);
|
||||
iterator itr = std::find_if(begin_visible(), end_visible(), entry_is(download));
|
||||
|
||||
if (itr == end_visible())
|
||||
return;
|
||||
@@ -190,8 +206,10 @@ View::set_not_visible(Download* download) {
|
||||
|
||||
// Don't optimize erase since we want to keep the order of the
|
||||
// non-visible elements.
|
||||
auto entry = *itr;
|
||||
|
||||
base_type::erase(itr);
|
||||
base_type::push_back(download);
|
||||
base_type::push_back(entry);
|
||||
|
||||
rpc::call_object_nothrow(m_event_removed, rpc::make_target(download));
|
||||
}
|
||||
@@ -241,12 +259,12 @@ View::prev_focus(unsigned int i) {
|
||||
|
||||
void
|
||||
View::sort() {
|
||||
Download* curFocus = focus() != end_visible() ? *focus() : NULL;
|
||||
Download* curFocus = focus() != end_visible() ? focus()->get() : NULL;
|
||||
|
||||
// Don't go randomly switching around equivalent elements.
|
||||
std::stable_sort(begin(), end_visible(), view_downloads_compare(m_sortCurrent));
|
||||
|
||||
m_focus = position(std::find(begin(), end_visible(), curFocus));
|
||||
m_focus = position(std::find_if(begin(), end_visible(), entry_is(curFocus)));
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
@@ -280,10 +298,10 @@ View::filter() {
|
||||
// set the elements to NULL as we trigger commands on them. Or
|
||||
// perhaps always clear them, thus not throwing anything.
|
||||
if (!m_event_removed.is_empty())
|
||||
std::for_each(changed.begin(), splitChanged, std::bind(&rpc::call_object_d_nothrow, m_event_removed, std::placeholders::_1));
|
||||
std::for_each(changed.begin(), splitChanged, [this](const auto& d) { rpc::call_object_d_nothrow(m_event_removed, d.get()); });
|
||||
|
||||
if (!m_event_added.is_empty())
|
||||
std::for_each(changed.begin(), splitChanged, std::bind(&rpc::call_object_d_nothrow, m_event_added, std::placeholders::_1));
|
||||
std::for_each(changed.begin(), splitChanged, [this](const auto& d) { rpc::call_object_d_nothrow(m_event_added, d.get()); });
|
||||
|
||||
emit_changed();
|
||||
}
|
||||
@@ -294,21 +312,23 @@ View::filter_by(const torrent::Object& condition, View::base_type& result) {
|
||||
view_downloads_filter matches = view_downloads_filter(condition, m_temp_filter);
|
||||
|
||||
for (iterator itr = begin_visible(); itr != end_visible(); ++itr)
|
||||
if (matches(*itr))
|
||||
if (matches(itr->get()))
|
||||
result.push_back(*itr);
|
||||
}
|
||||
|
||||
void
|
||||
View::filter_download(core::Download* download) {
|
||||
iterator itr = std::find(base_type::begin(), base_type::end(), download);
|
||||
iterator itr = std::find_if(base_type::begin(), base_type::end(), entry_is(download));
|
||||
|
||||
if (itr == base_type::end())
|
||||
throw torrent::internal_error("View::filter_download(...) could not find download.");
|
||||
|
||||
if (view_downloads_filter(m_filter, m_temp_filter)(download)) {
|
||||
if (itr >= end_visible()) {
|
||||
auto entry = *itr;
|
||||
|
||||
erase_internal(itr);
|
||||
insert_visible(download);
|
||||
insert_visible(entry);
|
||||
|
||||
rpc::call_object_nothrow(m_event_added, rpc::make_target(download));
|
||||
|
||||
@@ -317,16 +337,20 @@ View::filter_download(core::Download* download) {
|
||||
// already visible.
|
||||
//
|
||||
// Consider removing this.
|
||||
auto entry = *itr;
|
||||
|
||||
erase_internal(itr);
|
||||
insert_visible(download);
|
||||
insert_visible(entry);
|
||||
}
|
||||
|
||||
} else {
|
||||
if (itr >= end_visible())
|
||||
return;
|
||||
|
||||
auto entry = *itr;
|
||||
|
||||
erase_internal(itr);
|
||||
base_type::push_back(download);
|
||||
base_type::push_back(entry);
|
||||
|
||||
rpc::call_object_nothrow(m_event_removed, rpc::make_target(download));
|
||||
}
|
||||
@@ -345,8 +369,8 @@ View::clear_filter_on() {
|
||||
}
|
||||
|
||||
inline void
|
||||
View::insert_visible(Download* d) {
|
||||
auto itr = std::find_if(begin_visible(), end_visible(), [this, d](auto d2) { return view_downloads_compare(m_sortNew)(d, d2); });
|
||||
View::insert_visible(const std::shared_ptr<Download>& d) {
|
||||
auto itr = std::find_if(begin_visible(), end_visible(), [this, &d](const auto& d2) { return view_downloads_compare(m_sortNew)(d.get(), d2.get()); });
|
||||
|
||||
m_size++;
|
||||
m_focus += (m_focus >= position(itr));
|
||||
|
||||
+6
-5
@@ -15,6 +15,7 @@
|
||||
|
||||
#include <functional>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <torrent/object.h>
|
||||
@@ -26,9 +27,9 @@ namespace core {
|
||||
|
||||
class Download;
|
||||
|
||||
class View : private std::vector<Download*> {
|
||||
class View : private std::vector<std::shared_ptr<Download>> {
|
||||
public:
|
||||
typedef std::vector<Download*> base_type;
|
||||
typedef std::vector<std::shared_ptr<Download>> base_type;
|
||||
typedef std::function<void()> slot_void;
|
||||
typedef std::list<slot_void> signal_void;
|
||||
|
||||
@@ -72,7 +73,7 @@ public:
|
||||
emit_changed();
|
||||
}
|
||||
|
||||
void insert(Download* download) { base_type::push_back(download); }
|
||||
void insert(const std::shared_ptr<Download>& download) { base_type::push_back(download); }
|
||||
void erase(Download* download);
|
||||
|
||||
void set_visible(Download* download);
|
||||
@@ -124,9 +125,9 @@ private:
|
||||
View(const View&);
|
||||
void operator=(const View&);
|
||||
|
||||
void push_back(Download* d) { base_type::push_back(d); }
|
||||
void push_back(const std::shared_ptr<Download>& d) { base_type::push_back(d); }
|
||||
|
||||
inline void insert_visible(Download* d);
|
||||
inline void insert_visible(const std::shared_ptr<Download>& d);
|
||||
inline void erase_internal(iterator itr);
|
||||
|
||||
void emit_changed();
|
||||
|
||||
@@ -345,7 +345,7 @@ print_status_info(char* first, char* last) {
|
||||
if (!torrent::up_throttle_global()->is_throttled()) {
|
||||
first = print_buffer(first, last, "[Throttle off");
|
||||
} else {
|
||||
first = print_buffer(first, last, "[Throttle %3i", torrent::up_throttle_global()->max_rate() / 1024);
|
||||
first = print_buffer(first, last, "[Throttle %3i", (int)(torrent::up_throttle_global()->max_rate() / 1024));
|
||||
|
||||
if (!throttle_up_names.empty())
|
||||
first = print_status_throttle_limit(first, last, true, throttle_up_names);
|
||||
@@ -354,7 +354,7 @@ print_status_info(char* first, char* last) {
|
||||
if (!torrent::down_throttle_global()->is_throttled()) {
|
||||
first = print_buffer(first, last, " / off KB]");
|
||||
} else {
|
||||
first = print_buffer(first, last, " / %3i", torrent::down_throttle_global()->max_rate() / 1024);
|
||||
first = print_buffer(first, last, " / %3i", (int)(torrent::down_throttle_global()->max_rate() / 1024));
|
||||
|
||||
if (!throttle_down_names.empty())
|
||||
first = print_status_throttle_limit(first, last, false, throttle_down_names);
|
||||
|
||||
@@ -37,7 +37,7 @@ WindowDownloadList::set_view(core::View* l) {
|
||||
// Return a pair of ints, representing a) the ncurses attributes and b) the ncurses color pair ID to use
|
||||
std::pair<int, int>
|
||||
WindowDownloadList::get_attr_color(core::View::iterator selected) {
|
||||
core::Download* item = *selected;
|
||||
core::Download* item = selected->get();
|
||||
unsigned long focus_attr = selected == m_view->focus() ? m_canvas->attr_map().at(RCOLOR_FOCUS) : 0;
|
||||
int offset = (((selected - m_view->begin_visible()) & 1) + 1) * RCOLOR_MAX; // Determine the even/odd offset for the color pair
|
||||
bool active = item->is_open() && item->is_active();
|
||||
@@ -132,15 +132,15 @@ WindowDownloadList::redraw() {
|
||||
ColorKind focus_color = is_focused ? RCOLOR_FOCUS : RCOLOR_LABEL;
|
||||
auto attr_color = get_attr_color(range.first);
|
||||
|
||||
print_download_title(buffer.data(), last, *range.first);
|
||||
print_download_title(buffer.data(), last, range.first->get());
|
||||
m_canvas->print(0, pos, "%c %s", focus_char, buffer.data());
|
||||
m_canvas->set_attr(2, pos++, -1, attr_color.first, attr_color.second);
|
||||
|
||||
print_download_info_full(buffer.data(), last, *range.first);
|
||||
print_download_info_full(buffer.data(), last, range.first->get());
|
||||
m_canvas->print(0, pos, "%c %s", focus_char, buffer.data());
|
||||
m_canvas->set_attr(2, pos++, -1, focus_color);
|
||||
|
||||
print_download_status(buffer.data(), last, *range.first);
|
||||
print_download_status(buffer.data(), last, range.first->get());
|
||||
m_canvas->print(0, pos, "%c %s", focus_char, buffer.data());
|
||||
m_canvas->set_attr(2, pos++, -1, focus_color);
|
||||
|
||||
@@ -152,7 +152,7 @@ WindowDownloadList::redraw() {
|
||||
char focus_char = range.first == m_view->focus() ? '*' : ' ';
|
||||
auto attr_color = get_attr_color(range.first);
|
||||
|
||||
print_download_info_compact(buffer.data(), last, *range.first);
|
||||
print_download_info_compact(buffer.data(), last, range.first->get());
|
||||
m_canvas->print(0, pos, "%c %s", focus_char, buffer.data());
|
||||
m_canvas->set_attr(2, pos++, -1, attr_color.first, attr_color.second);
|
||||
|
||||
|
||||
+9
-1
@@ -1,5 +1,7 @@
|
||||
#include "config.h"
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include "core/download.h"
|
||||
#include "parse.h"
|
||||
|
||||
@@ -41,7 +43,13 @@ command_base_call_value_base(command_base* command_raw, target_type target, cons
|
||||
return command_base::_call<typename command_value_function<T>::type, T>(command_raw, target, val);
|
||||
}
|
||||
|
||||
return command_base::_call<typename command_value_function<T>::type, T>(command_raw, target, unit * arg.as_value());
|
||||
auto value = arg.as_value();
|
||||
|
||||
if (value > std::numeric_limits<int64_t>::max() / unit ||
|
||||
value < std::numeric_limits<int64_t>::min() / unit)
|
||||
throw torrent::input_error("Value out of range.");
|
||||
|
||||
return command_base::_call<typename command_value_function<T>::type, T>(command_raw, target, unit * value);
|
||||
}
|
||||
|
||||
template <typename T> const torrent::Object
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef RTORRENT_RPC_COMMAND_MAP_H
|
||||
#define RTORRENT_RPC_COMMAND_MAP_H
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
@@ -104,6 +105,10 @@ inline target_type make_target(T target) {
|
||||
return target_type((int)target_type_id<T>::value, target);
|
||||
}
|
||||
|
||||
inline target_type make_target(const std::shared_ptr<core::Download>& target) {
|
||||
return make_target(target.get());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline target_type make_target_pair(T target1, T target2) {
|
||||
return target_type((int)target_type_id<T, T>::value, target1, target2);
|
||||
|
||||
+14
-9
@@ -26,10 +26,12 @@ constexpr int JSONRPC_METHOD_NOT_FOUND_ERROR = -32601;
|
||||
constexpr int JSONRPC_INVALID_PARAMS_ERROR = -32602;
|
||||
constexpr int JSONRPC_INTERNAL_ERROR = -32000;
|
||||
|
||||
constexpr uint32_t max_json_depth = 1024;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
torrent::Object
|
||||
json_to_object(const json& value) {
|
||||
json_to_object(const json& value, uint32_t depth = 0) {
|
||||
switch (value.type()) {
|
||||
case json::value_t::number_unsigned:
|
||||
case json::value_t::number_integer:
|
||||
@@ -42,20 +44,26 @@ json_to_object(const json& value) {
|
||||
return torrent::Object(value.get<std::string>());
|
||||
|
||||
case json::value_t::array: {
|
||||
if (++depth >= max_json_depth)
|
||||
throw torrent::input_error("invalid parameters: max depth reached");
|
||||
|
||||
auto array_raw = torrent::Object::create_list();
|
||||
auto& array = array_raw.as_list();
|
||||
|
||||
for (const auto& entry : value)
|
||||
array.push_back(json_to_object(entry));
|
||||
array.push_back(json_to_object(entry, depth));
|
||||
|
||||
return array_raw;
|
||||
}
|
||||
case json::value_t::object: {
|
||||
if (++depth >= max_json_depth)
|
||||
throw torrent::input_error("invalid parameters: max depth reached");
|
||||
|
||||
auto map_raw = torrent::Object::create_map();
|
||||
auto& map = map_raw.as_map();
|
||||
|
||||
for (const auto& entry : value.items())
|
||||
map[entry.key()] = json_to_object(entry.value());
|
||||
map[entry.key()] = json_to_object(entry.value(), depth);
|
||||
|
||||
return map_raw;
|
||||
}
|
||||
@@ -138,7 +146,7 @@ jsonrpc_call_command(const std::string& method, const json& params) {
|
||||
|
||||
CommandMap::iterator itr = commands.find(method.c_str());
|
||||
|
||||
if (itr == commands.end()) {
|
||||
if (itr == commands.end() || !(itr->second.m_flags & CommandMap::flag_public_rpc)) {
|
||||
throw rpc_error(JSONRPC_METHOD_NOT_FOUND_ERROR, "method not found: " + method);
|
||||
}
|
||||
|
||||
@@ -258,11 +266,8 @@ JsonRpc::process(const char* in_buffer, uint32_t length, slot_write callback) {
|
||||
|
||||
return callback(response_str.c_str(), response_str.size());
|
||||
|
||||
} catch (json::parse_error& e) {
|
||||
auto err_str = json_error(JSONRPC_PARSE_ERROR, e.what(), nullptr).dump(-1, ' ', false, json::error_handler_t::replace);
|
||||
return callback(err_str.c_str(), err_str.size());
|
||||
} catch (json::type_error& e) {
|
||||
// Type errors may be caused by invalid UTF-8 strings in exception strings, hence the ::replace
|
||||
} catch (json::exception& e) {
|
||||
// Exception strings may contain invalid UTF-8, hence the ::replace
|
||||
auto err_str = json_error(JSONRPC_PARSE_ERROR, e.what(), nullptr).dump(-1, ' ', false, json::error_handler_t::replace);
|
||||
return callback(err_str.c_str(), err_str.size());
|
||||
}
|
||||
|
||||
+37
-19
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <locale>
|
||||
#include <torrent/exceptions.h>
|
||||
|
||||
@@ -10,6 +11,8 @@
|
||||
|
||||
namespace rpc {
|
||||
|
||||
constexpr uint32_t max_parse_depth = 1024;
|
||||
|
||||
const char*
|
||||
parse_skip_wspace(const char* first, const char* last) {
|
||||
while (first != last && parse_is_space(*first))
|
||||
@@ -99,6 +102,12 @@ parse_whole_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
value_fits_shifted(int64_t value, int shift) {
|
||||
return value <= (std::numeric_limits<int64_t>::max() >> shift) &&
|
||||
value >= (std::numeric_limits<int64_t>::min() >> shift);
|
||||
}
|
||||
|
||||
const char*
|
||||
parse_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
if (unit <= 0)
|
||||
@@ -121,20 +130,26 @@ parse_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
case 'B': ++last; break;
|
||||
case 'k':
|
||||
case 'K':
|
||||
if (*value > (int64_t)0x1FFFFFFFFFFFFF) return src; // overflow guard
|
||||
if (!value_fits_shifted(*value, 10)) return src; // overflow guard
|
||||
*value = *value << 10; ++last; break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
if (*value > (int64_t)0x7FFFFFFFFFF) return src; // overflow guard
|
||||
if (!value_fits_shifted(*value, 20)) return src; // overflow guard
|
||||
*value = *value << 20; ++last; break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
if (*value > (int64_t)0x1FFFFFFFF) return src; // overflow guard
|
||||
if (!value_fits_shifted(*value, 30)) return src; // overflow guard
|
||||
*value = *value << 30; ++last; break;
|
||||
// case ' ':
|
||||
// case '\0': *value = *value * unit; break;
|
||||
// default: throw torrent::input_error("Could not parse value.");
|
||||
default: *value = *value * unit; break;
|
||||
default:
|
||||
if (*value > std::numeric_limits<int64_t>::max() / unit ||
|
||||
*value < std::numeric_limits<int64_t>::min() / unit)
|
||||
return src; // overflow guard
|
||||
|
||||
*value = *value * unit;
|
||||
break;
|
||||
}
|
||||
|
||||
return last;
|
||||
@@ -142,10 +157,13 @@ parse_value_nothrow(const char* src, int64_t* value, int base, int unit) {
|
||||
|
||||
// Somewhat ugly...
|
||||
const char*
|
||||
parse_object(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char)) {
|
||||
parse_object(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char), uint32_t depth) {
|
||||
if (++depth >= max_parse_depth)
|
||||
throw torrent::input_error("Max parse depth reached.");
|
||||
|
||||
if (*first == '{') {
|
||||
*dest = torrent::Object::create_list();
|
||||
first = parse_list(first + 1, last, dest, &parse_is_delim_block);
|
||||
first = parse_list(first + 1, last, dest, &parse_is_delim_block, depth);
|
||||
first = parse_skip_wspace(first, last);
|
||||
|
||||
if (first == last || *first != '}')
|
||||
@@ -154,18 +172,18 @@ parse_object(const char* first, const char* last, torrent::Object* dest, bool (*
|
||||
return ++first;
|
||||
|
||||
} else if (*first == '(') {
|
||||
int32_t depth = 1;
|
||||
int32_t parentheses = 1;
|
||||
|
||||
while (first + 1 != last && *(first + 1) == '(') {
|
||||
first++;
|
||||
depth++;
|
||||
parentheses++;
|
||||
}
|
||||
|
||||
if (depth > 3)
|
||||
if (parentheses > 3)
|
||||
throw torrent::input_error("Max 3 parentheses per object allowed.");
|
||||
|
||||
*dest = torrent::Object::create_dict_key();
|
||||
dest->set_flags(torrent::Object::flag_function << (depth - 1));
|
||||
dest->set_flags(torrent::Object::flag_function << (parentheses - 1));
|
||||
|
||||
first = parse_string(first + 1, last, &dest->as_dict_key(), &parse_is_delim_func);
|
||||
first = parse_skip_wspace(first, last);
|
||||
@@ -176,16 +194,16 @@ parse_object(const char* first, const char* last, torrent::Object* dest, bool (*
|
||||
if (*first == ',') {
|
||||
// This will always create a list even for single argument functions...
|
||||
dest->as_dict_obj() = torrent::Object::create_list();
|
||||
first = parse_list(first + 1, last, &dest->as_dict_obj(), &parse_is_delim_func);
|
||||
first = parse_list(first + 1, last, &dest->as_dict_obj(), &parse_is_delim_func, depth);
|
||||
first = parse_skip_wspace(first, last);
|
||||
}
|
||||
|
||||
while (depth != 0 && first != last && *first == ')') {
|
||||
while (parentheses != 0 && first != last && *first == ')') {
|
||||
first++;
|
||||
depth--;
|
||||
parentheses--;
|
||||
}
|
||||
|
||||
if (depth != 0)
|
||||
if (parentheses != 0)
|
||||
throw torrent::input_error("Parentheses mismatch.");
|
||||
|
||||
return first;
|
||||
@@ -198,7 +216,7 @@ parse_object(const char* first, const char* last, torrent::Object* dest, bool (*
|
||||
}
|
||||
|
||||
const char*
|
||||
parse_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char)) {
|
||||
parse_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char), uint32_t depth) {
|
||||
if (!dest->is_list())
|
||||
throw torrent::internal_error("parse_list(...) !dest->is_list().");
|
||||
|
||||
@@ -206,7 +224,7 @@ parse_list(const char* first, const char* last, torrent::Object* dest, bool (*de
|
||||
torrent::Object tmp;
|
||||
|
||||
first = parse_skip_wspace(first, last);
|
||||
first = parse_object(first, last, &tmp, delim);
|
||||
first = parse_object(first, last, &tmp, delim, depth);
|
||||
first = parse_skip_wspace(first, last);
|
||||
|
||||
dest->as_list().push_back(tmp);
|
||||
@@ -221,9 +239,9 @@ parse_list(const char* first, const char* last, torrent::Object* dest, bool (*de
|
||||
}
|
||||
|
||||
const char*
|
||||
parse_whole_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char)) {
|
||||
parse_whole_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char), uint32_t depth) {
|
||||
first = parse_skip_wspace(first, last);
|
||||
first = parse_object(first, last, dest, delim);
|
||||
first = parse_object(first, last, dest, delim, depth);
|
||||
first = parse_skip_wspace(first, last);
|
||||
|
||||
if (first != last && parse_is_seperator(*first)) {
|
||||
@@ -231,7 +249,7 @@ parse_whole_list(const char* first, const char* last, torrent::Object* dest, boo
|
||||
tmp.swap(*dest);
|
||||
|
||||
dest->as_list().push_back(tmp);
|
||||
first = parse_list(++first, last, dest, delim);
|
||||
first = parse_list(++first, last, dest, delim, depth);
|
||||
}
|
||||
|
||||
return first;
|
||||
|
||||
+3
-3
@@ -77,9 +77,9 @@ const char* parse_value_nothrow(const char* first, const char* last, int64_t* va
|
||||
void parse_whole_value(const char* src, int64_t* value, int base = 0, int unit = 1);
|
||||
bool parse_whole_value_nothrow(const char* src, int64_t* value, int base = 0, int unit = 1);
|
||||
|
||||
const char* parse_object (const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
|
||||
const char* parse_list (const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
|
||||
const char* parse_whole_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default);
|
||||
const char* parse_object (const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default, uint32_t depth = 0);
|
||||
const char* parse_list (const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default, uint32_t depth = 0);
|
||||
const char* parse_whole_list(const char* first, const char* last, torrent::Object* dest, bool (*delim)(const char) = &parse_is_delim_default, uint32_t depth = 0);
|
||||
|
||||
std::string convert_to_string(const torrent::Object& src);
|
||||
|
||||
|
||||
+16
-1
@@ -14,6 +14,7 @@
|
||||
#include <torrent/runtime/socket_manager.h>
|
||||
#include <torrent/system/callbacks.h>
|
||||
#include <torrent/system/poll.h>
|
||||
#include <torrent/system/scheduler.h>
|
||||
#include <torrent/utils/log.h>
|
||||
|
||||
#include "control.h"
|
||||
@@ -27,6 +28,8 @@ namespace rpc {
|
||||
SCgiTask::SCgiTask()
|
||||
: m_callback_id(torrent::system::make_callback_id()) {
|
||||
|
||||
m_task_timeout.slot() = [this]() { close(); };
|
||||
|
||||
reset_file_descriptor();
|
||||
}
|
||||
|
||||
@@ -50,6 +53,8 @@ SCgiTask::open(SCgi* parent, int fd) {
|
||||
torrent::this_thread::poll()->open(this);
|
||||
torrent::this_thread::poll()->insert_read(this);
|
||||
|
||||
torrent::this_thread::scheduler()->update_wait_for_ceil_seconds(&m_task_timeout, timeout_request);
|
||||
|
||||
auto lock = std::lock_guard<std::mutex>(m_result_mutex);
|
||||
|
||||
// Leave room for terminating nul byte for parsing the header.
|
||||
@@ -61,6 +66,8 @@ SCgiTask::cancel_open() {
|
||||
if (!is_open())
|
||||
return;
|
||||
|
||||
torrent::this_thread::scheduler()->erase(&m_task_timeout);
|
||||
|
||||
torrent::this_thread::poll()->remove_and_close(this);
|
||||
|
||||
torrent::fd_close(file_descriptor());
|
||||
@@ -72,6 +79,8 @@ SCgiTask::close() {
|
||||
if (!is_open())
|
||||
return;
|
||||
|
||||
torrent::this_thread::scheduler()->erase(&m_task_timeout);
|
||||
|
||||
torrent::system::cancel_callback_and_wait(m_callback_id, scgi_thread::thread(), torrent::main_thread::thread());
|
||||
|
||||
torrent::runtime::socket_manager()->close_event_or_throw(this, [this]() {
|
||||
@@ -94,8 +103,12 @@ SCgiTask::event_read() {
|
||||
if (m_content_length == 0)
|
||||
read_length--;
|
||||
|
||||
if (read_length <= 0)
|
||||
if (read_length <= 0) {
|
||||
if (m_content_length == 0)
|
||||
return close();
|
||||
|
||||
throw torrent::internal_error("SCgiTask::event_read() no space in buffer for event_read.");
|
||||
}
|
||||
|
||||
int bytes = ::recv(file_descriptor(), m_buffer.data() + m_position, read_length, 0);
|
||||
|
||||
@@ -154,6 +167,8 @@ SCgiTask::event_read() {
|
||||
|
||||
torrent::this_thread::poll()->remove_read(this);
|
||||
|
||||
torrent::this_thread::scheduler()->update_wait_for_ceil_seconds(&m_task_timeout, timeout_request);
|
||||
|
||||
if (m_parent->log_fd() >= 0) {
|
||||
[[maybe_unused]] int result;
|
||||
|
||||
|
||||
+7
-2
@@ -1,10 +1,12 @@
|
||||
#ifndef RTORRENT_RPC_SCGI_TASK_H
|
||||
#define RTORRENT_RPC_SCGI_TASK_H
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
#include <torrent/system/event.h>
|
||||
#include <torrent/system/scheduler.h>
|
||||
|
||||
namespace rpc {
|
||||
|
||||
@@ -16,6 +18,8 @@ public:
|
||||
static constexpr int max_header_size = 2000;
|
||||
static constexpr int max_content_size = (2 << 23);
|
||||
|
||||
static constexpr auto timeout_request = std::chrono::seconds(60);
|
||||
|
||||
enum ContentType { XML, JSON };
|
||||
|
||||
SCgiTask();
|
||||
@@ -54,8 +58,9 @@ private:
|
||||
void plaintext_response(const char* buffer, uint32_t content_length);
|
||||
void gzip_response(const char* buffer, uint32_t content_length);
|
||||
|
||||
SCgi* m_parent{};
|
||||
torrent::system::callback_id m_callback_id;
|
||||
SCgi* m_parent{};
|
||||
torrent::system::callback_id m_callback_id;
|
||||
torrent::system::SchedulerEntry m_task_timeout;
|
||||
|
||||
std::mutex m_result_mutex;
|
||||
|
||||
|
||||
@@ -49,13 +49,23 @@ element_access(const tinyxml2::XMLElement* elem, std::initializer_list<std::stri
|
||||
return result;
|
||||
}
|
||||
|
||||
const char*
|
||||
element_text_value(const tinyxml2::XMLNode* node) {
|
||||
auto text = node->ToText();
|
||||
|
||||
if (text == nullptr)
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "expected a text value");
|
||||
|
||||
return text->Value();
|
||||
}
|
||||
|
||||
long long
|
||||
element_to_int(const tinyxml2::XMLNode* elem) {
|
||||
char* pos;
|
||||
if (elem->FirstChild() == nullptr) {
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "unable to parse empty integer");
|
||||
}
|
||||
auto str = elem->FirstChild()->ToText()->Value();
|
||||
auto str = element_text_value(elem->FirstChild());
|
||||
auto result = std::strtoll(str, &pos, 10);
|
||||
if (pos == str || *pos != '\0')
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "unable to parse integer value");
|
||||
@@ -85,7 +95,7 @@ xml_value_to_object(const tinyxml2::XMLNode* elem) {
|
||||
if (child_element == nullptr)
|
||||
return torrent::Object("");
|
||||
|
||||
return torrent::Object(child_element->ToText()->Value());
|
||||
return torrent::Object(element_text_value(child_element));
|
||||
|
||||
} else if (std::strncmp(root_type, "int", sizeof("int")) == 0 ||
|
||||
std::strncmp(root_type, "i4", sizeof("i4")) == 0 ||
|
||||
@@ -98,7 +108,7 @@ xml_value_to_object(const tinyxml2::XMLNode* elem) {
|
||||
if (child_element == nullptr)
|
||||
throw rpc_error(XMLRPC_TYPE_ERROR, "empty boolean element");
|
||||
|
||||
auto boolean_text = std::string(child_element->ToText()->Value());
|
||||
auto boolean_text = std::string(element_text_value(child_element));
|
||||
|
||||
if (boolean_text == "1")
|
||||
return torrent::Object((int64_t)1);
|
||||
@@ -129,7 +139,12 @@ xml_value_to_object(const tinyxml2::XMLNode* elem) {
|
||||
if (name_element == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "struct member missing name element");
|
||||
|
||||
map[name_element->GetText()] = std::move(xml_value_to_object(child->FirstChildElement("value")));
|
||||
auto name_text = name_element->GetText();
|
||||
|
||||
if (name_text == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "struct member has an empty name element");
|
||||
|
||||
map[name_text] = std::move(xml_value_to_object(child->FirstChildElement("value")));
|
||||
}
|
||||
|
||||
return map_raw;
|
||||
@@ -140,7 +155,7 @@ xml_value_to_object(const tinyxml2::XMLNode* elem) {
|
||||
if (child_element == nullptr)
|
||||
return torrent::Object("");
|
||||
|
||||
return torrent::Object(utils::decode_base64(utils::remove_newlines(child_element->ToText()->Value())));
|
||||
return torrent::Object(utils::decode_base64(utils::remove_newlines(element_text_value(child_element))));
|
||||
|
||||
} else {
|
||||
throw rpc_error(XMLRPC_INTERNAL_ERROR, "received unsupported value type: " + std::string(root_type));
|
||||
@@ -300,6 +315,9 @@ process_document(const tinyxml2::XMLDocument* doc, tinyxml2::XMLPrinter* printer
|
||||
if (doc->FirstChildElement("methodCall")->FirstChildElement("methodName") == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "methodName element not found");
|
||||
auto method_name = doc->FirstChildElement("methodCall")->FirstChildElement("methodName")->GetText();
|
||||
|
||||
if (method_name == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "methodName element is empty");
|
||||
torrent::Object result;
|
||||
|
||||
// Add a shim here for system.multicall to allow better code reuse, and
|
||||
@@ -310,6 +328,9 @@ process_document(const tinyxml2::XMLDocument* doc, tinyxml2::XMLPrinter* printer
|
||||
auto parent_elements = element_access(doc->RootElement(), {"params", "param", "value", "array", "data"});
|
||||
for (auto child = parent_elements->FirstChildElement("value"); child; child = child->NextSiblingElement("value")) {
|
||||
auto sub_method_name = element_access(child, {"struct", "member", "value", "string"})->GetText();
|
||||
|
||||
if (sub_method_name == nullptr)
|
||||
throw rpc_error(XMLRPC_PARSE_ERROR, "multicall methodName element is empty");
|
||||
// If sub_params ends up a nullptr at the end of this if-chian,
|
||||
// execute_command will turn it into an empty list
|
||||
auto sub_params = element_access(child, {"struct", "member"});
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ parse_main_options(int argc, char** argv) {
|
||||
|
||||
optionParser.insert_option('b', [](auto& arg) { rpc::call_command_set_string("network.bind_address.set", arg); });
|
||||
optionParser.insert_option('d', [](auto& arg) { rpc::call_command_set_string("directory.default.set", arg); });
|
||||
optionParser.insert_option('i', [](auto& arg) { rpc::call_command_set_string("ip", arg); });
|
||||
optionParser.insert_option('i', [](auto& arg) { rpc::call_command_set_string("network.local_address.set", arg); });
|
||||
optionParser.insert_option('p', [](auto& arg) { rpc::call_command_set_string("network.listen.port.range.set", arg); });
|
||||
optionParser.insert_option('s', [](auto& arg) { rpc::call_command_set_string("session", arg); });
|
||||
|
||||
|
||||
+5
-2
@@ -1,3 +1,4 @@
|
||||
#include <memory>
|
||||
#include "config.h"
|
||||
|
||||
#include <cassert>
|
||||
@@ -30,8 +31,10 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
Download::Download(core::Download* d)
|
||||
: m_download(d) {
|
||||
Download::Download(const std::shared_ptr<core::Download>& download)
|
||||
: m_download(download.get()) {
|
||||
|
||||
auto* d = download.get();
|
||||
|
||||
m_windowDownloadStatus = std::make_unique<WDownloadStatus>(d);
|
||||
m_windowDownloadStatus->set_bottom(true);
|
||||
|
||||
+2
-1
@@ -2,6 +2,7 @@
|
||||
#define RTORRENT_UI_DOWNLOAD_H
|
||||
|
||||
#include <list>
|
||||
#include <memory>
|
||||
#include <torrent/peer/peer.h>
|
||||
|
||||
#include "display/manager.h"
|
||||
@@ -36,7 +37,7 @@ public:
|
||||
DISPLAY_MAX_SIZE
|
||||
} Display;
|
||||
|
||||
Download(core::Download* d);
|
||||
Download(const std::shared_ptr<core::Download>& d);
|
||||
~Download();
|
||||
|
||||
void activate(display::Frame* frame, bool focus = true);
|
||||
|
||||
@@ -89,7 +89,7 @@ DownloadList::unfocus_download(core::Download* d) {
|
||||
if (m_state == DISPLAY_DOWNLOAD && d == static_cast<Download*>(m_uiArray[DISPLAY_DOWNLOAD])->download())
|
||||
activate_display(DISPLAY_DOWNLOAD_LIST);
|
||||
|
||||
if (*current_view()->focus() == d && current_view()->focus() < current_view()->end_visible())
|
||||
if (current_view()->focus() < current_view()->end_visible() && current_view()->focus()->get() == d)
|
||||
current_view()->next_focus();
|
||||
}
|
||||
|
||||
|
||||
@@ -196,7 +196,7 @@ ElementDownloadList::receive_cycle_throttle() {
|
||||
if (m_view->focus() == m_view->end_visible())
|
||||
return;
|
||||
|
||||
core::Download* download = *m_view->focus();
|
||||
core::Download* download = m_view->focus()->get();
|
||||
if (download->is_active()) {
|
||||
lt_log_print(torrent::LOG_TORRENT_WARN, "Cannot change throttle on active download.");
|
||||
return;
|
||||
|
||||
+4
-2
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string.h>
|
||||
#include <torrent/throttle.h>
|
||||
#include <torrent/torrent.h>
|
||||
@@ -354,8 +355,9 @@ Root::reset_input_history_attributes(ui::DownloadList::Input type) {
|
||||
|
||||
void
|
||||
Root::set_input_history_size(int size) {
|
||||
if (size < 1)
|
||||
throw torrent::input_error("Invalid input history size.");
|
||||
if (size < 1 || size > max_input_history_size)
|
||||
throw torrent::input_error("Input history size must be between 1 and " +
|
||||
std::to_string(max_input_history_size) + ".");
|
||||
|
||||
for (auto& [entry, category] : m_input_history) {
|
||||
// Reserve the latest input history entries if new size is smaller than original.
|
||||
|
||||
@@ -54,6 +54,8 @@ public:
|
||||
typedef std::vector<std::string> InputHistoryCategory;
|
||||
typedef std::map<int, InputHistoryCategory> InputHistory;
|
||||
|
||||
static constexpr int max_input_history_size = 4096;
|
||||
|
||||
Root();
|
||||
|
||||
void init(Control* c);
|
||||
|
||||
@@ -35,6 +35,8 @@ rtorrent_Test_Rpc_SOURCES = $(rtorrent_Test_Common) \
|
||||
rpc/test_command.h \
|
||||
rpc/test_command_map.cc \
|
||||
rpc/test_command_map.h \
|
||||
rpc/test_command_scheduler.cc \
|
||||
rpc/test_command_scheduler.h \
|
||||
rpc/test_jsonrpc.cc \
|
||||
rpc/test_jsonrpc.h \
|
||||
rpc/test_xmlrpc.cc \
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
#include "config.h"
|
||||
|
||||
#include "test/rpc/test_command_scheduler.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "rpc/command_scheduler.h"
|
||||
#include "rpc/command_scheduler_item.h"
|
||||
#include "torrent/object.h"
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestCommandScheduler);
|
||||
|
||||
namespace {
|
||||
|
||||
const torrent::Object test_command = torrent::Object(std::string("print=scheduled"));
|
||||
|
||||
std::chrono::microseconds
|
||||
time_scheduled(rpc::CommandScheduler& scheduler, const std::string& key) {
|
||||
auto itr = scheduler.find(key);
|
||||
|
||||
CPPUNIT_ASSERT(itr != scheduler.end());
|
||||
|
||||
return (*itr)->time_scheduled();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandScheduler::setUp() {
|
||||
TestFixtureWithMainThread::setUp();
|
||||
|
||||
m_main_thread->test_set_cached_time(std::chrono::seconds(0));
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandScheduler::tearDown() {
|
||||
TestFixtureWithMainThread::tearDown();
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandScheduler::test_parse_rearms_existing_key() {
|
||||
rpc::CommandScheduler scheduler;
|
||||
|
||||
scheduler.parse("key", "3600", "3600", test_command);
|
||||
|
||||
auto first = time_scheduled(scheduler, "key");
|
||||
|
||||
m_main_thread->test_add_cached_time(std::chrono::seconds(600));
|
||||
scheduler.parse("key", "3600", "3600", test_command);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(size_t{1}, scheduler.size());
|
||||
CPPUNIT_ASSERT(time_scheduled(scheduler, "key") == first + std::chrono::seconds(600));
|
||||
}
|
||||
|
||||
void
|
||||
TestCommandScheduler::test_find_locates_a_scheduled_key() {
|
||||
rpc::CommandScheduler scheduler;
|
||||
|
||||
CPPUNIT_ASSERT(scheduler.find("key") == scheduler.end());
|
||||
|
||||
scheduler.parse("key", "3600", "3600", test_command);
|
||||
|
||||
CPPUNIT_ASSERT(scheduler.find("key") != scheduler.end());
|
||||
CPPUNIT_ASSERT(scheduler.find("other") == scheduler.end());
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#include "test/helpers/test_main_thread.h"
|
||||
|
||||
class TestCommandScheduler : public TestFixtureWithMainThread {
|
||||
CPPUNIT_TEST_SUITE(TestCommandScheduler);
|
||||
|
||||
CPPUNIT_TEST(test_parse_rearms_existing_key);
|
||||
CPPUNIT_TEST(test_find_locates_a_scheduled_key);
|
||||
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
void setUp();
|
||||
void tearDown();
|
||||
|
||||
void test_parse_rearms_existing_key();
|
||||
void test_find_locates_a_scheduled_key();
|
||||
};
|
||||
Reference in New Issue
Block a user