mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Regularize RPC handling.
This commit is contained in:
@@ -317,9 +317,6 @@ Json::Value RPCHandler::doAccountInfo(Json::Value params)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Json::Value RPCHandler::doConnect(Json::Value params)
|
Json::Value RPCHandler::doConnect(Json::Value params)
|
||||||
{
|
{
|
||||||
if (theConfig.RUN_STANDALONE)
|
if (theConfig.RUN_STANDALONE)
|
||||||
@@ -458,7 +455,6 @@ Json::Value RPCHandler::doOwnerInfo(Json::Value params)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Json::Value RPCHandler::doPeers(Json::Value params)
|
Json::Value RPCHandler::doPeers(Json::Value params)
|
||||||
{
|
{
|
||||||
Json::Value obj(Json::objectValue);
|
Json::Value obj(Json::objectValue);
|
||||||
@@ -2140,14 +2136,31 @@ Json::Value RPCHandler::doUnsubscribe(Json::Value jvRequest)
|
|||||||
return jvResult;
|
return jvResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& params, int role)
|
Json::Value RPCHandler::doRpcCommand(const std::string& strCommand, Json::Value& jvParams, int iRole)
|
||||||
{
|
{
|
||||||
cLog(lsTRACE) << "RPC:" << command;
|
if (!jvParams.isArray() || jvParams.size() > 1)
|
||||||
cLog(lsTRACE) << "RPC params:" << params;
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
|
Json::Value jvRequest = jvParams[0u];
|
||||||
|
|
||||||
|
jvRequest["command"] = strCommand;
|
||||||
|
|
||||||
|
return doCommand(jvRequest, iRole);
|
||||||
|
}
|
||||||
|
|
||||||
|
Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole)
|
||||||
|
{
|
||||||
|
if (!jvParams.isMember("command"))
|
||||||
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
|
std::string strCommand = jvParams["command"].asString();
|
||||||
|
|
||||||
|
cLog(lsTRACE) << "COMMAND:" << strCommand;
|
||||||
|
cLog(lsTRACE) << "REQUEST:" << jvParams;
|
||||||
|
|
||||||
LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC));
|
LoadEvent::autoptr le(theApp->getJobQueue().getLoadEventAP(jtRPC));
|
||||||
|
|
||||||
mRole = role;
|
mRole = iRole;
|
||||||
|
|
||||||
static struct {
|
static struct {
|
||||||
const char* pCommand;
|
const char* pCommand;
|
||||||
@@ -2213,7 +2226,7 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param
|
|||||||
|
|
||||||
int i = NUMBER(commandsA);
|
int i = NUMBER(commandsA);
|
||||||
|
|
||||||
while (i-- && command != commandsA[i].pCommand)
|
while (i-- && strCommand != commandsA[i].pCommand)
|
||||||
;
|
;
|
||||||
|
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
@@ -2230,11 +2243,12 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param
|
|||||||
}
|
}
|
||||||
else if (commandsA[i].iMinParams >= 0
|
else if (commandsA[i].iMinParams >= 0
|
||||||
? commandsA[i].iMaxParams
|
? commandsA[i].iMaxParams
|
||||||
? (params.size() < commandsA[i].iMinParams
|
? (jvParams.size() < commandsA[i].iMinParams
|
||||||
|| (commandsA[i].iMaxParams >= 0 && params.size() > commandsA[i].iMaxParams))
|
|| (commandsA[i].iMaxParams >= 0 && jvParams.size() > commandsA[i].iMaxParams))
|
||||||
: false
|
: false
|
||||||
: params.isArray())
|
: jvParams.isArray())
|
||||||
{
|
{
|
||||||
|
cLog(lsDEBUG) << "params.size: " << jvParams.size() << " array: " << jvParams.isArray();
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
}
|
}
|
||||||
else if ((commandsA[i].iOptions & optNetwork) && !mNetOps->available())
|
else if ((commandsA[i].iOptions & optNetwork) && !mNetOps->available())
|
||||||
@@ -2255,7 +2269,7 @@ Json::Value RPCHandler::doCommand(const std::string& command, Json::Value& param
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return (this->*(commandsA[i].dfpFunc))(params);
|
return (this->*(commandsA[i].dfpFunc))(jvParams);
|
||||||
}
|
}
|
||||||
catch (std::exception& e)
|
catch (std::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -106,7 +106,8 @@ public:
|
|||||||
RPCHandler(NetworkOPs* netOps);
|
RPCHandler(NetworkOPs* netOps);
|
||||||
RPCHandler(NetworkOPs* netOps, InfoSub* infoSub);
|
RPCHandler(NetworkOPs* netOps, InfoSub* infoSub);
|
||||||
|
|
||||||
Json::Value doCommand(const std::string& command, Json::Value& params, int role);
|
Json::Value doCommand(Json::Value& jvRequest, int role);
|
||||||
|
Json::Value doRpcCommand(const std::string& strCommand, Json::Value& jvParams, int iRole);
|
||||||
|
|
||||||
Json::Value handleJSONSubmit(Json::Value jvRequest);
|
Json::Value handleJSONSubmit(Json::Value jvRequest);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ std::string RPCServer::handleRequest(const std::string& requestStr)
|
|||||||
RPCHandler mRPCHandler(mNetOps);
|
RPCHandler mRPCHandler(mNetOps);
|
||||||
|
|
||||||
cLog(lsTRACE) << valParams;
|
cLog(lsTRACE) << valParams;
|
||||||
Json::Value result = mRPCHandler.doCommand(strMethod, valParams, mRole);
|
Json::Value result = mRPCHandler.doRpcCommand(strMethod, valParams, mRole);
|
||||||
cLog(lsTRACE) << result;
|
cLog(lsTRACE) << result;
|
||||||
|
|
||||||
std::string strReply = JSONRPCReply(result, Json::Value(), id);
|
std::string strReply = JSONRPCReply(result, Json::Value(), id);
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
SETUP_LOG();
|
SETUP_LOG();
|
||||||
|
|
||||||
|
#include "CallRPC.h" // XXX Remove this, don't provide support for RPC syntax.
|
||||||
#include "WSConnection.h"
|
#include "WSConnection.h"
|
||||||
#include "WSHandler.h"
|
#include "WSHandler.h"
|
||||||
|
|
||||||
@@ -48,13 +49,28 @@ Json::Value WSConnection::invokeCommand(Json::Value& jvRequest)
|
|||||||
RPCHandler mRPCHandler(&mNetwork, this);
|
RPCHandler mRPCHandler(&mNetwork, this);
|
||||||
Json::Value jvResult(Json::objectValue);
|
Json::Value jvResult(Json::objectValue);
|
||||||
|
|
||||||
// Regular RPC command
|
// XXX Temporarily support RPC style commands over websocket. Remove this.
|
||||||
|
if (jvRequest.isMember("params"))
|
||||||
|
{
|
||||||
|
RPCParser rpParser;
|
||||||
|
|
||||||
|
Json::Value jvRpcRequest = rpParser.parseCommand(jvRequest["command"].asString(), jvRequest["params"]);
|
||||||
|
|
||||||
|
if (jvRpcRequest.isMember("error"))
|
||||||
|
{
|
||||||
|
jvResult = jvRpcRequest;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
jvResult["result"] = mRPCHandler.doCommand(
|
||||||
|
jvRpcRequest,
|
||||||
|
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
jvResult["result"] = mRPCHandler.doCommand(
|
jvResult["result"] = mRPCHandler.doCommand(
|
||||||
jvRequest["command"].asString(),
|
jvRequest,
|
||||||
jvRequest.isMember("params")
|
|
||||||
? jvRequest["params"]
|
|
||||||
: jvRequest,
|
|
||||||
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
|
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user