mirror of
https://github.com/rakshasa/rtorrent.git
synced 2026-08-05 17:52:29 +00:00
Strict checking of d.views push_back arguments.
This commit is contained in:
+21
-2
@@ -550,6 +550,14 @@ d_list_push_back(core::Download* download, const torrent::Object& rawArgs, const
|
||||
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();
|
||||
download_get_variable(download, first_key, second_key).as_list().push_back(arg);
|
||||
|
||||
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;
|
||||
@@ -561,6 +569,17 @@ d_list_push_back_unique(core::Download* download, const torrent::Object& 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();
|
||||
torrent::Object::list_type& list = download_get_variable(download, first_key, second_key).as_list();
|
||||
|
||||
if (std::none_of(list.begin(), list.end(), [arg](const torrent::Object& obj) { return torrent::object_equal(obj, arg); }))
|
||||
list.push_back(arg);
|
||||
|
||||
return torrent::Object();
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
d_list_has(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;
|
||||
@@ -773,8 +792,8 @@ initialize_command_download() {
|
||||
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"));
|
||||
CMD2_DL ("d.views.push_back", std::bind(&d_list_push_back_string, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views"));
|
||||
CMD2_DL ("d.views.push_back_unique", std::bind(&d_list_push_back_unique_string, std::placeholders::_1, std::placeholders::_2, "rtorrent", "views"));
|
||||
|
||||
// This command really needs to be improved, so we have proper
|
||||
// logging support.
|
||||
|
||||
+19
-3
@@ -11,7 +11,15 @@
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION(TestXmlrpc);
|
||||
|
||||
torrent::Object xmlrpc_cmd_test_reflect([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) { return obj; }
|
||||
torrent::Object
|
||||
xmlrpc_cmd_test_reflect([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
torrent::Object
|
||||
xmlrpc_cmd_([[maybe_unused]] rpc::target_type t, const torrent::Object& obj) {
|
||||
return obj;
|
||||
}
|
||||
|
||||
void initialize_command_dynamic();
|
||||
|
||||
@@ -109,9 +117,17 @@ TestXmlrpc::setUp() {
|
||||
setlocale(LC_ALL, "");
|
||||
control = new Control;
|
||||
|
||||
if (rpc::commands.find("xmlrpc_reflect") == rpc::commands.end()) {
|
||||
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"));
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
@@ -27,6 +27,4 @@ private:
|
||||
std::unique_ptr<TestMainThread> m_test_main_thread;
|
||||
|
||||
rpc::XmlRpc m_xmlrpc;
|
||||
rpc::CommandMap m_map;
|
||||
rpc::command_base m_commands[cmd_size];
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user