diff --git a/src/command_download.cc b/src/command_download.cc index b3bd633e..0b542078 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -698,7 +698,7 @@ initialize_command_download() { CMD2_DL ("d.uploads_max", std::tr1::bind(&torrent::ConnectionList::max_size, CMD2_BIND_CL)); CMD2_DL_VALUE_V ("d.uploads_max.set", std::tr1::bind(&torrent::ConnectionList::set_max_size, CMD2_BIND_CL, std::tr1::placeholders::_2)); CMD2_DL ("d.peers_connected", std::tr1::bind(&torrent::ConnectionList::size, CMD2_BIND_CL)); - CMD2_DL ("d.peers_note_connected", std::tr1::bind(&torrent::PeerList::available_list_size, CMD2_BIND_PL)); + CMD2_DL ("d.peers_not_connected", std::tr1::bind(&torrent::PeerList::available_list_size, CMD2_BIND_PL)); CMD2_DL ("d.peers_complete", CMD2_ON_DL(peers_complete)); CMD2_DL ("d.peers_accounted", CMD2_ON_DL(peers_accounted)); diff --git a/src/command_dynamic.cc b/src/command_dynamic.cc index 7e88dcf2..6b9ae012 100644 --- a/src/command_dynamic.cc +++ b/src/command_dynamic.cc @@ -114,15 +114,6 @@ system_method_insert(const torrent::Object::list_type& args) { rpc::commands.insert_type(create_new_key<0>(rawKey, ""), command, slot, flags, NULL, NULL); - } else if (options.find("redirect") != std::string::npos) { - if (++itrArgs == args.end()) - throw torrent::input_error("Invalid argument count."); - - rpc::Command::any_slot slot = &rpc::CommandFunction::call_redirect; - rpc::Command* command = new rpc::CommandFunction(itrArgs->as_string()); - - rpc::commands.insert_type(create_new_key<0>(rawKey, ""), command, slot, flags, NULL, NULL); - } else if (options.find("value") != std::string::npos || options.find("bool") != std::string::npos || options.find("string") != std::string::npos || @@ -190,6 +181,20 @@ system_method_erase(const torrent::Object::string_type& args) { return torrent::Object(); } +torrent::Object +system_method_redirect(const torrent::Object::list_type& args) { + if (args.size() != 2) + throw torrent::input_error("Invalid argument count."); + + std::string new_key = torrent::object_create_string(args.front()); + std::string dest_key = torrent::object_create_string(args.back()); + + rpc::commands.create_redirect(new_key.c_str(), dest_key.c_str(), + rpc::CommandMap::flag_public_xmlrpc | rpc::CommandMap::flag_delete_key); + + return torrent::Object(); +} + torrent::Object system_method_get(const torrent::Object::string_type& args) { rpc::CommandFunction* function; @@ -278,6 +283,7 @@ void initialize_command_dynamic() { CMD2_ANY_LIST ("method.insert", std::tr1::bind(&system_method_insert, std::tr1::placeholders::_2)); CMD2_ANY_STRING ("method.erase", std::tr1::bind(&system_method_erase, std::tr1::placeholders::_2)); + CMD2_ANY_LIST ("method.redirect", std::tr1::bind(&system_method_redirect, std::tr1::placeholders::_2)); CMD2_ANY_STRING ("method.get", std::tr1::bind(&system_method_get, std::tr1::placeholders::_2)); CMD2_ANY_LIST ("method.set", std::tr1::bind(&system_method_set, std::tr1::placeholders::_2)); CMD2_ANY_LIST ("method.set_key", std::tr1::bind(&system_method_set_key, std::tr1::placeholders::_2)); diff --git a/src/command_events.cc b/src/command_events.cc index 1b093d82..3e3d8013 100644 --- a/src/command_events.cc +++ b/src/command_events.cc @@ -50,7 +50,6 @@ #include "core/manager.h" #include "core/view_manager.h" #include "rpc/command_scheduler.h" -#include "rpc/command_slot.h" #include "rpc/command_variable.h" #include "rpc/parse.h" #include "rpc/parse_commands.h" diff --git a/src/command_helpers.cc b/src/command_helpers.cc index 1bab69f8..686b0b8a 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -38,32 +38,12 @@ #include -#include "rpc/command_slot.h" #include "rpc/command_variable.h" #include "globals.h" #include "control.h" #include "command_helpers.h" -rpc::CommandSlot commandSlots[COMMAND_SLOTS_SIZE]; -rpc::CommandSlot* commandSlotsItr = commandSlots; -rpc::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; -rpc::CommandVariable* commandVariablesItr = commandVariables; -rpc::CommandObjectPtr commandObjectPtrs[COMMAND_OBJECT_PTR_SIZE]; -rpc::CommandObjectPtr* commandObjectPtrsItr = commandObjectPtrs; -rpc::CommandSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE]; -rpc::CommandSlot* commandDownloadSlotsItr = commandDownloadSlots; -rpc::CommandSlot commandFileSlots[COMMAND_FILE_SLOTS_SIZE]; -rpc::CommandSlot* commandFileSlotsItr = commandFileSlots; -rpc::CommandSlot commandFileItrSlots[COMMAND_FILE_ITR_SLOTS_SIZE]; -rpc::CommandSlot* commandFileItrSlotsItr = commandFileItrSlots; -rpc::CommandSlot commandPeerSlots[COMMAND_PEER_SLOTS_SIZE]; -rpc::CommandSlot* commandPeerSlotsItr = commandPeerSlots; -rpc::CommandSlot commandTrackerSlots[COMMAND_TRACKER_SLOTS_SIZE]; -rpc::CommandSlot* commandTrackerSlotsItr = commandTrackerSlots; -rpc::CommandSlot commandAnySlots[COMMAND_ANY_SLOTS_SIZE]; -rpc::CommandSlot* commandAnySlotsItr = commandAnySlots; - rpc::command_base commandNewSlots[COMMAND_NEW_SLOTS_SIZE]; rpc::command_base* commandNewSlotItr = commandNewSlots; @@ -92,43 +72,9 @@ initialize_commands() { initialize_command_scheduler(); #ifdef ADDING_COMMANDS - if (commandSlotsItr > commandSlots + COMMAND_SLOTS_SIZE || - commandVariablesItr > commandVariables + COMMAND_VARIABLES_SIZE || - commandObjectPtrsItr > commandObjectPtrs + COMMAND_OBJECT_PTR_SIZE || - commandDownloadSlotsItr > commandDownloadSlots + COMMAND_DOWNLOAD_SLOTS_SIZE || - commandFileSlotsItr > commandFileSlots + COMMAND_FILE_SLOTS_SIZE || - commandFileItrSlotsItr > commandFileItrSlots + COMMAND_FILE_ITR_SLOTS_SIZE || - commandPeerSlotsItr > commandPeerSlots + COMMAND_PEER_SLOTS_SIZE || - commandTrackerSlotsItr > commandTrackerSlots + COMMAND_TRACKER_SLOTS_SIZE || - commandAnySlotsItr > commandAnySlots + COMMAND_ANY_SLOTS_SIZE || - commandNewSlotItr > commandNewSlots + COMMAND_NEW_SLOTS_SIZE) + if (commandNewSlotItr > commandNewSlots + COMMAND_NEW_SLOTS_SIZE) #else - if (commandSlotsItr != commandSlots + COMMAND_SLOTS_SIZE || - commandVariablesItr != commandVariables + COMMAND_VARIABLES_SIZE || - commandObjectPtrsItr != commandObjectPtrs + COMMAND_OBJECT_PTR_SIZE || - commandDownloadSlotsItr != commandDownloadSlots + COMMAND_DOWNLOAD_SLOTS_SIZE || - commandFileSlotsItr != commandFileSlots + COMMAND_FILE_SLOTS_SIZE || - commandFileItrSlotsItr != commandFileItrSlots + COMMAND_FILE_ITR_SLOTS_SIZE || - commandPeerSlotsItr != commandPeerSlots + COMMAND_PEER_SLOTS_SIZE || - commandTrackerSlotsItr != commandTrackerSlots + COMMAND_TRACKER_SLOTS_SIZE || - commandAnySlotsItr != commandAnySlots + COMMAND_ANY_SLOTS_SIZE || - commandNewSlotItr != commandNewSlots + COMMAND_NEW_SLOTS_SIZE) + if (commandNewSlotItr != commandNewSlots + COMMAND_NEW_SLOTS_SIZE) #endif throw torrent::internal_error("initialize_commands() static command array size mismatch."); } - -void -add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, - rpc::Command::cleaned_slot getSlot, rpc::Command::cleaned_slot setSlot, - const torrent::Object& defaultObject) { - rpc::CommandVariable* variable = commandVariablesItr++; - variable->set_variable(defaultObject); - - rpc::commands.insert_type(getKey, variable, getSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); - - if (setKey) - rpc::commands.insert_type(setKey, variable, setSlot, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, "i:", ""); - - if (defaultSetKey) - rpc::commands.insert_type(defaultSetKey, variable, setSlot, rpc::CommandMap::flag_dont_delete, "i:", ""); -} diff --git a/src/command_helpers.h b/src/command_helpers.h index ff1890ed..f7af8cdb 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -37,7 +37,6 @@ #ifndef RTORRENT_UTILS_COMMAND_HELPERS_H #define RTORRENT_UTILS_COMMAND_HELPERS_H -#include "rpc/command_slot.h" #include "rpc/command_new_slot.h" #include "rpc/command_function.h" #include "rpc/parse_commands.h" @@ -49,186 +48,15 @@ namespace rpc { // By using a static array we avoid allocating the variables on the // heap. This should reduce memory use and improve cache locality. -#define COMMAND_SLOTS_SIZE 200 -#define COMMAND_VARIABLES_SIZE 100 -#define COMMAND_OBJECT_PTR_SIZE 20 -#define COMMAND_DOWNLOAD_SLOTS_SIZE 150 -#define COMMAND_FILE_SLOTS_SIZE 30 -#define COMMAND_FILE_ITR_SLOTS_SIZE 10 -#define COMMAND_PEER_SLOTS_SIZE 20 -#define COMMAND_TRACKER_SLOTS_SIZE 15 -#define COMMAND_ANY_SLOTS_SIZE 50 - #define COMMAND_NEW_SLOTS_SIZE 500 #define ADDING_COMMANDS -extern rpc::CommandSlot commandSlots[COMMAND_SLOTS_SIZE]; -extern rpc::CommandSlot* commandSlotsItr; -extern rpc::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; -extern rpc::CommandVariable* commandVariablesItr; -extern rpc::CommandObjectPtr commandObjectPtrs[COMMAND_OBJECT_PTR_SIZE]; -extern rpc::CommandObjectPtr* commandObjectPtrsItr; -extern rpc::CommandSlot commandDownloadSlots[COMMAND_DOWNLOAD_SLOTS_SIZE]; -extern rpc::CommandSlot* commandDownloadSlotsItr; -extern rpc::CommandSlot commandFileSlots[COMMAND_FILE_SLOTS_SIZE]; -extern rpc::CommandSlot* commandFileSlotsItr; -extern rpc::CommandSlot commandFileItrSlots[COMMAND_FILE_ITR_SLOTS_SIZE]; -extern rpc::CommandSlot* commandFileItrSlotsItr; -extern rpc::CommandSlot commandPeerSlots[COMMAND_PEER_SLOTS_SIZE]; -extern rpc::CommandSlot* commandPeerSlotsItr; -extern rpc::CommandSlot commandTrackerSlots[COMMAND_TRACKER_SLOTS_SIZE]; -extern rpc::CommandSlot* commandTrackerSlotsItr; -extern rpc::CommandSlot commandAnySlots[COMMAND_ANY_SLOTS_SIZE]; -extern rpc::CommandSlot* commandAnySlotsItr; - extern rpc::command_base commandNewSlots[COMMAND_NEW_SLOTS_SIZE]; extern rpc::command_base* commandNewSlotItr; void initialize_commands(); -void -add_variable(const char* getKey, const char* setKey, const char* defaultSetKey, - rpc::Command::cleaned_slot getSlot, rpc::Command::cleaned_slot setSlot, - const torrent::Object& defaultObject); - -#define ADD_VARIABLE_BOOL(key, defaultValue) \ -add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_bool, &rpc::CommandVariable::set_bool, (int64_t)defaultValue); - -#define ADD_VARIABLE_VALUE(key, defaultValue) \ -add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_value, &rpc::CommandVariable::set_value, (int64_t)defaultValue); - -#define ADD_VARIABLE_STRING(key, defaultValue) \ -add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_string, &rpc::CommandVariable::set_string, std::string(defaultValue)); - -#define ADD_C_STRING(key, defaultValue) \ -add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::string(defaultValue)); - -#define ADD_COMMAND_SLOT(key, function, slot, parm, doc) \ - commandSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define ADD_ANY_SLOT(key, function, slot, parm, doc) \ - commandAnySlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandAnySlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define ADD_COMMAND_SLOT_PRIVATE(key, function, slot) \ - commandSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandSlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, NULL, NULL); - -#define ADD_COMMAND_COPY(key, function, parm, doc) \ - rpc::commands.insert_type(key, (commandSlotsItr - 1), &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define ADD_COMMAND_COPY_PRIVATE(key, function) \ - rpc::commands.insert_type(key, (commandSlotsItr - 1), &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete, NULL, NULL); - -#define ADD_COMMAND_VALUE_TRI(key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value, rpc::object_value_fn(set)) \ - ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_COMMAND_VALUE_TRI_KB(key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value_kb, rpc::object_value_fn(set)) \ - ADD_COMMAND_COPY("set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_COMMAND_VALUE_SET_OCT(prefix, key, set) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, rpc::object_value_fn(set)) \ - ADD_COMMAND_COPY(prefix "set_" key, call_value, "i:i", "") - -#define ADD_COMMAND_VALUE_TRI_OCT(prefix, key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, rpc::object_value_fn(set)) \ - ADD_COMMAND_COPY(prefix "set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT(prefix "get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") - -#define ADD_COMMAND_STRING_PREFIX(prefix, key, set, get) \ - ADD_COMMAND_SLOT_PRIVATE(key, call_string, rpc::object_string_fn(set)) \ - ADD_COMMAND_COPY(prefix "set_" key, call_string, "i:s", "") \ - ADD_COMMAND_SLOT(prefix "get_" key, call_unknown, rpc::object_void_fn(get), "s:", "") - -#define ADD_COMMAND_STRING_TRI(key, set, get) \ - ADD_COMMAND_STRING_PREFIX("", key, set, get) - -#define ADD_COMMAND_VOID(key, slot) \ - ADD_COMMAND_SLOT(key, call_unknown, rpc::object_void_fn(slot), "i:", "") - -#define ADD_COMMAND_VALUE_UN(key, slot) \ - ADD_COMMAND_SLOT(key, call_value, rpc::object_value_fn(slot), "i:i", "") - -#define ADD_COMMAND_STRING(key, slot) \ - ADD_COMMAND_SLOT(key, call_string, slot, "i:s", "") - -#define ADD_COMMAND_STRING_UN(key, slot) \ - ADD_COMMAND_SLOT(key, call_string, rpc::object_string_fn(slot), "i:s", "") - -#define ADD_COMMAND_NONE(key, slot) \ - ADD_COMMAND_SLOT(key, call_unknown, slot, "i:", "") - -#define ADD_COMMAND_NONE_L(key, slot) \ - ADD_COMMAND_SLOT(key, call_unknown, slot, "A:", "") - -// -// NEW COMMAND MACROS -// - -// -// DOWNLOAD RELATED COMMANDS -// - -#define CMD_V(prefix, postfix, type, defaultValue) \ - add_variable(prefix "" postfix, prefix "set_" postfix, NULL, &rpc::CommandVariable::get_##type, &rpc::CommandVariable::set_##type, defaultValue); - -#define CMD_G_SLOT(key, function, slot, parm, doc) \ - commandAnySlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandAnySlotsItr++, &rpc::CommandSlot::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define CMD_G(key, slot) \ - CMD_G_SLOT(key, call_unknown, slot, "i:", "") - -#define CMD_G_STRING(key, slot) \ - CMD_G_SLOT(key, call_string, slot, "i:", "") - -#define CMD_N_SLOT(key, function, slot, parm, doc) \ - commandAnySlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandAnySlotsItr++, &rpc::CommandSlot::function, \ - rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_no_target | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define CMD_N(key, slot) CMD_N_SLOT(key, call_unknown, slot, "i:", "") -#define CMD_N_VOID(key, slot) CMD_N_SLOT(key, call_unknown, slot, "i:", "") -#define CMD_N_VALUE(key, slot) CMD_N_SLOT(key, call_value, slot, "i:", "") -#define CMD_N_STRING(key, slot) CMD_N_SLOT(key, call_string, slot, "i:", "") -#define CMD_N_LIST(key, slot) CMD_N_SLOT(key, call_list, slot, "i:", "") - -#define CMD_D_SLOT(key, function, slot, parm, doc) \ - commandDownloadSlotsItr->set_slot(slot); \ - rpc::commands.insert_type(key, commandDownloadSlotsItr++, &rpc::CommandSlot::function, \ - rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, parm, doc); - -#define CMD_D(key, slot) \ - CMD_D_SLOT(key, call_unknown, slot, "i:", "") - -#define CMD_D_ANY(key, slot) \ - CMD_D_SLOT(key, call_unknown, slot, "i:", "") - -#define CMD_D_STRING(key, slot) \ - CMD_D_SLOT(key, call_string, slot, "i:", "") - -#define CMD_D_VOID(key, slot) \ - CMD_D_SLOT(key, call_unknown, rpc::object_fn(slot), "i:", "") - -#define CMD_D_VOID_SLOT(key, slot) \ - CMD_D_SLOT(key, call_unknown, rpc::object_void_fn(slot), "i:", "") - -#define CMD_D_VALUE_SLOT(key, slot) \ - CMD_D_SLOT(key, call_value, rpc::object_value_fn(slot), "i:i", "") - -#define CMD_FUNC_SINGLE(key, command) \ - rpc::commands.insert_type(key, new rpc::CommandFunction(command), &rpc::CommandFunction::call, rpc::CommandMap::flag_public_xmlrpc, NULL, NULL); - -#define CMD_OBJ_P(key, function, target) \ - commandObjectPtrsItr->set_object(target); \ - rpc::commands.insert_type(key, commandObjectPtrsItr++, &rpc::CommandObjectPtr::function, rpc::CommandMap::flag_dont_delete | rpc::CommandMap::flag_public_xmlrpc, NULL, NULL); - // // New std::function based command_base helper functions: // @@ -246,6 +74,7 @@ add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::stri // #define CMD2_ANY(key, slot) CMD2_A_FUNCTION(key, command_base_call_any, slot, "i:", "") #define CMD2_ANY(key, slot) CMD2_A_FUNCTION(key, command_base_call, slot, "i:", "") +#define CMD2_ANY_P(key, slot) CMD2_A_FUNCTION_PRIVATE(key, command_base_call, slot, "i:", "") #define CMD2_ANY_V(key, slot) CMD2_A_FUNCTION(key, command_base_call_list, object_convert_void(slot), "i:", "") #define CMD2_ANY_L(key, slot) CMD2_A_FUNCTION(key, command_base_call_list, slot, "A:", "") diff --git a/src/command_local.cc b/src/command_local.cc index 1d5a4bbb..b9a32175 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -50,7 +50,6 @@ #include "core/download_store.h" #include "core/manager.h" #include "rak/string_manip.h" -#include "rpc/command_slot.h" #include "rpc/command_variable.h" #include "rpc/parse_commands.h" #include "rpc/scgi.h" @@ -247,10 +246,10 @@ initialize_command_local() { *rpc::Command::argument(1) = "placeholder.1"; *rpc::Command::argument(2) = "placeholder.2"; *rpc::Command::argument(3) = "placeholder.3"; - CMD_OBJ_P("argument.0", get_generic, rpc::Command::argument(0)); - CMD_OBJ_P("argument.1", get_generic, rpc::Command::argument(1)); - CMD_OBJ_P("argument.2", get_generic, rpc::Command::argument(2)); - CMD_OBJ_P("argument.3", get_generic, rpc::Command::argument(3)); + CMD2_ANY_P("argument.0", std::tr1::bind(&rpc::Command::argument_ref, 0)); + CMD2_ANY_P("argument.1", std::tr1::bind(&rpc::Command::argument_ref, 1)); + CMD2_ANY_P("argument.2", std::tr1::bind(&rpc::Command::argument_ref, 2)); + CMD2_ANY_P("argument.3", std::tr1::bind(&rpc::Command::argument_ref, 3)); CMD2_ANY_LIST ("group.insert", std::tr1::bind(&group_insert, std::tr1::placeholders::_2)); } diff --git a/src/command_network.cc b/src/command_network.cc index 07289a11..df30d487 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -54,7 +54,6 @@ #include "core/manager.h" #include "rpc/scgi.h" #include "ui/root.h" -#include "rpc/command_slot.h" #include "rpc/command_variable.h" #include "rpc/parse.h" #include "rpc/parse_commands.h" diff --git a/src/command_ui.cc b/src/command_ui.cc index 20e60a3e..a51b9a98 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -47,7 +47,6 @@ #include "core/view_manager.h" #include "ui/root.h" #include "ui/download_list.h" -#include "rpc/command_slot.h" #include "rpc/command_variable.h" #include "rpc/parse.h" diff --git a/src/main.cc b/src/main.cc index 3a9d4489..57be7b67 100644 --- a/src/main.cc +++ b/src/main.cc @@ -305,276 +305,268 @@ main(int argc, char** argv) { // Deprecated commands. Don't use these anymore. if (!OptionParser::has_flag('D', argc, argv)) { + // Deprecated in 0.7.0: + // + // List of cleaned up files: + // * command_download.cc + // * command_dynamic.cc + // * command_events.cc + // * command_file.cc + // * command_helpers.cc + // + command_local.cc + // * command_network.cc + // * command_object.cc + // * command_peer.cc + // * command_scheduler.cc + // * command_tracker.cc + // * command_ui.cc - rpc::parse_command_multiple - (rpc::make_target(), - // Deprecated in 0.7.0: - // - // List of cleaned up files: - // - command_download.cc - // * command_dynamic.cc - // * command_events.cc - // * command_file.cc - // - command_helpers.cc - // + command_local.cc - // * command_network.cc - // * command_object.cc - // * command_peer.cc - // * command_scheduler.cc - // * command_tracker.cc - // * command_ui.cc + rpc::commands.create_redirect("system.method.insert", "method.insert", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("system.method.set", "method.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("system.method.set_key", "method.set_key", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = system.method.insert,redirect|const,method.insert\n" - "method.insert = system.method.set,redirect|const,method.set\n" - "method.insert = system.method.set_key,redirect|const,method.set_key\n" + rpc::commands.create_redirect("get_handshake_log", "log.handshake", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_handshake_log", "log.handshake.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_log.tracker", "log.tracker", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_log.tracker", "log.tracker.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_key_layout,redirect|const,key_layout\n" - "method.insert = set_key_layout,redirect|const,key_layout.set\n" + rpc::commands.create_redirect("get_name", "system.session_name", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_name", "system.session_name.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("system.file_allocate", "system.file.allocate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("system.file_allocate.set", "system.file.allocate.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_handshake_log,redirect|const,log.handshake\n" - "method.insert = set_handshake_log,redirect|const,log.handshake.set\n" - "method.insert = get_log.tracker,redirect|const,log.tracker\n" - "method.insert = set_log.tracker,redirect|const,log.tracker.set\n" + rpc::commands.create_redirect("get_preload_type", "pieces.preload.type", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_preload_min_size", "pieces.preload.min_size", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_preload_required_rate", "pieces.preload.min_rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_preload_type", "pieces.preload.type.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_preload_min_size", "pieces.preload.min_size.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_preload_required_rate", "pieces.preload.min_rate.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_stats_preloaded", "pieces.stats_preloaded", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_stats_not_preloaded", "pieces.stats_not_preloaded", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_name,redirect|const,system.session_name\n" - "method.insert = set_name,redirect|const,system.session_name.set\n" - "method.insert = system.file_allocate,redirect|const,system.file.allocate\n" - "method.insert = system.file_allocate.set,redirect|const,system.file.allocate.set\n" + rpc::commands.create_redirect("get_memory_usage", "pieces.memory.current", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_max_memory_usage", "pieces.memory.max", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_max_memory_usage", "pieces.memory.max.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_preload_type,redirect|const,pieces.preload.type\n" - "method.insert = get_preload_min_size,redirect|const,pieces.preload.min_size\n" - "method.insert = get_preload_required_rate,redirect|const,pieces.preload.min_rate\n" - "method.insert = set_preload_type,redirect|const,pieces.preload.type.set\n" - "method.insert = set_preload_min_size,redirect|const,pieces.preload.min_size.set\n" - "method.insert = set_preload_required_rate,redirect|const,pieces.preload.min_rate.set\n" - "method.insert = get_stats_preloaded,redirect|const,pieces.stats_preloaded\n" - "method.insert = get_stats_not_preloaded,redirect|const,pieces.stats_not_preloaded\n" + rpc::commands.create_redirect("get_send_buffer_size", "network.send_buffer.size", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_send_buffer_size", "network.send_buffer.size.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_receive_buffer_size", "network.receive_buffer.size", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_receive_buffer_size", "network.receive_buffer.size.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_memory_usage,redirect|const,pieces.memory.current\n" - "method.insert = get_max_memory_usage,redirect|const,pieces.memory.max\n" - "method.insert = set_max_memory_usage,redirect|const,pieces.memory.max.set\n" + rpc::commands.create_redirect("get_up_rate", "throttle.global_up.rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_up_total", "throttle.global_up.total", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_upload_rate", "throttle.global_up.max_rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_upload_rate", "throttle.global_up.max_rate.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_down_rate", "throttle.global_down.rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_down_total", "throttle.global_down.total", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_download_rate", "throttle.global_down.max_rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_download_rate", "throttle.global_down.max_rate.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_send_buffer_size,redirect|const,network.send_buffer.size\n" - "method.insert = set_send_buffer_size,redirect|const,network.send_buffer.size.set\n" - "method.insert = get_receive_buffer_size,redirect|const,network.receive_buffer.size\n" - "method.insert = set_receive_buffer_size,redirect|const,network.receive_buffer.size.set\n" + rpc::commands.create_redirect("bind", "network.bind_address.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_bind", "network.bind_address.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_bind", "network.bind_address", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_up_rate,redirect|const,throttle.global_up.rate\n" - "method.insert = get_up_total,redirect|const,throttle.global_up.total\n" - "method.insert = get_upload_rate,redirect|const,throttle.global_up.max_rate\n" - "method.insert = set_upload_rate,redirect|const,throttle.global_up.max_rate.set\n" - "method.insert = get_down_rate,redirect|const,throttle.global_down.rate\n" - "method.insert = get_down_total,redirect|const,throttle.global_down.total\n" - "method.insert = get_download_rate,redirect|const,throttle.global_down.max_rate\n" - "method.insert = set_download_rate,redirect|const,throttle.global_down.max_rate.set\n" + rpc::commands.create_redirect("ip", "network.local_address.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_ip", "network.local_address.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_ip", "network.local_address", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = bind, redirect|const,network.bind_address.set\n" - "method.insert = set_bind,redirect|const,network.bind_address.set\n" - "method.insert = get_bind,redirect|const,network.bind_address\n" + rpc::commands.create_redirect("proxy_address", "network.proxy_address.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_proxy_address", "network.proxy_address.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_proxy_address", "network.proxy_address", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = ip, redirect|const,network.local_address.set\n" - "method.insert = set_ip,redirect|const,network.local_address.set\n" - "method.insert = get_ip,redirect|const,network.local_address\n" + rpc::commands.create_redirect("scgi_port", "network.scgi.open_port", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("scgi_local", "network.scgi.open_local", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = proxy_address, redirect|const,network.proxy_address.set\n" - "method.insert = set_proxy_address,redirect|const,network.proxy_address.set\n" - "method.insert = get_proxy_address,redirect|const,network.proxy_address\n" + rpc::commands.create_redirect("scgi_dont_route", "network.scgi.dont_route.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_scgi_dont_route", "network.scgi.dont_route.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_scgi_dont_route", "network.scgi.dont_route", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = scgi_port, redirect|const,network.scgi.open_port\n" - "method.insert = scgi_local,redirect|const,network.scgi.open_local\n" + rpc::commands.create_redirect("xmlrpc_dialect", "network.xmlrpc.size_limit.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = scgi_dont_route, redirect|const,network.scgi.dont_route.set\n" - "method.insert = set_scgi_dont_route,redirect|const,network.scgi.dont_route.set\n" - "method.insert = get_scgi_dont_route,redirect|const,network.scgi.dont_route\n" + rpc::commands.create_redirect("get_connection_leech", "connection_leech", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_connection_leech", "connection_leech.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_connection_seed", "connection_seed", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_connection_seed", "connection_seed.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = xmlrpc_dialect, redirect|const,network.xmlrpc.size_limit.set\n" + rpc::commands.create_redirect("dht", "dht.mode.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("dht_add_node", "dht.add_node", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("dht_statistics", "dht.statistics", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_dht_port", "dht.port", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_dht_port", "dht.port", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_dht_throttle", "dht.throttle.name", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_dht_throttle", "dht.throttle.name.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = get_connection_leech,redirect|const,connection_leech\n" - "method.insert = set_connection_leech,redirect|const,connection_leech.set\n" - "method.insert = get_connection_seed,redirect|const,connection_seed\n" - "method.insert = set_connection_seed,redirect|const,connection_seed.set\n" + rpc::commands.create_redirect("directory", "directory.default.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("get_directory", "directory.default", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("set_directory", "directory.default.set", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = dht,redirect|const,dht.mode.set\n" - "method.insert = dht_add_node, redirect|const,dht.add_node\n" - "method.insert = dht_statistics, redirect|const,dht.statistics\n" - "method.insert = get_dht_port, redirect|const,dht.port\n" - "method.insert = set_dht_port, redirect|const,dht.port\n" - "method.insert = get_dht_throttle,redirect|const,dht.throttle\n" - "method.insert = set_dht_throttle,redirect|const,dht.throttle.set\n" + // + // Download: + // - "method.insert = directory,redirect|const,directory.default.set\n" - "method.insert = get_directory,redirect|const,directory.default\n" - "method.insert = set_directory,redirect|const,directory.default.set\n" + rpc::commands.create_redirect("d.get_hash", "d.hash", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_local_id", "d.local_id", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_local_id_html", "d.local_id_html", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_bitfield", "d.bitfield", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_base_path", "d.base_path", rpc::CommandMap::flag_public_xmlrpc); - // - // Download: - // + rpc::commands.create_redirect("d.get_name", "d.name", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_creation_date", "d.creation_date", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = d.get_hash,redirect|const,d.hash\n" - "method.insert = d.get_local_id,redirect|const,d.local_id\n" - "method.insert = d.get_local_id_html,redirect|const,d.local_id_html\n" - "method.insert = d.get_bitfield,redirect|const,d.bitfield\n" - "method.insert = d.get_base_path,redirect|const,d.base_path\n" + rpc::commands.create_redirect("d.get_peer_exchange", "d.peer_exchange", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = d.get_name,redirect|const,d.name\n" - "method.insert = d.get_creation_date,redirect|const,d.creation_date\n" + rpc::commands.create_redirect("d.get_up_rate", "d.up.rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_up_total", "d.up.total", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_down_rate", "d.down.rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_down_total", "d.down.total", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_skip_rate", "d.skip.rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_skip_total", "d.skip.total", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = d.get_peer_exchange,redirect|const,d.peer_exchange\n" + // + rpc::commands.create_redirect("d.get_bytes_done", "d.bytes_done", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_chunk_size", "d.chunk_size", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_chunks_hashed", "d.chunks_hashed", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_complete", "d.complete", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_completed_bytes", "d.completed_bytes", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_completed_chunks", "d.completed_chunks", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_connection_current", "d.connection_current", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_connection_leech", "d.connection_leech", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_connection_seed", "d.connection_seed", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom", "d.custom", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom1", "d.custom1", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom2", "d.custom2", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom3", "d.custom3", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom4", "d.custom4", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom5", "d.custom5", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_custom_throw", "d.custom_throw", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_directory", "d.directory", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_directory_base", "d.directory_base", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_free_diskspace", "d.free_diskspace", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_hashing", "d.hashing", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_hashing_failed", "d.hashing_failed", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_ignore_commands", "d.ignore_commands", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_left_bytes", "d.left_bytes", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_loaded_file", "d.loaded_file", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_max_file_size", "d.max_file_size", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_max_size_pex", "d.max_size_pex", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_message", "d.message", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_mode", "d.mode", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_peers_accounted", "d.peers_accounted", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_peers_complete", "d.peers_complete", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_peers_connected", "d.peers_connected", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_peers_max", "d.peers_max", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_peers_min", "d.peers_min", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_peers_not_connected", "d.peers_not_connected", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_priority", "d.priority", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_priority_str", "d.priority_str", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_ratio", "d.ratio", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_size_bytes", "d.size_bytes", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_size_chunks", "d.size_chunks", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_size_files", "d.size_files", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_size_pex", "d.size_pex", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_state", "d.state", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_state_changed", "d.state_changed", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_state_counter", "d.state_counter", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_throttle_name", "d.throttle_name", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_tied_to_file", "d.tied_to_file", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_tracker_focus", "d.tracker_focus", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_tracker_numwant", "d.tracker_numwant", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_tracker_size", "d.tracker_size", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.get_uploads_max", "d.uploads_max", rpc::CommandMap::flag_public_xmlrpc); - "method.insert = d.get_up_rate,redirect|const,d.up.rate\n" - "method.insert = d.get_up_total,redirect|const,d.up.total\n" - "method.insert = d.get_down_rate,redirect|const,d.down.rate\n" - "method.insert = d.get_down_total,redirect|const,d.down.total\n" - "method.insert = d.get_skip_rate,redirect|const,d.skip.rate\n" - "method.insert = d.get_skip_total,redirect|const,d.skip.total\n" + rpc::commands.create_redirect("d.set_connection_current", "d.connection_current.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_custom", "d.custom.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_custom1", "d.custom1.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_custom2", "d.custom2.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_custom3", "d.custom3.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_custom4", "d.custom4.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_custom5", "d.custom5.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_directory", "d.directory.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_directory_base", "d.directory_base.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_hashing_failed", "d.hashing_failed.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_ignore_commands", "d.ignore_commands.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_max_file_size", "d.max_file_size.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_message", "d.message.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_peers_max", "d.peers_max.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_peers_min", "d.peers_min.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_priority", "d.priority.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_throttle_name", "d.throttle_name.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_tied_to_file", "d.tied_to_file.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_tracker_numwant", "d.tracker_numwant.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("d.set_uploads_max", "d.uploads_max.set", rpc::CommandMap::flag_public_xmlrpc); - // - "method.insert = d.get_bytes_done,redirect|const,d.bytes_done\n" - "method.insert = d.get_chunk_size,redirect|const,d.chunk_size\n" - "method.insert = d.get_chunks_hashed,redirect|const,d.chunks_hashed\n" - "method.insert = d.get_complete,redirect|const,d.complete\n" - "method.insert = d.get_completed_bytes,redirect|const,d.completed_bytes\n" - "method.insert = d.get_completed_chunks,redirect|const,d.completed_chunks\n" - "method.insert = d.get_connection_current,redirect|const,d.connection_current\n" - "method.insert = d.get_connection_leech,redirect|const,d.connection_leech\n" - "method.insert = d.get_connection_seed,redirect|const,d.connection_seed\n" - "method.insert = d.get_custom,redirect|const,d.custom\n" - "method.insert = d.get_custom1,redirect|const,d.custom1\n" - "method.insert = d.get_custom2,redirect|const,d.custom2\n" - "method.insert = d.get_custom3,redirect|const,d.custom3\n" - "method.insert = d.get_custom4,redirect|const,d.custom4\n" - "method.insert = d.get_custom5,redirect|const,d.custom5\n" - "method.insert = d.get_custom_throw,redirect|const,d.custom_throw\n" - "method.insert = d.get_directory,redirect|const,d.directory\n" - "method.insert = d.get_directory_base,redirect|const,d.directory_base\n" - "method.insert = d.get_free_diskspace,redirect|const,d.free_diskspace\n" - "method.insert = d.get_hashing,redirect|const,d.hashing\n" - "method.insert = d.get_hashing_failed,redirect|const,d.hashing_failed\n" - "method.insert = d.get_ignore_commands,redirect|const,d.ignore_commands\n" - "method.insert = d.get_left_bytes,redirect|const,d.left_bytes\n" - "method.insert = d.get_loaded_file,redirect|const,d.loaded_file\n" - "method.insert = d.get_max_file_size,redirect|const,d.max_file_size\n" - "method.insert = d.get_max_size_pex,redirect|const,d.max_size_pex\n" - "method.insert = d.get_message,redirect|const,d.message\n" - "method.insert = d.get_mode,redirect|const,d.mode\n" - "method.insert = d.get_peers_accounted,redirect|const,d.peers_accounted\n" - "method.insert = d.get_peers_complete,redirect|const,d.peers_complete\n" - "method.insert = d.get_peers_connected,redirect|const,d.peers_connected\n" - "method.insert = d.get_peers_max,redirect|const,d.peers_max\n" - "method.insert = d.get_peers_min,redirect|const,d.peers_min\n" - "method.insert = d.get_peers_not_connected,redirect|const,d.peers_not_connected\n" - "method.insert = d.get_priority,redirect|const,d.priority\n" - "method.insert = d.get_priority_str,redirect|const,d.priority_str\n" - "method.insert = d.get_ratio,redirect|const,d.ratio\n" - "method.insert = d.get_size_bytes,redirect|const,d.size_bytes\n" - "method.insert = d.get_size_chunks,redirect|const,d.size_chunks\n" - "method.insert = d.get_size_files,redirect|const,d.size_files\n" - "method.insert = d.get_size_pex,redirect|const,d.size_pex\n" - "method.insert = d.get_state,redirect|const,d.state\n" - "method.insert = d.get_state_changed,redirect|const,d.state_changed\n" - "method.insert = d.get_state_counter,redirect|const,d.state_counter\n" - "method.insert = d.get_throttle_name,redirect|const,d.throttle_name\n" - "method.insert = d.get_tied_to_file,redirect|const,d.tied_to_file\n" - "method.insert = d.get_tracker_focus,redirect|const,d.tracker_focus\n" - "method.insert = d.get_tracker_numwant,redirect|const,d.tracker_numwant\n" - "method.insert = d.get_tracker_size,redirect|const,d.tracker_size\n" - "method.insert = d.get_uploads_max,redirect|const,d.uploads_max\n" + // + // Tracker: + // - "method.insert = d.get_connection_current,redirect|const,d.connection_current.set\n" - "method.insert = d.get_custom,redirect|const,d.custom.set\n" - "method.insert = d.get_custom1,redirect|const,d.custom1.set\n" - "method.insert = d.get_custom2,redirect|const,d.custom2.set\n" - "method.insert = d.get_custom3,redirect|const,d.custom3.set\n" - "method.insert = d.get_custom4,redirect|const,d.custom4.set\n" - "method.insert = d.get_custom5,redirect|const,d.custom5.set\n" - "method.insert = d.get_directory,redirect|const,d.directory.set\n" - "method.insert = d.get_directory_base,redirect|const,d.directory_base.set\n" - "method.insert = d.get_hashing_failed,redirect|const,d.hashing_failed.set\n" - "method.insert = d.get_ignore_commands,redirect|const,d.ignore_commands.set\n" - "method.insert = d.get_max_file_size,redirect|const,d.max_file_size.set\n" - "method.insert = d.get_message,redirect|const,d.message.set\n" - "method.insert = d.get_peers_max,redirect|const,d.peers_max.set\n" - "method.insert = d.get_peers_min,redirect|const,d.peers_min.set\n" - "method.insert = d.get_priority,redirect|const,d.priority.set\n" - "method.insert = d.get_throttle_name,redirect|const,d.throttle_name.set\n" - "method.insert = d.get_tied_to_file,redirect|const,d.tied_to_file.set\n" - "method.insert = d.get_tracker_numwant,redirect|const,d.tracker_numwant.set\n" - "method.insert = d.get_uploads_max,redirect|const,d.uploads_max.set\n" + rpc::commands.create_redirect("t.get_group", "t.group", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_id", "t.id", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_min_interval", "t.min_interval", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_normal_interval", "t.normal_interval", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_scrape_complete", "t.scrape_complete", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_scrape_downloaded", "t.scrape_downloaded", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_scrape_incomplete", "t.scrape_incomplete", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_scrape_time_last", "t.scrape_time_last", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_type", "t.type", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("t.get_url", "t.url", rpc::CommandMap::flag_public_xmlrpc); - // - // Tracker: - // + // + // Tracker: + // - "method.insert = t.get_group,redirect|const,t.get_group\n" - "method.insert = t.get_id,redirect|const,t.get_id\n" - "method.insert = t.get_min_interval,redirect|const,t.get_min_interval\n" - "method.insert = t.get_normal_interval,redirect|const,t.get_normal_interval\n" - "method.insert = t.get_scrape_complete,redirect|const,t.get_scrape_complete\n" - "method.insert = t.get_scrape_downloaded,redirect|const,t.get_scrape_downloaded\n" - "method.insert = t.get_scrape_incomplete,redirect|const,t.get_scrape_incomplete\n" - "method.insert = t.get_scrape_time_last,redirect|const,t.get_scrape_time_last\n" - "method.insert = t.get_type,redirect|const,t.get_type\n" - "method.insert = t.get_url,redirect|const,t.get_url\n" + rpc::commands.create_redirect("f.get_completed_chunks", "f.completed_chunks", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_frozen_path", "f.frozen_path", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_last_touched", "f.last_touched", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_match_depth_next", "f.match_depth_next", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_match_depth_prev", "f.match_depth_prev", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_offset", "f.offset", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_path", "f.path", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_path_components", "f.path_components", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_path_depth", "f.path_depth", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_priority", "f.priority", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_range_first", "f.range_first", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_range_second", "f.range_second", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_size_bytes", "f.size_bytes", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.get_size_chunks", "f.size_chunks", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("f.set_priority", "f.priority.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("fi.get_filename_last", "fi.filename_last", rpc::CommandMap::flag_public_xmlrpc); - // - // Tracker: - // + // + // Peer: + // - "method.insert = f.get_completed_chunks,redirect|const,f.completed_chunks\n" - "method.insert = f.get_frozen_path,redirect|const,f.frozen_path\n" - "method.insert = f.get_last_touched,redirect|const,f.last_touched\n" - "method.insert = f.get_match_depth_next,redirect|const,f.match_depth_next\n" - "method.insert = f.get_match_depth_prev,redirect|const,f.match_depth_prev\n" - "method.insert = f.get_offset,redirect|const,f.offset\n" - "method.insert = f.get_path,redirect|const,f.path\n" - "method.insert = f.get_path_components,redirect|const,f.path_components\n" - "method.insert = f.get_path_depth,redirect|const,f.path_depth\n" - "method.insert = f.get_priority,redirect|const,f.priority\n" - "method.insert = f.get_range_first,redirect|const,f.range_first\n" - "method.insert = f.get_range_second,redirect|const,f.range_second\n" - "method.insert = f.get_size_bytes,redirect|const,f.size_bytes\n" - "method.insert = f.get_size_chunks,redirect|const,f.size_chunks\n" - "method.insert = f.set_priority,redirect|const,f.priority.set\n" - "method.insert = fi.get_filename_last,redirect|const,fi.filename_last\n" + rpc::commands.create_redirect("p.get_address", "p.address", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_client_version", "p.client_version", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_completed_percent", "p.completed_percent", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_down_rate", "p.down_rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_down_total", "p.down_total", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_id", "p.id", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_id_html", "p.id_html", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_options_str", "p.options_str", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_peer_rate", "p.peer_rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_peer_total", "p.peer_total", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_port", "p.port", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_up_rate", "p.up_rate", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("p.get_up_total", "p.up_total", rpc::CommandMap::flag_public_xmlrpc); - // - // Peer: - // + // + // View: + // - "method.insert = p.get_address,redirect|const,p.address\n" - "method.insert = p.get_client_version,redirect|const,p.client_version\n" - "method.insert = p.get_completed_percent,redirect|const,p.completed_percent\n" - "method.insert = p.get_down_rate,redirect|const,p.down_rate\n" - "method.insert = p.get_down_total,redirect|const,p.down_total\n" - "method.insert = p.get_id,redirect|const,p.id\n" - "method.insert = p.get_id_html,redirect|const,p.id_html\n" - "method.insert = p.get_options_str,redirect|const,p.options_str\n" - "method.insert = p.get_peer_rate,redirect|const,p.peer_rate\n" - "method.insert = p.get_peer_total,redirect|const,p.peer_total\n" - "method.insert = p.get_port,redirect|const,p.port\n" - "method.insert = p.get_up_rate,redirect|const,p.up_rate\n" - "method.insert = p.get_up_total,redirect|const,p.up_total\n" - - // - // View: - // - - "method.insert = view_add,redirect|const,view.add\n" - "method.insert = view_filter,redirect|const,view.filter\n" - "method.insert = view_filter_on,redirect|const,view.filter_on\n" - "method.insert = view_list,redirect|const,view.list\n" - "method.insert = view_set,redirect|const,view.set\n" - "method.insert = view_sort,redirect|const,view.sort\n" - "method.insert = view_sort_current,redirect|const,view.sort_current\n" - "method.insert = view_sort_new,redirect|const,view.sort_new\n" - - // Functions that might not get depracted as they are nice for - // configuration files, and thus might do with just some - // cleanup. - "method.insert = upload_rate,redirect|const,throttle.global_up.max_rate.set\n" - "method.insert = download_rate,redirect|const,throttle.global_down.max_rate.set\n" - ); + rpc::commands.create_redirect("view_add", "view.add", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_filter", "view.filter", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_filter_on", "view.filter_on", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_list", "view.list", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_set", "view.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_sort", "view.sort", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_sort_current", "view.sort_current", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("view_sort_new", "view.sort_new", rpc::CommandMap::flag_public_xmlrpc); + // Functions that might not get depracted as they are nice for + // configuration files, and thus might do with just some + // cleanup. + rpc::commands.create_redirect("upload_rate", "throttle.global_up.max_rate.set", rpc::CommandMap::flag_public_xmlrpc); + rpc::commands.create_redirect("download_rate", "throttle.global_down.max_rate.set", rpc::CommandMap::flag_public_xmlrpc); } if (OptionParser::has_flag('n', argc, argv)) diff --git a/src/rpc/Makefile.am b/src/rpc/Makefile.am index 1318fb7f..dad377cb 100644 --- a/src/rpc/Makefile.am +++ b/src/rpc/Makefile.am @@ -10,8 +10,6 @@ libsub_rpc_a_SOURCES = \ command_scheduler.h \ command_scheduler_item.cc \ command_scheduler_item.h \ - command_slot.cc \ - command_slot.h \ command_new_slot.cc \ command_new_slot.h \ command_variable.cc \ diff --git a/src/rpc/command.h b/src/rpc/command.h index 25a50fad..0740e7ed 100644 --- a/src/rpc/command.h +++ b/src/rpc/command.h @@ -132,6 +132,7 @@ public: virtual ~Command() {} static torrent::Object* argument(unsigned int index) { return m_arguments + index; } + static torrent::Object& argument_ref(unsigned int index) { return *(m_arguments + index); } static const unsigned int max_arguments = 10; static torrent::Object m_arguments[max_arguments]; diff --git a/src/rpc/command_map.cc b/src/rpc/command_map.cc index 48910013..bca72230 100644 --- a/src/rpc/command_map.cc +++ b/src/rpc/command_map.cc @@ -104,6 +104,10 @@ CommandMap::erase(iterator itr) { if (itr == end()) return; + // TODO: Remove the redirects instead... + if (itr->second.m_flags & flag_has_redirects) + throw torrent::input_error("Can't erase a command that has redirects."); + if (!(itr->second.m_flags & flag_dont_delete)) delete itr->second.m_variable; @@ -113,6 +117,37 @@ CommandMap::erase(iterator itr) { delete [] key; } +void +CommandMap::create_redirect(key_type key_new, key_type key_dest, int flags) { + iterator new_itr = base_type::find(key_new); + iterator dest_itr = base_type::find(key_dest); + + if (dest_itr == base_type::end()) + throw torrent::input_error("Tried to redirect to a key that doesn't exist: '" + std::string(key_dest) + "'."); + + if (new_itr != base_type::end()) + throw torrent::input_error("Tried to create a redirect key that already exists: '" + std::string(key_new) + "'."); + + if (dest_itr->second.m_flags & flag_is_redirect) + throw torrent::input_error("Tried to redirect to a key that is not marked 'flag_is_redirect': '" + + std::string(key_dest) + "'."); + + dest_itr->second.m_flags |= flag_has_redirects; + + flags |= flag_dont_delete; + flags |= dest_itr->second.m_flags & ~(flag_delete_key | flag_has_redirects); + + iterator itr = base_type::insert(base_type::end(), + value_type(key_new, command_map_data_type(dest_itr->second.m_variable, + flags, + dest_itr->second.m_parm, + dest_itr->second.m_doc))); + + // We can assume all the slots are the same size. + itr->second.m_target = dest_itr->second.m_target; + itr->second.m_genericSlot = dest_itr->second.m_genericSlot; +} + const CommandMap::mapped_type CommandMap::call_catch(key_type key, target_type target, const mapped_type& args, const char* err) { try { diff --git a/src/rpc/command_map.h b/src/rpc/command_map.h index b58ea3f2..aa4ff38a 100644 --- a/src/rpc/command_map.h +++ b/src/rpc/command_map.h @@ -104,6 +104,8 @@ public: static const int flag_public_xmlrpc = 0x4; static const int flag_no_target = 0x8; static const int flag_modifiable = 0x10; + static const int flag_is_redirect = 0x20; + static const int flag_has_redirects = 0x40; CommandMap() {} ~CommandMap(); @@ -127,6 +129,8 @@ public: void insert(key_type key, const command_map_data_type src); void erase(iterator itr); + void create_redirect(key_type key_new, key_type key_dest, int flags); + const mapped_type call(key_type key, const mapped_type& args = mapped_type()); const mapped_type call(key_type key, target_type target, const mapped_type& args = mapped_type()) { return call_command(key, args, target); } const mapped_type call_catch(key_type key, target_type target, const mapped_type& args = mapped_type(), const char* err = "Command failed: "); diff --git a/src/rpc/command_slot.cc b/src/rpc/command_slot.cc deleted file mode 100644 index fe2b1966..00000000 --- a/src/rpc/command_slot.cc +++ /dev/null @@ -1,146 +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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#include "config.h" - -#include "core/download.h" -#include "parse.h" - -#include "command_slot.h" - -namespace rpc { - -template const torrent::Object -CommandSlot::call_unknown(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawCommand); - - return command->m_slot(target, rawArgs); -} - -template const torrent::Object -CommandSlot::call_list(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawCommand); - - switch (rawArgs.type()) { - case torrent::Object::TYPE_LIST: - return command->m_slot(target, rawArgs); - - case torrent::Object::TYPE_VALUE: - case torrent::Object::TYPE_STRING: - case torrent::Object::TYPE_NONE: - { - torrent::Object tmpList = torrent::Object::create_list(); - tmpList.as_list().push_back(rawArgs); - - return command->m_slot(target, tmpList); - } - default: - throw torrent::input_error("Not a list."); - } -} - -template const torrent::Object -CommandSlot::call_value_base(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs, int base, int unit) { - CommandSlot* command = static_cast(rawCommand); - - const torrent::Object& arg = convert_to_single_argument(rawArgs); - - switch (arg.type()) { - case torrent::Object::TYPE_VALUE: - // Should shift this one too, so it gives the right unit. - return command->m_slot(target, arg); - - case torrent::Object::TYPE_STRING: - { - torrent::Object argValue = torrent::Object::create_value(); - - if (!parse_whole_value_nothrow(arg.as_string().c_str(), &argValue.as_value(), base, unit)) - throw torrent::input_error("Not a value."); - - return command->m_slot(target, argValue); - } - default: - throw torrent::input_error("Not a value."); - } -} - -template const torrent::Object -CommandSlot::call_string(Command* rawCommand, cleaned_type target, const torrent::Object& rawArgs) { - CommandSlot* command = static_cast(rawCommand); - - const torrent::Object& arg = convert_to_single_argument(rawArgs); - - switch (arg.type()) { -// case torrent::Object::TYPE_VALUE: -// break; - - case torrent::Object::TYPE_STRING: - return command->m_slot(target, arg); - break; - - default: - throw torrent::input_error("Not a string."); - } -} - -torrent::Object -set_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) { - if (m_firstKey == NULL) - download->bencode()->get_key(m_secondKey) = arg1; - else - download->bencode()->get_key(m_firstKey).get_key(m_secondKey) = arg1; - - return torrent::Object(); -} - -torrent::Object -get_variable_d_fn_t::operator () (core::Download* download, const torrent::Object& arg1) { - if (m_firstKey == NULL) - return download->bencode()->get_key(m_secondKey); - else - return download->bencode()->get_key(m_firstKey).get_key(m_secondKey); -} - -// Initialize the necessary template classes. -template class CommandSlot; -template class CommandSlot; -template class CommandSlot; -template class CommandSlot; -template class CommandSlot; -template class CommandSlot; -template class CommandSlot; - -} diff --git a/src/rpc/command_slot.h b/src/rpc/command_slot.h deleted file mode 100644 index 7ae1c98b..00000000 --- a/src/rpc/command_slot.h +++ /dev/null @@ -1,276 +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 -// -// Skomakerveien 33 -// 3185 Skoppum, NORWAY - -#ifndef RTORRENT_RPC_COMMAND_SLOT_H -#define RTORRENT_RPC_COMMAND_SLOT_H - -#include -#include -#include -#include -#include - -#include "command.h" - -namespace core { - class Download; -} - -namespace torrent { - class File; - class FileListIterator; - class Peer; - class Tracker; -} - -namespace rpc { - -template -class CommandSlot : public Command { -public: - typedef typename target_wrapper::target_type target_type; - typedef typename target_wrapper::cleaned_type cleaned_type; - - typedef rak::function2 slot_type; - - CommandSlot() {} - CommandSlot(typename slot_type::base_type* s) { m_slot.set(s); } - - void set_slot(typename slot_type::base_type* s) { m_slot.set(s); } - - static const torrent::Object call_unknown(Command* rawCommand, cleaned_type target, const torrent::Object& args); - - static const torrent::Object call_list(Command* rawCommand, cleaned_type target, const torrent::Object& args); - static const torrent::Object call_string(Command* rawCommand, cleaned_type target, const torrent::Object& args); - - static const torrent::Object call_value_base(Command* rawCommand, cleaned_type target, const torrent::Object& args, int base, int unit); - - static const torrent::Object call_value(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1); } - static const torrent::Object call_value_kb(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 0, 1 << 10); } - static const torrent::Object call_value_oct(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, 8, 1); } - - template - static const torrent::Object call_value_tmpl(Command* rawCommand, cleaned_type target, const torrent::Object& args) { return call_value_base(rawCommand, target, args, base, unit); } - -// static const torrent::Object& get_list(Command* rawCommand, const torrent::Object& args); - -private: - slot_type m_slot; -}; - -// Some slots that convert torrent::Object arguments to proper -// function calls. - -template -class object_void_fn_t : public rak::function_base2 { -public: - object_void_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { return torrent::Object(m_func(target)); } - -private: - Func m_func; -}; - -template -class object_void_fn_t : public rak::function_base2 { -public: - object_void_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { m_func(target); return torrent::Object(); } - -private: - Func m_func; -}; - -template -class object_void_fn_t : public rak::function_base1 { -public: - object_void_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object(m_func()); } - -private: - Func m_func; -}; - -template -class object_void_fn_t : public rak::function_base1 { -public: - object_void_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (const torrent::Object& arg1) { m_func(); return torrent::Object(); } - -private: - Func m_func; -}; - -template -class object_value_fn_t : public rak::function_base2 { -public: - object_value_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { return torrent::Object((int64_t)m_func(target, arg1.as_value())); } - -private: - Func m_func; -}; - -template -class object_value_fn_t : public rak::function_base2 { -public: - object_value_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { m_func(target, arg1.as_value()); return torrent::Object(); } - -private: - Func m_func; -}; - -template -class object_value_fn_t : public rak::function_base1 { -public: - object_value_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object((int64_t)m_func(arg1.as_value())); } - -private: - Func m_func; -}; - -template -class object_value_fn_t : public rak::function_base1 { -public: - object_value_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (const torrent::Object& arg1) { m_func(arg1.as_value()); return torrent::Object(); } - -private: - Func m_func; -}; - -template -class object_string_fn_t : public rak::function_base2 { -public: - object_string_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { return torrent::Object(m_func(target, arg1.as_string())); } - -private: - Func m_func; -}; - -template -class object_string_fn_t : public rak::function_base2 { -public: - object_string_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (Target target, const torrent::Object& arg1) { m_func(target, arg1.as_string()); return torrent::Object(); } - -private: - Func m_func; -}; - -template -class object_string_fn_t : public rak::function_base1 { -public: - object_string_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (const torrent::Object& arg1) { return torrent::Object(m_func(arg1.as_string())); } - -private: - Func m_func; -}; - -template -class object_string_fn_t : public rak::function_base1 { -public: - object_string_fn_t(Func func) : m_func(func) {} - - virtual torrent::Object operator () (const torrent::Object& arg1) { m_func(arg1.as_string()); return torrent::Object(); } - -private: - Func m_func; -}; - -// Add more of these helpers. -template object_void_fn_t* -object_fn(Return (*func)(Target)) { return new object_void_fn_t(func); } -template object_void_fn_t* -object_fn(Return (*func)()) { return new object_void_fn_t(func); } - -template object_void_fn_t* -object_void_fn(Return (*func)(Target)) { return new object_void_fn_t(func); } -template object_void_fn_t* -object_void_fn(Return (*func)()) { return new object_void_fn_t(func); } - -template object_void_fn_t* object_void_fn(Func func) { return new object_void_fn_t(func); } -template object_void_fn_t* object_void_fn(Func func) { return new object_void_fn_t(func); } -template object_value_fn_t* object_value_fn(Func func) { return new object_value_fn_t(func); } -template object_value_fn_t* object_value_fn(Func func) { return new object_value_fn_t(func); } -template object_string_fn_t* object_string_fn(Func func) { return new object_string_fn_t(func); } -template object_string_fn_t* object_string_fn(Func func) { return new object_string_fn_t(func); } - -class set_variable_d_fn_t : public rak::function_base2 { -public: - set_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {} - - virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1); - -private: - const char* m_firstKey; - const char* m_secondKey; -}; - -class get_variable_d_fn_t : public rak::function_base2 { -public: - get_variable_d_fn_t(const char* firstKey, const char* secondKey) : m_firstKey(firstKey), m_secondKey(secondKey) {} - - virtual torrent::Object operator () (core::Download* download, const torrent::Object& arg1); - -private: - const char* m_firstKey; - const char* m_secondKey; -}; - -inline set_variable_d_fn_t* -set_variable_d_fn(const char* firstKey, const char* secondKey) { return new set_variable_d_fn_t(firstKey, secondKey); } -inline get_variable_d_fn_t* -get_variable_d_fn(const char* firstKey, const char* secondKey) { return new get_variable_d_fn_t(firstKey, secondKey); } - -} - -#endif