diff --git a/src/command_download.cc b/src/command_download.cc index 476ad4e3..865351cd 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -202,7 +203,7 @@ retrieve_d_priority_str(core::Download* download) { } torrent::Object -apply_d_ratio(core::Download* download) { +retrieve_d_ratio(core::Download* download) { if (download->is_hash_checking()) return int64_t(); @@ -212,6 +213,13 @@ apply_d_ratio(core::Download* download) { return bytesDone > 0 ? (1000 * upTotal) / bytesDone : 0; } +torrent::Object +retrieve_d_hash(core::Download* download) { + const torrent::HashString* hashString = &download->download()->info_hash(); + + return torrent::Object(rak::transform_hex(hashString->begin(), hashString->end())); +} + #define ADD_CD_SLOT(key, function, slot, parm, doc) \ commandDownloadSlotsItr->set_slot(slot); \ rpc::commands.insert_download(key, commandDownloadSlotsItr++, &rpc::CommandDownloadSlot::function, rpc::CommandMap::flag_dont_delete, parm, doc); @@ -276,6 +284,7 @@ add_copy_to_download(const char* src, const char* dest) { void initialize_command_download() { + ADD_CD_VOID("hash", &retrieve_d_hash); ADD_CD_VOID("base_path", &retrieve_d_base_path); ADD_CD_VOID("base_filename", &retrieve_d_base_filename); ADD_CD_STRING_UNI("name", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::name))); @@ -313,6 +322,7 @@ initialize_command_download() { // 0 - Not hashing // 1 - Normal hashing // 2 - Download finished, hashing + // 3 - Rehashing ADD_CD_VARIABLE_VALUE("hashing", "rtorrent", "hashing"); ADD_CD_VARIABLE_STRING("tied_to_file", "rtorrent", "tied_to_file"); @@ -352,7 +362,7 @@ initialize_command_download() { ADD_CD_VALUE_MEM_UNI("skip_total", &torrent::Download::mutable_skip_rate, &torrent::Rate::total); ADD_CD_VALUE_UNI("bytes_done", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::bytes_done))); - ADD_CD_VALUE_UNI("ratio", std::ptr_fun(&apply_d_ratio)); + ADD_CD_VALUE_UNI("ratio", std::ptr_fun(&retrieve_d_ratio)); ADD_CD_VALUE_UNI("chunks_hashed", rak::on(std::mem_fun(&core::Download::download), std::mem_fun(&torrent::Download::chunks_hashed))); ADD_CD_VALUE_UNI("free_diskspace", rak::on(std::mem_fun(&core::Download::file_list), std::mem_fun(&torrent::FileList::free_diskspace))); diff --git a/src/command_local.cc b/src/command_local.cc index b5547099..7ecf7f2b 100644 --- a/src/command_local.cc +++ b/src/command_local.cc @@ -38,6 +38,7 @@ #include #include +#include #include #include #include @@ -78,6 +79,19 @@ apply_execute_log(const torrent::Object& rawArgs) { return torrent::Object(); } +torrent::Object +apply_get_hostname() { + char buffer[1024]; + + if (gethostname(buffer, 1023) == -1) + throw torrent::input_error("Unable to read hostname."); + +// if (shorten) +// *std::find(buffer, buffer + 1023, '.') = '\0'; + + return std::string(buffer); +} + void initialize_command_local() { torrent::ChunkManager* chunkManager = torrent::chunk_manager(); @@ -87,6 +101,8 @@ initialize_command_local() { ADD_VARIABLE_C_STRING("client_version", PACKAGE_VERSION); ADD_VARIABLE_C_STRING("library_version", torrent::version()); + ADD_COMMAND_VOID("get_hostname", rak::ptr_fun(&apply_get_hostname)); + ADD_VARIABLE_VALUE("max_file_size", -1); ADD_VARIABLE_VALUE("split_file_size", -1); ADD_VARIABLE_STRING("split_suffix", ".part"); diff --git a/src/command_network.cc b/src/command_network.cc index c51fcc51..e4cba99e 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -270,6 +270,7 @@ initialize_command_network() { ADD_VARIABLE_BOOL("use_udp_trackers", true); + // Isn't port_open used? ADD_VARIABLE_BOOL("port_open", true); ADD_VARIABLE_BOOL("port_random", true); ADD_VARIABLE_STRING("port_range", "6881-6999"); diff --git a/src/command_ui.cc b/src/command_ui.cc index 2719fbd2..529de683 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -40,7 +40,6 @@ #include #include -// #include "core/download_list.h" #include "core/manager.h" #include "core/view_manager.h" #include "rpc/command_slot.h"