mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-13 21:52:30 +00:00
* Add support for any number of custom download values identified by string keys.
d.set_custom=key,value d.get_custom=key (returns "" if not set) d.get_custom_throw=key (returns error if not set) * With this patch, rtorrent will detect and complain about .torrent files with broken bencode representation (e.g. where the order of dictionary keys is not lexicographic). * Choose a different poll type using the RTORRENT_POLL env. variable (if it's implemented), probably only useful as RTORRENT_POLL=select. * Add the commands execute_capture and execute_capture_nothrow that work like their other counterparts but return the OUTPUT (stdout) of the given command. Note that the output is not modified in any way, in particular a trailing newline is NOT removed. To work around this, have the command write its output without it e.g. using echo -n. Also note that with execute_capture_nothrow there is no way to check if the command failed. Example usage: d.set_custom4=$execute_capture=handler.sh * When logging peer communication errors, show IP and peer ID to help debugging. All patches above by Josef Drexler. git-svn-id: svn://rakshasa.no/libtorrent/trunk/rtorrent@1088 e378c898-3ddf-0310-93e7-cc216c733640
This commit is contained in:
@@ -252,6 +252,42 @@ retrieve_d_local_id_html(core::Download* download) {
|
||||
return torrent::Object(rak::copy_escape_html(hashString->begin(), hashString->end()));
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
apply_d_custom(core::Download* download, const torrent::Object& rawArgs) {
|
||||
torrent::Object::list_const_iterator itr = rawArgs.as_list().begin();
|
||||
if (itr == rawArgs.as_list().end())
|
||||
throw torrent::bencode_error("Missing key argument.");
|
||||
|
||||
const std::string& key = itr->as_string();
|
||||
if (++itr == rawArgs.as_list().end())
|
||||
throw torrent::bencode_error("Missing value argument.");
|
||||
|
||||
download->bencode()->get_key("rtorrent").
|
||||
insert_preserve_copy("custom", torrent::Object::create_map()).first->second.
|
||||
insert_key(key, itr->as_string());
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
retrieve_d_custom(core::Download* download, const std::string& key) {
|
||||
try {
|
||||
return download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key);
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
retrieve_d_custom_throw(core::Download* download, const std::string& key) {
|
||||
try {
|
||||
return download->bencode()->get_key("rtorrent").get_key("custom").get_key_string(key);
|
||||
|
||||
} catch (torrent::bencode_error& e) {
|
||||
throw torrent::input_error("No such custom value.");
|
||||
}
|
||||
}
|
||||
|
||||
// Just a helper function atm.
|
||||
torrent::Object
|
||||
cmd_d_initialize_logs(core::Download* download) {
|
||||
@@ -560,6 +596,10 @@ initialize_command_download() {
|
||||
ADD_CD_VARIABLE_STRING_PUBLIC("custom4", "rtorrent", "custom4");
|
||||
ADD_CD_VARIABLE_STRING_PUBLIC("custom5", "rtorrent", "custom5");
|
||||
|
||||
ADD_CD_SLOT_PUBLIC("d.set_custom", call_list, rak::ptr_fn(&apply_d_custom), "i:", "");
|
||||
ADD_CD_SLOT_PUBLIC("d.get_custom", call_string, rpc::object_string_fn<core::Download*>(std::ptr_fun(&retrieve_d_custom)), "s:s", "");
|
||||
ADD_CD_SLOT_PUBLIC("d.get_custom_throw", call_string, rpc::object_string_fn<core::Download*>(std::ptr_fun(&retrieve_d_custom_throw)), "s:s", "");
|
||||
|
||||
// 0 - stopped
|
||||
// 1 - started
|
||||
ADD_CD_VARIABLE_VALUE("state", "rtorrent", "state");
|
||||
|
||||
Reference in New Issue
Block a user