/** execute an rpc command and store the results in a string. */ void executerpc ( rpc::context& context, std::string& output, yieldstrategy const& strategy) { boost::optional <handler const&> handler; if (auto error = fillhandler (context, handler)) { auto wo = stringwriterobject (output); auto&& sub = addobject (*wo, jss::result); inject_error (error, sub); } else if (auto method = handler->objectmethod_) { auto wo = stringwriterobject (output); getresult (context, method, *wo, handler->name_); } else if (auto method = handler->valuemethod_) { auto object = json::value (json::objectvalue); getresult (context, method, object, handler->name_); if (strategy.streaming == yieldstrategy::streaming::yes) output = jsonasstring (object); else output = to_string (object); } else { // can't ever get here. assert (false); throw rpc::jsonexception ("rpc handler with no method"); } }
Status doCommand ( RPC::Context& context, Json::Value& result) { Handler const * handler = nullptr; if (auto error = fillHandler (context, handler)) { inject_error (error, result); return error; } if (auto method = handler->valueMethod_) { if (! context.headers.user.empty() || ! context.headers.forwardedFor.empty()) { JLOG(context.j.debug()) << "start command: " << handler->name_ << ", X-User: "******", X-Forwarded-For: " << context.headers.forwardedFor; auto ret = callMethod (context, method, handler->name_, result); JLOG(context.j.debug()) << "finish command: " << handler->name_ << ", X-User: "******", X-Forwarded-For: " << context.headers.forwardedFor; return ret; } else { return callMethod (context, method, handler->name_, result); } } return rpcUNKNOWN_COMMAND; }
status docommand ( rpc::context& context, json::value& result, yieldstrategy const&) { boost::optional <handler const&> handler; if (auto error = fillhandler (context, handler)) { inject_error (error, result); return error; } if (auto method = handler->valuemethod_) return callmethod (context, method, handler->name_, result); return rpcunknown_command; }
Json::Value make_error (error_code_i code, std::string const& message) { Json::Value json; inject_error (code, message, json); return json; }
Json::Value make_error (error_code_i code) { Json::Value json; inject_error (code, json); return json; }