From 92627182d83bb49b07e6f0a78285ca8b3a2fd4d9 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 27 Jan 2015 15:04:09 +0000 Subject: add GNUNET_CONFIGURATION_get_data from Taler --- src/include/gnunet_configuration_lib.h | 23 +++++++++++++++ src/util/configuration.c | 54 ++++++++++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index ac14dde64..ce5679c81 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -430,6 +430,29 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle * const char *option); +/** + * Get Crockford32-encoded fixed-size binary data from a configuration. + * + * @param cfg configuration to access + * @param section section to access + * @param option option to access + * @param buf where to store the decoded binary result + * @param buf_size exact number of bytes to store in @a buf + * @return #GNUNET_OK on success + * #GNUNET_NO is the value does not exist + * #GNUNET_SYSERR on decoding error + */ +int +GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, + void *buf, + size_t buf_size); + + + + + /** * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" * where either in the "PATHS" section or the environtment "FOO" is diff --git a/src/util/configuration.c b/src/util/configuration.c index 3e6710543..26e65a378 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c @@ -920,8 +920,8 @@ GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle * @return #GNUNET_OK on success, #GNUNET_SYSERR on error */ int -GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle - *cfg, const char *section, +GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, const char *option, struct GNUNET_TIME_Relative *time) { @@ -1035,6 +1035,53 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle } +/** + * Get crockford32-encoded fixed-size binary data from a configuration. + * + * @param cfg configuration to access + * @param section section to access + * @param option option to access + * @param buf where to store the decoded binary result + * @param buf_size exact number of bytes to store in @a buf + * @return #GNUNET_OK on success + * #GNUNET_NO is the value does not exist + * #GNUNET_SYSERR on decoding error + */ +int +GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, + const char *section, + const char *option, + void *buf, + size_t buf_size) +{ + char *enc; + int res; + size_t data_size; + + if (GNUNET_OK != + (res = GNUNET_CONFIGURATION_get_value_string (cfg, + section, + option, + &enc))) + return res; + data_size = (strlen (enc) * 5) / 8; + if (data_size != buf_size) + { + GNUNET_free (enc); + return GNUNET_SYSERR; + } + if (GNUNET_OK != + GNUNET_STRINGS_string_to_data (enc, + strlen (enc), + buf, buf_size)) + { + GNUNET_free (enc); + return GNUNET_SYSERR; + } + return GNUNET_OK; +} + + /** * Test if we have a value for a particular option * @@ -1045,7 +1092,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle */ int GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *section, const char *option) + const char *section, + const char *option) { struct ConfigEntry *e; -- cgit v1.2.3