16 using namespace XmlRpc;
71 MethodMap::iterator i =
_methods.find(methodName);
81 MethodMap::const_iterator i =
_methods.find(name);
134 XmlRpcUtil::log(2,
"XmlRpcServer::bindAndListen: server listening on port %d fd %d", port, fd);
191 XmlRpcUtil::log(2,
"XmlRpcServer::acceptConnection: creating a connection");
241 static const std::string
LIST_METHODS(
"system.listMethods");
242 static const std::string
METHOD_HELP(
"system.methodHelp");
243 static const std::string
MULTICALL(
"system.multicall");
254 _server->listMethods(result);
257 std::string
help() {
return std::string(
"List all methods available on a server as an array of strings"); }
279 std::string
help() {
return std::string(
"Retrieve the help string for a named method"); }
317 result[i++] = it->first;
331 XmlRpcUtil::log(2,
"XmlRpcServer::executeRequest: server calling method '%s'",
334 std::string response;
382 if ( ! method)
return false;
384 method->
execute(params, result);
388 result = std::string();
399 if (methodName !=
MULTICALL)
return false;
405 int nc = params[0].
size();
408 for (
int i=0; i<nc; ++i) {
411 ! params[0][i].hasMember(
PARAMS)) {
414 ": Invalid argument (expected a struct with members methodName and params)";
418 const std::string& methodName = params[0][i][
METHODNAME];
424 if ( !
executeMethod(methodName, methodParams, resultValue[0]) &&
428 result[i][
FAULTSTRING] = methodName +
": unknown method name";
431 result[i] = resultValue;
447 const char RESPONSE_1[] =
448 "<?xml version=\"1.0\"?>\r\n"
449 "<methodResponse><params><param>\r\n\t";
450 const char RESPONSE_2[] =
451 "\r\n</param></params></methodResponse>\r\n";
453 std::string body = RESPONSE_1 + resultXml + RESPONSE_2;
455 std::string response = header + body;
457 XmlRpcUtil::log(5,
"XmlRpcServer::generateResponse:\n%s\n", response.c_str());
467 "HTTP/1.1 200 OK\r\n"
471 "Content-Type: text/xml\r\n"
475 sprintf(buffLen,
"%zu\r\n\r\n", body.size());
477 return header + buffLen;
484 const char RESPONSE_1[] =
485 "<?xml version=\"1.0\"?>\r\n"
486 "<methodResponse><fault>\r\n\t";
487 const char RESPONSE_2[] =
488 "\r\n</fault></methodResponse>\r\n";
493 std::string body = RESPONSE_1 + faultStruct.
toXml() + RESPONSE_2;
496 return header + body;