diff --git a/doc/rtorrent.1.xml b/doc/rtorrent.1.xml index 68ba17dd..5fcb5aca 100644 --- a/doc/rtorrent.1.xml +++ b/doc/rtorrent.1.xml @@ -981,7 +981,7 @@ by the program. - working_directory = directory + cwd = directory Changes the working directory of the process using diff --git a/rak/socket_address.h b/rak/socket_address.h index 9fedb00f..25fdb37f 100644 --- a/rak/socket_address.h +++ b/rak/socket_address.h @@ -74,7 +74,7 @@ public: static const int pf_local = PF_LOCAL; #else static const sa_family_t af_local = AF_UNIX; - static const itn pf_local = PF_UNIX; + static const int pf_local = PF_UNIX; #endif bool is_valid() const; diff --git a/src/command_download.cc b/src/command_download.cc index 2c8302dd..bafafec7 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -312,6 +312,10 @@ t_multicall(core::Download* download, const torrent::Object& rawArgs) { ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \ ADD_CD_SLOT("d.set_" key, call_string, rpc::set_variable_d_fn(firstKey, secondKey), "i:s", ""); +#define ADD_CD_VARIABLE_STRING_PUBLIC(key, firstKey, secondKey) \ + ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \ + ADD_CD_SLOT_PUBLIC("d.set_" key, call_string, rpc::set_variable_d_fn(firstKey, secondKey), "i:s", ""); + #define ADD_CD_VALUE_UNI(key, get) \ ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "") @@ -371,6 +375,12 @@ initialize_command_download() { ADD_CD_VALUE_UNI("is_hash_checking", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::is_hash_checking))); ADD_CD_VALUE_UNI("is_multi_file", rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(&torrent::FileList::is_multi_file))); + ADD_CD_VARIABLE_STRING_PUBLIC("custom1", "rtorrent", "custom1"); + ADD_CD_VARIABLE_STRING_PUBLIC("custom2", "rtorrent", "custom2"); + ADD_CD_VARIABLE_STRING_PUBLIC("custom3", "rtorrent", "custom3"); + ADD_CD_VARIABLE_STRING_PUBLIC("custom4", "rtorrent", "custom4"); + ADD_CD_VARIABLE_STRING_PUBLIC("custom5", "rtorrent", "custom5"); + // 0 - stopped // 1 - started ADD_CD_VARIABLE_VALUE("state", "rtorrent", "state"); diff --git a/src/command_helpers.h b/src/command_helpers.h index 82dae5a4..84602fec 100644 --- a/src/command_helpers.h +++ b/src/command_helpers.h @@ -88,8 +88,8 @@ add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_value, &rpc #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_VARIABLE_C_STRING(key, defaultValue) \ -add_variable("get_" key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, 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); \ @@ -115,15 +115,22 @@ add_variable("get_" key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, st 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_OCT(key, set, get) \ +#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("set_" key, call_value, "i:i", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "i:", "") + ADD_COMMAND_COPY(prefix "set_" key, call_value, "i:i", "") -#define ADD_COMMAND_STRING_TRI(key, set, get) \ +#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("set_" key, call_string, "i:s", "") \ - ADD_COMMAND_SLOT("get_" key, call_unknown, rpc::object_void_fn(get), "s:", "") + 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:", "") diff --git a/src/command_local.cc b/src/command_local.cc index c80a48a3..af93999e 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -81,7 +82,7 @@ apply_execute_log(const torrent::Object& rawArgs) { } torrent::Object -apply_get_hostname() { +system_hostname() { char buffer[1024]; if (gethostname(buffer, 1023) == -1) @@ -93,19 +94,43 @@ apply_get_hostname() { return std::string(buffer); } +torrent::Object +system_get_cwd() { + char* buffer = getcwd(NULL, 0); + + if (buffer == NULL) + throw torrent::input_error("Unable to read cwd."); + + torrent::Object result = torrent::Object(std::string(buffer)); + free(buffer); + + return result; +} + +torrent::Object +system_set_cwd(const torrent::Object& rawArgs) { + if (::chdir(rawArgs.as_string().c_str()) != 0) + throw torrent::input_error("Could not change current working directory."); + + return torrent::Object(); +} + void initialize_command_local() { torrent::ChunkManager* chunkManager = torrent::chunk_manager(); core::DownloadList* dList = control->core()->download_list(); core::DownloadStore* dStore = control->core()->download_store(); - ADD_VARIABLE_C_STRING("client_version", PACKAGE_VERSION); - ADD_VARIABLE_C_STRING("library_version", torrent::version()); + ADD_C_STRING("system.client_version", PACKAGE_VERSION); + ADD_C_STRING("system.library_version", torrent::version()); - ADD_COMMAND_VOID("get_hostname", rak::ptr_fun(&apply_get_hostname)); - ADD_COMMAND_VOID("get_pid", rak::ptr_fun(&getpid)); + ADD_COMMAND_VOID("system.hostname", rak::ptr_fun(&system_hostname)); + ADD_COMMAND_VOID("system.pid", rak::ptr_fun(&getpid)); - ADD_VARIABLE_STRING("name", ""); + ADD_COMMAND_VALUE_SET_OCT("system.", "umask", std::ptr_fun(&umask)); + ADD_COMMAND_STRING_PREFIX("system.", "cwd", std::ptr_fun(system_set_cwd), rak::ptr_fun(&system_get_cwd)); + + ADD_VARIABLE_STRING("name", ""); ADD_VARIABLE_VALUE("max_file_size", -1); ADD_VARIABLE_VALUE("split_file_size", -1); @@ -125,9 +150,6 @@ initialize_command_local() { ADD_COMMAND_STRING_TRI("session", rak::make_mem_fun(dStore, &core::DownloadStore::set_path), rak::make_mem_fun(dStore, &core::DownloadStore::path)); ADD_COMMAND_VOID("session_save", rak::make_mem_fun(dList, &core::DownloadList::session_save)); - ADD_COMMAND_VALUE_TRI_OCT("umask", rak::make_mem_fun(control, &Control::set_umask), rak::make_mem_fun(control, &Control::umask)); - ADD_COMMAND_STRING_TRI("working_directory", rak::make_mem_fun(control, &Control::set_working_directory), rak::make_mem_fun(control, &Control::working_directory)); - ADD_COMMAND_LIST("execute", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_throw | rpc::ExecFile::flag_expand_tilde)); ADD_COMMAND_LIST("execute_nothrow", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_expand_tilde)); ADD_COMMAND_LIST("execute_raw", rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_throw)); diff --git a/src/control.cc b/src/control.cc index 6f332039..f723359a 100644 --- a/src/control.cc +++ b/src/control.cc @@ -159,16 +159,3 @@ torrent::Poll* Control::poll() { return m_core->get_poll_manager()->get_torrent_poll(); } - -void -Control::set_umask(mode_t m) { - ::umask(m); - - m_umask = m; -} - -void -Control::set_working_directory(const std::string& dir) { - if (::chdir(dir.c_str()) != 0) - throw torrent::input_error("Could not change working directory."); -} diff --git a/src/control.h b/src/control.h index d1e0b52f..ddcc3366 100644 --- a/src/control.h +++ b/src/control.h @@ -105,9 +105,6 @@ public: uint64_t tick() const { return m_tick; } void inc_tick() { m_tick++; } - mode_t umask() const { return m_umask; } - void set_umask(mode_t m); - const std::string& working_directory() const { return m_workingDirectory; } void set_working_directory(const std::string& dir); diff --git a/src/core/download_factory.cc b/src/core/download_factory.cc index a2626c62..aba0d5d9 100644 --- a/src/core/download_factory.cc +++ b/src/core/download_factory.cc @@ -174,6 +174,12 @@ DownloadFactory::receive_success() { initialize_rtorrent(download, rtorrent); + if (!rtorrent->has_key_string("custom1")) rtorrent->insert_key("custom1", std::string()); + if (!rtorrent->has_key_string("custom2")) rtorrent->insert_key("custom2", std::string()); + if (!rtorrent->has_key_string("custom3")) rtorrent->insert_key("custom3", std::string()); + if (!rtorrent->has_key_string("custom4")) rtorrent->insert_key("custom4", std::string()); + if (!rtorrent->has_key_string("custom5")) rtorrent->insert_key("custom5", std::string()); + // Move to 'rtorrent'. rpc::call_command_d("d.set_connection_leech", download, m_variables["connection_leech"]); rpc::call_command_d("d.set_connection_seed", download, m_variables["connection_seed"]); diff --git a/src/main.cc b/src/main.cc index f1942039..44be810f 100644 --- a/src/main.cc +++ b/src/main.cc @@ -166,8 +166,8 @@ main(int argc, char** argv) { initialize_commands(); rpc::parse_command_multiple(rpc::make_target(), -// "set_name = $cat={$get_hostname=,:,$get_pid=}\n" - "set_name = \"$cat=$get_hostname=,:,$get_pid=\"\n" +// "set_name = $cat={$system.hostname=,:,$system.pid=}\n" + "set_name = \"$cat=$system.hostname=,:,$system.pid=\"\n" // Currently not doing any sorting on main. "view_add = main\n"