commit 429ff6ca1366d903d801a19737cdcdddad312467
parent a5e8d156412cc74f6701854a977d82c0dadf9d2d
Author: Christian Grothoff <grothoff@gnunet.org>
Date: Sat, 14 Feb 2026 21:54:31 +0100
ensure CB is always called async in mhd typst
Diffstat:
1 file changed, 52 insertions(+), 5 deletions(-)
diff --git a/src/mhd/mhd_typst.c b/src/mhd/mhd_typst.c
@@ -98,6 +98,16 @@ struct TALER_MHD_TypstContext
char *output_file;
/**
+ * Context for fail_async_cb().
+ */
+ char *async_hint;
+
+ /**
+ * Context for fail_async_cb().
+ */
+ enum TALER_ErrorCode async_ec;
+
+ /**
* Length of the @e stages array.
*/
unsigned int num_stages;
@@ -280,6 +290,44 @@ typst_context_fail (struct TALER_MHD_TypstContext *tc,
/**
+ * Helper task for typst_context_fail_async().
+ *
+ * @param cls a `struct TALER_MHD_TypstContext`
+ */
+static void
+fail_async_cb (void *cls)
+{
+ struct TALER_MHD_TypstContext *tc = cls;
+
+ tc->t = NULL;
+ typst_context_fail (tc,
+ tc->async_ec,
+ tc->async_hint);
+ GNUNET_free (tc->async_hint);
+ TALER_MHD_typst_cancel (tc);
+}
+
+
+/**
+ * Generate a response for @a tc indicating an error of type @a ec.
+ *
+ * @param[in,out] tc context to fail
+ * @param ec error code to return
+ * @param hint hint text to return
+ */
+static void
+typst_context_fail_async (struct TALER_MHD_TypstContext *tc,
+ enum TALER_ErrorCode ec,
+ const char *hint)
+{
+ tc->async_ec = ec;
+ tc->async_hint = (NULL == hint) ? NULL : GNUNET_strdup (hint);
+ tc->t = GNUNET_SCHEDULER_add_now (&fail_async_cb,
+ tc);
+}
+
+
+/**
* Called when the pdftk helper exited.
*
* @param cls our `struct TALER_MHD_TypstContext *`
@@ -751,11 +799,10 @@ TALER_MHD_typst (
sizeof (err),
"Typst setup failed on stage %u",
i);
- typst_context_fail (tc,
- TALER_EC_EXCHANGE_GENERIC_TYPST_TEMPLATE_FAILURE,
- err);
- TALER_MHD_typst_cancel (tc);
- return NULL;
+ typst_context_fail_async (tc,
+ TALER_EC_EXCHANGE_GENERIC_TYPST_TEMPLATE_FAILURE,
+ err);
+ return tc;
}
}
GNUNET_free (template_path);