From 7dc2b9ff1670856136b5843b2cf718d94dce54ca Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 12 Feb 2012 23:13:21 +0900 Subject: [PATCH] Allow missing params in XML-RPC request. Now following request is legal: aria2.getVersion --- src/rpc_helper.cc | 10 ++++++---- test/RpcHelperTest.cc | 13 ++++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/rpc_helper.cc b/src/rpc_helper.cc index d8d92acb..a9d6e721 100644 --- a/src/rpc_helper.cc +++ b/src/rpc_helper.cc @@ -50,11 +50,13 @@ RpcRequest xmlParseMemory(const char* xml, size_t size) if(!XmlParser(&psm).parseMemory(xml, size)) { throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST); } - if(!downcast(psm.getCurrentFrameValue())) { - throw DL_ABORT_EX("Bad XML-RPC parameter list"); + SharedHandle params; + if(downcast(psm.getCurrentFrameValue())) { + params = static_pointer_cast(psm.getCurrentFrameValue()); + } else { + params = List::g(); } - return RpcRequest(psm.getMethodName(), - static_pointer_cast(psm.getCurrentFrameValue())); + return RpcRequest(psm.getMethodName(), params); } #endif // ENABLE_XML_RPC diff --git a/test/RpcHelperTest.cc b/test/RpcHelperTest.cc index 8f04c434..38f2fac3 100644 --- a/test/RpcHelperTest.cc +++ b/test/RpcHelperTest.cc @@ -29,6 +29,7 @@ public: #ifdef ENABLE_XML_RPC void testParseMemory(); void testParseMemory_shouldFail(); + void testParseMemory_withoutParams(); void testParseMemory_withoutStringTag(); #endif // ENABLE_XML_RPC }; @@ -105,6 +106,10 @@ void RpcHelperTest::testParseMemory_shouldFail() } catch(RecoverableException& e) { // success } +} + +void RpcHelperTest::testParseMemory_withoutParams() +{ { std::string s = "" @@ -115,15 +120,13 @@ void RpcHelperTest::testParseMemory_shouldFail() RpcRequest req = xmlParseMemory(s.c_str(), s.size()); CPPUNIT_ASSERT(req.params); } - try { + { std::string s = "" " aria2.addURI" ""; - xmlParseMemory(s.c_str(), s.size()); - CPPUNIT_FAIL("exception must be thrown."); - } catch(RecoverableException& e) { - // success + RpcRequest req = xmlParseMemory(s.c_str(), s.size()); + CPPUNIT_ASSERT(req.params->size()); } }