From ad1573472e3eff7378f9e28e0d267f919c368907 Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Thu, 29 Dec 2016 13:05:51 +0000 Subject: [PATCH] RPC: Pass on JSONRPCRequest metadata (URI/user/etc) for "help" method --- src/rpc/server.cpp | 11 +++++++---- src/rpc/server.h | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 0b763acd4..46f7d3590 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -178,7 +178,7 @@ vector ParseHexO(const UniValue& o, string strKey) * Note: This interface may still be subject to change. */ -std::string CRPCTable::help(const std::string& strCommand) const +std::string CRPCTable::help(const std::string& strCommand, const JSONRPCRequest& helpreq) const { string strRet; string category; @@ -189,6 +189,10 @@ std::string CRPCTable::help(const std::string& strCommand) const vCommands.push_back(make_pair(mi->second->category + mi->first, mi->second)); sort(vCommands.begin(), vCommands.end()); + JSONRPCRequest jreq(helpreq); + jreq.fHelp = true; + jreq.params = UniValue(); + BOOST_FOREACH(const PAIRTYPE(string, const CRPCCommand*)& command, vCommands) { const CRPCCommand *pcmd = command.second; @@ -198,10 +202,9 @@ std::string CRPCTable::help(const std::string& strCommand) const continue; if ((strCommand != "" || pcmd->category == "hidden") && strMethod != strCommand) continue; + jreq.strMethod = strMethod; try { - JSONRPCRequest jreq; - jreq.fHelp = true; rpcfn_type pfn = pcmd->actor; if (setDone.insert(pfn).second) (*pfn)(jreq); @@ -250,7 +253,7 @@ UniValue help(const JSONRPCRequest& jsonRequest) if (jsonRequest.params.size() > 0) strCommand = jsonRequest.params[0].get_str(); - return tableRPC.help(strCommand); + return tableRPC.help(strCommand, jsonRequest); } diff --git a/src/rpc/server.h b/src/rpc/server.h index 72ffc7652..0850f68f1 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -154,7 +154,7 @@ private: public: CRPCTable(); const CRPCCommand* operator[](const std::string& name) const; - std::string help(const std::string& name) const; + std::string help(const std::string& name, const JSONRPCRequest& helpreq) const; /** * Execute a method.