2 This file is part of GNUnet.
3 Copyright (C) 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
17 * @file util/gnunet-config.c
18 * @brief tool to access and manipulate GNUnet configuration files
19 * @author Christian Grothoff
22 #include "gnunet_util_lib.h"
41 * Treat option as a filename.
43 static int is_filename;
46 * Whether to show the sections.
48 static int list_sections;
51 * Return value from 'main'.
56 * Should we generate a configuration file that is clean and
57 * only contains the deltas to the defaults?
62 * Print each option in a given section.
65 * @param section name of the section
66 * @param option name of the option
67 * @param value value of the option
70 print_option (void *cls,
85 * Print out given section name.
88 * @param section a section in the configuration file
91 print_section_name (void *cls,
102 * Main function that will be run by the scheduler.
105 * @param args remaining command-line arguments
106 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
107 * @param cfg configuration
113 const struct GNUNET_CONFIGURATION_Handle *cfg)
115 struct GNUNET_CONFIGURATION_Handle *out = NULL;
116 struct GNUNET_CONFIGURATION_Handle *diff = NULL;
122 struct GNUNET_CONFIGURATION_Handle *def;
124 def = GNUNET_CONFIGURATION_create ();
126 GNUNET_CONFIGURATION_load (def, NULL))
129 _("failed to load configuration defaults"));
133 diff = GNUNET_CONFIGURATION_get_diff (def,
137 if ( ((! rewrite) && (NULL == section)) || list_sections)
142 _("--section argument is required\n"));
145 _("The following sections are available:\n"));
146 GNUNET_CONFIGURATION_iterate_sections (cfg,
153 if ( (NULL != section) && (NULL == value) )
157 GNUNET_CONFIGURATION_iterate_section_values (cfg,
167 GNUNET_CONFIGURATION_get_value_filename (cfg,
172 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
181 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &value))
183 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
189 fprintf (stdout, "%s\n", value);
192 else if (NULL != section)
196 fprintf (stderr, _("--option argument required to set value\n"));
200 out = GNUNET_CONFIGURATION_dup (cfg);
201 GNUNET_CONFIGURATION_set_value_string (out,
206 if ( (NULL != diff) || (NULL != out) )
209 GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
214 GNUNET_CONFIGURATION_destroy (out);
217 GNUNET_CONFIGURATION_destroy (diff);
222 * Program to manipulate configuration files.
224 * @param argc number of arguments from the command line
225 * @param argv command line arguments
226 * @return 0 ok, 1 on error
232 struct GNUNET_GETOPT_CommandLineOption options[] = {
233 GNUNET_GETOPT_option_flag ('f',
235 gettext_noop ("obtain option of value as a filename (with $-expansion)"),
237 GNUNET_GETOPT_option_string ('s',
240 gettext_noop ("name of the section to access"),
242 GNUNET_GETOPT_option_string ('o',
245 gettext_noop ("name of the option to access"),
247 GNUNET_GETOPT_option_string ('V',
250 gettext_noop ("value to set"),
252 GNUNET_GETOPT_option_flag ('S',
254 gettext_noop ("print available configuration sections"),
256 GNUNET_GETOPT_option_flag ('w',
258 gettext_noop ("write configuration file that only contains delta to defaults"),
260 GNUNET_GETOPT_OPTION_END
263 GNUNET_STRINGS_get_utf8_args (argc, argv,
268 GNUNET_PROGRAM_run (argc,
270 "gnunet-config [OPTIONS]",
271 gettext_noop ("Manipulate GNUnet configuration files"),
273 &run, NULL)) ? 0 : ret;
274 GNUNET_free ((void*) argv);
278 /* end of gnunet-config.c */