2 This file is part of GNUnet.
3 (C) 2012 Christian Grothoff (and other contributing authors)
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., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, 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 * Return value from 'main'.
57 * Print each option in a given section.
60 * @param section name of the section
61 * @param option name of the option
62 * @param value value of the option
65 print_option (void *cls, const char *section,
70 "%s = %s\n", option, value);
75 * Main function that will be run by the scheduler.
78 * @param args remaining command-line arguments
79 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
80 * @param cfg configuration
83 run (void *cls, char *const *args, const char *cfgfile,
84 const struct GNUNET_CONFIGURATION_Handle *cfg)
86 struct GNUNET_CONFIGURATION_Handle *out;
90 fprintf (stderr, _("--section argument is required\n"));
99 GNUNET_CONFIGURATION_iterate_section_values (cfg, section,
100 &print_option, NULL);
107 GNUNET_CONFIGURATION_get_value_filename (cfg, section, option, &value))
109 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
118 GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &value))
120 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
126 fprintf (stdout, "%s\n", value);
133 fprintf (stderr, _("--option argument required to set value\n"));
137 out = GNUNET_CONFIGURATION_dup (cfg);
138 GNUNET_CONFIGURATION_set_value_string (out, section, option, value);
140 GNUNET_CONFIGURATION_write (out, cfgfile))
142 GNUNET_CONFIGURATION_destroy (out);
149 * Program to manipulate configuration files.
151 * @param argc number of arguments from the command line
152 * @param argv command line arguments
153 * @return 0 ok, 1 on error
156 main (int argc, char *const *argv)
158 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
159 { 'f', "filename", NULL,
160 gettext_noop ("obtain option of value as a filename (with $-expansion)"),
161 0, &GNUNET_GETOPT_set_one, &is_filename },
162 { 's', "section", "SECTION",
163 gettext_noop ("name of the section to access"),
164 1, &GNUNET_GETOPT_set_string, §ion },
165 { 'o', "option", "OPTION",
166 gettext_noop ("name of the option to access"),
167 1, &GNUNET_GETOPT_set_string, &option },
168 { 'V', "value", "VALUE",
169 gettext_noop ("value to set"),
170 1, &GNUNET_GETOPT_set_string, &value },
171 GNUNET_GETOPT_OPTION_END
173 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
177 GNUNET_PROGRAM_run (argc, argv, "gnunet-config [OPTIONS]",
178 gettext_noop ("Manipulate GNUnet configuration files"),
179 options, &run, NULL)) ? 0 : ret;
180 GNUNET_free ((void*) argv);
184 /* end of gnunet-config.c */