libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 3d1b941137f9d8379e6e67d5abd57be5ae6ebe1a
parent 3751044dc81a4b37de14b20dfc4cc7902fc36344
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon, 22 Jul 2019 11:49:42 +0200

introducte MHD_RO_FREE_FUNCTION as proposed by Nicolas Mora on the list

Diffstat:
MChangeLog | 5++++-
Mdoc/libmicrohttpd.texi | 8++++++++
Msrc/include/microhttpd.h | 39++++++++++++++++++++++++++++-----------
Msrc/microhttpd/response.c | 10+++++++++-
4 files changed, 49 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,3 +1,6 @@ +Mon 22 Jul 2019 11:49:03 AM CEST + Introduce MHD_RO_FREE_FUNCTION. -NM/CG + Tue Jul 16 19:56:14 CEST 2019 Add MHD_OPTION_HTTPS_CERT_CALLBACK2 to allow OCSP stapling and MHD_FEATURE_HTTPS_CERT_CALLBACK2 to check for. -TR @@ -102,7 +105,7 @@ Sun Apr 21 16:40:00 MSK 2019 Fri Apr 19 23:00:00 MSK 2019 Rewritten SHA-256 calculations from scratch to avoid changing LGPL version; - Added usage of GCC/Clang built-ins for bytes swap to significantly improve + Added usage of GCC/Clang built-ins for bytes swap to significantly improve speed of MD5 and SHA-256 calculation on platforms with known endianness. Added test for SHA-256 calculations. -EG diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi @@ -1219,6 +1219,14 @@ Response-specific options. Passed in the varargs portion of @item MHD_RO_END No more options / last option. This is used to terminate the VARARGs list. + +@item MHD_RO_FREE_FUNCTION +Use a custom function for freeing the memory passed when using +@code{MHD_create_response_from_buffer} with +@code{MHD_RESPMEM_MUST_FREE}. This replaces the use of libc's +@code{free()} function to release the memory with an implementation +provided by the application. The next argument must be of type +@code{MHD_FreeFunction}. @end table @end deftp diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -132,7 +132,7 @@ typedef intptr_t ssize_t; * Current version of the library. * 0x01093001 = 1.9.30-1. */ -#define MHD_VERSION 0x00096502 +#define MHD_VERSION 0x00096503 /** * MHD-internal return code for "YES". @@ -2678,7 +2678,7 @@ _MHD_EXTERN int MHD_set_connection_value (struct MHD_Connection *connection, enum MHD_ValueKind kind, const char *key, - const char *value); + const char *value); /** @@ -2708,11 +2708,11 @@ MHD_set_connection_value (struct MHD_Connection *connection, */ int MHD_set_connection_value_n (struct MHD_Connection *connection, - enum MHD_ValueKind kind, - const char *key, + enum MHD_ValueKind kind, + const char *key, size_t key_size, - const char *value, - size_t value_size); + const char *value, + size_t value_size); /** @@ -2806,7 +2806,7 @@ MHD_lookup_connection_value_n (struct MHD_Connection *connection, _MHD_EXTERN int MHD_queue_response (struct MHD_Connection *connection, unsigned int status_code, - struct MHD_Response *response); + struct MHD_Response *response); /** @@ -2895,14 +2895,31 @@ enum MHD_ResponseFlags */ enum MHD_ResponseOptions { - /** - * End of the list of options. - */ - MHD_RO_END = 0 + + /** + * End of the list of options. + */ + MHD_RO_END = 0, + + /** + * Set a specific free() function + * to free response buffer instead of libc void free(void * ptr) + */ + MHD_RO_FREE_FUNCTION = 1 + }; /** + * This typedef is defined to be able to pass a function pointer + * as a va_arg in #MHD_set_response_options() in combination + * with #MHD_RO_FREE_FUNCTION. + */ +typedef void +(*MHD_FreeFunction)(void *); + + +/** * Set special flags and options for a response. * * @param response the response to modify diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -400,7 +400,6 @@ MHD_create_response_from_callback (uint64_t size, return response; } - /** * Set special flags and options for a response. * @@ -425,6 +424,15 @@ MHD_set_response_options (struct MHD_Response *response, { switch (ro) { + case MHD_RO_FREE_FUNCTION: + va_start (ap, flags); + if (NULL != (response->crfc = va_arg (ap, MHD_free_ptr))) { + ret = MHD_YES; + } else { + ret = MHD_NO; + } + va_end (ap); + break; default: ret = MHD_NO; break;