diff --git a/src/Makefile.am b/src/Makefile.am index 13b1bead..6660d477 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ rtorrent_LDADD = \ $(top_srcdir)/src/utils/libsub_utils.a rtorrent_SOURCES = \ + command_download.cc \ command_events.cc \ command_helpers.cc \ command_helpers.h \ diff --git a/src/command_download.cc b/src/command_download.cc new file mode 100644 index 00000000..d2c5154b --- /dev/null +++ b/src/command_download.cc @@ -0,0 +1,45 @@ +// rTorrent - BitTorrent client +// Copyright (C) 2005-2006, 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 + +void +initialize_command_download() { +// utils::VariableMap* variables = control->variable(); + +} diff --git a/src/command_helpers.cc b/src/command_helpers.cc index f25c5a03..495ee836 100644 --- a/src/command_helpers.cc +++ b/src/command_helpers.cc @@ -51,6 +51,7 @@ utils::CommandVariable commandVariables[COMMAND_VARIABLES_SIZE]; utils::CommandVariable* commandVariablesItr = commandVariables; void initialize_download_variables(); +void initialize_command_download(); void initialize_command_events(); void initialize_command_local(); void initialize_command_network(); @@ -59,6 +60,7 @@ void initialize_command_ui(); void initialize_commands() { initialize_download_variables(); + initialize_command_download(); initialize_command_events(); initialize_command_network(); initialize_command_local(); diff --git a/src/command_network.cc b/src/command_network.cc index 96a4e857..f40eb472 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -136,7 +136,7 @@ apply_enable_trackers(int64_t arg) { else tl.get(i).disable(); - if (arg && !control->variable()->get_value("get_use_udp_trackers")) + if (arg && !control->variable()->call_command_value("get_use_udp_trackers")) (*itr)->enable_udp_trackers(false); } } diff --git a/src/control.cc b/src/control.cc index 89eff59d..682aca83 100644 --- a/src/control.cc +++ b/src/control.cc @@ -116,7 +116,7 @@ Control::initialize() { m_core->initialize_second(); m_core->listen_open(); - m_core->download_store()->enable(m_variables->get_value("get_session_lock")); + m_core->download_store()->enable(m_variables->call_command_value("get_session_lock")); m_core->set_hashing_view(*m_viewManager->find_throw("hashing")); m_scheduler->set_view(*m_viewManager->find_throw("scheduler")); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index bceb5752..2eb68d9a 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -48,6 +48,7 @@ #include #include "utils/variable_generic.h" +#include "utils/variable_map.h" #include "curl_get.h" #include "control.h" @@ -75,10 +76,10 @@ DownloadFactory::DownloadFactory(const std::string& uri, Manager* m) : m_taskLoad.set_slot(rak::mem_fn(this, &DownloadFactory::receive_load)); m_taskCommit.set_slot(rak::mem_fn(this, &DownloadFactory::receive_commit)); - m_variables.insert("connection_leech", new utils::VariableAny(control->variable()->get("get_connection_leech"))); - m_variables.insert("connection_seed", new utils::VariableAny(control->variable()->get("get_connection_seed"))); - m_variables.insert("directory", new utils::VariableAny(control->variable()->get("get_directory"))); - m_variables.insert("tied_to_file", new utils::VariableBool(false)); + m_variables["connection_leech"] = control->variable()->call_command_void("get_connection_leech"); + m_variables["connection_seed"] = control->variable()->call_command_void("get_connection_seed"); + m_variables["directory"] = control->variable()->call_command_void("directory"); + m_variables["tied_to_file"] = torrent::Object((int64_t)false); } DownloadFactory::~DownloadFactory() { @@ -112,7 +113,7 @@ DownloadFactory::receive_load() { (*itr)->signal_done().slots().push_front(sigc::mem_fun(*this, &DownloadFactory::receive_loaded)); (*itr)->signal_failed().slots().push_front(sigc::mem_fun(*this, &DownloadFactory::receive_failed)); - m_variables.set("tied_to_file", (int64_t)false); + m_variables["tied_to_file"] = (int64_t)false; } else { std::fstream* stream = new std::fstream(rak::path_expand(m_uri).c_str(), std::ios::in | std::ios::binary); @@ -173,43 +174,43 @@ DownloadFactory::receive_success() { initialize_rtorrent(download, rtorrent); // Move to 'rtorrent'. - download->set("connection_leech", m_variables.get("connection_leech")); - download->set("connection_seed", m_variables.get("connection_seed")); + download->set("connection_leech", m_variables["connection_leech"]); + download->set("connection_seed", m_variables["get_connection_seed"]); - download->set("max_uploads", control->variable()->get("get_max_uploads")); - download->set("min_peers", control->variable()->get("get_min_peers")); - download->set("max_peers", control->variable()->get("get_max_peers")); - download->set("tracker_numwant", control->variable()->get("get_tracker_numwant")); + download->set("max_uploads", control->variable()->call_command_void("get_max_uploads")); + download->set("min_peers", control->variable()->call_command_void("get_min_peers")); + download->set("max_peers", control->variable()->call_command_void("get_max_peers")); + download->set("tracker_numwant", control->variable()->call_command_void("get_tracker_numwant")); if (download->get_value("complete") != 0) { - if (control->variable()->get_value("get_min_peers_seed") >= 0) - download->set("min_peers", control->variable()->get("get_min_peers_seed")); + if (control->variable()->call_command_value("get_min_peers_seed") >= 0) + download->set("min_peers", control->variable()->call_command_void("get_min_peers_seed")); - if (control->variable()->get_value("get_max_peers_seed") >= 0) - download->set("max_peers", control->variable()->get("get_max_peers_seed")); + if (control->variable()->call_command_value("get_max_peers_seed") >= 0) + download->set("max_peers", control->variable()->call_command_void("get_max_peers_seed")); } - if (!control->variable()->get_value("get_use_udp_trackers")) + if (!control->variable()->call_command_value("get_use_udp_trackers")) download->enable_udp_trackers(false); - if (control->variable()->get_value("get_max_file_size") > 0) - download->set("max_file_size", control->variable()->get("get_max_file_size")); + if (control->variable()->call_command_value("get_max_file_size") > 0) + download->set("max_file_size", control->variable()->call_command_void("get_max_file_size")); // Check first if we already have these values set in the session // torrent, so that it is safe to change the values. // // Need to also catch the exceptions. - if (control->variable()->get_value("get_split_file_size") >= 0) + if (control->variable()->call_command_value("get_split_file_size") >= 0) torrent::file_split_all(download->download()->file_list(), - control->variable()->get_value("get_split_file_size"), - control->variable()->get_string("split_suffix")); + control->variable()->call_command_value("get_split_file_size"), + control->variable()->call_command_string("split_suffix")); if (!rtorrent->has_key_string("directory")) - download->set("directory", m_variables.get("directory")); + download->set("directory", m_variables["get_directory"]); else download->set("directory", rtorrent->get_key("directory")); - if (!m_session && m_variables.get("tied_to_file").as_value()) + if (!m_session && m_variables["tied_to_file"].as_value()) download->set("tied_to_file", m_uri); torrent::Object& resumeObject = root->has_key_map("libtorrent_resume") diff --git a/src/core/download_factory.h b/src/core/download_factory.h index ac27802c..9c5a5bf1 100644 --- a/src/core/download_factory.h +++ b/src/core/download_factory.h @@ -44,8 +44,7 @@ #include #include #include - -#include "utils/variable_map.h" +#include #include "http_queue.h" @@ -67,7 +66,7 @@ public: void load(); void commit(); - utils::VariableMap* variable() { return &m_variables; } + torrent::Object::map_type& variables() { return m_variables; } bool get_session() const { return m_session; } void set_session(bool v) { m_session = v; } @@ -100,7 +99,7 @@ private: bool m_start; bool m_printLog; - utils::VariableMap m_variables; + torrent::Object::map_type m_variables; Slot m_slotFinished; rak::priority_item m_taskLoad; diff --git a/src/core/download_list.cc b/src/core/download_list.cc index dc46a63f..62e87f61 100644 --- a/src/core/download_list.cc +++ b/src/core/download_list.cc @@ -501,7 +501,7 @@ void DownloadList::received_finished(Download* download) { check_contains(download); - if (control->variable()->get_value("get_check_hash")) { + if (control->variable()->call_command_value("get_check_hash")) { // Set some 'checking_finished_thingie' variable to make hash_done // trigger correctly, also so it can bork on missing data. hash_queue(download, Download::variable_hashing_last); @@ -521,15 +521,15 @@ DownloadList::confirm_finished(Download* download) { download->set_connection_type(download->get_string("connection_seed")); download->set_priority(download->priority()); - if (download->get_value("min_peers") == control->variable()->get_value("get_min_peers") && control->variable()->get_value("get_min_peers_seed") >= 0) - download->set("min_peers", control->variable()->get("get_min_peers_seed")); + if (download->get_value("min_peers") == control->variable()->call_command_value("get_min_peers") && control->variable()->call_command_value("get_min_peers_seed") >= 0) + download->set("min_peers", control->variable()->call_command_void("get_min_peers_seed")); - if (download->get_value("max_peers") == control->variable()->get_value("get_max_peers") && control->variable()->get_value("get_max_peers_seed") >= 0) - download->set("max_peers", control->variable()->get("get_max_peers_seed")); + if (download->get_value("max_peers") == control->variable()->call_command_value("get_max_peers") && control->variable()->call_command_value("get_max_peers_seed") >= 0) + download->set("max_peers", control->variable()->call_command_void("get_max_peers_seed")); // Do this before the slots are called in case one of them closes // the download. - if (!download->is_active() && control->variable()->get_value("get_session_on_completion") != 0) { + if (!download->is_active() && control->variable()->call_command_value("get_session_on_completion") != 0) { torrent::resume_save_progress(*download->download(), download->download()->bencode()->get_key("libtorrent_resume")); control->core()->download_store()->save(download); } diff --git a/src/core/manager.cc b/src/core/manager.cc index 0bab4d65..6f1981aa 100644 --- a/src/core/manager.cc +++ b/src/core/manager.cc @@ -85,13 +85,13 @@ connect_signal_storage_log(Download* d, torrent::Download::slot_string_type s) { // Need a proper logging class for this. static void connect_signal_tracker_dump(Download* d, torrent::Download::slot_dump_type s) { - if (!control->variable()->get_string("get_tracker_dump").empty()) + if (!control->variable()->call_command_string("get_tracker_dump").empty()) d->download()->signal_tracker_dump(s); } static void receive_tracker_dump(const std::string& url, const char* data, size_t size) { - const std::string& filename = control->variable()->get_string("get_tracker_dump"); + const std::string& filename = control->variable()->call_command_string("get_tracker_dump"); if (filename.empty()) return; @@ -108,7 +108,7 @@ receive_tracker_dump(const std::string& url, const char* data, size_t size) { void Manager::handshake_log(const sockaddr* sa, int msg, int err, const torrent::HashString* hash) { - if (!control->variable()->get_value("get_handshake_log")) + if (!control->variable()->call_command_value("get_handshake_log")) return; std::string peer; @@ -276,11 +276,11 @@ void Manager::listen_open() { // This stuff really should be moved outside of manager, make it // part of the init script. - if (!control->variable()->get_value("get_port_open")) + if (!control->variable()->call_command_value("get_port_open")) return; int portFirst, portLast; - torrent::Object portRange = control->variable()->get("get_port_range"); + torrent::Object portRange = control->variable()->call_command_void("get_port_range"); if (portRange.is_string()) { if (std::sscanf(portRange.as_string().c_str(), "%i-%i", &portFirst, &portLast) != 2) @@ -295,7 +295,7 @@ Manager::listen_open() { if (portFirst > portLast || portLast >= (1 << 16)) throw torrent::input_error("Invalid port range."); - if (control->variable()->get_value("get_port_random")) { + if (control->variable()->call_command_value("get_port_random")) { int boundary = portFirst + random() % (portLast - portFirst + 1); if (torrent::connection_manager()->listen_open(boundary, portLast) || @@ -415,7 +415,7 @@ Manager::try_create_download(const std::string& uri, bool start, bool printLog, // Adding download. DownloadFactory* f = new DownloadFactory(uri, this); - f->variable()->set("tied_to_file", tied ? "yes" : "no"); + f->variables()["tied_to_file"] = (int64_t)tied; f->set_start(start); f->set_print_log(printLog); diff --git a/src/main.cc b/src/main.cc index a9b33155..63898161 100644 --- a/src/main.cc +++ b/src/main.cc @@ -82,14 +82,14 @@ parse_options(Control* c, int argc, char** argv) { optionParser.insert_flag('h', sigc::ptr_fun(&print_help)); optionParser.insert_flag('n', OptionParser::Slot()); - optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "bind")); - optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "directory")); - optionParser.insert_option('i', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "ip")); - optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "port_range")); - optionParser.insert_option('s', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::set_string), "session")); + optionParser.insert_option('b', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "bind")); + optionParser.insert_option('d', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "directory")); + optionParser.insert_option('i', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "ip")); + optionParser.insert_option('p', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "port_range")); + optionParser.insert_option('s', sigc::bind<0>(sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_string), "session")); optionParser.insert_option('O', sigc::mem_fun(c->variable(), &utils::VariableMap::process_std_single)); - optionParser.insert_option_list('o', sigc::mem_fun(c->variable(), &utils::VariableMap::set_std_string)); + optionParser.insert_option_list('o', sigc::mem_fun(c->variable(), &utils::VariableMap::call_command_set_std_string)); return optionParser.process(argc, argv); diff --git a/src/rpc/xmlrpc.cc b/src/rpc/xmlrpc.cc index 5bdd4a34..c25f582a 100644 --- a/src/rpc/xmlrpc.cc +++ b/src/rpc/xmlrpc.cc @@ -187,8 +187,12 @@ XmlRpc::insert_command(const char* name, const char* parm, const char* doc) { XmlRpc::XmlRpc() { throw torrent::resource_error("XMLRPC not supported."); } XmlRpc::~XmlRpc() {} +void XmlRpc::insert_command(const char* name, const char* parm, const char* doc) {} + bool XmlRpc::process(const char* inBuffer, uint32_t length, slot_write slotWrite) { return false; } +xmlrpc_value* XmlRpc::call_command(xmlrpc_env* env, xmlrpc_value* args, void* voidServerInfo) { return NULL; } + #endif } diff --git a/src/ui/download_list.cc b/src/ui/download_list.cc index 46117b19..2e5d9889 100644 --- a/src/ui/download_list.cc +++ b/src/ui/download_list.cc @@ -232,7 +232,7 @@ DownloadList::receive_view_input(Input type) { case INPUT_CHANGE_DIRECTORY: title = "change_directory"; - input->str() = control->variable()->get_string("get_directory"); + input->str() = control->variable()->call_command_string("get_directory"); input->set_pos(input->str().length()); break; diff --git a/src/ui/root.cc b/src/ui/root.cc index 15198fc7..1483d8f7 100644 --- a/src/ui/root.cc +++ b/src/ui/root.cc @@ -126,7 +126,7 @@ void Root::setup_keys() { m_control->input()->push_back(&m_bindings); - const std::string& keyLayout = control->variable()->get_string("get_key_layout"); + const std::string& keyLayout = control->variable()->call_command_string("get_key_layout"); if (strcasecmp(keyLayout.c_str(), "azerty") == 0) { m_bindings['q'] = sigc::bind(sigc::mem_fun(*this, &Root::adjust_up_throttle), 1); @@ -187,14 +187,14 @@ Root::set_down_throttle(unsigned int throttle) { torrent::set_down_throttle(throttle * 1024); - int64_t div = control->variable()->get_value("get_max_downloads_div"); + int64_t div = control->variable()->call_command_value("get_max_downloads_div"); if (throttle == 0 || div <= 0) { torrent::set_max_download_unchoked(m_maxDownloadsGlobal); return; } - throttle /= control->variable()->get_value("get_max_downloads_div"); + throttle /= control->variable()->call_command_value("get_max_downloads_div"); unsigned int maxUnchoked; @@ -216,14 +216,14 @@ Root::set_up_throttle(unsigned int throttle) { torrent::set_up_throttle(throttle * 1024); - int64_t div = control->variable()->get_value("get_max_uploads_div"); + int64_t div = control->variable()->call_command_value("get_max_uploads_div"); if (throttle == 0 || div <= 0) { torrent::set_max_unchoked(m_maxUploadsGlobal); return; } - throttle /= control->variable()->get_value("get_max_uploads_div"); + throttle /= control->variable()->call_command_value("get_max_uploads_div"); unsigned int maxUnchoked; diff --git a/src/utils/variable_map.cc b/src/utils/variable_map.cc index acd9e602..2ad2d8fc 100644 --- a/src/utils/variable_map.cc +++ b/src/utils/variable_map.cc @@ -72,19 +72,6 @@ VariableMap::insert(key_type key, Variable* variable, generic_slot genericSlot, base_type::insert(itr, value_type(key, variable_map_data_type(variable, genericSlot, NULL, flags, parm, doc))); } -const VariableMap::mapped_type -VariableMap::get(key_type key) const { - const_iterator itr = base_type::find(key); - - if (itr == base_type::end()) - throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist."); - - if (itr->second.m_genericSlot != NULL) - return itr->second.m_genericSlot(itr->second.m_variable, torrent::Object()); - - return itr->second.m_variable->get(); -} - const VariableMap::mapped_type VariableMap::get_d(core::Download* download, key_type key) const { const_iterator itr = base_type::find(key); @@ -101,23 +88,6 @@ VariableMap::get_d(core::Download* download, key_type key) const { return itr->second.m_variable->get_d(download); } -void -VariableMap::set(key_type key, const mapped_type& arg) { - iterator itr = base_type::find(key); - - // Later, allow the user to create new variables. Have a slot to - // register that thing. - if (itr == base_type::end()) - throw torrent::input_error("Variable \"" + std::string(key) + "\" does not exist."); - - if (itr->second.m_genericSlot != NULL) { - itr->second.m_genericSlot(itr->second.m_variable, arg); - return; - } - - itr->second.m_variable->set(arg); -} - void VariableMap::set_d(core::Download* download, key_type key, const mapped_type& arg) { iterator itr = base_type::find(key); @@ -188,7 +158,7 @@ VariableMap::process_single(const char* first, const char* last) { mapped_type args; first = parse_whole_list(first + 1, last, &args); - set(key.c_str(), args); + call_command(key.c_str(), args); return first; } diff --git a/src/utils/variable_map.h b/src/utils/variable_map.h index a90dd5ad..732a32d6 100644 --- a/src/utils/variable_map.h +++ b/src/utils/variable_map.h @@ -116,28 +116,15 @@ public: const char* parm = "", const char* doc = ""); // Consider uninlining the helper functions. - - const mapped_type get(key_type key) const; const mapped_type get_d(core::Download* download, key_type key) const; - - const std::string get_string(key_type key) const { return get(key).as_string(); } const std::string get_d_string(core::Download* download, key_type key) const { return get_d(download, key).as_string(); } - - mapped_value_type get_value(key_type key) const { return get(key).as_value(); } mapped_value_type get_d_value(core::Download* download, key_type key) const { return get_d(download, key).as_value(); } - void set(key_type key, const mapped_type& arg); void set_d(core::Download* download, key_type key, const mapped_type& arg); - - void set_string(key_type key, const std::string& arg) { set(key, mapped_type(arg)); } void set_d_string(core::Download* download, key_type key, const std::string& arg) { set_d(download, key, mapped_type(arg)); } void set_d_std_string(core::Download* download, const std::string& key, const std::string& arg) { set_d(download, key.c_str(), mapped_type(arg)); } - - void set_value(key_type key, mapped_value_type arg) { set(key, mapped_type(arg)); } void set_d_value(core::Download* download, key_type key, mapped_value_type arg) { set_d(download, key, mapped_type(arg)); } - void set_std_string(const std::string& key, const std::string& arg) { set(key.c_str(), mapped_type(arg)); } - const char* process_single(const char* first); const char* process_single(const char* first, const char* last); void process_std_single(const std::string& cmd) { process_single(cmd.c_str(), cmd.c_str() + cmd.size()); } @@ -153,6 +140,12 @@ public: // The new API, which is atm just a wrapper over the old and // requires seperate calls to get and set. These will be merged. const mapped_type call_command(key_type key, const mapped_type& arg); + const mapped_type call_command_void(key_type key) { return call_command(key, torrent::Object()); } + const std::string call_command_string(key_type key) { return call_command(key, torrent::Object()).as_string(); } + mapped_value_type call_command_value(key_type key) { return call_command(key, torrent::Object()).as_value(); } + + void call_command_set_string(key_type key, const std::string& arg) { call_command(key, mapped_type(arg)); } + void call_command_set_std_string(const std::string& key, const std::string& arg) { call_command(key.c_str(), mapped_type(arg)); } private: VariableMap(const VariableMap&);