aboutsummaryrefslogtreecommitdiff
path: root/src/util/gnunet-config.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/gnunet-config.c')
-rw-r--r--src/util/gnunet-config.c130
1 files changed, 66 insertions, 64 deletions
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index 361fa55d6..f700428a2 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -73,9 +73,9 @@ static int rewrite;
73 */ 73 */
74static void 74static void
75print_option (void *cls, 75print_option (void *cls,
76 const char *section, 76 const char *section,
77 const char *option, 77 const char *option,
78 const char *value) 78 const char *value)
79{ 79{
80 const struct GNUNET_CONFIGURATION_Handle *cfg = cls; 80 const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
81 81
@@ -86,27 +86,27 @@ print_option (void *cls,
86 char *fn; 86 char *fn;
87 87
88 GNUNET_assert (GNUNET_OK == 88 GNUNET_assert (GNUNET_OK ==
89 GNUNET_CONFIGURATION_get_value_filename (cfg, 89 GNUNET_CONFIGURATION_get_value_filename (cfg,
90 section, 90 section,
91 option, 91 option,
92 &value_fn)); 92 &value_fn));
93 fn = GNUNET_STRINGS_filename_expand (value_fn); 93 fn = GNUNET_STRINGS_filename_expand (value_fn);
94 if (NULL == fn) 94 if (NULL == fn)
95 fn = value_fn; 95 fn = value_fn;
96 else 96 else
97 GNUNET_free (value_fn); 97 GNUNET_free (value_fn);
98 fprintf (stdout, 98 fprintf (stdout,
99 "%s = %s\n", 99 "%s = %s\n",
100 option, 100 option,
101 fn); 101 fn);
102 GNUNET_free (fn); 102 GNUNET_free (fn);
103 } 103 }
104 else 104 else
105 { 105 {
106 fprintf (stdout, 106 fprintf (stdout,
107 "%s = %s\n", 107 "%s = %s\n",
108 option, 108 option,
109 value); 109 value);
110 } 110 }
111} 111}
112 112
@@ -123,8 +123,8 @@ print_section_name (void *cls,
123{ 123{
124 (void) cls; 124 (void) cls;
125 fprintf (stdout, 125 fprintf (stdout,
126 "%s\n", 126 "%s\n",
127 section); 127 section);
128} 128}
129 129
130 130
@@ -133,7 +133,8 @@ print_section_name (void *cls,
133 * 133 *
134 * @param cls closure 134 * @param cls closure
135 * @param args remaining command-line arguments 135 * @param args remaining command-line arguments
136 * @param cfgfile name of the configuration file used (for saving, can be NULL!) 136 * @param cfgfile name of the configuration file used (for saving,
137 * can be NULL!)
137 * @param cfg configuration 138 * @param cfg configuration
138 */ 139 */
139static void 140static void
@@ -192,35 +193,36 @@ run (void *cls,
192 { 193 {
193 GNUNET_CONFIGURATION_iterate_section_values (cfg, 194 GNUNET_CONFIGURATION_iterate_section_values (cfg,
194 section, 195 section,
195 &print_option, 196 &print_option,
196 (void *) cfg); 197 (void *) cfg);
197 } 198 }
198 else 199 else
199 { 200 {
200 if (is_filename) 201 if (is_filename)
201 { 202 {
202 if (GNUNET_OK != 203 if (GNUNET_OK !=
203 GNUNET_CONFIGURATION_get_value_filename (cfg, 204 GNUNET_CONFIGURATION_get_value_filename (cfg,
204 section, 205 section,
205 option, 206 option,
206 &value)) 207 &value))
207 { 208 {
208 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 209 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
209 section, option); 210 section, option);
210 ret = 3; 211 ret = 3;
211 goto cleanup; 212 goto cleanup;
212 } 213 }
213 } 214 }
214 else 215 else
215 { 216 {
216 if (GNUNET_OK != 217 if (GNUNET_OK !=
217 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &value)) 218 GNUNET_CONFIGURATION_get_value_string (cfg, section,
218 { 219 option, &value))
219 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, 220 {
220 section, option); 221 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
221 ret = 3; 222 section, option);
223 ret = 3;
222 goto cleanup; 224 goto cleanup;
223 } 225 }
224 } 226 }
225 fprintf (stdout, "%s\n", value); 227 fprintf (stdout, "%s\n", value);
226 } 228 }
@@ -245,10 +247,10 @@ run (void *cls,
245 const char *xdg = getenv ("XDG_CONFIG_HOME"); 247 const char *xdg = getenv ("XDG_CONFIG_HOME");
246 if (NULL != xdg) 248 if (NULL != xdg)
247 GNUNET_asprintf (&cfg_fn, 249 GNUNET_asprintf (&cfg_fn,
248 "%s%s%s", 250 "%s%s%s",
249 xdg, 251 xdg,
250 DIR_SEPARATOR_STR, 252 DIR_SEPARATOR_STR,
251 GNUNET_OS_project_data_get ()->config_file); 253 GNUNET_OS_project_data_get ()->config_file);
252 else 254 else
253 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 255 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file);
254 cfgfile = cfg_fn; 256 cfgfile = cfg_fn;
@@ -256,14 +258,14 @@ run (void *cls,
256 if ( (NULL != diff) || (NULL != out) ) 258 if ( (NULL != diff) || (NULL != out) )
257 { 259 {
258 if (GNUNET_OK != 260 if (GNUNET_OK !=
259 GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, 261 GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
260 cfgfile)) 262 cfgfile))
261 ret = 2; 263 ret = 2;
262 } 264 }
263 GNUNET_free_non_null (cfg_fn); 265 GNUNET_free_non_null (cfg_fn);
264 if (NULL != out) 266 if (NULL != out)
265 GNUNET_CONFIGURATION_destroy (out); 267 GNUNET_CONFIGURATION_destroy (out);
266 cleanup: 268cleanup:
267 if (NULL != diff) 269 if (NULL != diff)
268 GNUNET_CONFIGURATION_destroy (diff); 270 GNUNET_CONFIGURATION_destroy (diff);
269} 271}
@@ -282,32 +284,32 @@ main (int argc,
282{ 284{
283 struct GNUNET_GETOPT_CommandLineOption options[] = { 285 struct GNUNET_GETOPT_CommandLineOption options[] = {
284 GNUNET_GETOPT_option_flag ('f', 286 GNUNET_GETOPT_option_flag ('f',
285 "filename", 287 "filename",
286 gettext_noop ("obtain option of value as a filename (with $-expansion)"), 288 gettext_noop ("interpret option value as a filename (with $-expansion)"),
287 &is_filename), 289 &is_filename),
288 GNUNET_GETOPT_option_string ('s', 290 GNUNET_GETOPT_option_string ('s',
289 "section", 291 "section",
290 "SECTION", 292 "SECTION",
291 gettext_noop ("name of the section to access"), 293 gettext_noop ("name of the section to access"),
292 &section), 294 &section),
293 GNUNET_GETOPT_option_string ('o', 295 GNUNET_GETOPT_option_string ('o',
294 "option", 296 "option",
295 "OPTION", 297 "OPTION",
296 gettext_noop ("name of the option to access"), 298 gettext_noop ("name of the option to access"),
297 &option), 299 &option),
298 GNUNET_GETOPT_option_string ('V', 300 GNUNET_GETOPT_option_string ('V',
299 "value", 301 "value",
300 "VALUE", 302 "VALUE",
301 gettext_noop ("value to set"), 303 gettext_noop ("value to set"),
302 &value), 304 &value),
303 GNUNET_GETOPT_option_flag ('S', 305 GNUNET_GETOPT_option_flag ('S',
304 "list-sections", 306 "list-sections",
305 gettext_noop ("print available configuration sections"), 307 gettext_noop ("print available configuration sections"),
306 &list_sections), 308 &list_sections),
307 GNUNET_GETOPT_option_flag ('w', 309 GNUNET_GETOPT_option_flag ('w',
308 "rewrite", 310 "rewrite",
309 gettext_noop ("write configuration file that only contains delta to defaults"), 311 gettext_noop ("write configuration file that only contains delta to defaults"),
310 &rewrite), 312 &rewrite),
311 GNUNET_GETOPT_OPTION_END 313 GNUNET_GETOPT_OPTION_END
312 }; 314 };
313 if (GNUNET_OK != 315 if (GNUNET_OK !=
@@ -316,12 +318,12 @@ main (int argc,
316 return 2; 318 return 2;
317 319
318 ret = (GNUNET_OK == 320 ret = (GNUNET_OK ==
319 GNUNET_PROGRAM_run (argc, 321 GNUNET_PROGRAM_run (argc,
320 argv, 322 argv,
321 "gnunet-config [OPTIONS]", 323 "gnunet-config [OPTIONS]",
322 gettext_noop ("Manipulate GNUnet configuration files"), 324 gettext_noop ("Manipulate GNUnet configuration files"),
323 options, 325 options,
324 &run, NULL)) ? 0 : ret; 326 &run, NULL)) ? 0 : ret;
325 GNUNET_free ((void*) argv); 327 GNUNET_free ((void*) argv);
326 return ret; 328 return ret;
327} 329}