mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-24 04:55:52 +00:00
Fixes. Template code must go in header files.
This commit is contained in:
@@ -1,10 +1,14 @@
|
|||||||
|
|
||||||
#include "../websocketpp/src/sockets/tls.hpp"
|
#include "../websocketpp/src/sockets/tls.hpp"
|
||||||
#include "../websocketpp/src/websocketpp.hpp"
|
#include "../websocketpp/src/websocketpp.hpp"
|
||||||
|
|
||||||
|
#include "../json/value.h"
|
||||||
|
|
||||||
#include "WSDoor.h"
|
#include "WSDoor.h"
|
||||||
#include "Application.h"
|
#include "Application.h"
|
||||||
|
|
||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "NetworkOPs.h"
|
#include "NetworkOPs.h"
|
||||||
|
#include "CallRPC.h"
|
||||||
|
|
||||||
template <typename endpoint_type>
|
template <typename endpoint_type>
|
||||||
class WSServerHandler;
|
class WSServerHandler;
|
||||||
@@ -22,7 +26,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
typedef void (WSConnection::*doFuncPtr)(Json::Value& jvResult, Json::Value &jvRequest);
|
typedef void (WSConnection::*doFuncPtr)(Json::Value& jvResult, Json::Value &jvRequest);
|
||||||
|
|
||||||
WSServerHandler<endpoint_type>* mHandler;
|
WSServerHandler<endpoint_type>* mHandler;
|
||||||
connection_ptr mConnection;
|
connection_ptr mConnection;
|
||||||
NetworkOPs& mNetwork;
|
NetworkOPs& mNetwork;
|
||||||
|
|
||||||
@@ -46,12 +50,78 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Implement overridden functions from base class:
|
// Implement overridden functions from base class:
|
||||||
template <typename endpoint_type>
|
void send(const Json::Value& jvObj)
|
||||||
void send(const Json::Value& jvObj);
|
{
|
||||||
|
mHandler->send(mConnection, jvObj);
|
||||||
|
}
|
||||||
|
|
||||||
// Utilities
|
// Utilities
|
||||||
template <typename endpoint_type>
|
Json::Value invokeCommand(Json::Value& jvRequest)
|
||||||
Json::Value invokeCommand(Json::Value& jvRequest);
|
{
|
||||||
|
if (!jvRequest.isMember("command"))
|
||||||
|
{
|
||||||
|
Json::Value jvResult(Json::objectValue);
|
||||||
|
|
||||||
|
jvResult["type"] = "response";
|
||||||
|
jvResult["result"] = "error";
|
||||||
|
jvResult["error"] = "missingCommand";
|
||||||
|
jvResult["command"] = jvRequest;
|
||||||
|
|
||||||
|
return jvResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
RPCHandler mRPCHandler(&mNetwork, this);
|
||||||
|
Json::Value jvResult(Json::objectValue);
|
||||||
|
|
||||||
|
// 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(
|
||||||
|
jvRequest,
|
||||||
|
mHandler->getPublic() ? RPCHandler::GUEST : RPCHandler::ADMIN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Currently we will simply unwrap errors returned by the RPC
|
||||||
|
// API, in the future maybe we can make the responses
|
||||||
|
// consistent.
|
||||||
|
//
|
||||||
|
// Regularize result. This is duplicate code.
|
||||||
|
if (jvResult["result"].isMember("error"))
|
||||||
|
{
|
||||||
|
jvResult = jvResult["result"];
|
||||||
|
jvResult["status"] = "error";
|
||||||
|
jvResult["request"] = jvRequest;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
jvResult["status"] = "success";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (jvRequest.isMember("id"))
|
||||||
|
{
|
||||||
|
jvResult["id"] = jvRequest["id"];
|
||||||
|
}
|
||||||
|
|
||||||
|
jvResult["type"] = "response";
|
||||||
|
|
||||||
|
return jvResult;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user