From 8f0331625a6d0b4dea754b7cedb4e1945b55d12c Mon Sep 17 00:00:00 2001 From: kannibalox Date: Tue, 24 Dec 2024 12:58:20 -0500 Subject: [PATCH] Correctly handle commands that are flagged as not using targets Fixes #1346 --- src/rpc/xmlrpc.cc | 3 +++ src/rpc/xmlrpc_tinyxml2.cc | 12 ++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/rpc/xmlrpc.cc b/src/rpc/xmlrpc.cc index f82b8bad..527daebd 100644 --- a/src/rpc/xmlrpc.cc +++ b/src/rpc/xmlrpc.cc @@ -59,6 +59,9 @@ private: void XmlRpc::object_to_target(const torrent::Object& obj, int callFlags, rpc::target_type* target) { + if (callFlags & CommandMap::flag_no_target) + return; + if (!obj.is_string()) { throw torrent::input_error("invalid parameters: target must be a string"); } diff --git a/src/rpc/xmlrpc_tinyxml2.cc b/src/rpc/xmlrpc_tinyxml2.cc index 9169e5ed..42ee5589 100644 --- a/src/rpc/xmlrpc_tinyxml2.cc +++ b/src/rpc/xmlrpc_tinyxml2.cc @@ -214,8 +214,10 @@ execute_command(std::string method_name, const tinyxml2::XMLElement* params_elem // Parse out the target if available const auto* child = params_element->FirstChildElement("param"); if (child != nullptr) { - XmlRpc::object_to_target(xml_value_to_object(child->FirstChildElement("value")), cmd_itr->second.m_flags, &target); - child = child->NextSiblingElement("param"); + if (!(cmd_itr->second.m_flags & CommandMap::flag_no_target)) { + XmlRpc::object_to_target(xml_value_to_object(child->FirstChildElement("value")), cmd_itr->second.m_flags, &target); + child = child->NextSiblingElement("param"); + } // Parse out any other params while (child != nullptr) { params.push_back(xml_value_to_object(child->FirstChildElement("value"))); @@ -226,8 +228,10 @@ execute_command(std::string method_name, const tinyxml2::XMLElement* params_elem // If it's not a , it's probably a passed in via system.multicall const auto* child = params_element->FirstChildElement("data")->FirstChildElement("value"); if (child != nullptr) { - XmlRpc::object_to_target(xml_value_to_object(child), cmd_itr->second.m_flags, &target); - child = child->NextSiblingElement("value"); + if (!(cmd_itr->second.m_flags & CommandMap::flag_no_target)) { + XmlRpc::object_to_target(xml_value_to_object(child), cmd_itr->second.m_flags, &target); + child = child->NextSiblingElement("value"); + } while (child != nullptr) { params.push_back(xml_value_to_object(child)); child = child->NextSiblingElement("value");