diff --git a/src/command_download.cc b/src/command_download.cc index 01bf72c7..b400fadd 100644 --- a/src/command_download.cc +++ b/src/command_download.cc @@ -546,13 +546,6 @@ download_set_variable_string(core::Download* download, const torrent::Object::st // // -torrent::Object -d_list_push_back(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) { - download_get_variable(download, first_key, second_key).as_list().push_back(rawArgs); - - return torrent::Object(); -} - torrent::Object d_list_push_back_string(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) { auto& arg = rawArgs.as_string(); @@ -561,17 +554,6 @@ d_list_push_back_string(core::Download* download, const torrent::Object& rawArgs return torrent::Object(); } -torrent::Object -d_list_push_back_unique(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) { - const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs; - torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list(); - - if (std::find_if(list.begin(), list.end(), [args](const torrent::Object& obj) { return torrent::object_equal(obj, args); }) == list.end()) - list.push_back(rawArgs); - - return torrent::Object(); -} - torrent::Object d_list_push_back_unique_string(core::Download* download, const torrent::Object& rawArgs, const char* first_key, const char* second_key) { auto& arg = rawArgs.as_string(); @@ -588,7 +570,7 @@ d_list_has(core::Download* download, const torrent::Object& rawArgs, const char* const torrent::Object& args = (rawArgs.is_list() && !rawArgs.as_list().empty()) ? rawArgs.as_list().front() : rawArgs; torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list(); - return (int64_t)(std::find_if(list.begin(), list.end(), [args](const torrent::Object& obj) { return torrent::object_equal(obj, args); }) != list.end()); + return (int64_t)(std::any_of(list.begin(), list.end(), [args](const auto& obj) { return torrent::object_equal(obj, args); })); } torrent::Object diff --git a/test/rpc/test_xmlrpc.cc b/test/rpc/test_xmlrpc.cc index dd07495c..b9557fc4 100644 --- a/test/rpc/test_xmlrpc.cc +++ b/test/rpc/test_xmlrpc.cc @@ -17,7 +17,7 @@ xmlrpc_cmd_test_reflect([[maybe_unused]] rpc::target_type t, const torrent::Obje } torrent::Object -xmlrpc_cmd_([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) { +xmlrpc_cmd_test_reflect_string([[maybe_unused]] rpc::target_type t, const std::string& obj) { return obj; } @@ -104,7 +104,12 @@ std::vector> basic_requests = std::make_tuple("Invalid - non-boolean boolean", "xmlrpc_reflectstring value", - "faultCode-501faultStringunknown boolean value: string value") + "faultCode-501faultStringunknown boolean value: string value"), + + std::make_tuple("CMD2_ANY_STRING", + "xmlrpc_reflect_stringtest", + "test") + }; void @@ -120,14 +125,8 @@ TestXmlrpc::setUp() { if (rpc::commands.find("xmlrpc_reflect") == rpc::commands.end()) CMD2_ANY("xmlrpc_reflect", &xmlrpc_cmd_test_reflect); - // TODO: Check if rtorrent:views must be initialized. - // TODO: Add checks to d.views that only allows strings. - - // CMD2_DL ("d.views", std::bind(&download_get_variable, std::placeholders::_1, "rtorrent", "views")); - // CMD2_DL ("d.views.has", std::bind(&d_list_has, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views")); - // CMD2_DL ("d.views.remove", std::bind(&d_list_remove, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views")); - // CMD2_DL ("d.views.push_back", std::bind(&d_list_push_back, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views")); - // CMD2_DL ("d.views.push_back_unique", std::bind(&d_list_push_back_unique, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views")); + if (rpc::commands.find("xmlrpc_reflect_string") == rpc::commands.end()) + CMD2_ANY_STRING("xmlrpc_reflect_string", &xmlrpc_cmd_test_reflect_string); } void