commit 72942193bd154ecec8868ca9a15e1d7190588aad
parent 8ae91fad4c5a57337253a3c93fb4f31f9b78ac0f
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Mon, 20 Jul 2026 15:56:16 +0200
Added MHD_response_from_callback_2cls()
Diffstat:
3 files changed, 73 insertions(+), 22 deletions(-)
diff --git a/src/include/microhttpd2.h b/src/include/microhttpd2.h
@@ -6382,18 +6382,43 @@ typedef const struct MHD_DynamicContentCreatorAction *
* @param sc status code to return
* @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
* @param dyn_cont callback to use to obtain response data
- * @param dyn_cont_cls extra argument to @a crc
- * @param dyn_cont_fc callback to call to free @a dyn_cont_cls resources
- * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @param dyn_cont_cls extra argument to @p dyn_cont
+ * @param free_cb callback to call to free @p dyn_cont_cls resources,
+ * can be NULL
+ * @param free_cb_cls the parameter for @p free_cb
+ * @return new response object on success,
+ * NULL on failure (i.e. invalid arguments, out of memory)
* FIXME: Call free callback on error?
* @ingroup response
*/
MHD_EXTERN_ struct MHD_Response *
-MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
- uint_fast64_t size,
- MHD_DynamicContentCreator dyn_cont,
- void *dyn_cont_cls,
- MHD_FreeCallback dyn_cont_fc);
+MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc,
+ uint_fast64_t size,
+ MHD_DynamicContentCreator dyn_cont,
+ void *dyn_cont_cls,
+ MHD_FreeCallback free_cb,
+ void *free_cb_cls);
+
+
+/**
+ * Create a response. The response object can be extended with
+ * header information.
+ *
+ * @param sc status code to return
+ * @param s size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
+ * @param d callback to use to obtain response data
+ * @param dc extra argument to @p d, evaluated twice!
+ * @param f callback to call to free @p dc resources
+ * @return new response object on success,
+ * NULL on failure (i.e. invalid arguments, out of memory)
+ * FIXME: Call free callback on error?
+ * @warning The @p dc parameter is evaluated twice; avoid expressions
+ * with side effects. Alternatively, just call function
+ * #MHD_response_from_callback_2cls() directly.
+ * @ingroup response
+ */
+#define MHD_response_from_callback(sc, s, d, dc, f) \
+ MHD_response_from_callback_2cls((sc),(s),(d),(dc),(f),(dc))
/**
diff --git a/src/include/microhttpd2_main.h.in b/src/include/microhttpd2_main.h.in
@@ -1464,18 +1464,43 @@ typedef const struct MHD_DynamicContentCreatorAction *
* @param sc status code to return
* @param size size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
* @param dyn_cont callback to use to obtain response data
- * @param dyn_cont_cls extra argument to @a crc
- * @param dyn_cont_fc callback to call to free @a dyn_cont_cls resources
- * @return NULL on error (i.e. invalid arguments, out of memory)
+ * @param dyn_cont_cls extra argument to @p dyn_cont
+ * @param free_cb callback to call to free @p dyn_cont_cls resources,
+ * can be NULL
+ * @param free_cb_cls the parameter for @p free_cb
+ * @return new response object on success,
+ * NULL on failure (i.e. invalid arguments, out of memory)
* FIXME: Call free callback on error?
* @ingroup response
*/
MHD_EXTERN_ struct MHD_Response *
-MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
- uint_fast64_t size,
- MHD_DynamicContentCreator dyn_cont,
- void *dyn_cont_cls,
- MHD_FreeCallback dyn_cont_fc);
+MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc,
+ uint_fast64_t size,
+ MHD_DynamicContentCreator dyn_cont,
+ void *dyn_cont_cls,
+ MHD_FreeCallback free_cb,
+ void *free_cb_cls);
+
+
+/**
+ * Create a response. The response object can be extended with
+ * header information.
+ *
+ * @param sc status code to return
+ * @param s size of the data portion of the response, #MHD_SIZE_UNKNOWN for unknown
+ * @param d callback to use to obtain response data
+ * @param dc extra argument to @p d, evaluated twice!
+ * @param f callback to call to free @p dc resources
+ * @return new response object on success,
+ * NULL on failure (i.e. invalid arguments, out of memory)
+ * FIXME: Call free callback on error?
+ * @warning The @p dc parameter is evaluated twice; avoid expressions
+ * with side effects. Alternatively, just call function
+ * #MHD_response_from_callback_2cls() directly.
+ * @ingroup response
+ */
+#define MHD_response_from_callback(sc, s, d, dc, f) \
+ MHD_response_from_callback_2cls((sc),(s),(d),(dc),(f),(dc))
/**
diff --git a/src/mhd2/response_from.c b/src/mhd2/response_from.c
@@ -132,14 +132,15 @@ mhd_response_deinit_content_data (struct MHD_Response *restrict r)
MHD_EXTERN_ struct MHD_Response *
-MHD_response_from_callback (enum MHD_HTTP_StatusCode sc,
- uint_fast64_t size,
- MHD_DynamicContentCreator dyn_cont,
- void *dyn_cont_cls,
- MHD_FreeCallback dyn_cont_fc)
+MHD_response_from_callback_2cls (enum MHD_HTTP_StatusCode sc,
+ uint_fast64_t size,
+ MHD_DynamicContentCreator dyn_cont,
+ void *dyn_cont_cls,
+ MHD_FreeCallback free_cb,
+ void *free_cb_cls)
{
struct MHD_Response *restrict res;
- res = response_create_basic (sc, size, dyn_cont_fc, dyn_cont_cls);
+ res = response_create_basic (sc, size, free_cb, free_cb_cls);
if (NULL != res)
{
res->cntn_dtype = mhd_RESPONSE_CONTENT_DATA_CALLBACK;