diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-06-22 23:28:58 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-06-22 23:28:58 +0200 |
commit | 988ac7f121b646cba3ca44567f54b1315398505d (patch) | |
tree | 96a6e224c13bd6c692b4bf68eb0f97c632095c46 /src/util/gnunet-config.c | |
parent | ea20a69462912d46cf4f9dc47e6c7945c9da5f97 (diff) | |
download | gnunet-988ac7f121b646cba3ca44567f54b1315398505d.tar.gz gnunet-988ac7f121b646cba3ca44567f54b1315398505d.zip |
finish #4623
Diffstat (limited to 'src/util/gnunet-config.c')
-rw-r--r-- | src/util/gnunet-config.c | 181 |
1 files changed, 81 insertions, 100 deletions
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 9c292205a..3b9b64d4e 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -103,18 +103,12 @@ print_option (void *cls, | |||
103 | fn = value_fn; | 103 | fn = value_fn; |
104 | else | 104 | else |
105 | GNUNET_free (value_fn); | 105 | GNUNET_free (value_fn); |
106 | fprintf (stdout, | 106 | fprintf (stdout, "%s = %s\n", option, fn); |
107 | "%s = %s\n", | ||
108 | option, | ||
109 | fn); | ||
110 | GNUNET_free (fn); | 107 | GNUNET_free (fn); |
111 | } | 108 | } |
112 | else | 109 | else |
113 | { | 110 | { |
114 | fprintf (stdout, | 111 | fprintf (stdout, "%s = %s\n", option, value); |
115 | "%s = %s\n", | ||
116 | option, | ||
117 | value); | ||
118 | } | 112 | } |
119 | } | 113 | } |
120 | 114 | ||
@@ -126,13 +120,10 @@ print_option (void *cls, | |||
126 | * @param section a section in the configuration file | 120 | * @param section a section in the configuration file |
127 | */ | 121 | */ |
128 | static void | 122 | static void |
129 | print_section_name (void *cls, | 123 | print_section_name (void *cls, const char *section) |
130 | const char *section) | ||
131 | { | 124 | { |
132 | (void) cls; | 125 | (void) cls; |
133 | fprintf (stdout, | 126 | fprintf (stdout, "%s\n", section); |
134 | "%s\n", | ||
135 | section); | ||
136 | } | 127 | } |
137 | 128 | ||
138 | 129 | ||
@@ -161,9 +152,7 @@ run (void *cls, | |||
161 | { | 152 | { |
162 | char *name; | 153 | char *name; |
163 | 154 | ||
164 | GNUNET_asprintf (&name, | 155 | GNUNET_asprintf (&name, "libgnunet_plugin_%s", backend_check); |
165 | "libgnunet_plugin_%s", | ||
166 | backend_check); | ||
167 | global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77; | 156 | global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77; |
168 | GNUNET_free (name); | 157 | GNUNET_free (name); |
169 | return; | 158 | return; |
@@ -173,40 +162,34 @@ run (void *cls, | |||
173 | struct GNUNET_CONFIGURATION_Handle *def; | 162 | struct GNUNET_CONFIGURATION_Handle *def; |
174 | 163 | ||
175 | def = GNUNET_CONFIGURATION_create (); | 164 | def = GNUNET_CONFIGURATION_create (); |
176 | if (GNUNET_OK != | 165 | if (GNUNET_OK != GNUNET_CONFIGURATION_load (def, NULL)) |
177 | GNUNET_CONFIGURATION_load (def, NULL)) | ||
178 | { | 166 | { |
179 | fprintf (stderr, | 167 | fprintf (stderr, _ ("failed to load configuration defaults")); |
180 | _("failed to load configuration defaults")); | ||
181 | global_ret = 1; | 168 | global_ret = 1; |
182 | return; | 169 | return; |
183 | } | 170 | } |
184 | diff = GNUNET_CONFIGURATION_get_diff (def, | 171 | diff = GNUNET_CONFIGURATION_get_diff (def, cfg); |
185 | cfg); | ||
186 | cfg = diff; | 172 | cfg = diff; |
187 | } | 173 | } |
188 | if ( ((! rewrite) && (NULL == section)) || list_sections) | 174 | if (((! rewrite) && (NULL == section)) || list_sections) |
189 | { | 175 | { |
190 | if (! list_sections) | 176 | if (! list_sections) |
191 | { | 177 | { |
192 | fprintf (stderr, | 178 | fprintf (stderr, |
193 | _("%s or %s argument is required\n"), | 179 | _ ("%s or %s argument is required\n"), |
194 | "--section", | 180 | "--section", |
195 | "--list-sections"); | 181 | "--list-sections"); |
196 | global_ret = 1; | 182 | global_ret = 1; |
197 | } | 183 | } |
198 | else | 184 | else |
199 | { | 185 | { |
200 | fprintf (stderr, | 186 | fprintf (stderr, _ ("The following sections are available:\n")); |
201 | _("The following sections are available:\n")); | 187 | GNUNET_CONFIGURATION_iterate_sections (cfg, &print_section_name, NULL); |
202 | GNUNET_CONFIGURATION_iterate_sections (cfg, | ||
203 | &print_section_name, | ||
204 | NULL); | ||
205 | } | 188 | } |
206 | goto cleanup; | 189 | goto cleanup; |
207 | } | 190 | } |
208 | 191 | ||
209 | if ( (NULL != section) && (NULL == value) ) | 192 | if ((NULL != section) && (NULL == value)) |
210 | { | 193 | { |
211 | if (NULL == option) | 194 | if (NULL == option) |
212 | { | 195 | { |
@@ -219,26 +202,24 @@ run (void *cls, | |||
219 | { | 202 | { |
220 | if (is_filename) | 203 | if (is_filename) |
221 | { | 204 | { |
222 | if (GNUNET_OK != | 205 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, |
223 | GNUNET_CONFIGURATION_get_value_filename (cfg, | 206 | section, |
224 | section, | 207 | option, |
225 | option, | 208 | &value)) |
226 | &value)) | ||
227 | { | 209 | { |
228 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 210 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option); |
229 | section, option); | ||
230 | global_ret = 3; | 211 | global_ret = 3; |
231 | goto cleanup; | 212 | goto cleanup; |
232 | } | 213 | } |
233 | } | 214 | } |
234 | else | 215 | else |
235 | { | 216 | { |
236 | if (GNUNET_OK != | 217 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, |
237 | GNUNET_CONFIGURATION_get_value_string (cfg, section, | 218 | section, |
238 | option, &value)) | 219 | option, |
220 | &value)) | ||
239 | { | 221 | { |
240 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 222 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option); |
241 | section, option); | ||
242 | global_ret = 3; | 223 | global_ret = 3; |
243 | goto cleanup; | 224 | goto cleanup; |
244 | } | 225 | } |
@@ -250,15 +231,12 @@ run (void *cls, | |||
250 | { | 231 | { |
251 | if (NULL == option) | 232 | if (NULL == option) |
252 | { | 233 | { |
253 | fprintf (stderr, _("--option argument required to set value\n")); | 234 | fprintf (stderr, _ ("--option argument required to set value\n")); |
254 | global_ret = 1; | 235 | global_ret = 1; |
255 | goto cleanup; | 236 | goto cleanup; |
256 | } | 237 | } |
257 | out = GNUNET_CONFIGURATION_dup (cfg); | 238 | out = GNUNET_CONFIGURATION_dup (cfg); |
258 | GNUNET_CONFIGURATION_set_value_string (out, | 239 | GNUNET_CONFIGURATION_set_value_string (out, section, option, value); |
259 | section, | ||
260 | option, | ||
261 | value); | ||
262 | } | 240 | } |
263 | cfg_fn = NULL; | 241 | cfg_fn = NULL; |
264 | if (NULL == cfgfile) | 242 | if (NULL == cfgfile) |
@@ -274,11 +252,10 @@ run (void *cls, | |||
274 | cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); | 252 | cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); |
275 | cfgfile = cfg_fn; | 253 | cfgfile = cfg_fn; |
276 | } | 254 | } |
277 | if ( (NULL != diff) || (NULL != out) ) | 255 | if ((NULL != diff) || (NULL != out)) |
278 | { | 256 | { |
279 | if (GNUNET_OK != | 257 | if (GNUNET_OK != |
280 | GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, | 258 | GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, cfgfile)) |
281 | cfgfile)) | ||
282 | global_ret = 2; | 259 | global_ret = 2; |
283 | } | 260 | } |
284 | GNUNET_free_non_null (cfg_fn); | 261 | GNUNET_free_non_null (cfg_fn); |
@@ -298,62 +275,66 @@ cleanup: | |||
298 | * @return 0 ok, 1 on error | 275 | * @return 0 ok, 1 on error |
299 | */ | 276 | */ |
300 | int | 277 | int |
301 | main (int argc, | 278 | main (int argc, char *const *argv) |
302 | char *const *argv) | ||
303 | { | 279 | { |
304 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 280 | struct GNUNET_GETOPT_CommandLineOption options[] = |
305 | GNUNET_GETOPT_option_flag ('f', | 281 | {GNUNET_GETOPT_option_flag ( |
306 | "filename", | 282 | 'f', |
307 | gettext_noop ("interpret option value as a filename (with $-expansion)"), | 283 | "filename", |
308 | &is_filename), | 284 | gettext_noop ("interpret option value as a filename (with $-expansion)"), |
309 | //GNUNET_GETOPT_option_exclusive | 285 | &is_filename), |
310 | (GNUNET_GETOPT_option_string ('b', | 286 | GNUNET_GETOPT_option_exclusive (GNUNET_GETOPT_option_string ( |
311 | "supported-backend", | 287 | 'b', |
312 | "BACKEND", | 288 | "supported-backend", |
313 | gettext_noop ("test if the current installation supports the specified BACKEND"), | 289 | "BACKEND", |
314 | &backend_check)), | 290 | gettext_noop ( |
315 | GNUNET_GETOPT_option_string ('s', | 291 | "test if the current installation supports the specified BACKEND"), |
316 | "section", | 292 | &backend_check)), |
317 | "SECTION", | 293 | GNUNET_GETOPT_option_string ('s', |
318 | gettext_noop ("name of the section to access"), | 294 | "section", |
319 | §ion), | 295 | "SECTION", |
320 | GNUNET_GETOPT_option_string ('o', | 296 | gettext_noop ( |
321 | "option", | 297 | "name of the section to access"), |
322 | "OPTION", | 298 | §ion), |
323 | gettext_noop ("name of the option to access"), | 299 | GNUNET_GETOPT_option_string ('o', |
324 | &option), | 300 | "option", |
325 | GNUNET_GETOPT_option_string ('V', | 301 | "OPTION", |
326 | "value", | 302 | gettext_noop ("name of the option to access"), |
327 | "VALUE", | 303 | &option), |
328 | gettext_noop ("value to set"), | 304 | GNUNET_GETOPT_option_string ('V', |
329 | &value), | 305 | "value", |
330 | GNUNET_GETOPT_option_flag ('S', | 306 | "VALUE", |
331 | "list-sections", | 307 | gettext_noop ("value to set"), |
332 | gettext_noop ("print available configuration sections"), | 308 | &value), |
333 | &list_sections), | 309 | GNUNET_GETOPT_option_flag ('S', |
334 | GNUNET_GETOPT_option_flag ('w', | 310 | "list-sections", |
335 | "rewrite", | 311 | gettext_noop ( |
336 | gettext_noop ("write configuration file that only contains delta to defaults"), | 312 | "print available configuration sections"), |
337 | &rewrite), | 313 | &list_sections), |
338 | GNUNET_GETOPT_OPTION_END | 314 | GNUNET_GETOPT_option_flag ( |
339 | }; | 315 | 'w', |
316 | "rewrite", | ||
317 | gettext_noop ( | ||
318 | "write configuration file that only contains delta to defaults"), | ||
319 | &rewrite), | ||
320 | GNUNET_GETOPT_OPTION_END}; | ||
340 | int ret; | 321 | int ret; |
341 | 322 | ||
342 | if (GNUNET_OK != | 323 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
343 | GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
344 | &argc, &argv)) | ||
345 | return 2; | 324 | return 2; |
346 | 325 | ||
347 | ret = GNUNET_PROGRAM_run (argc, | 326 | ret = |
348 | argv, | 327 | GNUNET_PROGRAM_run (argc, |
349 | "gnunet-config [OPTIONS]", | 328 | argv, |
350 | gettext_noop ("Manipulate GNUnet configuration files"), | 329 | "gnunet-config [OPTIONS]", |
351 | options, | 330 | gettext_noop ("Manipulate GNUnet configuration files"), |
352 | &run, NULL); | 331 | options, |
353 | GNUNET_free ((void*) argv); | 332 | &run, |
333 | NULL); | ||
334 | GNUNET_free ((void *) argv); | ||
354 | if (GNUNET_OK == ret) | 335 | if (GNUNET_OK == ret) |
355 | return global_ret; | 336 | return global_ret; |
356 | return 1; | 337 | return ret; |
357 | } | 338 | } |
358 | 339 | ||
359 | /* end of gnunet-config.c */ | 340 | /* end of gnunet-config.c */ |