From f0207ce6548026853ec57ab26f2e57a872f223bb Mon Sep 17 00:00:00 2001 From: rakshasa Date: Sat, 23 Jun 2018 17:01:34 +0900 Subject: [PATCH] Added "try" command that catches input_errors and logs them on rpc_events. --- src/command_network.cc | 6 ++---- src/command_ui.cc | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/command_network.cc b/src/command_network.cc index 3594c302..092287a5 100644 --- a/src/command_network.cc +++ b/src/command_network.cc @@ -167,8 +167,7 @@ apply_scgi(const std::string& arg, int type) { sa.sa_inet()->clear(); saPtr = &sa; - lt_log_print(torrent::LOG_RPC_EVENTS, - "The SCGI socket has not been bound to any address and likely poses a security risk."); + lt_log_print(torrent::LOG_RPC_EVENTS, "SCGI socket is open to any address and is a security risk"); } else if (std::sscanf(arg.c_str(), "%1023[^:]:%i%c", address, &port, &dummy) == 2 || std::sscanf(arg.c_str(), "[%64[^]]]:%i%c", address, &port, &dummy) == 2) { // [xx::xx]:port format @@ -177,8 +176,7 @@ apply_scgi(const std::string& arg, int type) { saPtr = ai->address(); - lt_log_print(torrent::LOG_RPC_EVENTS, - "The SCGI socket is bound to a specific network device yet may still pose a security risk, consider using 'scgi_local'."); + lt_log_print(torrent::LOG_RPC_EVENTS, "SCGI socket is bound to an address and might be a security risk"); } else { throw torrent::input_error("Could not parse address."); diff --git a/src/command_ui.cc b/src/command_ui.cc index fa331565..17658f7a 100644 --- a/src/command_ui.cc +++ b/src/command_ui.cc @@ -42,6 +42,7 @@ #include #include #include +#include #include "core/manager.h" #include "core/view_manager.h" @@ -172,6 +173,17 @@ apply_value(rpc::target_type target, const torrent::Object::list_type& args) { return val; } +torrent::Object +apply_try(rpc::target_type target, const torrent::Object& args) { + try { + return rpc::call_object(args, target); + } catch (torrent::input_error& e) { + lt_log_print(torrent::LOG_RPC_EVENTS, "try command caught input_error: %s", e.what()); + } + + return torrent::Object(); +} + // Move these boolean operators to a new file. inline bool @@ -713,6 +725,7 @@ initialize_command_ui() { CMD2_ANY("print", &apply_print); CMD2_ANY("cat", &apply_cat); CMD2_ANY_LIST("value", &apply_value); + CMD2_ANY("try", &apply_try); CMD2_ANY("if", std::bind(&apply_if, std::placeholders::_1, std::placeholders::_2, 0)); CMD2_ANY("not", &apply_not); CMD2_ANY("false", &apply_false);