Changeset View
Changeset View
Standalone View
Standalone View
src/httprpc.cpp
Show All 10 Lines | |||||
#include <key_io.h> | #include <key_io.h> | ||||
#include <random.h> | #include <random.h> | ||||
#include <rpc/protocol.h> | #include <rpc/protocol.h> | ||||
#include <rpc/server.h> | #include <rpc/server.h> | ||||
#include <sync.h> | #include <sync.h> | ||||
#include <ui_interface.h> | #include <ui_interface.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <walletinitinterface.h> | |||||
#include <boost/algorithm/string.hpp> // boost::trim | #include <boost/algorithm/string.hpp> // boost::trim | ||||
#include <cstdio> | #include <cstdio> | ||||
#include <memory> | #include <memory> | ||||
/** WWW-Authenticate to present with 401 Unauthorized response */ | /** WWW-Authenticate to present with 401 Unauthorized response */ | ||||
static const char *WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\""; | static const char *WWW_AUTH_HEADER_DATA = "Basic realm=\"jsonrpc\""; | ||||
▲ Show 20 Lines • Show All 356 Lines • ▼ Show 20 Lines | if (!InitRPCAuthentication(config)) { | ||||
return false; | return false; | ||||
} | } | ||||
const std::function<bool(Config &, HTTPRequest *, const std::string &)> | const std::function<bool(Config &, HTTPRequest *, const std::string &)> | ||||
&rpcFunction = | &rpcFunction = | ||||
std::bind(&HTTPRPCRequestProcessor::DelegateHTTPRequest, | std::bind(&HTTPRPCRequestProcessor::DelegateHTTPRequest, | ||||
&httpRPCRequestProcessor, std::placeholders::_2); | &httpRPCRequestProcessor, std::placeholders::_2); | ||||
RegisterHTTPHandler("/", true, rpcFunction); | RegisterHTTPHandler("/", true, rpcFunction); | ||||
#ifdef ENABLE_WALLET | if (g_wallet_init_interface.HasWalletSupport()) { | ||||
// ifdef can be removed once we switch to better endpoint support and API | |||||
// versioning | |||||
RegisterHTTPHandler("/wallet/", false, rpcFunction); | RegisterHTTPHandler("/wallet/", false, rpcFunction); | ||||
#endif | } | ||||
struct event_base *eventBase = EventBase(); | struct event_base *eventBase = EventBase(); | ||||
assert(eventBase); | assert(eventBase); | ||||
httpRPCTimerInterface = std::make_unique<HTTPRPCTimerInterface>(eventBase); | httpRPCTimerInterface = std::make_unique<HTTPRPCTimerInterface>(eventBase); | ||||
RPCSetTimerInterface(httpRPCTimerInterface.get()); | RPCSetTimerInterface(httpRPCTimerInterface.get()); | ||||
return true; | return true; | ||||
} | } | ||||
void InterruptHTTPRPC() { | void InterruptHTTPRPC() { | ||||
LogPrint(BCLog::RPC, "Interrupting HTTP RPC server\n"); | LogPrint(BCLog::RPC, "Interrupting HTTP RPC server\n"); | ||||
} | } | ||||
void StopHTTPRPC() { | void StopHTTPRPC() { | ||||
LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n"); | LogPrint(BCLog::RPC, "Stopping HTTP RPC server\n"); | ||||
UnregisterHTTPHandler("/", true); | UnregisterHTTPHandler("/", true); | ||||
#ifdef ENABLE_WALLET | if (g_wallet_init_interface.HasWalletSupport()) { | ||||
UnregisterHTTPHandler("/wallet/", false); | UnregisterHTTPHandler("/wallet/", false); | ||||
#endif | } | ||||
if (httpRPCTimerInterface) { | if (httpRPCTimerInterface) { | ||||
RPCUnsetTimerInterface(httpRPCTimerInterface.get()); | RPCUnsetTimerInterface(httpRPCTimerInterface.get()); | ||||
httpRPCTimerInterface.reset(); | httpRPCTimerInterface.reset(); | ||||
} | } | ||||
} | } |