Changeset View
Changeset View
Standalone View
Standalone View
src/httprpc.cpp
Show All 12 Lines | |||||
#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.h" | #include "util.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include "utilstrencodings.h" | #include "utilstrencodings.h" | ||||
#include <cstdio> | |||||
#include <boost/algorithm/string.hpp> // boost::trim | #include <boost/algorithm/string.hpp> // boost::trim | ||||
#include <cstdio> | |||||
/** 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\""; | ||||
/** Simple one-shot callback timer to be used by the RPC mechanism to e.g. | /** Simple one-shot callback timer to be used by the RPC mechanism to e.g. | ||||
* re-lock the wallet. | * re-lock the wallet. | ||||
*/ | */ | ||||
class HTTPRPCTimer : public RPCTimerBase { | class HTTPRPCTimer : public RPCTimerBase { | ||||
public: | public: | ||||
HTTPRPCTimer(struct event_base *eventBase, std::function<void(void)> &func, | HTTPRPCTimer(struct event_base *eventBase, std::function<void(void)> &func, | ||||
int64_t millis) | int64_t millis) | ||||
: ev(eventBase, false, func) { | : ev(eventBase, false, func) { | ||||
struct timeval tv; | struct timeval tv; | ||||
tv.tv_sec = millis / 1000; | tv.tv_sec = millis / 1000; | ||||
tv.tv_usec = (millis % 1000) * 1000; | tv.tv_usec = (millis % 1000) * 1000; | ||||
ev.trigger(&tv); | ev.trigger(&tv); | ||||
} | } | ||||
private: | private: | ||||
HTTPEvent ev; | HTTPEvent ev; | ||||
}; | }; | ||||
class HTTPRPCTimerInterface : public RPCTimerInterface { | class HTTPRPCTimerInterface : public RPCTimerInterface { | ||||
public: | public: | ||||
HTTPRPCTimerInterface(struct event_base *_base) : base(_base) {} | HTTPRPCTimerInterface(struct event_base *_base) : base(_base) {} | ||||
const char *Name() { return "HTTP"; } | const char *Name() override { return "HTTP"; } | ||||
RPCTimerBase *NewTimer(std::function<void(void)> &func, int64_t millis) { | RPCTimerBase *NewTimer(std::function<void(void)> &func, | ||||
int64_t millis) override { | |||||
return new HTTPRPCTimer(base, func, millis); | return new HTTPRPCTimer(base, func, millis); | ||||
} | } | ||||
private: | private: | ||||
struct event_base *base; | struct event_base *base; | ||||
}; | }; | ||||
/* Pre-base64-encoded authentication token */ | /* Pre-base64-encoded authentication token */ | ||||
▲ Show 20 Lines • Show All 209 Lines • Show Last 20 Lines |