aboutsummaryrefslogtreecommitdiff
path: root/src/util/config.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-15 20:08:38 +0100
committerChristian Grothoff <christian@grothoff.org>2020-03-15 20:08:38 +0100
commit4322bbf2f1722b4c53114901768772dabdb7e822 (patch)
treee2193282c2d179f2d3bdf32eb7aca7a6ba161f25 /src/util/config.c
parentd7cfb11fc6a171ece9c233d67ec849ac391bc818 (diff)
move common logic to parse currency into libtalerutil
Diffstat (limited to 'src/util/config.c')
-rw-r--r--src/util/config.c37
1 files changed, 37 insertions, 0 deletions
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;
+}