refactor: account for requiring libevent 2.1.8+

This commit is contained in:
fanquake 2022-03-30 10:56:48 +01:00 committed by Hennadii Stepanov
parent aaf72d62c1
commit 0598f36852
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
3 changed files with 3 additions and 27 deletions

View File

@ -184,7 +184,6 @@ struct HTTPReply
static std::string http_errorstring(int code) static std::string http_errorstring(int code)
{ {
switch(code) { switch(code) {
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
case EVREQ_HTTP_TIMEOUT: case EVREQ_HTTP_TIMEOUT:
return "timeout reached"; return "timeout reached";
case EVREQ_HTTP_EOF: case EVREQ_HTTP_EOF:
@ -197,7 +196,6 @@ static std::string http_errorstring(int code)
return "request was canceled"; return "request was canceled";
case EVREQ_HTTP_DATA_TOO_LONG: case EVREQ_HTTP_DATA_TOO_LONG:
return "response body is larger than allowed"; return "response body is larger than allowed";
#endif
default: default:
return "unknown"; return "unknown";
} }
@ -228,13 +226,11 @@ static void http_request_done(struct evhttp_request *req, void *ctx)
} }
} }
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
static void http_error_cb(enum evhttp_request_error err, void *ctx) static void http_error_cb(enum evhttp_request_error err, void *ctx)
{ {
HTTPReply *reply = static_cast<HTTPReply*>(ctx); HTTPReply *reply = static_cast<HTTPReply*>(ctx);
reply->error = err; reply->error = err;
} }
#endif
/** Class that handles the conversion from a command-line to a JSON-RPC request, /** Class that handles the conversion from a command-line to a JSON-RPC request,
* as well as converting back to a JSON object that can be shown as result. * as well as converting back to a JSON object that can be shown as result.
@ -745,11 +741,11 @@ static UniValue CallRPC(BaseRequestHandler* rh, const std::string& strMethod, co
HTTPReply response; HTTPReply response;
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response); raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);
if (req == nullptr) if (req == nullptr) {
throw std::runtime_error("create http request failed"); throw std::runtime_error("create http request failed");
#if LIBEVENT_VERSION_NUMBER >= 0x02010300 }
evhttp_request_set_error_cb(req.get(), http_error_cb); evhttp_request_set_error_cb(req.get(), http_error_cb);
#endif
// Get credentials // Get credentials
std::string strRPCUserColonPass; std::string strRPCUserColonPass;

View File

@ -403,17 +403,12 @@ bool InitHTTPServer()
} }
bool UpdateHTTPServerLogging(bool enable) { bool UpdateHTTPServerLogging(bool enable) {
#if LIBEVENT_VERSION_NUMBER >= 0x02010100
if (enable) { if (enable) {
event_enable_debug_logging(EVENT_DBG_ALL); event_enable_debug_logging(EVENT_DBG_ALL);
} else { } else {
event_enable_debug_logging(EVENT_DBG_NONE); event_enable_debug_logging(EVENT_DBG_NONE);
} }
return true; return true;
#else
// Can't update libevent logging if version < 02010100
return false;
#endif
} }
static std::thread g_thread_http; static std::thread g_thread_http;

View File

@ -19,23 +19,8 @@
#include <string> #include <string>
#include <vector> #include <vector>
// workaround for libevent versions before 2.1.1,
// when internal functions didn't have underscores at the end
#if LIBEVENT_VERSION_NUMBER < 0x02010100
extern "C" int evhttp_parse_firstline(struct evhttp_request*, struct evbuffer*);
extern "C" int evhttp_parse_headers(struct evhttp_request*, struct evbuffer*);
inline int evhttp_parse_firstline_(struct evhttp_request* r, struct evbuffer* b)
{
return evhttp_parse_firstline(r, b);
}
inline int evhttp_parse_headers_(struct evhttp_request* r, struct evbuffer* b)
{
return evhttp_parse_headers(r, b);
}
#else
extern "C" int evhttp_parse_firstline_(struct evhttp_request*, struct evbuffer*); extern "C" int evhttp_parse_firstline_(struct evhttp_request*, struct evbuffer*);
extern "C" int evhttp_parse_headers_(struct evhttp_request*, struct evbuffer*); extern "C" int evhttp_parse_headers_(struct evhttp_request*, struct evbuffer*);
#endif
std::string RequestMethodString(HTTPRequest::RequestMethod m); std::string RequestMethodString(HTTPRequest::RequestMethod m);