diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-09-05 16:58:55 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-09-05 16:59:04 +0200 |
commit | b4e034d9aa471c6244718914e08be3ee414b18e6 (patch) | |
tree | d92d932db4a769eeb5780a91abcc8601ff31a503 /src/util | |
parent | 00c03c7bb03f7ecae5b082eadf05a9bb29b0b957 (diff) | |
download | gnunet-b4e034d9aa471c6244718914e08be3ee414b18e6.tar.gz gnunet-b4e034d9aa471c6244718914e08be3ee414b18e6.zip |
refactor gnunet-config to make preload hacks obsolete
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 1 | ||||
-rw-r--r-- | src/util/configuration_helper.c | 316 | ||||
-rw-r--r-- | src/util/gnunet-config.c | 386 |
3 files changed, 334 insertions, 369 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 6d5307235..a3a77073e 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am | |||
@@ -49,6 +49,7 @@ libgnunetutil_la_SOURCES = \ | |||
49 | common_endian.c \ | 49 | common_endian.c \ |
50 | common_logging.c \ | 50 | common_logging.c \ |
51 | configuration.c \ | 51 | configuration.c \ |
52 | configuration_helper.c \ | ||
52 | consttime_memcmp.c \ | 53 | consttime_memcmp.c \ |
53 | container_bloomfilter.c \ | 54 | container_bloomfilter.c \ |
54 | container_heap.c \ | 55 | container_heap.c \ |
diff --git a/src/util/configuration_helper.c b/src/util/configuration_helper.c new file mode 100644 index 000000000..eb8b543d1 --- /dev/null +++ b/src/util/configuration_helper.c | |||
@@ -0,0 +1,316 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2006, 2007, 2008, 2009, 2013, 2020, 2021 GNUnet e.V. | ||
4 | |||
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. | ||
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 | Affero General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Affero General Public License | ||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | |||
18 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @file src/util/configuration_helper.c | ||
22 | * @brief helper logic for gnunet-config | ||
23 | * @author Christian Grothoff | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | #include "gnunet_util_lib.h" | ||
27 | |||
28 | /** | ||
29 | * Print each option in a given section as a filename. | ||
30 | * | ||
31 | * @param cls closure | ||
32 | * @param section name of the section | ||
33 | * @param option name of the option | ||
34 | * @param value value of the option | ||
35 | */ | ||
36 | static void | ||
37 | print_filename_option (void *cls, | ||
38 | const char *section, | ||
39 | const char *option, | ||
40 | const char *value) | ||
41 | { | ||
42 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
43 | |||
44 | char *value_fn; | ||
45 | char *fn; | ||
46 | |||
47 | GNUNET_assert (GNUNET_OK == | ||
48 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
49 | section, | ||
50 | option, | ||
51 | &value_fn)); | ||
52 | fn = GNUNET_STRINGS_filename_expand (value_fn); | ||
53 | if (NULL == fn) | ||
54 | fn = value_fn; | ||
55 | else | ||
56 | GNUNET_free (value_fn); | ||
57 | fprintf (stdout, | ||
58 | "%s = %s\n", | ||
59 | option, | ||
60 | fn); | ||
61 | GNUNET_free (fn); | ||
62 | } | ||
63 | |||
64 | |||
65 | /** | ||
66 | * Print each option in a given section. | ||
67 | * | ||
68 | * @param cls closure | ||
69 | * @param section name of the section | ||
70 | * @param option name of the option | ||
71 | * @param value value of the option | ||
72 | */ | ||
73 | static void | ||
74 | print_option (void *cls, | ||
75 | const char *section, | ||
76 | const char *option, | ||
77 | const char *value) | ||
78 | { | ||
79 | (void) cls; | ||
80 | (void) section; | ||
81 | |||
82 | fprintf (stdout, | ||
83 | "%s = %s\n", | ||
84 | option, | ||
85 | value); | ||
86 | } | ||
87 | |||
88 | |||
89 | /** | ||
90 | * Print out given section name. | ||
91 | * | ||
92 | * @param cls unused | ||
93 | * @param section a section in the configuration file | ||
94 | */ | ||
95 | static void | ||
96 | print_section_name (void *cls, | ||
97 | const char *section) | ||
98 | { | ||
99 | (void) cls; | ||
100 | fprintf (stdout, | ||
101 | "%s\n", | ||
102 | section); | ||
103 | } | ||
104 | |||
105 | |||
106 | void | ||
107 | GNUNET_CONFIGURATION_config_tool_run ( | ||
108 | void *cls, | ||
109 | char *const *args, | ||
110 | const char *cfgfile, | ||
111 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
112 | { | ||
113 | struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls; | ||
114 | struct GNUNET_CONFIGURATION_Handle *out = NULL; | ||
115 | struct GNUNET_CONFIGURATION_Handle *ncfg = NULL; | ||
116 | |||
117 | (void) args; | ||
118 | if (NULL != cs->backend_check) | ||
119 | { | ||
120 | char *name; | ||
121 | |||
122 | GNUNET_asprintf (&name, | ||
123 | "libgnunet_plugin_%s", | ||
124 | cs->backend_check); | ||
125 | cs->global_ret = (GNUNET_OK == | ||
126 | GNUNET_PLUGIN_test (name)) ? 0 : 77; | ||
127 | GNUNET_free (name); | ||
128 | return; | ||
129 | } | ||
130 | |||
131 | if (cs->diagnostics) | ||
132 | { | ||
133 | /* Re-parse the configuration with diagnostics enabled. */ | ||
134 | ncfg = GNUNET_CONFIGURATION_create (); | ||
135 | GNUNET_CONFIGURATION_enable_diagnostics (ncfg); | ||
136 | GNUNET_CONFIGURATION_load (ncfg, | ||
137 | cfgfile); | ||
138 | cfg = ncfg; | ||
139 | } | ||
140 | |||
141 | if (cs->full) | ||
142 | cs->rewrite = GNUNET_YES; | ||
143 | if (cs->list_sections) | ||
144 | { | ||
145 | fprintf (stderr, | ||
146 | _ ("The following sections are available:\n")); | ||
147 | GNUNET_CONFIGURATION_iterate_sections (cfg, | ||
148 | &print_section_name, | ||
149 | NULL); | ||
150 | return; | ||
151 | } | ||
152 | if ( (! cs->rewrite) && | ||
153 | (NULL == cs->section) ) | ||
154 | { | ||
155 | char *serialization; | ||
156 | |||
157 | if (! cs->diagnostics) | ||
158 | { | ||
159 | fprintf (stderr, | ||
160 | _ ("%s, %s or %s argument is required\n"), | ||
161 | "--section", | ||
162 | "--list-sections", | ||
163 | "--diagnostics"); | ||
164 | cs->global_ret = EXIT_INVALIDARGUMENT; | ||
165 | return; | ||
166 | } | ||
167 | serialization = GNUNET_CONFIGURATION_serialize_diagnostics (cfg); | ||
168 | fprintf (stdout, | ||
169 | "%s", | ||
170 | serialization); | ||
171 | GNUNET_free (serialization); | ||
172 | } | ||
173 | else if ( (NULL != cs->section) && | ||
174 | (NULL == cs->value) ) | ||
175 | { | ||
176 | if (NULL == cs->option) | ||
177 | { | ||
178 | GNUNET_CONFIGURATION_iterate_section_values ( | ||
179 | cfg, | ||
180 | cs->section, | ||
181 | cs->is_filename | ||
182 | ? &print_filename_option | ||
183 | : &print_option, | ||
184 | (void *) cfg); | ||
185 | } | ||
186 | else | ||
187 | { | ||
188 | char *value; | ||
189 | |||
190 | if (cs->is_filename) | ||
191 | { | ||
192 | if (GNUNET_OK != | ||
193 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
194 | cs->section, | ||
195 | cs->option, | ||
196 | &value)) | ||
197 | { | ||
198 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
199 | cs->section, | ||
200 | cs->option); | ||
201 | cs->global_ret = EXIT_NOTCONFIGURED; | ||
202 | return; | ||
203 | } | ||
204 | } | ||
205 | else | ||
206 | { | ||
207 | if (GNUNET_OK != | ||
208 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
209 | cs->section, | ||
210 | cs->option, | ||
211 | &value)) | ||
212 | { | ||
213 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
214 | cs->section, | ||
215 | cs->option); | ||
216 | cs->global_ret = EXIT_NOTCONFIGURED; | ||
217 | return; | ||
218 | } | ||
219 | } | ||
220 | fprintf (stdout, | ||
221 | "%s\n", | ||
222 | value); | ||
223 | GNUNET_free (value); | ||
224 | } | ||
225 | } | ||
226 | else if (NULL != cs->section) | ||
227 | { | ||
228 | if (NULL == cs->option) | ||
229 | { | ||
230 | fprintf (stderr, | ||
231 | _ ("--option argument required to set value\n")); | ||
232 | cs->global_ret = EXIT_INVALIDARGUMENT; | ||
233 | return; | ||
234 | } | ||
235 | out = GNUNET_CONFIGURATION_dup (cfg); | ||
236 | GNUNET_CONFIGURATION_set_value_string (out, | ||
237 | cs->section, | ||
238 | cs->option, | ||
239 | cs->value); | ||
240 | cs->rewrite = GNUNET_YES; | ||
241 | } | ||
242 | if (cs->rewrite) | ||
243 | { | ||
244 | char *cfg_fn = NULL; | ||
245 | |||
246 | if (NULL == out) | ||
247 | out = GNUNET_CONFIGURATION_dup (cfg); | ||
248 | |||
249 | if (NULL == cfgfile) | ||
250 | { | ||
251 | const char *xdg = getenv ("XDG_CONFIG_HOME"); | ||
252 | |||
253 | if (NULL != xdg) | ||
254 | GNUNET_asprintf (&cfg_fn, | ||
255 | "%s%s%s", | ||
256 | xdg, | ||
257 | DIR_SEPARATOR_STR, | ||
258 | GNUNET_OS_project_data_get ()->config_file); | ||
259 | else | ||
260 | cfg_fn = GNUNET_strdup ( | ||
261 | GNUNET_OS_project_data_get ()->user_config_file); | ||
262 | cfgfile = cfg_fn; | ||
263 | } | ||
264 | |||
265 | if (! cs->full) | ||
266 | { | ||
267 | struct GNUNET_CONFIGURATION_Handle *def; | ||
268 | |||
269 | def = GNUNET_CONFIGURATION_create (); | ||
270 | if (GNUNET_OK != | ||
271 | GNUNET_CONFIGURATION_load (def, | ||
272 | NULL)) | ||
273 | { | ||
274 | fprintf (stderr, | ||
275 | _ ("failed to load configuration defaults")); | ||
276 | cs->global_ret = 1; | ||
277 | GNUNET_CONFIGURATION_destroy (def); | ||
278 | GNUNET_CONFIGURATION_destroy (out); | ||
279 | GNUNET_free (cfg_fn); | ||
280 | return; | ||
281 | } | ||
282 | if (GNUNET_OK != | ||
283 | GNUNET_CONFIGURATION_write_diffs (def, | ||
284 | out, | ||
285 | cfgfile)) | ||
286 | cs->global_ret = 2; | ||
287 | GNUNET_CONFIGURATION_destroy (def); | ||
288 | } | ||
289 | else | ||
290 | { | ||
291 | if (GNUNET_OK != | ||
292 | GNUNET_CONFIGURATION_write (out, | ||
293 | cfgfile)) | ||
294 | cs->global_ret = 2; | ||
295 | } | ||
296 | GNUNET_free (cfg_fn); | ||
297 | } | ||
298 | if (NULL != out) | ||
299 | GNUNET_CONFIGURATION_destroy (out); | ||
300 | if (NULL != ncfg) | ||
301 | GNUNET_CONFIGURATION_destroy (ncfg); | ||
302 | } | ||
303 | |||
304 | |||
305 | void | ||
306 | GNUNET_CONFIGURATION_config_settings_free ( | ||
307 | struct GNUNET_CONFIGURATION_ConfigSettings *cs) | ||
308 | { | ||
309 | GNUNET_free (cs->option); | ||
310 | GNUNET_free (cs->section); | ||
311 | GNUNET_free (cs->value); | ||
312 | GNUNET_free (cs->backend_check); | ||
313 | } | ||
314 | |||
315 | |||
316 | /* end of configuration_helper.c */ | ||
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 807df0d74..202ef7866 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2012 GNUnet e.V. | 3 | Copyright (C) 2012-2021 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 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 | 6 | under the terms of the GNU Affero General Public License as published |
@@ -28,313 +28,6 @@ | |||
28 | 28 | ||
29 | 29 | ||
30 | /** | 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 | * Backend to check if the respective plugin is | ||
47 | * loadable. NULL if no check is to be performed. | ||
48 | * The value is the "basename" of the plugin to load. | ||
49 | */ | ||
50 | static char *backend_check; | ||
51 | |||
52 | /** | ||
53 | * Treat option as a filename. | ||
54 | */ | ||
55 | static int is_filename; | ||
56 | |||
57 | /** | ||
58 | * Whether to show the sections. | ||
59 | */ | ||
60 | static int list_sections; | ||
61 | |||
62 | /** | ||
63 | * Return value from 'main'. | ||
64 | */ | ||
65 | static int global_ret; | ||
66 | |||
67 | /** | ||
68 | * Should we write out the configuration file, even if no value was changed? | ||
69 | */ | ||
70 | static int rewrite; | ||
71 | |||
72 | /** | ||
73 | * Should we give extra diagnostics? | ||
74 | */ | ||
75 | static int diagnostics; | ||
76 | |||
77 | |||
78 | /** | ||
79 | * Should the generated configuration file contain the whole configuration? | ||
80 | */ | ||
81 | static int full; | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Print each option in a given section. | ||
86 | * | ||
87 | * @param cls closure | ||
88 | * @param section name of the section | ||
89 | * @param option name of the option | ||
90 | * @param value value of the option | ||
91 | */ | ||
92 | static void | ||
93 | print_option (void *cls, | ||
94 | const char *section, | ||
95 | const char *option, | ||
96 | const char *value) | ||
97 | { | ||
98 | const struct GNUNET_CONFIGURATION_Handle *cfg = cls; | ||
99 | |||
100 | (void) section; | ||
101 | if (is_filename) | ||
102 | { | ||
103 | char *value_fn; | ||
104 | char *fn; | ||
105 | |||
106 | GNUNET_assert (GNUNET_OK == | ||
107 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
108 | section, | ||
109 | option, | ||
110 | &value_fn)); | ||
111 | fn = GNUNET_STRINGS_filename_expand (value_fn); | ||
112 | if (NULL == fn) | ||
113 | fn = value_fn; | ||
114 | else | ||
115 | GNUNET_free (value_fn); | ||
116 | fprintf (stdout, "%s = %s\n", option, fn); | ||
117 | GNUNET_free (fn); | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | fprintf (stdout, "%s = %s\n", option, value); | ||
122 | } | ||
123 | } | ||
124 | |||
125 | |||
126 | /** | ||
127 | * Print out given section name. | ||
128 | * | ||
129 | * @param cls unused | ||
130 | * @param section a section in the configuration file | ||
131 | */ | ||
132 | static void | ||
133 | print_section_name (void *cls, const char *section) | ||
134 | { | ||
135 | (void) cls; | ||
136 | fprintf (stdout, "%s\n", section); | ||
137 | } | ||
138 | |||
139 | |||
140 | /** | ||
141 | * Main function that will be run by the scheduler. | ||
142 | * | ||
143 | * @param cls closure | ||
144 | * @param args remaining command-line arguments | ||
145 | * @param cfgfile name of the configuration file used (for saving, | ||
146 | * can be NULL!) | ||
147 | * @param cfg configuration | ||
148 | */ | ||
149 | static void | ||
150 | run (void *cls, | ||
151 | char *const *args, | ||
152 | const char *cfgfile, | ||
153 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
154 | { | ||
155 | struct GNUNET_CONFIGURATION_Handle *out = NULL; | ||
156 | |||
157 | (void) cls; | ||
158 | (void) args; | ||
159 | if (NULL != backend_check) | ||
160 | { | ||
161 | char *name; | ||
162 | |||
163 | GNUNET_asprintf (&name, | ||
164 | "libgnunet_plugin_%s", | ||
165 | backend_check); | ||
166 | global_ret = (GNUNET_OK == | ||
167 | GNUNET_PLUGIN_test (name)) ? 0 : 77; | ||
168 | GNUNET_free (name); | ||
169 | return; | ||
170 | } | ||
171 | |||
172 | if (diagnostics) | ||
173 | { | ||
174 | struct GNUNET_CONFIGURATION_Handle *ncfg; | ||
175 | /* Re-parse the configuration with diagnostics enabled. */ | ||
176 | ncfg = GNUNET_CONFIGURATION_create (); | ||
177 | GNUNET_CONFIGURATION_enable_diagnostics (ncfg); | ||
178 | GNUNET_CONFIGURATION_load (ncfg, cfgfile); | ||
179 | cfg = ncfg; | ||
180 | } | ||
181 | |||
182 | if (full) | ||
183 | rewrite = GNUNET_YES; | ||
184 | if (list_sections) | ||
185 | { | ||
186 | fprintf (stderr, | ||
187 | _ ("The following sections are available:\n")); | ||
188 | GNUNET_CONFIGURATION_iterate_sections (cfg, | ||
189 | &print_section_name, | ||
190 | NULL); | ||
191 | return; | ||
192 | } | ||
193 | if ( (! rewrite) && | ||
194 | (NULL == section) ) | ||
195 | { | ||
196 | char *serialization; | ||
197 | |||
198 | if (! diagnostics) | ||
199 | { | ||
200 | fprintf (stderr, | ||
201 | _ ("%s, %s or %s argument is required\n"), | ||
202 | "--section", | ||
203 | "--list-sections", | ||
204 | "--diagnostics"); | ||
205 | global_ret = 1; | ||
206 | return; | ||
207 | } | ||
208 | serialization = GNUNET_CONFIGURATION_serialize_diagnostics (cfg); | ||
209 | fprintf (stdout, | ||
210 | "%s", | ||
211 | serialization); | ||
212 | GNUNET_free (serialization); | ||
213 | } | ||
214 | else if ( (NULL != section) && | ||
215 | (NULL == value) ) | ||
216 | { | ||
217 | if (NULL == option) | ||
218 | { | ||
219 | GNUNET_CONFIGURATION_iterate_section_values (cfg, | ||
220 | section, | ||
221 | &print_option, | ||
222 | (void *) cfg); | ||
223 | } | ||
224 | else | ||
225 | { | ||
226 | if (is_filename) | ||
227 | { | ||
228 | if (GNUNET_OK != | ||
229 | GNUNET_CONFIGURATION_get_value_filename (cfg, | ||
230 | section, | ||
231 | option, | ||
232 | &value)) | ||
233 | { | ||
234 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
235 | section, | ||
236 | option); | ||
237 | global_ret = 3; | ||
238 | return; | ||
239 | } | ||
240 | } | ||
241 | else | ||
242 | { | ||
243 | if (GNUNET_OK != | ||
244 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
245 | section, | ||
246 | option, | ||
247 | &value)) | ||
248 | { | ||
249 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | ||
250 | section, | ||
251 | option); | ||
252 | global_ret = 3; | ||
253 | return; | ||
254 | } | ||
255 | } | ||
256 | fprintf (stdout, | ||
257 | "%s\n", | ||
258 | value); | ||
259 | } | ||
260 | } | ||
261 | else if (NULL != section) | ||
262 | { | ||
263 | if (NULL == option) | ||
264 | { | ||
265 | fprintf (stderr, | ||
266 | _ ("--option argument required to set value\n")); | ||
267 | global_ret = 1; | ||
268 | return; | ||
269 | } | ||
270 | out = GNUNET_CONFIGURATION_dup (cfg); | ||
271 | GNUNET_CONFIGURATION_set_value_string (out, | ||
272 | section, | ||
273 | option, | ||
274 | value); | ||
275 | rewrite = GNUNET_YES; | ||
276 | } | ||
277 | if (rewrite) | ||
278 | { | ||
279 | char *cfg_fn = NULL; | ||
280 | |||
281 | if (NULL == out) | ||
282 | out = GNUNET_CONFIGURATION_dup (cfg); | ||
283 | |||
284 | if (NULL == cfgfile) | ||
285 | { | ||
286 | const char *xdg = getenv ("XDG_CONFIG_HOME"); | ||
287 | if (NULL != xdg) | ||
288 | GNUNET_asprintf (&cfg_fn, | ||
289 | "%s%s%s", | ||
290 | xdg, | ||
291 | DIR_SEPARATOR_STR, | ||
292 | GNUNET_OS_project_data_get ()->config_file); | ||
293 | else | ||
294 | cfg_fn = GNUNET_strdup ( | ||
295 | GNUNET_OS_project_data_get ()->user_config_file); | ||
296 | cfgfile = cfg_fn; | ||
297 | } | ||
298 | |||
299 | if (! full) | ||
300 | { | ||
301 | struct GNUNET_CONFIGURATION_Handle *def; | ||
302 | |||
303 | def = GNUNET_CONFIGURATION_create (); | ||
304 | if (GNUNET_OK != | ||
305 | GNUNET_CONFIGURATION_load (def, | ||
306 | NULL)) | ||
307 | { | ||
308 | fprintf (stderr, | ||
309 | _ ("failed to load configuration defaults")); | ||
310 | global_ret = 1; | ||
311 | GNUNET_CONFIGURATION_destroy (def); | ||
312 | GNUNET_CONFIGURATION_destroy (out); | ||
313 | GNUNET_free (cfg_fn); | ||
314 | return; | ||
315 | } | ||
316 | if (GNUNET_OK != | ||
317 | GNUNET_CONFIGURATION_write_diffs (def, | ||
318 | out, | ||
319 | cfgfile)) | ||
320 | global_ret = 2; | ||
321 | GNUNET_CONFIGURATION_destroy (def); | ||
322 | } | ||
323 | else | ||
324 | { | ||
325 | if (GNUNET_OK != | ||
326 | GNUNET_CONFIGURATION_write (out, | ||
327 | cfgfile)) | ||
328 | global_ret = 2; | ||
329 | } | ||
330 | GNUNET_free (cfg_fn); | ||
331 | } | ||
332 | if (NULL != out) | ||
333 | GNUNET_CONFIGURATION_destroy (out); | ||
334 | } | ||
335 | |||
336 | |||
337 | /** | ||
338 | * Program to manipulate configuration files. | 31 | * Program to manipulate configuration files. |
339 | * | 32 | * |
340 | * @param argc number of arguments from the command line | 33 | * @param argc number of arguments from the command line |
@@ -342,82 +35,37 @@ run (void *cls, | |||
342 | * @return 0 ok, 1 on error | 35 | * @return 0 ok, 1 on error |
343 | */ | 36 | */ |
344 | int | 37 | int |
345 | main (int argc, char *const *argv) | 38 | main (int argc, |
39 | char *const *argv) | ||
346 | { | 40 | { |
41 | struct GNUNET_CONFIGURATION_ConfigSettings cs = { | ||
42 | .global_ret = EXIT_SUCCESS | ||
43 | }; | ||
347 | struct GNUNET_GETOPT_CommandLineOption options[] = { | 44 | struct GNUNET_GETOPT_CommandLineOption options[] = { |
348 | GNUNET_GETOPT_option_exclusive ( | 45 | GNUNET_CONFIGURATION_CONFIG_OPTIONS (&cs), |
349 | GNUNET_GETOPT_option_string ( | ||
350 | 'b', | ||
351 | "supported-backend", | ||
352 | "BACKEND", | ||
353 | gettext_noop ( | ||
354 | "test if the current installation supports the specified BACKEND"), | ||
355 | &backend_check)), | ||
356 | GNUNET_GETOPT_option_flag ( | ||
357 | 'F', | ||
358 | "full", | ||
359 | gettext_noop ( | ||
360 | "write the full configuration file, including default values"), | ||
361 | &full), | ||
362 | GNUNET_GETOPT_option_flag ( | ||
363 | 'f', | ||
364 | "filename", | ||
365 | gettext_noop ("interpret option value as a filename (with $-expansion)"), | ||
366 | &is_filename), | ||
367 | GNUNET_GETOPT_option_string ('o', | ||
368 | "option", | ||
369 | "OPTION", | ||
370 | gettext_noop ("name of the option to access"), | ||
371 | &option), | ||
372 | GNUNET_GETOPT_option_flag ( | ||
373 | 'r', | ||
374 | "rewrite", | ||
375 | gettext_noop ( | ||
376 | "rewrite the configuration file, even if nothing changed"), | ||
377 | &rewrite), | ||
378 | GNUNET_GETOPT_option_flag ( | ||
379 | 'd', | ||
380 | "diagnostics", | ||
381 | gettext_noop ( | ||
382 | "output extra diagnostics"), | ||
383 | &diagnostics), | ||
384 | GNUNET_GETOPT_option_flag ('S', | ||
385 | "list-sections", | ||
386 | gettext_noop ( | ||
387 | "print available configuration sections"), | ||
388 | &list_sections), | ||
389 | GNUNET_GETOPT_option_string ('s', | ||
390 | "section", | ||
391 | "SECTION", | ||
392 | gettext_noop ( | ||
393 | "name of the section to access"), | ||
394 | §ion), | ||
395 | GNUNET_GETOPT_option_string ('V', | ||
396 | "value", | ||
397 | "VALUE", | ||
398 | gettext_noop ("value to set"), | ||
399 | &value), | ||
400 | GNUNET_GETOPT_OPTION_END | 46 | GNUNET_GETOPT_OPTION_END |
401 | }; | 47 | }; |
402 | int ret; | 48 | enum GNUNET_GenericReturnValue ret; |
403 | 49 | ||
404 | if (GNUNET_OK != | 50 | if (GNUNET_OK != |
405 | GNUNET_STRINGS_get_utf8_args (argc, argv, | 51 | GNUNET_STRINGS_get_utf8_args (argc, argv, |
406 | &argc, &argv)) | 52 | &argc, &argv)) |
407 | return 2; | 53 | return EXIT_FAILURE; |
408 | |||
409 | ret = | 54 | ret = |
410 | GNUNET_PROGRAM_run (argc, | 55 | GNUNET_PROGRAM_run (argc, |
411 | argv, | 56 | argv, |
412 | "gnunet-config [OPTIONS]", | 57 | "gnunet-config [OPTIONS]", |
413 | gettext_noop ("Manipulate GNUnet configuration files"), | 58 | gettext_noop ("Manipulate GNUnet configuration files"), |
414 | options, | 59 | options, |
415 | &run, | 60 | &GNUNET_CONFIGURATION_config_tool_run, |
416 | NULL); | 61 | &cs); |
417 | GNUNET_free_nz ((void *) argv); | 62 | GNUNET_free_nz ((void *) argv); |
418 | if (GNUNET_OK == ret) | 63 | GNUNET_CONFIGURATION_config_settings_free (&cs); |
419 | return global_ret; | 64 | if (GNUNET_NO == ret) |
420 | return ret; | 65 | return 0; |
66 | if (GNUNET_SYSERR == ret) | ||
67 | return EXIT_INVALIDARGUMENT; | ||
68 | return cs.global_ret; | ||
421 | } | 69 | } |
422 | 70 | ||
423 | 71 | ||