Changeset View
Changeset View
Standalone View
Standalone View
src/httprpc.cpp
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | RPCTimerBase *NewTimer(std::function<void(void)> &func, | ||||
return new HTTPRPCTimer(base, func, millis); | return new HTTPRPCTimer(base, func, millis); | ||||
} | } | ||||
private: | private: | ||||
struct event_base *base; | struct event_base *base; | ||||
}; | }; | ||||
/* Stored RPC timer interface (for unregistration) */ | /* Stored RPC timer interface (for unregistration) */ | ||||
static HTTPRPCTimerInterface *httpRPCTimerInterface = nullptr; | static std::unique_ptr<HTTPRPCTimerInterface> httpRPCTimerInterface; | ||||
static void JSONErrorReply(HTTPRequest *req, const UniValue &objError, | static void JSONErrorReply(HTTPRequest *req, const UniValue &objError, | ||||
const UniValue &id) { | const UniValue &id) { | ||||
// Send error reply from json-rpc error object. | // Send error reply from json-rpc error object. | ||||
int nStatus = HTTP_INTERNAL_SERVER_ERROR; | int nStatus = HTTP_INTERNAL_SERVER_ERROR; | ||||
int code = find_value(objError, "code").get_int(); | int code = find_value(objError, "code").get_int(); | ||||
if (code == RPC_INVALID_REQUEST) | if (code == RPC_INVALID_REQUEST) | ||||
▲ Show 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | const std::function<bool(Config &, HTTPRequest *, const std::string &)> | ||||
&httpRPCRequestProcessor, std::placeholders::_2); | &httpRPCRequestProcessor, std::placeholders::_2); | ||||
RegisterHTTPHandler("/", true, rpcFunction); | RegisterHTTPHandler("/", true, rpcFunction); | ||||
#ifdef ENABLE_WALLET | #ifdef ENABLE_WALLET | ||||
// ifdef can be removed once we switch to better endpoint support and API | // ifdef can be removed once we switch to better endpoint support and API | ||||
// versioning | // versioning | ||||
RegisterHTTPHandler("/wallet/", false, rpcFunction); | RegisterHTTPHandler("/wallet/", false, rpcFunction); | ||||
#endif | #endif | ||||
assert(EventBase()); | assert(EventBase()); | ||||
httpRPCTimerInterface = new HTTPRPCTimerInterface(EventBase()); | httpRPCTimerInterface = std::unique_ptr<HTTPRPCTimerInterface>( | ||||
RPCSetTimerInterface(httpRPCTimerInterface); | new HTTPRPCTimerInterface(EventBase())); | ||||
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); | ||||
if (httpRPCTimerInterface) { | if (httpRPCTimerInterface) { | ||||
RPCUnsetTimerInterface(httpRPCTimerInterface); | RPCUnsetTimerInterface(httpRPCTimerInterface.get()); | ||||
delete httpRPCTimerInterface; | httpRPCTimerInterface.reset(); | ||||
httpRPCTimerInterface = nullptr; | |||||
} | } | ||||
} | } |