diff options
-rw-r--r-- | doc/man/Makefile.am | 1 | ||||
-rw-r--r-- | doc/man/gnunet-config.1 | 43 | ||||
-rw-r--r-- | src/util/Makefile.am | 10 | ||||
-rw-r--r-- | src/util/gnunet-config.c | 183 |
4 files changed, 237 insertions, 0 deletions
diff --git a/doc/man/Makefile.am b/doc/man/Makefile.am index 4a50dec55..34ea50d21 100644 --- a/doc/man/Makefile.am +++ b/doc/man/Makefile.am | |||
@@ -1,6 +1,7 @@ | |||
1 | man_MANS = \ | 1 | man_MANS = \ |
2 | gnunet-arm.1 \ | 2 | gnunet-arm.1 \ |
3 | gnunet-auto-share.1 \ | 3 | gnunet-auto-share.1 \ |
4 | gnunet-config.1 \ | ||
4 | gnunet-core.1 \ | 5 | gnunet-core.1 \ |
5 | gnunet-directory.1 \ | 6 | gnunet-directory.1 \ |
6 | gnunet-download.1 \ | 7 | gnunet-download.1 \ |
diff --git a/doc/man/gnunet-config.1 b/doc/man/gnunet-config.1 new file mode 100644 index 000000000..3a7fa624b --- /dev/null +++ b/doc/man/gnunet-config.1 | |||
@@ -0,0 +1,43 @@ | |||
1 | .TH GNUNET\-CONFIG 1 "Jul 15, 2012" "GNUnet" | ||
2 | |||
3 | .SH NAME | ||
4 | gnunet\-config \- manipulate GNUnet configuration files | ||
5 | |||
6 | .SH SYNOPSIS | ||
7 | .B gnunet\-config | ||
8 | .RI [ options ] | ||
9 | .br | ||
10 | |||
11 | .SH DESCRIPTION | ||
12 | \fBgnunet\-config\fP can be used to read or modify GNUnet configuration files. | ||
13 | |||
14 | .SH OPTIONS | ||
15 | .B | ||
16 | .IP "\-f, \-\-filename" | ||
17 | When accessing a specific option using \-s and \-o, perform expansions as if the value represents a filename. | ||
18 | .B | ||
19 | .IP "\-s SECTION, \-\-section=SECTION" | ||
20 | Which configuration section should be accessed or edited. Required option. | ||
21 | .B | ||
22 | .IP "\-o OPTION, \-\-option=OPTION" | ||
23 | Which configuration option should be accessed or edited. Required to set a value. If not given, all values of a given section will be printed in the format "OPTION = VALUE". | ||
24 | .B | ||
25 | .IP "\-V VALUE, \-\-value VALUE" | ||
26 | Configuration value to store in the given section under the given option. Must only be given together with \-s and \-o options. | ||
27 | .B | ||
28 | .IP "\-c FILENAME, \-\-config=FILENAME" | ||
29 | Use the configuration file FILENAME. | ||
30 | .B | ||
31 | .IP "\-h, \-\-help" | ||
32 | Print short help on options. | ||
33 | .B | ||
34 | .IP "\-L LOGLEVEL, \-\-loglevel=LOGLEVEL" | ||
35 | Use LOGLEVEL for logging. Valid values are DEBUG, INFO, WARNING and ERROR. | ||
36 | .B | ||
37 | .IP "\-v, \-\-version" | ||
38 | Print GNUnet version number. | ||
39 | |||
40 | |||
41 | .SH BUGS | ||
42 | Report bugs by using Mantis <https://gnunet.org/bugs/> or by sending electronic mail to <gnunet\-developers@gnu.org> | ||
43 | |||
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 87681fd88..35b006483 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -122,6 +122,7 @@ libgnunetutil_la_LDFLAGS = \ | |||
122 | bin_PROGRAMS = \ | 122 | bin_PROGRAMS = \ |
123 | gnunet-service-resolver \ | 123 | gnunet-service-resolver \ |
124 | gnunet-resolver \ | 124 | gnunet-resolver \ |
125 | gnunet-config \ | ||
125 | gnunet-rsa \ | 126 | gnunet-rsa \ |
126 | gnunet-uri | 127 | gnunet-uri |
127 | 128 | ||
@@ -153,6 +154,15 @@ gnunet_rsa_DEPENDENCIES = \ | |||
153 | libgnunetutil.la | 154 | libgnunetutil.la |
154 | 155 | ||
155 | 156 | ||
157 | gnunet_config_SOURCES = \ | ||
158 | gnunet-config.c | ||
159 | gnunet_config_LDADD = \ | ||
160 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
161 | $(GN_LIBINTL) | ||
162 | gnunet_config_DEPENDENCIES = \ | ||
163 | libgnunetutil.la | ||
164 | |||
165 | |||
156 | gnunet_uri_SOURCES = \ | 166 | gnunet_uri_SOURCES = \ |
157 | gnunet-uri.c | 167 | gnunet-uri.c |
158 | gnunet_uri_LDADD = \ | 168 | gnunet_uri_LDADD = \ |
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c new file mode 100644 index 000000000..5c8a715de --- /dev/null +++ b/src/util/gnunet-config.c | |||
@@ -0,0 +1,183 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | (C) 2012 Christian Grothoff (and other contributing authors) | ||
4 | |||
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. | ||
9 | |||
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. | ||
14 | |||
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. | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file util/gnunet-config.c | ||
23 | * @brief tool to access and manipulate GNUnet configuration files | ||
24 | * @author Christian Grothoff | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | |||
29 | |||
30 | /** | ||
31 | * Name of the section | ||
32 | */ | ||
33 | static char *section; | ||
34 | |||
35 | /** | ||
36 | * Name of the option | ||
37 | */ | ||
38 | static char *option; | ||
39 | |||
40 | /** | ||
41 | * Value to set | ||
42 | */ | ||
43 | static char *value; | ||
44 | |||
45 | /** | ||
46 | * Treat option as a filename. | ||
47 | */ | ||
48 | static int is_filename; | ||
49 | |||
50 | /** | ||
51 | * Return value from 'main'. | ||
52 | */ | ||
53 | static int ret; | ||
54 | |||
55 | |||
56 | /** | ||
57 | * Print each option in a given section. | ||
58 | * | ||
59 | * @param cls closure | ||
60 | * @param section name of the section | ||
61 | * @param option name of the option | ||
62 | * @param value value of the option | ||
63 | */ | ||
64 | static void | ||
65 | print_option (void *cls, const char *section, | ||
66 | const char *option, | ||
67 | const char *value) | ||
68 | { | ||
69 | fprintf (stdout, | ||
70 | "%s = %s\n", option, value); | ||
71 | } | ||
72 | |||
73 | |||
74 | /** | ||
75 | * Main function that will be run by the scheduler. | ||
76 | * | ||
77 | * @param cls closure | ||
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 | ||
81 | */ | ||
82 | static void | ||
83 | run (void *cls, char *const *args, const char *cfgfile, | ||
84 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
85 | { | ||
86 | struct GNUNET_CONFIGURATION_Handle *out; | ||
87 | |||
88 | if (NULL == section) | ||
89 | { | ||
90 | fprintf (stderr, _("--section argument is required\n")); | ||
91 | ret = 1; | ||
92 | return; | ||
93 | } | ||
94 | |||
95 | if (NULL == value) | ||
96 | { | ||
97 | if (NULL == option) | ||
98 | { | ||
99 | GNUNET_CONFIGURATION_iterate_section_values (cfg, section, | ||
100 | &print_option, NULL); | ||
101 | } | ||
102 | else | ||
103 | { | ||
104 | if (is_filename) | ||
105 | { | ||
106 | if (GNUNET_OK != | ||
107 | GNUNET_CONFIGURATION_get_value_filename (cfg, section, option, &value)) | ||
108 | { | ||
109 | fprintf (stderr, _("No value for option `%s' in section `%s'\n"), | ||
110 | option, section); | ||
111 | ret = 3; | ||
112 | return; | ||
113 | } | ||
114 | } | ||
115 | else | ||
116 | { | ||
117 | if (GNUNET_OK != | ||
118 | GNUNET_CONFIGURATION_get_value_string (cfg, section, option, &value)) | ||
119 | { | ||
120 | fprintf (stderr, _("No value for option `%s' in section `%s'\n"), | ||
121 | option, section); | ||
122 | ret = 3; | ||
123 | return; | ||
124 | } | ||
125 | } | ||
126 | fprintf (stdout, "%s\n", value); | ||
127 | } | ||
128 | } | ||
129 | else | ||
130 | { | ||
131 | if (NULL == option) | ||
132 | { | ||
133 | fprintf (stderr, _("--option argument required to set value\n")); | ||
134 | ret = 1; | ||
135 | return; | ||
136 | } | ||
137 | out = GNUNET_CONFIGURATION_dup (cfg); | ||
138 | GNUNET_CONFIGURATION_set_value_string (out, section, option, value); | ||
139 | if (GNUNET_OK != | ||
140 | GNUNET_CONFIGURATION_write (out, cfgfile)) | ||
141 | ret = 2; | ||
142 | GNUNET_CONFIGURATION_destroy (out); | ||
143 | return; | ||
144 | } | ||
145 | } | ||
146 | |||
147 | |||
148 | /** | ||
149 | * The main function to obtain statistics in GNUnet. | ||
150 | * | ||
151 | * @param argc number of arguments from the command line | ||
152 | * @param argv command line arguments | ||
153 | * @return 0 ok, 1 on error | ||
154 | */ | ||
155 | int | ||
156 | main (int argc, char *const *argv) | ||
157 | { | ||
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 | ||
172 | }; | ||
173 | |||
174 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | ||
175 | return 2; | ||
176 | |||
177 | return (GNUNET_OK == | ||
178 | GNUNET_PROGRAM_run (argc, argv, "gnunet-config [OPTIONS]", | ||
179 | gettext_noop ("Manipulate GNUnet configuration files"), | ||
180 | options, &run, NULL)) ? 0 : ret; | ||
181 | } | ||
182 | |||
183 | /* end of gnunet-config.c */ | ||