Changeset 963

Show
Ignore:
Timestamp:
08/23/07 17:21:11 (5 years ago)
Author:
rakshasa
Message:

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

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

Location:
trunk
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • trunk/libtorrent/rak/socket_address.h

    r962 r963  
    7575#else 
    7676  static const sa_family_t af_local  = AF_UNIX; 
    77   static const itn         pf_local  = PF_UNIX; 
     77  static const int         pf_local  = PF_UNIX; 
    7878#endif 
    7979 
  • trunk/rtorrent/doc/rtorrent.1.xml

    r961 r963  
    982982 
    983983      <varlistentry> 
    984         <term>working_directory = <replaceable>directory</replaceable></term> 
     984        <term>cwd = <replaceable>directory</replaceable></term> 
    985985        <listitem><para> 
    986986 
  • trunk/rtorrent/rak/socket_address.h

    r962 r963  
    7575#else 
    7676  static const sa_family_t af_local  = AF_UNIX; 
    77   static const itn         pf_local  = PF_UNIX; 
     77  static const int         pf_local  = PF_UNIX; 
    7878#endif 
    7979 
  • trunk/rtorrent/src/command_download.cc

    r962 r963  
    313313  ADD_CD_SLOT("d.set_" key, call_string,  rpc::set_variable_d_fn(firstKey, secondKey), "i:s", ""); 
    314314 
     315#define ADD_CD_VARIABLE_STRING_PUBLIC(key, firstKey, secondKey) \ 
     316  ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::get_variable_d_fn(firstKey, secondKey), "i:", ""); \ 
     317  ADD_CD_SLOT_PUBLIC("d.set_" key, call_string,  rpc::set_variable_d_fn(firstKey, secondKey), "i:s", ""); 
     318 
    315319#define ADD_CD_VALUE_UNI(key, get) \ 
    316320  ADD_CD_SLOT_PUBLIC("d.get_" key, call_unknown, rpc::object_void_d_fn(get), "i:", "") 
     
    371375  ADD_CD_VALUE_UNI("is_hash_checking", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::is_hash_checking))); 
    372376  ADD_CD_VALUE_UNI("is_multi_file",    rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(&torrent::FileList::is_multi_file))); 
     377 
     378  ADD_CD_VARIABLE_STRING_PUBLIC("custom1", "rtorrent", "custom1"); 
     379  ADD_CD_VARIABLE_STRING_PUBLIC("custom2", "rtorrent", "custom2"); 
     380  ADD_CD_VARIABLE_STRING_PUBLIC("custom3", "rtorrent", "custom3"); 
     381  ADD_CD_VARIABLE_STRING_PUBLIC("custom4", "rtorrent", "custom4"); 
     382  ADD_CD_VARIABLE_STRING_PUBLIC("custom5", "rtorrent", "custom5"); 
    373383 
    374384  // 0 - stopped 
  • trunk/rtorrent/src/command_helpers.h

    r959 r963  
    8989add_variable("get_" key, "set_" key, key, &rpc::CommandVariable::get_string, &rpc::CommandVariable::set_string, std::string(defaultValue)); 
    9090 
    91 #define ADD_VARIABLE_C_STRING(key, defaultValue) \ 
    92 add_variable("get_" key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::string(defaultValue)); 
     91#define ADD_C_STRING(key, defaultValue) \ 
     92add_variable(key, NULL, NULL, &rpc::CommandVariable::get_string, NULL, std::string(defaultValue)); 
    9393 
    9494#define ADD_COMMAND_SLOT(key, function, slot, parm, doc)    \ 
     
    116116  ADD_COMMAND_SLOT("get_" key,  call_unknown, rpc::object_void_fn(get), "i:", "") 
    117117 
    118 #define ADD_COMMAND_VALUE_TRI_OCT(key, set, get) \ 
     118#define ADD_COMMAND_VALUE_SET_OCT(prefix, key, set)                \ 
    119119  ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, rpc::object_value_fn(set)) \ 
    120   ADD_COMMAND_COPY("set_" key,  call_value, "i:i", "")                      \ 
    121   ADD_COMMAND_SLOT("get_" key,  call_unknown, rpc::object_void_fn(get), "i:", "") 
     120  ADD_COMMAND_COPY(prefix "set_" key,  call_value, "i:i", "") 
    122121 
    123 #define ADD_COMMAND_STRING_TRI(key, set, get) \ 
     122#define ADD_COMMAND_VALUE_TRI_OCT(prefix, key, set, get)                 \ 
     123  ADD_COMMAND_SLOT_PRIVATE(key, call_value_oct, rpc::object_value_fn(set)) \ 
     124  ADD_COMMAND_COPY(prefix "set_" key,  call_value, "i:i", "")                      \ 
     125  ADD_COMMAND_SLOT(prefix "get_" key,  call_unknown, rpc::object_void_fn(get), "i:", "") 
     126 
     127#define ADD_COMMAND_STRING_PREFIX(prefix, key, set, get) \ 
    124128  ADD_COMMAND_SLOT_PRIVATE(key, call_string, rpc::object_string_fn(set))      \ 
    125   ADD_COMMAND_COPY("set_" key,  call_string, "i:s", "") \ 
    126   ADD_COMMAND_SLOT("get_" key,  call_unknown, rpc::object_void_fn(get), "s:", "") 
     129  ADD_COMMAND_COPY(prefix "set_" key,  call_string, "i:s", "") \ 
     130  ADD_COMMAND_SLOT(prefix "get_" key,  call_unknown, rpc::object_void_fn(get), "s:", "") 
     131 
     132#define ADD_COMMAND_STRING_TRI(key, set, get)                    \ 
     133  ADD_COMMAND_STRING_PREFIX("", key, set, get) 
    127134 
    128135#define ADD_COMMAND_VOID(key, slot) \ 
  • trunk/rtorrent/src/command_local.cc

    r959 r963  
    4242#include <rak/path.h> 
    4343#include <sys/types.h> 
     44#include <sys/stat.h> 
    4445#include <torrent/torrent.h> 
    4546#include <torrent/chunk_manager.h> 
     
    8283 
    8384torrent::Object 
    84 apply_get_hostname() { 
     85system_hostname() { 
    8586  char buffer[1024]; 
    8687 
     
    9495} 
    9596 
     97torrent::Object 
     98system_get_cwd() { 
     99  char* buffer = getcwd(NULL, 0); 
     100 
     101  if (buffer == NULL) 
     102    throw torrent::input_error("Unable to read cwd."); 
     103 
     104  torrent::Object result = torrent::Object(std::string(buffer)); 
     105  free(buffer); 
     106 
     107  return result; 
     108} 
     109 
     110torrent::Object 
     111system_set_cwd(const torrent::Object& rawArgs) { 
     112  if (::chdir(rawArgs.as_string().c_str()) != 0) 
     113    throw torrent::input_error("Could not change current working directory."); 
     114 
     115  return torrent::Object(); 
     116} 
     117 
    96118void 
    97119initialize_command_local() { 
     
    100122  core::DownloadStore*   dStore = control->core()->download_store(); 
    101123 
    102   ADD_VARIABLE_C_STRING("client_version",  PACKAGE_VERSION); 
    103   ADD_VARIABLE_C_STRING("library_version", torrent::version()); 
     124  ADD_C_STRING("system.client_version",          PACKAGE_VERSION); 
     125  ADD_C_STRING("system.library_version",        torrent::version()); 
    104126 
    105   ADD_COMMAND_VOID("get_hostname",         rak::ptr_fun(&apply_get_hostname)); 
    106   ADD_COMMAND_VOID("get_pid",              rak::ptr_fun(&getpid)); 
     127  ADD_COMMAND_VOID("system.hostname",            rak::ptr_fun(&system_hostname)); 
     128  ADD_COMMAND_VOID("system.pid",                 rak::ptr_fun(&getpid)); 
    107129 
    108   ADD_VARIABLE_STRING("name",              ""); 
     130  ADD_COMMAND_VALUE_SET_OCT("system.", "umask",  std::ptr_fun(&umask)); 
     131  ADD_COMMAND_STRING_PREFIX("system.", "cwd",    std::ptr_fun(system_set_cwd), rak::ptr_fun(&system_get_cwd)); 
     132 
     133  ADD_VARIABLE_STRING("name",            ""); 
    109134 
    110135  ADD_VARIABLE_VALUE("max_file_size", -1); 
     
    126151  ADD_COMMAND_VOID("session_save",             rak::make_mem_fun(dList, &core::DownloadList::session_save)); 
    127152 
    128   ADD_COMMAND_VALUE_TRI_OCT("umask",           rak::make_mem_fun(control, &Control::set_umask), rak::make_mem_fun(control, &Control::umask)); 
    129   ADD_COMMAND_STRING_TRI("working_directory",  rak::make_mem_fun(control, &Control::set_working_directory), rak::make_mem_fun(control, &Control::working_directory)); 
    130  
    131153  ADD_COMMAND_LIST("execute",             rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_throw | rpc::ExecFile::flag_expand_tilde)); 
    132154  ADD_COMMAND_LIST("execute_nothrow",     rak::bind2_mem_fn(&rpc::execFile, &rpc::ExecFile::execute_object, rpc::ExecFile::flag_expand_tilde)); 
  • trunk/rtorrent/src/control.cc

    r938 r963  
    160160  return m_core->get_poll_manager()->get_torrent_poll(); 
    161161} 
    162  
    163 void 
    164 Control::set_umask(mode_t m) { 
    165   ::umask(m); 
    166  
    167   m_umask = m; 
    168 } 
    169  
    170 void 
    171 Control::set_working_directory(const std::string& dir) { 
    172   if (::chdir(dir.c_str()) != 0) 
    173     throw torrent::input_error("Could not change working directory."); 
    174 } 
  • trunk/rtorrent/src/control.h

    r938 r963  
    106106  void                inc_tick()                    { m_tick++; } 
    107107 
    108   mode_t              umask() const                 { return m_umask; } 
    109   void                set_umask(mode_t m); 
    110  
    111108  const std::string&  working_directory() const     { return m_workingDirectory; } 
    112109  void                set_working_directory(const std::string& dir); 
  • trunk/rtorrent/src/core/download_factory.cc

    r955 r963  
    175175  initialize_rtorrent(download, rtorrent); 
    176176 
     177  if (!rtorrent->has_key_string("custom1")) rtorrent->insert_key("custom1", std::string()); 
     178  if (!rtorrent->has_key_string("custom2")) rtorrent->insert_key("custom2", std::string()); 
     179  if (!rtorrent->has_key_string("custom3")) rtorrent->insert_key("custom3", std::string()); 
     180  if (!rtorrent->has_key_string("custom4")) rtorrent->insert_key("custom4", std::string()); 
     181  if (!rtorrent->has_key_string("custom5")) rtorrent->insert_key("custom5", std::string()); 
     182 
    177183  // Move to 'rtorrent'. 
    178184  rpc::call_command_d("d.set_connection_leech", download, m_variables["connection_leech"]); 
  • trunk/rtorrent/src/main.cc

    r961 r963  
    167167 
    168168    rpc::parse_command_multiple(rpc::make_target(), 
    169 //       "set_name = $cat={$get_hostname=,:,$get_pid=}\n" 
    170        "set_name = \"$cat=$get_hostname=,:,$get_pid=\"\n" 
     169//       "set_name = $cat={$system.hostname=,:,$system.pid=}\n" 
     170       "set_name = \"$cat=$system.hostname=,:,$system.pid=\"\n" 
    171171 
    172172       // Currently not doing any sorting on main.