libmicrohttpd

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

commit 10bdf39505cf525b95886c140b3c2e82e7427d29
parent 3fc686e335437ec5f6d6270c8d713e9a01da966f
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  8 Nov 2018 14:53:19 +0100

add MHD_create_response_from_buffer_with_free_callback

Diffstat:
Mdoc/libmicrohttpd.texi | 18++++++++++++++++++
Msrc/include/microhttpd.h | 18++++++++++++++++++
Msrc/microhttpd/response.c | 28++++++++++++++++++++++++++++
3 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/doc/libmicrohttpd.texi b/doc/libmicrohttpd.texi @@ -2020,6 +2020,24 @@ Return @code{NULL} on error (i.e. invalid arguments, out of memory). @end deftypefun +@deftypefun {struct MHD_Response *} MHD_create_response_from_buffer_with_free_callback (size_t size, void *data, MHD_ContentReaderFreeCallback crfc) +Create a response object. The buffer at the end must be free'd +by calling the @var{crfc} function. + +@table @var +@item size +size of the data portion of the response; + +@item buffer +the data itself; + +@item crfc +function to call at the end to free memory allocated at @var{buffer}. +@end table + +Return @code{NULL} on error (i.e. invalid arguments, out of memory). +@end deftypefun + @deftypefun {struct MHD_Response *} MHD_create_response_from_data (size_t size, void *data, int must_free, int must_copy) Create a response object. The response object can be extended with header information and then it can be used any number of times. diff --git a/src/include/microhttpd.h b/src/include/microhttpd.h @@ -2763,6 +2763,24 @@ MHD_create_response_from_buffer (size_t size, enum MHD_ResponseMemoryMode mode); + + +/** + * Create a response object. The response object can be extended with + * header information and then be used any number of times. + * + * @param size size of the data portion of the response + * @param buffer size bytes containing the response's data portion + * @param crfc function to call to free the @a buffer + * @return NULL on error (i.e. invalid arguments, out of memory) + * @ingroup response + */ +_MHD_EXTERN struct MHD_Response * +MHD_create_response_from_buffer_with_free_callback (size_t size, + void *buffer, + MHD_ContentReaderFreeCallback crfc); + + /** * Create a response object. The response object can be extended with * header information and then be used any number of times. diff --git a/src/microhttpd/response.c b/src/microhttpd/response.c @@ -701,6 +701,34 @@ MHD_create_response_from_buffer (size_t size, } +/** + * Create a response object. The response object can be extended with + * header information and then be used any number of times. + * + * @param size size of the data portion of the response + * @param buffer size bytes containing the response's data portion + * @param crfc function to call to free the @a buffer + * @return NULL on error (i.e. invalid arguments, out of memory) + * @ingroup response + */ +_MHD_EXTERN struct MHD_Response * +MHD_create_response_from_buffer_with_free_callback (size_t size, + void *buffer, + MHD_ContentReaderFreeCallback crfc) +{ + struct MHD_Response *r; + + r = MHD_create_response_from_data (size, + buffer, + GNUNET_YES, + GNUNET_NO); + if (NULL == r) + return r; + r->crfc = crfc; + return r; +} + + #ifdef UPGRADE_SUPPORT /** * This connection-specific callback is provided by MHD to