Allow missing params in XML-RPC request.

Now following request is legal:

<methodCall>
  <methodName>aria2.getVersion</methodName>
</methodCall>
pull/12/head
Tatsuhiro Tsujikawa 2012-02-12 23:13:21 +09:00
parent 9b7e4219d9
commit 7dc2b9ff16
2 changed files with 14 additions and 9 deletions

View File

@ -50,11 +50,13 @@ RpcRequest xmlParseMemory(const char* xml, size_t size)
if(!XmlParser(&psm).parseMemory(xml, size)) { if(!XmlParser(&psm).parseMemory(xml, size)) {
throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST); throw DL_ABORT_EX(MSG_CANNOT_PARSE_XML_RPC_REQUEST);
} }
if(!downcast<List>(psm.getCurrentFrameValue())) { SharedHandle<List> params;
throw DL_ABORT_EX("Bad XML-RPC parameter list"); if(downcast<List>(psm.getCurrentFrameValue())) {
params = static_pointer_cast<List>(psm.getCurrentFrameValue());
} else {
params = List::g();
} }
return RpcRequest(psm.getMethodName(), return RpcRequest(psm.getMethodName(), params);
static_pointer_cast<List>(psm.getCurrentFrameValue()));
} }
#endif // ENABLE_XML_RPC #endif // ENABLE_XML_RPC

View File

@ -29,6 +29,7 @@ public:
#ifdef ENABLE_XML_RPC #ifdef ENABLE_XML_RPC
void testParseMemory(); void testParseMemory();
void testParseMemory_shouldFail(); void testParseMemory_shouldFail();
void testParseMemory_withoutParams();
void testParseMemory_withoutStringTag(); void testParseMemory_withoutStringTag();
#endif // ENABLE_XML_RPC #endif // ENABLE_XML_RPC
}; };
@ -105,6 +106,10 @@ void RpcHelperTest::testParseMemory_shouldFail()
} catch(RecoverableException& e) { } catch(RecoverableException& e) {
// success // success
} }
}
void RpcHelperTest::testParseMemory_withoutParams()
{
{ {
std::string s = std::string s =
"<methodCall>" "<methodCall>"
@ -115,15 +120,13 @@ void RpcHelperTest::testParseMemory_shouldFail()
RpcRequest req = xmlParseMemory(s.c_str(), s.size()); RpcRequest req = xmlParseMemory(s.c_str(), s.size());
CPPUNIT_ASSERT(req.params); CPPUNIT_ASSERT(req.params);
} }
try { {
std::string s = std::string s =
"<methodCall>" "<methodCall>"
" <methodName>aria2.addURI</methodName>" " <methodName>aria2.addURI</methodName>"
"</methodCall>"; "</methodCall>";
xmlParseMemory(s.c_str(), s.size()); RpcRequest req = xmlParseMemory(s.c_str(), s.size());
CPPUNIT_FAIL("exception must be thrown."); CPPUNIT_ASSERT(req.params->size());
} catch(RecoverableException& e) {
// success
} }
} }