Skip to content

Commit b82e5eb

Browse files
committed
Make possible to compile against old and new libmicrohttpd.
The return codes of current libmicrohttpd changed from int to MHD_Result at some point. Make it possible to be able to compile against the old and the new version of libmicrohttpd. Signed-off-by: Henner Zeller <[email protected]>
1 parent 1aa1564 commit b82e5eb

File tree

4 files changed

+30
-13
lines changed

4 files changed

+30
-13
lines changed

src/jsonrpccpp/server/connectors/httpserver.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ void HttpServer::SetUrlHandler(const string &url,
153153
this->SetHandler(NULL);
154154
}
155155

156-
int HttpServer::callback(void *cls, MHD_Connection *connection, const char *url,
157-
const char *method, const char *version,
158-
const char *upload_data, size_t *upload_data_size,
159-
void **con_cls) {
156+
HttpServer::MicroHttpdResult HttpServer::callback(
157+
void *cls, MHD_Connection *connection, const char *url,
158+
const char *method, const char *version,
159+
const char *upload_data, size_t *upload_data_size,
160+
void **con_cls) {
160161
(void)version;
161162
if (*con_cls == NULL) {
162163
struct mhd_coninfo *client_connection = new mhd_coninfo;

src/jsonrpccpp/server/connectors/httpserver.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class HttpServer : public AbstractServerConnector {
6666
void SetUrlHandler(const std::string &url, IClientConnectionHandler *handler);
6767

6868
private:
69+
#if MHD_VERSION >= 0x00097101
70+
typedef MHD_Result MicroHttpdResult;
71+
#else
72+
typedef int MicroHttpdResult;
73+
#endif
74+
6975
int port;
7076
int threads;
7177
bool running;
@@ -79,10 +85,12 @@ class HttpServer : public AbstractServerConnector {
7985
std::map<std::string, IClientConnectionHandler *> urlhandler;
8086
struct sockaddr_in loopback_addr;
8187

82-
static int callback(void *cls, struct MHD_Connection *connection,
83-
const char *url, const char *method, const char *version,
84-
const char *upload_data, size_t *upload_data_size,
85-
void **con_cls);
88+
static MicroHttpdResult callback(void *cls, struct MHD_Connection *connection,
89+
const char *url, const char *method,
90+
const char *version,
91+
const char *upload_data,
92+
size_t *upload_data_size,
93+
void **con_cls);
8694

8795
IClientConnectionHandler *GetHandler(const std::string &url);
8896
};

src/test/testhttpserver.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ std::string TestHttpServer::GetHeader(const std::string &key) {
4141
return "";
4242
}
4343

44-
int TestHttpServer::callback(void *cls, MHD_Connection *connection,
44+
TestHttpServer::MicroHttpdResult TestHttpServer::callback(
45+
void *cls, MHD_Connection *connection,
4546
const char *url, const char *method,
4647
const char *version, const char *upload_data,
4748
size_t *upload_data_size, void **con_cls) {
@@ -69,8 +70,9 @@ int TestHttpServer::callback(void *cls, MHD_Connection *connection,
6970
return MHD_YES;
7071
}
7172

72-
int TestHttpServer::header_iterator(void *cls, MHD_ValueKind kind,
73-
const char *key, const char *value) {
73+
TestHttpServer::MicroHttpdResult TestHttpServer::header_iterator(
74+
void *cls, MHD_ValueKind kind,
75+
const char *key, const char *value) {
7476
(void)kind;
7577
TestHttpServer *_this = static_cast<TestHttpServer *>(cls);
7678
_this->headers[key] = value;

src/test/testhttpserver.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ namespace jsonrpc {
3131
std::string GetHeader(const std::string &key);
3232

3333
private:
34+
#if MHD_VERSION >= 0x00097101
35+
typedef MHD_Result MicroHttpdResult;
36+
#else
37+
typedef int MicroHttpdResult;
38+
#endif
39+
3440
int port;
3541
MHD_Daemon* daemon;
3642
std::map<std::string,std::string> headers;
3743
std::string response;
3844

39-
static int callback(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls);
45+
static MicroHttpdResult callback(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls);
4046

41-
static int header_iterator (void *cls, enum MHD_ValueKind kind, const char *key, const char *value);
47+
static MicroHttpdResult header_iterator (void *cls, enum MHD_ValueKind kind, const char *key, const char *value);
4248
};
4349

4450
} // namespace jsonrpc

0 commit comments

Comments
 (0)