From 28a64040520aa9e043306a9e8af0f615227f2eb0 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Thu, 9 Apr 2015 19:33:53 +0200 Subject: fixed for older libmicrohttpd response function --- src/webserver.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/webserver.c b/src/webserver.c index 611cc42..4c6fedf 100644 --- a/src/webserver.c +++ b/src/webserver.c @@ -14,6 +14,17 @@ static struct MHD_Daemon *d; +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 +} + static int handle_request( 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 **ptr ) @@ -85,7 +96,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 = MHD_create_response_from_buffer( strlen( biruda_msg ), + response = wrap_response( strlen( biruda_msg ), (void *)biruda_msg, MHD_RESPMEM_MUST_COPY ); ret = MHD_queue_response( connection, MHD_HTTP_OK, response ); MHD_destroy_response( response ); @@ -121,7 +132,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, snprintf( biruda_msg, sizeof( biruda_msg ), "Queued start worker request\n" ); } - response = MHD_create_response_from_buffer( strlen( biruda_msg ), + response = wrap_response( 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 ); @@ -142,7 +153,7 @@ static int handle_request( void *cls, struct MHD_Connection *connection, snprintf( biruda_msg, sizeof( biruda_msg ), "Queued stop worker request\n" ); } - response = MHD_create_response_from_buffer( strlen( biruda_msg ), + response = wrap_response( 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