mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-08 11:12:31 +00:00
* Finished the move over to object_storage, removing command_function.*.
* Added redirects for several commands. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1166 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
+39
-39
@@ -97,6 +97,8 @@ system_method_insert_object(const torrent::Object::list_type& args, int flags) {
|
||||
case rpc::object_storage::flag_function_type:
|
||||
value = itrArgs != args.end() ? system_method_generate_command(itrArgs, args.end()) : "";
|
||||
break;
|
||||
case rpc::object_storage::flag_multi_type:
|
||||
break;
|
||||
default:
|
||||
throw torrent::input_error("Invalid type.");
|
||||
}
|
||||
@@ -113,7 +115,8 @@ system_method_insert_object(const torrent::Object::list_type& args, int flags) {
|
||||
// Add commands:
|
||||
rpc::command_base* command_get = new rpc::command_base();
|
||||
|
||||
if ((flags & rpc::object_storage::mask_type) == rpc::object_storage::flag_function_type)
|
||||
if ((flags & rpc::object_storage::mask_type) == rpc::object_storage::flag_function_type ||
|
||||
(flags & rpc::object_storage::mask_type) == rpc::object_storage::flag_multi_type)
|
||||
command_get->set_function_2<rpc::command_base_call<rpc::target_type> >
|
||||
(std::tr1::bind(&rpc::object_storage::call_function_str, control->object_storage(),
|
||||
rawKey, std::tr1::placeholders::_1, std::tr1::placeholders::_2));
|
||||
@@ -154,6 +157,7 @@ system_method_insert_object(const torrent::Object::list_type& args, int flags) {
|
||||
command_call = &rpc::command_base_call_string<rpc::target_type>;
|
||||
break;
|
||||
case rpc::object_storage::flag_function_type:
|
||||
case rpc::object_storage::flag_multi_type:
|
||||
default:
|
||||
delete command_set;
|
||||
return torrent::Object();
|
||||
@@ -202,11 +206,20 @@ system_method_insert(const torrent::Object::list_type& args) {
|
||||
flags &= ~rpc::CommandMap::flag_modifiable;
|
||||
|
||||
if (options.find("multi") != std::string::npos) {
|
||||
// Later, make it possible to add functions here.
|
||||
rpc::Command* command = new rpc::CommandFunctionList();
|
||||
rpc::Command::any_slot slot = &rpc::CommandFunctionList::call;
|
||||
torrent::Object::list_type new_args;
|
||||
new_args.push_back(rawKey);
|
||||
new_args.push_back(system_method_generate_command(++itrArgs, args.end()));
|
||||
|
||||
rpc::commands.insert_type(create_new_key<0>(rawKey, ""), command, slot, flags, NULL, NULL);
|
||||
int new_flags = rpc::object_storage::flag_multi_type;
|
||||
|
||||
if (options.find("static") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_static;
|
||||
if (options.find("private") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_private;
|
||||
if (options.find("const") != std::string::npos)
|
||||
new_flags |= rpc::object_storage::flag_constant;
|
||||
|
||||
return system_method_insert_object(new_args, new_flags);
|
||||
|
||||
} else if (options.find("simple") != std::string::npos) {
|
||||
torrent::Object::list_type new_args;
|
||||
@@ -313,57 +326,43 @@ system_method_set_function(const torrent::Object::list_type& args) {
|
||||
system_method_generate_command(++args.begin(), args.end()));
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
system_method_has_key(const torrent::Object::list_type& args) {
|
||||
if (args.empty() || ++args.begin() == args.end())
|
||||
throw torrent::input_error("Invalid argument count.");
|
||||
|
||||
torrent::Object::list_const_iterator itrArgs = args.begin();
|
||||
const std::string& key = (itrArgs++)->as_string();
|
||||
const std::string& cmd_key = (itrArgs++)->as_string();
|
||||
|
||||
return control->object_storage()->has_str_multi_key(key, cmd_key);
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
system_method_set_key(const torrent::Object::list_type& args) {
|
||||
if (args.empty() || ++args.begin() == args.end())
|
||||
throw torrent::input_error("Invalid argument count.");
|
||||
|
||||
rpc::CommandFunctionList* function;
|
||||
rpc::CommandMap::iterator itr = rpc::commands.find(args.front().as_string().c_str());
|
||||
|
||||
if (!rpc::commands.is_modifiable(itr) ||
|
||||
(function = dynamic_cast<rpc::CommandFunctionList*>(itr->second.m_variable)) == NULL)
|
||||
throw torrent::input_error("Command not modifiable or wrong type.");
|
||||
|
||||
torrent::Object::list_const_iterator itrArgs = ++args.begin();
|
||||
torrent::Object::list_const_iterator itrArgs = args.begin();
|
||||
const std::string& key = (itrArgs++)->as_string();
|
||||
const std::string& cmd_key = (itrArgs++)->as_string();
|
||||
|
||||
if (itrArgs != args.end())
|
||||
function->insert(key, system_method_generate_command(itrArgs, args.end()));
|
||||
control->object_storage()->set_str_multi_key(key, cmd_key, system_method_generate_command(itrArgs, args.end()));
|
||||
else
|
||||
function->erase(key);
|
||||
control->object_storage()->erase_str_multi_key(key, cmd_key);
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
system_method_has_key(const torrent::Object::list_type& args) {
|
||||
if (args.size() != 2)
|
||||
throw torrent::input_error("Invalid argument count.");
|
||||
|
||||
rpc::CommandFunctionList* function;
|
||||
rpc::CommandMap::iterator itr = rpc::commands.find(args.front().as_string().c_str());
|
||||
|
||||
if (itr == rpc::commands.end() ||
|
||||
(function = dynamic_cast<rpc::CommandFunctionList*>(itr->second.m_variable)) == NULL)
|
||||
throw torrent::input_error("Command is the wrong type.");
|
||||
|
||||
return torrent::Object((int64_t)(function->find(args.back().as_string().c_str()) != function->end()));
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
system_method_list_keys(const torrent::Object::string_type& args) {
|
||||
rpc::CommandFunctionList* function;
|
||||
rpc::CommandMap::iterator itr = rpc::commands.find(args.c_str());
|
||||
|
||||
if (itr == rpc::commands.end() ||
|
||||
(function = dynamic_cast<rpc::CommandFunctionList*>(itr->second.m_variable)) == NULL)
|
||||
throw torrent::input_error("Command is the wrong type.");
|
||||
|
||||
const torrent::Object::map_type& multi_cmd = control->object_storage()->get_str(args).as_map();
|
||||
|
||||
torrent::Object rawResult = torrent::Object::create_list();
|
||||
torrent::Object::list_type& result = rawResult.as_list();
|
||||
|
||||
for (rpc::CommandFunctionList::const_iterator itr = function->begin(), last = function->end(); itr != last; itr++)
|
||||
for (torrent::Object::map_const_iterator itr = multi_cmd.begin(), last = multi_cmd.end(); itr != last; itr++)
|
||||
result.push_back(itr->first);
|
||||
|
||||
return rawResult;
|
||||
@@ -389,7 +388,8 @@ initialize_command_dynamic() {
|
||||
CMD2_ANY_STRING ("method.get", std::tr1::bind(&rpc::object_storage::get_str, control->object_storage(),
|
||||
std::tr1::placeholders::_2));
|
||||
CMD2_ANY_LIST ("method.set", std::tr1::bind(&system_method_set_function, std::tr1::placeholders::_2));
|
||||
CMD2_ANY_LIST ("method.set_key", std::tr1::bind(&system_method_set_key, std::tr1::placeholders::_2));
|
||||
|
||||
CMD2_ANY_LIST ("method.has_key", std::tr1::bind(&system_method_has_key, std::tr1::placeholders::_2));
|
||||
CMD2_ANY_LIST ("method.set_key", std::tr1::bind(&system_method_set_key, std::tr1::placeholders::_2));
|
||||
CMD2_ANY_STRING ("method.list_keys", std::tr1::bind(&system_method_list_keys, std::tr1::placeholders::_2));
|
||||
}
|
||||
|
||||
@@ -38,7 +38,6 @@
|
||||
#define RTORRENT_UTILS_COMMAND_HELPERS_H
|
||||
|
||||
#include "rpc/command_new_slot.h"
|
||||
#include "rpc/command_function.h"
|
||||
#include "rpc/parse_commands.h"
|
||||
#include "rpc/object_storage.h"
|
||||
|
||||
|
||||
+15
-12
@@ -420,17 +420,17 @@ initialize_command_network() {
|
||||
CMD2_VAR_STRING("connection_leech", "leech");
|
||||
CMD2_VAR_STRING("connection_seed", "seed");
|
||||
|
||||
CMD2_VAR_VALUE("min_peers", 40);
|
||||
CMD2_VAR_VALUE("max_peers", 100);
|
||||
CMD2_VAR_VALUE("min_peers_seed", -1);
|
||||
CMD2_VAR_VALUE("max_peers_seed", -1);
|
||||
CMD2_VAR_VALUE ("throttle.min_peers.normal", 40);
|
||||
CMD2_VAR_VALUE ("throttle.max_peers.normal", 100);
|
||||
CMD2_VAR_VALUE ("throttle.min_peers.seed", -1);
|
||||
CMD2_VAR_VALUE ("throttle.max_peers.seed", -1);
|
||||
|
||||
CMD2_VAR_VALUE("max_uploads", 15);
|
||||
CMD2_VAR_VALUE ("throttle.max_uploads", 15);
|
||||
|
||||
CMD2_VAR_VALUE("max_uploads_div", 1);
|
||||
CMD2_VAR_VALUE("max_uploads_global", 0);
|
||||
CMD2_VAR_VALUE("max_downloads_div", 1);
|
||||
CMD2_VAR_VALUE("max_downloads_global", 0);
|
||||
CMD2_VAR_VALUE ("throttle.max_uploads.div", 1);
|
||||
CMD2_VAR_VALUE ("throttle.max_uploads.global", 0);
|
||||
CMD2_VAR_VALUE ("throttle.max_downloads.div", 1);
|
||||
CMD2_VAR_VALUE ("throttle.max_downloads.global", 0);
|
||||
|
||||
// TODO: Move the logic into some libtorrent function.
|
||||
CMD2_ANY ("throttle.global_up.rate", std::tr1::bind(&torrent::Rate::rate, torrent::up_rate()));
|
||||
@@ -490,9 +490,12 @@ initialize_command_network() {
|
||||
CMD2_ANY ("network.xmlrpc.size_limit", std::tr1::bind(&rpc::XmlRpc::size_limit));
|
||||
CMD2_ANY_VALUE_V ("network.xmlrpc.size_limit.set", std::tr1::bind(&rpc::XmlRpc::set_size_limit, std::tr1::placeholders::_2));
|
||||
|
||||
// ADD_COMMAND_VALUE_TRI("hash_read_ahead", std::ptr_fun(&apply_hash_read_ahead), rak::ptr_fun(torrent::hash_read_ahead));
|
||||
// ADD_COMMAND_VALUE_TRI("hash_interval", std::ptr_fun(&apply_hash_interval), rak::ptr_fun(torrent::hash_interval));
|
||||
// ADD_COMMAND_VALUE_TRI("hash_max_tries", std::ptr_fun(&torrent::set_hash_max_tries), rak::ptr_fun(&torrent::hash_max_tries));
|
||||
CMD2_ANY ("system.hash.read_ahead", std::tr1::bind(&torrent::hash_read_ahead));
|
||||
CMD2_ANY_VALUE_V ("system.hash.read_ahead.set", std::tr1::bind(&apply_hash_read_ahead, std::tr1::placeholders::_2));
|
||||
CMD2_ANY ("system.hash.interval", std::tr1::bind(&torrent::hash_interval));
|
||||
CMD2_ANY_VALUE_V ("system.hash.interval.set", std::tr1::bind(&apply_hash_interval, std::tr1::placeholders::_2));
|
||||
CMD2_ANY ("system.hash.max_tries", std::tr1::bind(&torrent::hash_max_tries));
|
||||
CMD2_ANY_VALUE_V ("system.hash.max_tries.set", std::tr1::bind(&torrent::set_hash_max_tries, std::tr1::placeholders::_2));
|
||||
|
||||
CMD2_ANY_VALUE ("trackers.enable", std::tr1::bind(&apply_enable_trackers, int64_t(1)));
|
||||
CMD2_ANY_VALUE ("trackers.disable", std::tr1::bind(&apply_enable_trackers, int64_t(0)));
|
||||
|
||||
+3
-3
@@ -86,15 +86,15 @@ Control::~Control() {
|
||||
delete m_inputStdin;
|
||||
delete m_input;
|
||||
|
||||
delete m_commandScheduler;
|
||||
delete m_objectStorage;
|
||||
|
||||
delete m_viewManager;
|
||||
|
||||
delete m_ui;
|
||||
delete m_display;
|
||||
delete m_core;
|
||||
delete m_dhtManager;
|
||||
|
||||
delete m_commandScheduler;
|
||||
delete m_objectStorage;
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -251,17 +251,17 @@ DownloadFactory::receive_success() {
|
||||
if (!rtorrent->has_key_string("custom4")) rtorrent->insert_key("custom4", std::string());
|
||||
if (!rtorrent->has_key_string("custom5")) rtorrent->insert_key("custom5", std::string());
|
||||
|
||||
rpc::call_command("d.uploads_max.set", rpc::call_command_void("max_uploads"), rpc::make_target(download));
|
||||
rpc::call_command("d.peers_min.set", rpc::call_command_void("min_peers"), rpc::make_target(download));
|
||||
rpc::call_command("d.peers_max.set", rpc::call_command_void("max_peers"), rpc::make_target(download));
|
||||
rpc::call_command("d.uploads_max.set", rpc::call_command_void("throttle.max_uploads"), rpc::make_target(download));
|
||||
rpc::call_command("d.peers_min.set", rpc::call_command_void("throttle.min_peers.normal"), rpc::make_target(download));
|
||||
rpc::call_command("d.peers_max.set", rpc::call_command_void("throttle.max_peers.normal"), rpc::make_target(download));
|
||||
rpc::call_command("d.tracker_numwant.set", rpc::call_command_void("trackers.numwant"), rpc::make_target(download));
|
||||
|
||||
if (rpc::call_command_value("d.complete", rpc::make_target(download)) != 0) {
|
||||
if (rpc::call_command_value("min_peers_seed") >= 0)
|
||||
rpc::call_command("d.peers_min.set", rpc::call_command_void("min_peers_seed"), rpc::make_target(download));
|
||||
if (rpc::call_command_value("throttle.min_peers.seed") >= 0)
|
||||
rpc::call_command("d.peers_min.set", rpc::call_command_void("throttle.min_peers.seed"), rpc::make_target(download));
|
||||
|
||||
if (rpc::call_command_value("max_peers_seed") >= 0)
|
||||
rpc::call_command("d.peers_max.set", rpc::call_command_void("max_peers_seed"), rpc::make_target(download));
|
||||
if (rpc::call_command_value("throttle.max_peers.seed") >= 0)
|
||||
rpc::call_command("d.peers_max.set", rpc::call_command_void("throttle.max_peers.seed"), rpc::make_target(download));
|
||||
}
|
||||
|
||||
if (!rpc::call_command_value("trackers.use_udp"))
|
||||
|
||||
@@ -579,11 +579,11 @@ DownloadList::confirm_finished(Download* download) {
|
||||
rpc::call_command("d.connection_current.set", rpc::call_command_void("d.connection_seed", rpc::make_target(download)), rpc::make_target(download));
|
||||
download->set_priority(download->priority());
|
||||
|
||||
if (rpc::call_command_value("d.peers_min", rpc::make_target(download)) == rpc::call_command_value("min_peers") && rpc::call_command_value("min_peers_seed") >= 0)
|
||||
rpc::call_command("d.peers_min.set", rpc::call_command_void("min_peers_seed"), rpc::make_target(download));
|
||||
if (rpc::call_command_value("d.peers_min", rpc::make_target(download)) == rpc::call_command_value("throttle.min_peers.normal") && rpc::call_command_value("throttle.min_peers.seed") >= 0)
|
||||
rpc::call_command("d.peers_min.set", rpc::call_command_void("throttle.min_peers.seed"), rpc::make_target(download));
|
||||
|
||||
if (rpc::call_command_value("d.peers_max", rpc::make_target(download)) == rpc::call_command_value("max_peers") && rpc::call_command_value("max_peers_seed") >= 0)
|
||||
rpc::call_command("d.peers_max.set", rpc::call_command_void("max_peers_seed"), rpc::make_target(download));
|
||||
if (rpc::call_command_value("d.peers_max", rpc::make_target(download)) == rpc::call_command_value("throttle.max_peers.normal") && rpc::call_command_value("throttle.max_peers.seed") >= 0)
|
||||
rpc::call_command("d.peers_max.set", rpc::call_command_void("throttle.max_peers.seed"), rpc::make_target(download));
|
||||
|
||||
// Do this before the slots are called in case one of them closes
|
||||
// the download.
|
||||
|
||||
+82
-7
@@ -303,6 +303,18 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT ("ratio.max.set", "group.seeding.ratio.max.set");
|
||||
CMD2_REDIRECT ("ratio.upload.set", "group.seeding.ratio.upload.set");
|
||||
|
||||
CMD2_REDIRECT ("min_peers", "throttle.min_peers.normal.set");
|
||||
CMD2_REDIRECT ("max_peers", "throttle.max_peers.normal.set");
|
||||
CMD2_REDIRECT ("min_peers_seed", "throttle.min_peers.seed.set");
|
||||
CMD2_REDIRECT ("max_peers_seed", "throttle.max_peers.seed.set");
|
||||
|
||||
CMD2_REDIRECT ("max_uploads", "throttle.max_uploads.set");
|
||||
|
||||
CMD2_REDIRECT ("max_uploads_div", "throttle.max_uploads.div.set");
|
||||
CMD2_REDIRECT ("max_uploads_global", "throttle.max_uploads.global.set");
|
||||
CMD2_REDIRECT ("max_downloads_div", "throttle.max_downloads.div.set");
|
||||
CMD2_REDIRECT ("max_downloads_global", "throttle.max_downloads.global.set");
|
||||
|
||||
// Deprecated commands. Don't use these anymore.
|
||||
|
||||
if (!OptionParser::has_flag('D', argc, argv)) {
|
||||
@@ -354,10 +366,33 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT_GENERIC("get_max_memory_usage", "pieces.memory.max");
|
||||
CMD2_REDIRECT_GENERIC("set_max_memory_usage", "pieces.memory.max.set");
|
||||
|
||||
CMD2_REDIRECT ("get_send_buffer_size", "network.send_buffer.size");
|
||||
CMD2_REDIRECT_GENERIC("set_send_buffer_size", "network.send_buffer.size.set");
|
||||
CMD2_REDIRECT ("get_receive_buffer_size", "network.receive_buffer.size");
|
||||
CMD2_REDIRECT_GENERIC("set_receive_buffer_size", "network.receive_buffer.size.set");
|
||||
//
|
||||
// Throttle:
|
||||
//
|
||||
|
||||
CMD2_REDIRECT_GENERIC("set_min_peers", "throttle.min_peers.normal.set");
|
||||
CMD2_REDIRECT_GENERIC("set_max_peers", "throttle.max_peers.normal.set");
|
||||
CMD2_REDIRECT_GENERIC("set_min_peers_seed", "throttle.min_peers.seed.set");
|
||||
CMD2_REDIRECT_GENERIC("set_max_peers_seed", "throttle.max_peers.seed.set");
|
||||
|
||||
CMD2_REDIRECT_GENERIC("set_max_uploads", "throttle.max_uploads.set");
|
||||
|
||||
CMD2_REDIRECT_GENERIC("set_max_uploads_div", "throttle.max_uploads.div.set");
|
||||
CMD2_REDIRECT_GENERIC("set_max_uploads_global", "throttle.max_uploads.global.set");
|
||||
CMD2_REDIRECT_GENERIC("set_max_downloads_div", "throttle.max_downloads.div.set");
|
||||
CMD2_REDIRECT_GENERIC("set_max_downloads_global", "throttle.max_downloads.global.set");
|
||||
|
||||
CMD2_REDIRECT ("get_min_peers", "throttle.min_peers.normal");
|
||||
CMD2_REDIRECT ("get_max_peers", "throttle.max_peers.normal");
|
||||
CMD2_REDIRECT ("get_min_peers_seed", "throttle.min_peers.seed");
|
||||
CMD2_REDIRECT ("get_max_peers_seed", "throttle.max_peers.seed");
|
||||
|
||||
CMD2_REDIRECT ("get_max_uploads", "throttle.max_uploads");
|
||||
|
||||
CMD2_REDIRECT ("get_max_uploads_div", "throttle.max_uploads.div");
|
||||
CMD2_REDIRECT ("get_max_uploads_global", "throttle.max_uploads.global");
|
||||
CMD2_REDIRECT ("get_max_downloads_div", "throttle.max_downloads.div");
|
||||
CMD2_REDIRECT ("get_max_downloads_global", "throttle.max_downloads.global");
|
||||
|
||||
CMD2_REDIRECT ("get_up_rate", "throttle.global_up.rate");
|
||||
CMD2_REDIRECT ("get_up_total", "throttle.global_up.total");
|
||||
@@ -368,6 +403,15 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT ("get_download_rate", "throttle.global_down.max_rate");
|
||||
CMD2_REDIRECT_GENERIC("set_download_rate", "throttle.global_down.max_rate.set");
|
||||
|
||||
//
|
||||
// Network:
|
||||
//
|
||||
|
||||
CMD2_REDIRECT ("get_send_buffer_size", "network.send_buffer.size");
|
||||
CMD2_REDIRECT_GENERIC("set_send_buffer_size", "network.send_buffer.size.set");
|
||||
CMD2_REDIRECT ("get_receive_buffer_size", "network.receive_buffer.size");
|
||||
CMD2_REDIRECT_GENERIC("set_receive_buffer_size", "network.receive_buffer.size.set");
|
||||
|
||||
CMD2_REDIRECT ("bind", "network.bind_address.set");
|
||||
CMD2_REDIRECT_GENERIC("set_bind", "network.bind_address.set");
|
||||
CMD2_REDIRECT ("get_bind", "network.bind_address");
|
||||
@@ -399,6 +443,9 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT_GENERIC("set_scgi_dont_route", "network.scgi.dont_route.set");
|
||||
CMD2_REDIRECT ("get_scgi_dont_route", "network.scgi.dont_route");
|
||||
|
||||
CMD2_REDIRECT ("get_max_open_files", "network.max_open_files");
|
||||
CMD2_REDIRECT_GENERIC("set_max_open_files", "network.max_open_files.set");
|
||||
|
||||
//
|
||||
// XMLRPC stuff:
|
||||
//
|
||||
@@ -422,11 +469,13 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT ("get_http_cacert", "network.http.cacert");
|
||||
CMD2_REDIRECT_GENERIC("set_http_cacert", "network.http.cacert.set");
|
||||
|
||||
CMD2_REDIRECT ("get_http_max_open", "network.http.max_open");
|
||||
CMD2_REDIRECT_GENERIC("set_http_max_open", "network.http.max_open.set");
|
||||
|
||||
CMD2_REDIRECT_GENERIC("http_proxy_address", "network.http.proxy_address.set");
|
||||
CMD2_REDIRECT ("get_http_proxy_address", "network.http.proxy_address");
|
||||
CMD2_REDIRECT_GENERIC("set_http_proxy_address", "network.http.proxy_address.set");
|
||||
|
||||
|
||||
CMD2_REDIRECT ("get_connection_leech", "connection_leech");
|
||||
CMD2_REDIRECT_GENERIC("set_connection_leech", "connection_leech.set");
|
||||
CMD2_REDIRECT ("get_connection_seed", "connection_seed");
|
||||
@@ -436,6 +485,18 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT ("get_peer_exchange", "protocol.pex");
|
||||
CMD2_REDIRECT_GENERIC("set_peer_exchange", "protocol.pex.set");
|
||||
|
||||
//
|
||||
// Trackers:
|
||||
//
|
||||
|
||||
CMD2_REDIRECT ("tracker_numwant", "trackers.numwant.set");
|
||||
CMD2_REDIRECT ("get_tracker_numwant", "trackers.numwant");
|
||||
CMD2_REDIRECT_GENERIC("set_tracker_numwant", "trackers.numwant.set");
|
||||
|
||||
CMD2_REDIRECT ("use_udp_trackers", "trackers.use_udp.set");
|
||||
CMD2_REDIRECT ("get_use_udp_trackers", "trackers.use_udp");
|
||||
CMD2_REDIRECT_GENERIC("set_use_udp_trackers", "trackers.use_udp.set");
|
||||
|
||||
//
|
||||
// DHT stuff
|
||||
//
|
||||
@@ -452,17 +513,31 @@ main(int argc, char** argv) {
|
||||
CMD2_REDIRECT ("get_directory", "directory.default");
|
||||
CMD2_REDIRECT_GENERIC("set_directory", "directory.default.set");
|
||||
|
||||
//
|
||||
// Various system stuff:
|
||||
//
|
||||
|
||||
CMD2_REDIRECT ("get_session_lock", "system.session.use_lock");
|
||||
CMD2_REDIRECT_GENERIC("set_session_lock", "system.session.use_lock.set");
|
||||
CMD2_REDIRECT ("get_session_on_completion", "system.session.on_completion");
|
||||
CMD2_REDIRECT_GENERIC("set_session_on_completion", "system.session.on_completion.set");
|
||||
|
||||
CMD2_REDIRECT ("hash_read_ahead", "system.hash.read_ahead.set");
|
||||
CMD2_REDIRECT ("get_hash_read_ahead", "system.hash.read_ahead");
|
||||
CMD2_REDIRECT_GENERIC("set_hash_read_ahead", "system.hash.read_ahead.set");
|
||||
|
||||
CMD2_REDIRECT ("hash_interval", "system.hash.interval.set");
|
||||
CMD2_REDIRECT ("get_hash_interval", "system.hash.interval");
|
||||
CMD2_REDIRECT_GENERIC("set_hash_interval", "system.hash.interval.set");
|
||||
|
||||
CMD2_REDIRECT ("hash_max_tries", "system.hash.max_tries.set");
|
||||
CMD2_REDIRECT ("get_hash_max_tries", "system.hash.max_tries");
|
||||
CMD2_REDIRECT_GENERIC("set_hash_max_tries", "system.hash.max_tries.set");
|
||||
|
||||
CMD2_REDIRECT ("check_hash", "pieces.hash.on_completion.set");
|
||||
CMD2_REDIRECT ("get_check_hash", "pieces.hash.on_completion");
|
||||
CMD2_REDIRECT_GENERIC("set_check_hash", "pieces.hash.on_completion.set");
|
||||
|
||||
// CMD2_REDIRECT ("get_hash_interval", "pieces.hash.interval");
|
||||
|
||||
//
|
||||
// Download:
|
||||
//
|
||||
|
||||
+1
-2
@@ -3,8 +3,6 @@ noinst_LIBRARIES = libsub_rpc.a
|
||||
libsub_rpc_a_SOURCES = \
|
||||
command.h \
|
||||
command_impl.h \
|
||||
command_function.cc \
|
||||
command_function.h \
|
||||
command_map.cc \
|
||||
command_map.h \
|
||||
command_scheduler.cc \
|
||||
@@ -15,6 +13,7 @@ libsub_rpc_a_SOURCES = \
|
||||
command_new_slot.h \
|
||||
exec_file.cc \
|
||||
exec_file.h \
|
||||
fixed_key.h \
|
||||
object_storage.cc \
|
||||
object_storage.h \
|
||||
parse.cc \
|
||||
|
||||
@@ -1,129 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2007, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <rak/functional.h>
|
||||
|
||||
#include "parse.h"
|
||||
#include "parse_commands.h"
|
||||
#include "command_function.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
// Temp until it can be moved somewhere better...
|
||||
const torrent::Object
|
||||
command_function_call(const torrent::raw_string& cmd, target_type target, const torrent::Object& args) {
|
||||
rpc::Command::stack_type stack;
|
||||
torrent::Object* last_stack;
|
||||
|
||||
if (args.is_list())
|
||||
last_stack = rpc::Command::push_stack(args.as_list(), &stack);
|
||||
else if (args.type() != torrent::Object::TYPE_NONE)
|
||||
last_stack = rpc::Command::push_stack(&args, &args + 1, &stack);
|
||||
else
|
||||
last_stack = rpc::Command::push_stack(NULL, NULL, &stack);
|
||||
|
||||
try {
|
||||
torrent::Object result = parse_command_multiple(target, cmd.begin(), cmd.end());
|
||||
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
return result;
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
CommandFunctionList::call(Command* rawCommand, target_type target, const torrent::Object& args) {
|
||||
rpc::Command::stack_type stack;
|
||||
torrent::Object* last_stack;
|
||||
|
||||
if (args.is_list())
|
||||
last_stack = rpc::Command::push_stack(args.as_list(), &stack);
|
||||
else if (args.type() != torrent::Object::TYPE_NONE)
|
||||
last_stack = rpc::Command::push_stack(&args, &args + 1, &stack);
|
||||
else
|
||||
last_stack = rpc::Command::push_stack(NULL, NULL, &stack);
|
||||
|
||||
CommandFunctionList* command = reinterpret_cast<CommandFunctionList*>(rawCommand);
|
||||
|
||||
try {
|
||||
for (base_type::const_iterator itr = command->begin(), last = command->end(); itr != last; itr++)
|
||||
parse_command_multiple(target, itr->second.c_str(), itr->second.c_str() + itr->second.size());
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
throw e;
|
||||
}
|
||||
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
CommandFunctionList::const_iterator
|
||||
CommandFunctionList::find(const char* key) {
|
||||
base_type::iterator itr = std::find_if(begin(), end(), rak::less_equal(key, rak::mem_ref(&base_type::value_type::first)));
|
||||
|
||||
if (itr == end() || itr->first != key)
|
||||
return end();
|
||||
else
|
||||
return itr;
|
||||
}
|
||||
|
||||
void
|
||||
CommandFunctionList::insert(const std::string& key, const std::string& cmd) {
|
||||
base_type::iterator itr = std::find_if(begin(), end(), rak::less_equal(key, rak::mem_ref(&base_type::value_type::first)));
|
||||
|
||||
if (itr != end() && itr->first == key)
|
||||
itr->second = cmd;
|
||||
else
|
||||
base_type::insert(itr, base_type::value_type(key, cmd));
|
||||
}
|
||||
|
||||
void
|
||||
CommandFunctionList::erase(const std::string& key) {
|
||||
base_type::iterator itr = std::find_if(begin(), end(), rak::less_equal(key, rak::mem_ref(&base_type::value_type::first)));
|
||||
|
||||
if (itr != end() && itr->first == key)
|
||||
base_type::erase(itr);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,82 +0,0 @@
|
||||
// rTorrent - BitTorrent client
|
||||
// Copyright (C) 2005-2007, Jari Sundell
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation; either version 2 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
// In addition, as a special exception, the copyright holders give
|
||||
// permission to link the code of portions of this program with the
|
||||
// OpenSSL library under certain conditions as described in each
|
||||
// individual source file, and distribute linked combinations
|
||||
// including the two.
|
||||
//
|
||||
// You must obey the GNU General Public License in all respects for
|
||||
// all of the code used other than OpenSSL. If you modify file(s)
|
||||
// with this exception, you may extend this exception to your version
|
||||
// of the file(s), but you are not obligated to do so. If you do not
|
||||
// wish to do so, delete this exception statement from your version.
|
||||
// If you delete this exception statement from all source files in the
|
||||
// program, then also delete it here.
|
||||
//
|
||||
// Contact: Jari Sundell <jaris@ifi.uio.no>
|
||||
//
|
||||
// Skomakerveien 33
|
||||
// 3185 Skoppum, NORWAY
|
||||
|
||||
#ifndef RTORRENT_RPC_COMMAND_FUNCTION_H
|
||||
#define RTORRENT_RPC_COMMAND_FUNCTION_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <limits>
|
||||
#include <inttypes.h>
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "command.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
class CommandFunctionList : public Command,
|
||||
private std::vector<std::pair<std::string, std::string> > {
|
||||
public:
|
||||
typedef std::vector<std::pair<std::string, std::string> > base_type;
|
||||
|
||||
using Command::value_type;
|
||||
using base_type::iterator;
|
||||
using base_type::const_iterator;
|
||||
using base_type::begin;
|
||||
using base_type::end;
|
||||
|
||||
CommandFunctionList() {}
|
||||
|
||||
const_iterator find(const char* key);
|
||||
|
||||
void insert(const std::string& key, const std::string& cmd);
|
||||
void erase(const std::string& key);
|
||||
|
||||
static const torrent::Object call(Command* rawCommand, target_type target, const torrent::Object& args);
|
||||
};
|
||||
|
||||
// Temp until it can be moved somewhere better...
|
||||
const torrent::Object
|
||||
command_function_call(const torrent::raw_string& cmd, target_type target, const torrent::Object& args);
|
||||
|
||||
inline const torrent::Object
|
||||
command_function_call_str(const std::string& cmd, target_type target, const torrent::Object& args) {
|
||||
return command_function_call(torrent::raw_string::from_string(cmd), target, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+39
-14
@@ -39,7 +39,7 @@
|
||||
#include "object_storage.h"
|
||||
|
||||
#include "parse.h"
|
||||
#include "command_function.h"
|
||||
#include "parse_commands.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
@@ -69,6 +69,7 @@ object_storage::insert(const char* key_data, uint32_t key_size, const torrent::O
|
||||
case flag_value_type: object = convert_to_value(rawObject); break;
|
||||
case flag_string_type: object = convert_to_string(rawObject); break;
|
||||
case flag_function_type: object = convert_to_string(rawObject); break;
|
||||
case flag_multi_type: object = torrent::Object::create_map(); break;
|
||||
}
|
||||
|
||||
if (!(flags & mask_type))
|
||||
@@ -95,17 +96,6 @@ object_storage::get(const torrent::raw_string& key) {
|
||||
return itr->second.object;
|
||||
}
|
||||
|
||||
// const torrent::Object&
|
||||
// object_storage::set(const torrent::raw_string& key, const torrent::Object& object) {
|
||||
// local_iterator itr = find_local(key);
|
||||
|
||||
// if (itr == end(bucket_count()) || (itr->second.flags & mask_type) != flag_generic_type)
|
||||
// throw torrent::input_error("Key not found or wrong type.");
|
||||
|
||||
// return itr->second.object = object;
|
||||
// }
|
||||
|
||||
|
||||
const torrent::Object&
|
||||
object_storage::set_bool(const torrent::raw_string& key, int64_t object) {
|
||||
local_iterator itr = find_local(key);
|
||||
@@ -152,10 +142,45 @@ torrent::Object
|
||||
object_storage::call_function(const torrent::raw_string& key, target_type target, const torrent::Object& object) {
|
||||
local_iterator itr = find_local(key);
|
||||
|
||||
if (itr == end(bucket_count()) || !itr->second.object.is_string())
|
||||
if (itr == end(bucket_count()))
|
||||
throw torrent::input_error("Key not found or wrong type.");
|
||||
|
||||
return command_function_call_str(itr->second.object.as_string(), target, object);
|
||||
switch (itr->second.flags & mask_type) {
|
||||
case flag_function_type:
|
||||
return command_function_call_str(itr->second.object.as_string(), target, object);
|
||||
case flag_multi_type:
|
||||
return command_function_multi_call(itr->second.object.as_map(), target, object);
|
||||
default:
|
||||
throw torrent::input_error("Key not found or wrong type.");
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
object_storage::has_multi_key(const torrent::raw_string& key, const std::string& cmd_key) {
|
||||
local_iterator itr = find_local(key);
|
||||
|
||||
return itr != end(0) && (itr->second.flags & mask_type) == flag_multi_type &&
|
||||
itr->second.object.has_key(cmd_key);
|
||||
}
|
||||
|
||||
void
|
||||
object_storage::erase_multi_key(const torrent::raw_string& key, const std::string& cmd_key) {
|
||||
local_iterator itr = find_local(key);
|
||||
|
||||
if (itr != end(0) && (itr->second.flags & mask_type) == flag_multi_type)
|
||||
return;
|
||||
|
||||
itr->second.object.erase_key(cmd_key);
|
||||
}
|
||||
|
||||
void
|
||||
object_storage::set_multi_key(const torrent::raw_string& key, const std::string& cmd_key, const std::string& object) {
|
||||
local_iterator itr = find_local(key);
|
||||
|
||||
if (itr == end(0) || (itr->second.flags & mask_type) != flag_multi_type)
|
||||
throw torrent::input_error("Key not found or wrong type.");
|
||||
|
||||
itr->second.object.insert_key(cmd_key, object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+35
-77
@@ -46,82 +46,10 @@
|
||||
#include <torrent/object.h>
|
||||
|
||||
#include "command.h"
|
||||
#include "fixed_key.h"
|
||||
|
||||
namespace rpc {
|
||||
|
||||
// The key size should be such that the value type size which includes
|
||||
// the next-pointer.
|
||||
|
||||
template <size_t MaxSize>
|
||||
class fixed_key_type {
|
||||
public:
|
||||
typedef char value_type;
|
||||
typedef const char* iterator;
|
||||
typedef const char* const_iterator;
|
||||
typedef uint32_t size_type;
|
||||
|
||||
static const size_type max_size = MaxSize - 1;
|
||||
|
||||
fixed_key_type() : m_size(0) { m_data[0] = '\0'; }
|
||||
fixed_key_type(const fixed_key_type& k) : m_size(k.m_size) { std::memcpy(m_data, k.m_data, k.m_size + 1); }
|
||||
|
||||
fixed_key_type(const value_type* src_data, size_type src_size) { set_data(src_data, src_size); }
|
||||
|
||||
static fixed_key_type from_c_str(const char* str) { fixed_key_type k; k.set_c_str(str); return k; }
|
||||
static fixed_key_type from_string(const std::string& str) { fixed_key_type k; k.set_c_str(str.c_str(), str.size()); return k; }
|
||||
static fixed_key_type from_raw_string(const torrent::raw_string& str) { fixed_key_type k; k.set_data(str.data(), str.size()); return k; }
|
||||
|
||||
bool empty() const { return m_size == 0;; }
|
||||
size_type size() const { return m_size; }
|
||||
|
||||
iterator begin() const { return m_data; }
|
||||
iterator end() const { return m_data + m_size; }
|
||||
|
||||
value_type* data() { return m_data; }
|
||||
const value_type* data() const { return m_data; }
|
||||
const char* c_str() const { return m_data; }
|
||||
|
||||
void set_data(const value_type* src_data, size_type src_size);
|
||||
void set_c_str(const value_type* src_data);
|
||||
void set_c_str(const value_type* src_data, size_type src_size);
|
||||
|
||||
bool operator == (const fixed_key_type& rhs) const { return m_size == rhs.m_size && std::memcmp(m_data, rhs.m_data, m_size) == 0; }
|
||||
bool operator != (const fixed_key_type& rhs) const { return m_size != rhs.m_size || std::memcmp(m_data, rhs.m_data, m_size) != 0; }
|
||||
|
||||
bool operator == (const std::string& rhs) const { return m_size == rhs.size() && std::memcmp(m_data, rhs.data(), m_size) == 0; }
|
||||
|
||||
private:
|
||||
size_type m_size;
|
||||
char m_data[max_size];
|
||||
};
|
||||
|
||||
struct hash_fixed_key_type {
|
||||
template <size_t MaxSize>
|
||||
inline std::size_t operator () (const fixed_key_type<MaxSize>& p) const { return hash(p.data()); }
|
||||
|
||||
static inline std::size_t hash(const char* data) {
|
||||
std::size_t result = 0;
|
||||
|
||||
while (*data != '\0')
|
||||
result = (result * 131) + *data++;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static inline std::size_t hash(const char* data, uint32_t size) {
|
||||
std::size_t result = 0;
|
||||
|
||||
while (size--)
|
||||
result = (result * 131) + *data++;
|
||||
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
struct object_storage_node {
|
||||
torrent::Object object;
|
||||
char flags;
|
||||
@@ -157,6 +85,7 @@ public:
|
||||
static const unsigned int flag_value_type = 0x3;
|
||||
static const unsigned int flag_string_type = 0x4;
|
||||
static const unsigned int flag_function_type = 0x5;
|
||||
static const unsigned int flag_multi_type = 0x6;
|
||||
|
||||
static const unsigned int mask_type = 0xf;
|
||||
|
||||
@@ -181,9 +110,6 @@ public:
|
||||
const torrent::Object& get_c_str(const char* str) { return get(torrent::raw_string(str, std::strlen(str))); }
|
||||
const torrent::Object& get_str(const std::string& str) { return get(torrent::raw_string(str.data(), str.size())); }
|
||||
|
||||
// const torrent::Object& set(const torrent::raw_string& key, const torrent::Object& object);
|
||||
// const torrent::Object& set_c_str(const char* str, const torrent::Object& object) { return set(torrent::raw_string(str, std::strlen(str)), object); }
|
||||
|
||||
const torrent::Object& set_bool(const torrent::raw_string& key, int64_t object);
|
||||
const torrent::Object& set_c_str_bool(const char* str, int64_t object) { return set_bool(torrent::raw_string::from_c_str(str), object); }
|
||||
const torrent::Object& set_str_bool(const std::string& str, int64_t object) { return set_bool(torrent::raw_string::from_string(str), object); }
|
||||
@@ -196,11 +122,23 @@ public:
|
||||
const torrent::Object& set_c_str_string(const char* str, const std::string& object) { return set_string(torrent::raw_string::from_c_str(str), object); }
|
||||
const torrent::Object& set_str_string(const std::string& str, const std::string& object) { return set_string(torrent::raw_string::from_string(str), object); }
|
||||
|
||||
// Functions callers:
|
||||
torrent::Object call_function(const torrent::raw_string& key, target_type target, const torrent::Object& object);
|
||||
torrent::Object call_function_str(const std::string& key, target_type target, const torrent::Object& object);
|
||||
|
||||
// Single-command function:
|
||||
|
||||
const torrent::Object& set_function(const torrent::raw_string& key, const std::string& object);
|
||||
const torrent::Object& set_str_function(const std::string& str, const std::string& object) { return set_function(torrent::raw_string::from_string(str), object); }
|
||||
const torrent::Object& set_str_function(const std::string& key, const std::string& object);
|
||||
|
||||
// Multi-command function:
|
||||
bool has_multi_key(const torrent::raw_string& key, const std::string& cmd_key);
|
||||
void erase_multi_key(const torrent::raw_string& key, const std::string& cmd_key);
|
||||
void set_multi_key(const torrent::raw_string& key, const std::string& cmd_key, const std::string& object);
|
||||
|
||||
bool has_str_multi_key(const std::string& key, const std::string& cmd_key);
|
||||
void erase_str_multi_key(const std::string& key, const std::string& cmd_key);
|
||||
void set_str_multi_key(const std::string& key, const std::string& cmd_key, const std::string& object);
|
||||
};
|
||||
|
||||
//
|
||||
@@ -262,6 +200,26 @@ object_storage::call_function_str(const std::string& key, target_type target, co
|
||||
return call_function(torrent::raw_string::from_string(key), target, object);
|
||||
}
|
||||
|
||||
inline const torrent::Object&
|
||||
object_storage::set_str_function(const std::string& key, const std::string& object) {
|
||||
return set_function(torrent::raw_string::from_string(key), object);
|
||||
}
|
||||
|
||||
inline bool
|
||||
object_storage::has_str_multi_key(const std::string& key, const std::string& cmd_key) {
|
||||
return has_multi_key(torrent::raw_string::from_string(key), cmd_key);
|
||||
}
|
||||
|
||||
inline void
|
||||
object_storage::erase_str_multi_key(const std::string& key, const std::string& cmd_key) {
|
||||
erase_multi_key(torrent::raw_string::from_string(key), cmd_key);
|
||||
}
|
||||
|
||||
inline void
|
||||
object_storage::set_str_multi_key(const std::string& key, const std::string& cmd_key, const std::string& object) {
|
||||
return set_multi_key(torrent::raw_string::from_string(key), cmd_key, object);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -223,4 +223,61 @@ parse_command_name(const char* first, const char* last, std::string* dest) {
|
||||
return first;
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
// Temp until it can be moved somewhere better...
|
||||
const torrent::Object
|
||||
command_function_call(const torrent::raw_string& cmd, target_type target, const torrent::Object& args) {
|
||||
rpc::Command::stack_type stack;
|
||||
torrent::Object* last_stack;
|
||||
|
||||
if (args.is_list())
|
||||
last_stack = rpc::Command::push_stack(args.as_list(), &stack);
|
||||
else if (args.type() != torrent::Object::TYPE_NONE)
|
||||
last_stack = rpc::Command::push_stack(&args, &args + 1, &stack);
|
||||
else
|
||||
last_stack = rpc::Command::push_stack(NULL, NULL, &stack);
|
||||
|
||||
try {
|
||||
torrent::Object result = parse_command_multiple(target, cmd.begin(), cmd.end());
|
||||
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
return result;
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
const torrent::Object
|
||||
command_function_multi_call(const torrent::Object::map_type& cmd, target_type target, const torrent::Object& args) {
|
||||
rpc::Command::stack_type stack;
|
||||
torrent::Object* last_stack;
|
||||
|
||||
if (args.is_list())
|
||||
last_stack = rpc::Command::push_stack(args.as_list(), &stack);
|
||||
else if (args.type() != torrent::Object::TYPE_NONE)
|
||||
last_stack = rpc::Command::push_stack(&args, &args + 1, &stack);
|
||||
else
|
||||
last_stack = rpc::Command::push_stack(NULL, NULL, &stack);
|
||||
|
||||
try {
|
||||
for (torrent::Object::map_const_iterator itr = cmd.begin(), last = cmd.end(); itr != last; itr++) {
|
||||
const std::string& cmd_str = itr->second.as_string();
|
||||
parse_command_multiple(target, cmd_str.c_str(), cmd_str.c_str() + cmd_str.size());
|
||||
}
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
throw e;
|
||||
}
|
||||
|
||||
rpc::Command::pop_stack(&stack, last_stack);
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -133,6 +133,21 @@ call_command_d_range(const char* key, core::Download* download, torrent::Object:
|
||||
return commands.call_command_d(key, download, rawArgs);
|
||||
}
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
// Temp until it can be moved somewhere better...
|
||||
const torrent::Object
|
||||
command_function_call(const torrent::raw_string& cmd, target_type target, const torrent::Object& args);
|
||||
const torrent::Object
|
||||
command_function_multi_call(const torrent::Object::map_type& cmd, target_type target, const torrent::Object& args);
|
||||
|
||||
inline const torrent::Object
|
||||
command_function_call_str(const std::string& cmd, target_type target, const torrent::Object& args) {
|
||||
return command_function_call(torrent::raw_string::from_string(cmd), target, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
+4
-4
@@ -166,8 +166,8 @@ Root::set_down_throttle(unsigned int throttle) {
|
||||
|
||||
torrent::down_throttle_global()->set_max_rate(throttle * 1024);
|
||||
|
||||
unsigned int div = std::max<int>(rpc::call_command_value("max_downloads_div"), 0);
|
||||
unsigned int global = std::max<int>(rpc::call_command_value("max_downloads_global"), 0);
|
||||
unsigned int div = std::max<int>(rpc::call_command_value("throttle.max_downloads.div"), 0);
|
||||
unsigned int global = std::max<int>(rpc::call_command_value("throttle.max_downloads.global"), 0);
|
||||
|
||||
if (throttle == 0 || div == 0) {
|
||||
torrent::set_max_download_unchoked(global);
|
||||
@@ -196,8 +196,8 @@ Root::set_up_throttle(unsigned int throttle) {
|
||||
|
||||
torrent::up_throttle_global()->set_max_rate(throttle * 1024);
|
||||
|
||||
unsigned int div = std::max<int>(rpc::call_command_value("max_uploads_div"), 0);
|
||||
unsigned int global = std::max<int>(rpc::call_command_value("max_uploads_global"), 0);
|
||||
unsigned int div = std::max<int>(rpc::call_command_value("throttle.max_uploads.div"), 0);
|
||||
unsigned int global = std::max<int>(rpc::call_command_value("throttle.max_uploads.global"), 0);
|
||||
|
||||
if (throttle == 0 || div == 0) {
|
||||
torrent::set_max_unchoked(global);
|
||||
|
||||
Reference in New Issue
Block a user