exchange

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

commit 02d3e378dc4c49b2444b45311f87e98dd97a90ec
parent e66e78fdc8902e9f65bf76eed0d501785d624358
Author: Christian Grothoff <christian@grothoff.org>
Date:   Thu,  4 Jun 2026 22:20:31 +0200

talermhd: add new TALER_MHD_arg_to_bool

Diffstat:
Msrc/include/taler/taler_mhd_lib.h | 44++++++++++++++++++++++++++++++++++++++++++++
Msrc/mhd/mhd.c | 30++++++++++++++++++++++++++++++
2 files changed, 74 insertions(+), 0 deletions(-)

diff --git a/src/include/taler/taler_mhd_lib.h b/src/include/taler/taler_mhd_lib.h @@ -99,6 +99,22 @@ TALER_MHD_arg_to_yna (struct MHD_Connection *connection, /** + * Convert query argument to @a b boolean value. + * + * @param connection connection to take query argument from + * @param arg argument to try for + * @param default_val value to assign if the argument is not present + * @param[out] b value to set + * @return true on success, false if the parameter was malformed + */ +bool +TALER_MHD_arg_to_bool (struct MHD_Connection *connection, + const char *arg, + bool default_val, + bool *b); + + +/** * Set global options for response generation within libtalermhd. * * @param go global options to use @@ -623,6 +639,34 @@ TALER_MHD_parse_request_arg_timestamp (struct MHD_Connection *connection, } \ } while (0) + +/** + * Extract optional "yes/no" argument from request. + * Macro that *returns* #MHD_YES/#MHD_NO if the + * argument existed but failed to parse. + * + * @param connection the MHD connection + * @param name name of the query parameter to parse + * @param def default value to set if absent + * @param[out] ret set to the yes/no/all value + */ +#define TALER_MHD_parse_request_bool(connection,name,def,ret) \ + do { \ + if (! (TALER_MHD_arg_to_bool (connection, \ + name, \ + def, \ + ret)) ) \ + { \ + GNUNET_break_op (0); \ + return TALER_MHD_reply_with_error ( \ + connection, \ + MHD_HTTP_BAD_REQUEST, \ + TALER_EC_GENERIC_PARAMETER_MALFORMED, \ + name); \ + } \ + } while (0) + + /** * Extract optional numeric limit argument from request. * diff --git a/src/mhd/mhd.c b/src/mhd/mhd.c @@ -97,3 +97,33 @@ TALER_MHD_arg_to_yna (struct MHD_Connection *connection, } return false; } + + +bool +TALER_MHD_arg_to_bool (struct MHD_Connection *connection, + const char *arg, + bool default_val, + bool *b) +{ + const char *str; + + str = MHD_lookup_connection_value (connection, + MHD_GET_ARGUMENT_KIND, + arg); + if (NULL == str) + { + *b = default_val; + return true; + } + if (0 == strcasecmp (str, "yes")) + { + *b = true; + return true; + } + if (0 == strcasecmp (str, "no")) + { + *b = false; + return true; + } + return false; +}