diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/taler_util.h | 18 | ||||
-rw-r--r-- | src/util/config.c | 47 |
2 files changed, 60 insertions, 5 deletions
diff --git a/src/include/taler_util.h b/src/include/taler_util.h index 66951e124..4c3a1c9f2 100644 --- a/src/include/taler_util.h +++ b/src/include/taler_util.h @@ -220,6 +220,12 @@ struct TALER_CurrencySpecification char currency[TALER_CURRENCY_LEN]; /** + * Human-readable long name of the currency, e.g. + * "Japanese Yen". + */ + char *name; + + /** * Character used to separate decimals. String as * multi-byte sequences may be required (UTF-8!). */ @@ -287,6 +293,18 @@ TALER_CONFIG_free_currencies ( /** + * Convert a currency specification to the + * respective JSON object. + * + * @param cspec currency specification + * @return JSON object encoding @a cspec for `/config`. + */ +json_t * +TALER_CONFIG_currency_specs_to_json (const struct + TALER_CurrencySpecification *cspec); + + +/** * Allow user to specify an amount on the command line. * * @param shortName short name of the option diff --git a/src/util/config.c b/src/util/config.c index 125ea7b1b..9e1156240 100644 --- a/src/util/config.c +++ b/src/util/config.c @@ -21,7 +21,7 @@ */ #include "platform.h" #include "taler_util.h" - +#include <gnunet/gnunet_json_lib.h> enum GNUNET_GenericReturnValue TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg, @@ -241,12 +241,12 @@ parse_currencies_cb (void *cls, if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cpc->cfg, section, - "NAME", + "CODE", &str)) { GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, - "NAME"); + "CODE"); cpc->failure = true; return; } @@ -254,8 +254,8 @@ parse_currencies_cb (void *cls, { GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR, section, - "NAME", - "Name given is too long"); + "CODE", + "Currency code name given is too long"); cpc->failure = true; GNUNET_free (str); return; @@ -279,6 +279,20 @@ parse_currencies_cb (void *cls, cspec->decimal_separator = str; if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_string (cpc->cfg, + section, + "NAME", + &str)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + section, + "NAME"); + cpc->failure = true; + return; + } + cspec->name = str; + + if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cpc->cfg, section, "FRACTIONAL_INPUT_DIGITS", @@ -407,6 +421,28 @@ TALER_CONFIG_parse_currencies (const struct GNUNET_CONFIGURATION_Handle *cfg, } +json_t * +TALER_CONFIG_currency_specs_to_json (const struct + TALER_CurrencySpecification *cspec) +{ + return GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("decimal_separator", + cspec->decimal_separator), + GNUNET_JSON_pack_string ("name", + cspec->name), + GNUNET_JSON_pack_uint64 ("num_fractional_input_digits", + cspec->num_fractional_input_digits), + GNUNET_JSON_pack_uint64 ("num_fractional_normal_digits", + cspec->num_fractional_normal_digits), + GNUNET_JSON_pack_uint64 ("num_fractional_trailing_zero_digits", + cspec->num_fractional_trailing_zero_digits), + GNUNET_JSON_pack_bool ("is_currency_name_leading", + cspec->is_currency_name_leading), + GNUNET_JSON_pack_object_incref ("alt_unit_names", + cspec->map_alt_unit_names)); +} + + void TALER_CONFIG_free_currencies ( unsigned int num_currencies, @@ -417,6 +453,7 @@ TALER_CONFIG_free_currencies ( struct TALER_CurrencySpecification *cspec = &cspecs[i]; GNUNET_free (cspec->decimal_separator); + GNUNET_free (cspec->name); json_decref (cspec->map_alt_unit_names); } GNUNET_array_grow (cspecs, |