From f27a9f38bb5de90a4d4ce240a8322c1e937820b8 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 9 Apr 2015 19:44:54 +0200 Subject: better solution for MHD_create_response_from_buffer --- src/webserver.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/webserver.c b/src/webserver.c index 4c6fedf..81ec523 100644 --- a/src/webserver.c +++ b/src/webserver.c @@ -14,16 +14,23 @@ static struct MHD_Daemon *d; +#if MHD_VERSION < 0x00090500 +enum MHD_ResponseMemoryMode { + MHD_RESPMEM_PERSISTENT, + MHD_RESPMEM_MUST_FREE, + MHD_RESPMEM_MUST_COPY +}; + +#define MHD_create_response_from_buffer wrap_response + static struct MHD_Response *wrap_response( size_t size, void *buffer, enum MHD_ResponseMemoryMode mode) { -#if MHD_VERSION >= 0x00090500 - return MHD_create_response_from_buffer( size, buffer, mode ); -#else return MHD_create_response_from_data( size, buffer, ( mode | MHD_RESPMEM_MUST_FREE ) == MHD_RESPMEM_MUST_FREE, ( mode | MHD_RESPMEM_MUST_COPY ) == MHD_RESPMEM_MUST_COPY ); -#endif } + +#endif static int handle_request( void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, @@ -96,7 +103,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, snprintf( biruda_msg, sizeof( biruda_msg ), "Welcome to biruda! Please state your wish..\n" ); } - response = wrap_response( strlen( biruda_msg ), + response = MHD_create_response_from_buffer( strlen( biruda_msg ), (void *)biruda_msg, MHD_RESPMEM_MUST_COPY ); ret = MHD_queue_response( connection, MHD_HTTP_OK, response ); MHD_destroy_response( response ); @@ -132,7 +139,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, snprintf( biruda_msg, sizeof( biruda_msg ), "Queued start worker request\n" ); } - response = wrap_response( strlen( biruda_msg ), + response = MHD_create_response_from_buffer( strlen( biruda_msg ), (void *)biruda_msg, MHD_RESPMEM_MUST_COPY ); ret = MHD_queue_response( connection, ( res == 0 ) ? MHD_HTTP_OK : MHD_HTTP_INTERNAL_SERVER_ERROR, response ); MHD_destroy_response( response ); @@ -153,7 +160,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, snprintf( biruda_msg, sizeof( biruda_msg ), "Queued stop worker request\n" ); } - response = wrap_response( strlen( biruda_msg ), + response = MHD_create_response_from_buffer( strlen( biruda_msg ), (void *)biruda_msg, MHD_RESPMEM_MUST_COPY ); ret = MHD_queue_response( connection, ( res == 0 ) ? MHD_HTTP_OK : MHD_HTTP_INTERNAL_SERVER_ERROR, response ); MHD_destroy_response( response ); -- cgit v1.2.3-54-g00ecf