From 4322bbf2f1722b4c53114901768772dabdb7e822 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 15 Mar 2020 20:08:38 +0100 Subject: move common logic to parse currency into libtalerutil --- src/util/config.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/util') diff --git a/src/util/config.c b/src/util/config.c index ee74fe8ff..160d541f0 100644 --- a/src/util/config.c +++ b/src/util/config.c @@ -55,3 +55,40 @@ TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_free (str); return GNUNET_OK; } + + +/** + * Load our currency from the @a cfg (in section [taler] + * the option "CURRENCY"). + * + * @param cfg configuration to use + * @param[out] currency where to write the result + * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure + */ +int +TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg, + char **currency) +{ + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cfg, + "taler", + "CURRENCY", + currency)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "taler", + "CURRENCY"); + return GNUNET_SYSERR; + } + if (strlen (*currency) >= TALER_CURRENCY_LEN) + { + fprintf (stderr, + "Currency `%s' longer than the allowed limit of %u characters.", + *currency, + (unsigned int) TALER_CURRENCY_LEN); + GNUNET_free (*currency); + *currency = NULL; + return GNUNET_SYSERR; + } + return GNUNET_OK; +} -- cgit v1.2.3