aboutsummaryrefslogtreecommitdiff
path: root/src/util/configuration.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/configuration.c')
-rw-r--r--src/util/configuration.c62
1 files changed, 53 insertions, 9 deletions
diff --git a/src/util/configuration.c b/src/util/configuration.c
index e00bbd64a..197c664db 100644
--- a/src/util/configuration.c
+++ b/src/util/configuration.c
@@ -138,6 +138,41 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg)
138 138
139 139
140/** 140/**
141 * Parse a configuration file @a filename and run the function
142 * @a cb with the resulting configuration object. Then free the
143 * configuration object and return the status value from @a cb.
144 *
145 * @param filename configuration to parse, NULL for "default"
146 * @param cb function to run
147 * @param cb_cls closure for @a cb
148 * @return #GNUNET_SYSERR if parsing the configuration failed,
149 * otherwise return value from @a cb.
150 */
151int
152GNUNET_CONFIGURATION_parse_and_run (const char *filename,
153 GNUNET_CONFIGURATION_Callback cb,
154 void *cb_cls)
155{
156 struct GNUNET_CONFIGURATION_Handle *cfg;
157 int ret;
158
159 cfg = GNUNET_CONFIGURATION_create ();
160 if (GNUNET_OK !=
161 GNUNET_CONFIGURATION_load (cfg,
162 filename))
163 {
164 GNUNET_break (0);
165 GNUNET_CONFIGURATION_destroy (cfg);
166 return GNUNET_SYSERR;
167 }
168 ret = cb (cb_cls,
169 cfg);
170 GNUNET_CONFIGURATION_destroy (cfg);
171 return ret;
172}
173
174
175/**
141 * De-serializes configuration 176 * De-serializes configuration
142 * 177 *
143 * @param cfg configuration to update 178 * @param cfg configuration to update
@@ -522,7 +557,7 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
522 GNUNET_free (fn); 557 GNUNET_free (fn);
523 GNUNET_free (cfg_buf); 558 GNUNET_free (cfg_buf);
524 LOG (GNUNET_ERROR_TYPE_WARNING, 559 LOG (GNUNET_ERROR_TYPE_WARNING,
525 "Writing configration to file `%s' failed\n", 560 "Writing configuration to file `%s' failed\n",
526 filename); 561 filename);
527 cfg->dirty = GNUNET_SYSERR; /* last write failed */ 562 cfg->dirty = GNUNET_SYSERR; /* last write failed */
528 return GNUNET_SYSERR; 563 return GNUNET_SYSERR;
@@ -893,22 +928,27 @@ GNUNET_CONFIGURATION_set_value_number (struct GNUNET_CONFIGURATION_Handle *cfg,
893 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 928 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
894 */ 929 */
895int 930int
896GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle 931GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle *cfg,
897 *cfg, const char *section, 932 const char *section,
898 const char *option, 933 const char *option,
899 unsigned long long *number) 934 unsigned long long *number)
900{ 935{
901 struct ConfigEntry *e; 936 struct ConfigEntry *e;
937 char dummy[2];
902 938
903 if (NULL == (e = find_entry (cfg, section, option))) 939 if (NULL == (e = find_entry (cfg, section, option)))
904 return GNUNET_SYSERR; 940 return GNUNET_SYSERR;
905 if (NULL == e->val) 941 if (NULL == e->val)
906 return GNUNET_SYSERR; 942 return GNUNET_SYSERR;
907 if (1 != SSCANF (e->val, "%llu", number)) 943 if (1 != SSCANF (e->val,
944 "%llu%1s",
945 number,
946 dummy))
908 return GNUNET_SYSERR; 947 return GNUNET_SYSERR;
909 return GNUNET_OK; 948 return GNUNET_OK;
910} 949}
911 950
951
912/** 952/**
913 * Get a configuration value that should be a floating point number. 953 * Get a configuration value that should be a floating point number.
914 * 954 *
@@ -919,18 +959,22 @@ GNUNET_CONFIGURATION_get_value_number (const struct GNUNET_CONFIGURATION_Handle
919 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 959 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
920 */ 960 */
921int 961int
922GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle 962GNUNET_CONFIGURATION_get_value_float (const struct GNUNET_CONFIGURATION_Handle *cfg,
923 *cfg, const char *section, 963 const char *section,
924 const char *option, 964 const char *option,
925 float *number) 965 float *number)
926{ 966{
927 struct ConfigEntry *e; 967 struct ConfigEntry *e;
928 968 char dummy[2];
969
929 if (NULL == (e = find_entry (cfg, section, option))) 970 if (NULL == (e = find_entry (cfg, section, option)))
930 return GNUNET_SYSERR; 971 return GNUNET_SYSERR;
931 if (NULL == e->val) 972 if (NULL == e->val)
932 return GNUNET_SYSERR; 973 return GNUNET_SYSERR;
933 if (1 != SSCANF (e->val, "%f", number)) 974 if (1 != SSCANF (e->val,
975 "%f%1s",
976 number,
977 dummy))
934 return GNUNET_SYSERR; 978 return GNUNET_SYSERR;
935 return GNUNET_OK; 979 return GNUNET_OK;
936} 980}