/* */ #include "RpcMethod.h" #include "DownloadEngine.h" #include "LogFactory.h" #include "RecoverableException.h" #include "message.h" #include "OptionParser.h" #include "OptionHandler.h" #include "Option.h" #include "array_fun.h" #include "download_helper.h" #include "RpcRequest.h" #include "RpcResponse.h" #include "prefs.h" #include "fmt.h" #include "DlAbortEx.h" namespace aria2 { namespace rpc { RpcMethod::RpcMethod() : optionParser_(OptionParser::getInstance()) {} RpcMethod::~RpcMethod() {} SharedHandle RpcMethod::createErrorResponse (const Exception& e, const RpcRequest& req) { SharedHandle params = Dict::g(); params->put((req.jsonRpc ? "code" : "faultCode"), Integer::g(1)); params->put((req.jsonRpc ? "message" : "faultString"), std::string(e.what())); return params; } RpcResponse RpcMethod::execute (const RpcRequest& req, DownloadEngine* e) { try { return RpcResponse(0, process(req, e), req.id); } catch(RecoverableException& ex) { A2_LOG_DEBUG_EX(EX_EXCEPTION_CAUGHT, ex); return RpcResponse(1, createErrorResponse(ex, req), req.id); } } namespace { template void gatherOption (InputIterator first, InputIterator last, const std::set& allowedOptions, const SharedHandle