diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-01-27 15:04:09 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-01-27 15:04:09 +0000 |
commit | 92627182d83bb49b07e6f0a78285ca8b3a2fd4d9 (patch) | |
tree | 896eac13693a215ebe1446160bb1157f9ea1d2a7 | |
parent | ecaf813d69580ee1af4bbcaf501caaccf21441db (diff) | |
download | gnunet-92627182d83bb49b07e6f0a78285ca8b3a2fd4d9.tar.gz gnunet-92627182d83bb49b07e6f0a78285ca8b3a2fd4d9.zip |
add GNUNET_CONFIGURATION_get_data from Taler
-rw-r--r-- | src/include/gnunet_configuration_lib.h | 23 | ||||
-rw-r--r-- | src/util/configuration.c | 54 |
2 files changed, 74 insertions, 3 deletions
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 | |||
@@ -431,6 +431,29 @@ GNUNET_CONFIGURATION_get_value_yesno (const struct GNUNET_CONFIGURATION_Handle * | |||
431 | 431 | ||
432 | 432 | ||
433 | /** | 433 | /** |
434 | * Get Crockford32-encoded fixed-size binary data from a configuration. | ||
435 | * | ||
436 | * @param cfg configuration to access | ||
437 | * @param section section to access | ||
438 | * @param option option to access | ||
439 | * @param buf where to store the decoded binary result | ||
440 | * @param buf_size exact number of bytes to store in @a buf | ||
441 | * @return #GNUNET_OK on success | ||
442 | * #GNUNET_NO is the value does not exist | ||
443 | * #GNUNET_SYSERR on decoding error | ||
444 | */ | ||
445 | int | ||
446 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
447 | const char *section, | ||
448 | const char *option, | ||
449 | void *buf, | ||
450 | size_t buf_size); | ||
451 | |||
452 | |||
453 | |||
454 | |||
455 | |||
456 | /** | ||
434 | * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" | 457 | * Expand an expression of the form "$FOO/BAR" to "DIRECTORY/BAR" |
435 | * where either in the "PATHS" section or the environtment "FOO" is | 458 | * where either in the "PATHS" section or the environtment "FOO" is |
436 | * set to "DIRECTORY". We also support default expansion, | 459 | * set to "DIRECTORY". We also support default expansion, |
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 | |||
920 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 920 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
921 | */ | 921 | */ |
922 | int | 922 | int |
923 | GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle | 923 | GNUNET_CONFIGURATION_get_value_time (const struct GNUNET_CONFIGURATION_Handle *cfg, |
924 | *cfg, const char *section, | 924 | const char *section, |
925 | const char *option, | 925 | const char *option, |
926 | struct GNUNET_TIME_Relative *time) | 926 | struct GNUNET_TIME_Relative *time) |
927 | { | 927 | { |
@@ -1036,6 +1036,53 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle | |||
1036 | 1036 | ||
1037 | 1037 | ||
1038 | /** | 1038 | /** |
1039 | * Get crockford32-encoded fixed-size binary data from a configuration. | ||
1040 | * | ||
1041 | * @param cfg configuration to access | ||
1042 | * @param section section to access | ||
1043 | * @param option option to access | ||
1044 | * @param buf where to store the decoded binary result | ||
1045 | * @param buf_size exact number of bytes to store in @a buf | ||
1046 | * @return #GNUNET_OK on success | ||
1047 | * #GNUNET_NO is the value does not exist | ||
1048 | * #GNUNET_SYSERR on decoding error | ||
1049 | */ | ||
1050 | int | ||
1051 | GNUNET_CONFIGURATION_get_data (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
1052 | const char *section, | ||
1053 | const char *option, | ||
1054 | void *buf, | ||
1055 | size_t buf_size) | ||
1056 | { | ||
1057 | char *enc; | ||
1058 | int res; | ||
1059 | size_t data_size; | ||
1060 | |||
1061 | if (GNUNET_OK != | ||
1062 | (res = GNUNET_CONFIGURATION_get_value_string (cfg, | ||
1063 | section, | ||
1064 | option, | ||
1065 | &enc))) | ||
1066 | return res; | ||
1067 | data_size = (strlen (enc) * 5) / 8; | ||
1068 | if (data_size != buf_size) | ||
1069 | { | ||
1070 | GNUNET_free (enc); | ||
1071 | return GNUNET_SYSERR; | ||
1072 | } | ||
1073 | if (GNUNET_OK != | ||
1074 | GNUNET_STRINGS_string_to_data (enc, | ||
1075 | strlen (enc), | ||
1076 | buf, buf_size)) | ||
1077 | { | ||
1078 | GNUNET_free (enc); | ||
1079 | return GNUNET_SYSERR; | ||
1080 | } | ||
1081 | return GNUNET_OK; | ||
1082 | } | ||
1083 | |||
1084 | |||
1085 | /** | ||
1039 | * Test if we have a value for a particular option | 1086 | * Test if we have a value for a particular option |
1040 | * | 1087 | * |
1041 | * @param cfg configuration to inspect | 1088 | * @param cfg configuration to inspect |
@@ -1045,7 +1092,8 @@ GNUNET_CONFIGURATION_get_value_choice (const struct GNUNET_CONFIGURATION_Handle | |||
1045 | */ | 1092 | */ |
1046 | int | 1093 | int |
1047 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, | 1094 | GNUNET_CONFIGURATION_have_value (const struct GNUNET_CONFIGURATION_Handle *cfg, |
1048 | const char *section, const char *option) | 1095 | const char *section, |
1096 | const char *option) | ||
1049 | { | 1097 | { |
1050 | struct ConfigEntry *e; | 1098 | struct ConfigEntry *e; |
1051 | 1099 | ||