exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 2a37ca8fd794105d349904d2c3e3a1436fa60bf4
parent a8143b31ca41d5e10c4085fc4176cf2cbd5705c5
Author: Christian Grothoff <christian@grothoff.org>
Date:   Tue, 14 Oct 2025 20:36:56 +0200

add helper to parse relative time arguments

Diffstat:
Mcontrib/gnunet.tag | 6++++++
Msrc/include/taler/taler_mhd_lib.h | 43+++++++++++++++++++++++++++++++++++++++++++
Msrc/mhd/Makefile.am | 2+-
Msrc/mhd/mhd_parsing.c | 41+++++++++++++++++++++++++++++++++++++++++
4 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/contrib/gnunet.tag b/contrib/gnunet.tag @@ -58,6 +58,12 @@ <anchorfile>gnunet_time_lib.h</anchorfile> <arglist></arglist> </member> + <member kind="define"> + <type>#define</type> + <name>GNUNET_TIME_UNIT_ZERO</name> + <anchorfile>gnunet_time_lib.h</anchorfile> + <arglist></arglist> + </member> </compound> <compound kind="file"> diff --git a/src/include/taler/taler_mhd_lib.h b/src/include/taler/taler_mhd_lib.h @@ -472,6 +472,49 @@ TALER_MHD_parse_json_array (struct MHD_Connection *connection, /** + * Extract optional relative time argument from request. + * + * @param connection the MHD connection + * @param label name of the argument to parse + * @param[out] duration set to #GNUNET_TIME_UNIT_ZERO if there was no duration argument given + * @return #GNUNET_OK on success, #GNUNET_NO if an + * error was returned on @a connection (caller should return #MHD_YES) and + * #GNUNET_SYSERR if we failed to return an error (caller should return #MHD_NO) + */ +enum GNUNET_GenericReturnValue +TALER_MHD_parse_request_arg_rel_time (struct MHD_Connection *connection, + const char *label, + struct GNUNET_TIME_Relative *duration); + + +/** + * Extract optional relative time argument from request. + * Macro that *returns* #MHD_YES/#MHD_NO if the @a label + * argument existed but failed to parse. + * + * @param connection the MHD connection + * @param label label to check for + * @param[out] duration set to #GNUNET_TIME_UNIT_ZERO if there was no duration given + */ +#define TALER_MHD_parse_request_rel_time(connection,label,duration) \ + do { \ + switch (TALER_MHD_parse_request_arg_rel_time (connection, \ + label, \ + expiration)) \ + { \ + case GNUNET_SYSERR: \ + GNUNET_break (0); \ + return MHD_NO; \ + case GNUNET_NO: \ + GNUNET_break_op (0); \ + return MHD_YES; \ + case GNUNET_OK: \ + break; \ + } \ + } while (0) + + +/** * Extract optional "timeout_ms" argument from request. * * @param connection the MHD connection diff --git a/src/mhd/Makefile.am b/src/mhd/Makefile.am @@ -18,7 +18,7 @@ libtalermhd_la_SOURCES = \ mhd_run.c \ mhd_spa.c libtalermhd_la_LDFLAGS = \ - -version-info 7:0:0 \ + -version-info 8:0:1 \ -no-undefined libtalermhd_la_LIBADD = \ $(top_builddir)/src/json/libtalerjson.la \ diff --git a/src/mhd/mhd_parsing.c b/src/mhd/mhd_parsing.c @@ -177,6 +177,47 @@ TALER_MHD_parse_request_header_data ( enum GNUNET_GenericReturnValue +TALER_MHD_parse_request_arg_rel_time ( + struct MHD_Connection *connection, + const char *label, + struct GNUNET_TIME_Relative *duration) +{ + const char *ts; + char dummy; + unsigned long long tms; + + ts = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + label); + if (NULL == ts) + { + *duration = GNUNET_TIME_UNIT_ZERO; + return GNUNET_OK; + } + if (1 != + sscanf (ts, + "%llu%c", + &tms, + &dummy)) + { + MHD_RESULT mret; + + GNUNET_break_op (0); + mret = TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PARAMETER_MALFORMED, + label); + return (MHD_YES == mret) + ? GNUNET_NO + : GNUNET_SYSERR; + } + *duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, + tms); + return GNUNET_OK; +} + + +enum GNUNET_GenericReturnValue TALER_MHD_parse_request_arg_timeout ( struct MHD_Connection *connection, struct GNUNET_TIME_Absolute *expiration)