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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file util/gnunet-config.c
23 * @brief tool to access and manipulate GNUnet configuration files
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
46 * Treat option as a filename.
48 static int is_filename;
51 * Whether to show the sections.
53 static int list_sections;
56 * Return value from 'main'.
61 * Should we generate a configuration file that is clean and
62 * only contains the deltas to the defaults?
67 * Print each option in a given section.
70 * @param section name of the section
71 * @param option name of the option
72 * @param value value of the option
75 print_option (void *cls,
90 * Print out given section name.
93 * @param section a section in the configuration file
96 print_section_name (void *cls,
107 * Main function that will be run by the scheduler.
110 * @param args remaining command-line arguments
111 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
112 * @param cfg configuration
118 const struct GNUNET_CONFIGURATION_Handle *cfg)
120 struct GNUNET_CONFIGURATION_Handle *out = NULL;
121 struct GNUNET_CONFIGURATION_Handle *diff = NULL;
127 struct GNUNET_CONFIGURATION_Handle *def;
129 def = GNUNET_CONFIGURATION_create ();
131 GNUNET_CONFIGURATION_load (def, NULL))
134 _("failed to load configuration defaults"));
138 diff = GNUNET_CONFIGURATION_get_diff (def,
142 if ( ((! rewrite) && (NULL == section)) || list_sections)
147 _("--section argument is required\n"));
150 _("The following sections are available:\n"));
151 GNUNET_CONFIGURATION_iterate_sections (cfg,
158 if ( (NULL != section) && (NULL == value) )
162 GNUNET_CONFIGURATION_iterate_section_values (cfg,
172 GNUNET_CONFIGURATION_get_value_filename (cfg,
177 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
186 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &value))
188 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
194 fprintf (stdout, "%s\n", value);
197 else if (NULL != section)
201 fprintf (stderr, _("--option argument required to set value\n"));
205 out = GNUNET_CONFIGURATION_dup (cfg);
206 GNUNET_CONFIGURATION_set_value_string (out,
211 if ( (NULL != diff) || (NULL != out) )
214 GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out,
219 GNUNET_CONFIGURATION_destroy (out);
222 GNUNET_CONFIGURATION_destroy (diff);
227 * Program to manipulate configuration files.
229 * @param argc number of arguments from the command line
230 * @param argv command line arguments
231 * @return 0 ok, 1 on error
237 struct GNUNET_GETOPT_CommandLineOption options[] = {
238 GNUNET_GETOPT_option_flag ('f',
240 gettext_noop ("obtain option of value as a filename (with $-expansion)"),
242 GNUNET_GETOPT_option_string ('s',
245 gettext_noop ("name of the section to access"),
247 GNUNET_GETOPT_option_string ('o',
250 gettext_noop ("name of the option to access"),
252 GNUNET_GETOPT_option_string ('V',
255 gettext_noop ("value to set"),
257 GNUNET_GETOPT_option_flag ('S',
259 gettext_noop ("print available configuration sections"),
261 GNUNET_GETOPT_option_flag ('w',
263 gettext_noop ("write configuration file that only contains delta to defaults"),
265 GNUNET_GETOPT_OPTION_END
268 GNUNET_STRINGS_get_utf8_args (argc, argv,
273 GNUNET_PROGRAM_run (argc,
275 "gnunet-config [OPTIONS]",
276 gettext_noop ("Manipulate GNUnet configuration files"),
278 &run, NULL)) ? 0 : ret;
279 GNUNET_free ((void*) argv);
283 /* end of gnunet-config.c */