mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 06:25:51 +00:00
Support paths for subscribe via json-rpc.
This commit is contained in:
@@ -537,6 +537,7 @@ int commandLineRPC(const std::vector<std::string>& vCmd)
|
|||||||
theConfig.RPC_PORT,
|
theConfig.RPC_PORT,
|
||||||
theConfig.RPC_USER,
|
theConfig.RPC_USER,
|
||||||
theConfig.RPC_PASSWORD,
|
theConfig.RPC_PASSWORD,
|
||||||
|
"",
|
||||||
jvRequest.isMember("method") // Allow parser to rewrite method.
|
jvRequest.isMember("method") // Allow parser to rewrite method.
|
||||||
? jvRequest["method"].asString()
|
? jvRequest["method"].asString()
|
||||||
: vCmd[0],
|
: vCmd[0],
|
||||||
@@ -597,7 +598,7 @@ int commandLineRPC(const std::vector<std::string>& vCmd)
|
|||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
Json::Value callRPC(const std::string& strIp, const int iPort, const std::string& strUsername, const std::string& strPassword, const std::string& strMethod, const Json::Value& params)
|
Json::Value callRPC(const std::string& strIp, const int iPort, const std::string& strUsername, const std::string& strPassword, const std::string& strPath, const std::string& strMethod, const Json::Value& params)
|
||||||
{
|
{
|
||||||
// Connect to localhost
|
// Connect to localhost
|
||||||
if (!theConfig.QUIET)
|
if (!theConfig.QUIET)
|
||||||
@@ -618,7 +619,7 @@ Json::Value callRPC(const std::string& strIp, const int iPort, const std::string
|
|||||||
// Send request
|
// Send request
|
||||||
std::string strRequest = JSONRPCRequest(strMethod, params, Json::Value(1));
|
std::string strRequest = JSONRPCRequest(strMethod, params, Json::Value(1));
|
||||||
cLog(lsDEBUG) << "send request " << strMethod << " : " << strRequest << std::endl;
|
cLog(lsDEBUG) << "send request " << strMethod << " : " << strRequest << std::endl;
|
||||||
std::string strPost = createHTTPPost(strRequest, mapRequestHeaders);
|
std::string strPost = createHTTPPost(strPath, strRequest, mapRequestHeaders);
|
||||||
stream << strPost << std::flush;
|
stream << strPost << std::flush;
|
||||||
|
|
||||||
// std::cerr << "post " << strPost << std::endl;
|
// std::cerr << "post " << strPost << std::endl;
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern int commandLineRPC(const std::vector<std::string>& vCmd);
|
extern int commandLineRPC(const std::vector<std::string>& vCmd);
|
||||||
extern Json::Value callRPC(const std::string& strIp, const int iPort, const std::string& strUsername, const std::string& strPassword, const std::string& strMethod, const Json::Value& params);
|
extern Json::Value callRPC(const std::string& strIp, const int iPort, const std::string& strUsername, const std::string& strPassword, const std::string& strPath, const std::string& strMethod, const Json::Value& params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ enum http_status_type
|
|||||||
extern std::string JSONRPCRequest(const std::string& strMethod, const Json::Value& params,
|
extern std::string JSONRPCRequest(const std::string& strMethod, const Json::Value& params,
|
||||||
const Json::Value& id);
|
const Json::Value& id);
|
||||||
|
|
||||||
extern std::string createHTTPPost(const std::string& strMsg,
|
extern std::string createHTTPPost(const std::string& strPath, const std::string& strMsg,
|
||||||
const std::map<std::string, std::string>& mapRequestHeaders);
|
const std::map<std::string, std::string>& mapRequestHeaders);
|
||||||
|
|
||||||
extern int ReadHTTP(std::basic_istream<char>& stream,
|
extern int ReadHTTP(std::basic_istream<char>& stream,
|
||||||
|
|||||||
@@ -10,9 +10,8 @@ RPCSub::RPCSub(const std::string& strUrl, const std::string& strUsername, const
|
|||||||
: mUrl(strUrl), mUsername(strUsername), mPassword(strPassword)
|
: mUrl(strUrl), mUsername(strUsername), mPassword(strPassword)
|
||||||
{
|
{
|
||||||
std::string strScheme;
|
std::string strScheme;
|
||||||
std::string strPath;
|
|
||||||
|
|
||||||
if (!parseUrl(strUrl, strScheme, mIp, mPort, strPath))
|
if (!parseUrl(strUrl, strScheme, mIp, mPort, mPath))
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to parse url.");
|
throw std::runtime_error("Failed to parse url.");
|
||||||
}
|
}
|
||||||
@@ -20,11 +19,6 @@ RPCSub::RPCSub(const std::string& strUrl, const std::string& strUsername, const
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Only http is supported.");
|
throw std::runtime_error("Only http is supported.");
|
||||||
}
|
}
|
||||||
else if (!strPath.empty())
|
|
||||||
{
|
|
||||||
// XXX FIXME: support path
|
|
||||||
throw std::runtime_error("Only empty path is supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
mSeq = 1;
|
mSeq = 1;
|
||||||
}
|
}
|
||||||
@@ -64,7 +58,7 @@ void RPCSub::sendThread()
|
|||||||
// Drop result.
|
// Drop result.
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
(void) callRPC(mIp, mPort, mUsername, mPassword, "event", jvEvent);
|
(void) callRPC(mIp, mPort, mUsername, mPassword, mPath, "event", jvEvent);
|
||||||
}
|
}
|
||||||
catch (const std::exception& e)
|
catch (const std::exception& e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ class RPCSub : public InfoSub
|
|||||||
int mPort;
|
int mPort;
|
||||||
std::string mUsername;
|
std::string mUsername;
|
||||||
std::string mPassword;
|
std::string mPassword;
|
||||||
|
std::string mPath;
|
||||||
|
|
||||||
int mSeq; // Next id to allocate.
|
int mSeq; // Next id to allocate.
|
||||||
|
|
||||||
|
|||||||
@@ -39,11 +39,13 @@ Json::Value JSONRPCError(int code, const std::string& message)
|
|||||||
// and to be compatible with other JSON-RPC implementations.
|
// and to be compatible with other JSON-RPC implementations.
|
||||||
//
|
//
|
||||||
|
|
||||||
std::string createHTTPPost(const std::string& strMsg, const std::map<std::string, std::string>& mapRequestHeaders)
|
std::string createHTTPPost(const std::string& strPath, const std::string& strMsg, const std::map<std::string, std::string>& mapRequestHeaders)
|
||||||
{
|
{
|
||||||
std::ostringstream s;
|
std::ostringstream s;
|
||||||
|
|
||||||
s << "POST / HTTP/1.1\r\n"
|
s << "POST "
|
||||||
|
<< (strPath.empty() ? "/" : strPath)
|
||||||
|
<< " HTTP/1.1\r\n"
|
||||||
<< "User-Agent: " SYSTEM_NAME "-json-rpc/" << FormatFullVersion() << "\r\n"
|
<< "User-Agent: " SYSTEM_NAME "-json-rpc/" << FormatFullVersion() << "\r\n"
|
||||||
<< "Host: 127.0.0.1\r\n"
|
<< "Host: 127.0.0.1\r\n"
|
||||||
<< "Content-Type: application/json\r\n"
|
<< "Content-Type: application/json\r\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user