* Cleaned up the 'umask' command and renamed 'working_directory' to

'cwd'.

* Added 'd.{get,set}_custom[1-5]' for user scripts.


git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@963 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
rakshasa
2007-08-23 21:21:11 +00:00
parent 38f8a00c0c
commit 85d14f0e96
9 changed files with 66 additions and 37 deletions
+1 -1
View File
@@ -981,7 +981,7 @@ by the program.
</varlistentry>
<varlistentry>
<term>working_directory = <replaceable>directory</replaceable></term>
<term>cwd = <replaceable>directory</replaceable></term>
<listitem><para>
Changes the working directory of the process using
+1 -1
View File
@@ -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;
+10
View File
@@ -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");
+15 -8
View File
@@ -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:", "")
+31 -9
View File
@@ -41,6 +41,7 @@
#include <unistd.h>
#include <rak/path.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <torrent/torrent.h>
#include <torrent/chunk_manager.h>
@@ -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));
-13
View File
@@ -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.");
}
-3
View File
@@ -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);
+6
View File
@@ -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"]);
+2 -2
View File
@@ -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"