aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/man/gnunet-config.111
-rw-r--r--po/POTFILES.in1
-rw-r--r--src/include/gnunet_configuration_lib.h16
-rw-r--r--src/util/gnunet-config.c249
4 files changed, 161 insertions, 116 deletions
diff --git a/doc/man/gnunet-config.1 b/doc/man/gnunet-config.1
index 3d243af89..03f180c29 100644
--- a/doc/man/gnunet-config.1
+++ b/doc/man/gnunet-config.1
@@ -1,5 +1,5 @@
1.\" This file is part of GNUnet. 1.\" This file is part of GNUnet.
2.\" Copyright (C) 2001-2019 GNUnet e.V. 2.\" Copyright (C) 2001-2021 GNUnet e.V.
3.\" 3.\"
4.\" Permission is granted to copy, distribute and/or modify this document 4.\" Permission is granted to copy, distribute and/or modify this document
5.\" under the terms of the GNU Free Documentation License, Version 1.3 or 5.\" under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -39,7 +39,8 @@
39.Op Fl s Ar SECTION | Fl -section= Ns Ar SECTION 39.Op Fl s Ar SECTION | Fl -section= Ns Ar SECTION
40.Op Fl V Ar VALUE | Fl -value Ar VALUE 40.Op Fl V Ar VALUE | Fl -value Ar VALUE
41.Op Fl v | -version 41.Op Fl v | -version
42.Op Fl w | -rewrite 42.Op Fl r | -rewrite
43.Op Fl F | -full
43.Sh DESCRIPTION 44.Sh DESCRIPTION
44.Nm 45.Nm
45can be used to read or modify GNUnet configuration files. 46can be used to read or modify GNUnet configuration files.
@@ -69,8 +70,10 @@ Configuration value to store in the given section under the given option.
69Must only be given together with -s and -o options. 70Must only be given together with -s and -o options.
70.It Fl v | -version 71.It Fl v | -version
71Print GNUnet version number. 72Print GNUnet version number.
72.It Fl w | -rewrite 73.It Fl r | -rewrite
73Write to file the full configuration, including default values, instead of just the differences. 74Write the configuration to file, even if it did not change.
75.It Fl F | -full
76Write the full configuration, not just the deltas to the defaults.
74.El 77.El
75.Sh SEE ALSO 78.Sh SEE ALSO
76The full documentation for gnunet is maintained as a Texinfo manual. 79The full documentation for gnunet is maintained as a Texinfo manual.
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 36f5e7734..3416e6c84 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -313,7 +313,6 @@ src/reclaim/plugin_rest_reclaim.c
313src/reclaim/reclaim_api.c 313src/reclaim/reclaim_api.c
314src/reclaim/reclaim_attribute.c 314src/reclaim/reclaim_attribute.c
315src/reclaim/reclaim_credential.c 315src/reclaim/reclaim_credential.c
316src/reclaim/test.c
317src/regex/gnunet-daemon-regexprofiler.c 316src/regex/gnunet-daemon-regexprofiler.c
318src/regex/gnunet-regex-profiler.c 317src/regex/gnunet-regex-profiler.c
319src/regex/gnunet-regex-simulation-profiler.c 318src/regex/gnunet-regex-simulation-profiler.c
diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h
index ad55c1b9a..21a5ab810 100644
--- a/src/include/gnunet_configuration_lib.h
+++ b/src/include/gnunet_configuration_lib.h
@@ -177,11 +177,10 @@ GNUNET_CONFIGURATION_write (struct GNUNET_CONFIGURATION_Handle *cfg,
177 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error 177 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
178 */ 178 */
179enum GNUNET_GenericReturnValue 179enum GNUNET_GenericReturnValue
180GNUNET_CONFIGURATION_write_diffs (const struct 180GNUNET_CONFIGURATION_write_diffs (
181 GNUNET_CONFIGURATION_Handle *cfg_default, 181 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
182 const struct 182 const struct GNUNET_CONFIGURATION_Handle *cfg_new,
183 GNUNET_CONFIGURATION_Handle *cfg_new, 183 const char *filename);
184 const char *filename);
185 184
186 185
187/** 186/**
@@ -192,10 +191,9 @@ GNUNET_CONFIGURATION_write_diffs (const struct
192 * @return configuration with only the differences, never NULL 191 * @return configuration with only the differences, never NULL
193 */ 192 */
194struct GNUNET_CONFIGURATION_Handle * 193struct GNUNET_CONFIGURATION_Handle *
195GNUNET_CONFIGURATION_get_diff (const struct 194GNUNET_CONFIGURATION_get_diff (
196 GNUNET_CONFIGURATION_Handle *cfg_default, 195 const struct GNUNET_CONFIGURATION_Handle *cfg_default,
197 const struct 196 const struct GNUNET_CONFIGURATION_Handle *cfg_new);
198 GNUNET_CONFIGURATION_Handle *cfg_new);
199 197
200 198
201/** 199/**
diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c
index 4d050cdd3..feab6123c 100644
--- a/src/util/gnunet-config.c
+++ b/src/util/gnunet-config.c
@@ -65,11 +65,14 @@ static int list_sections;
65static int global_ret; 65static int global_ret;
66 66
67/** 67/**
68 * Should the generated configuration file contain the whole configuration, or 68 * Should we write out the configuration file, even if no value was changed?
69 * just the differences with the defaults?
70 * If set to a non-zero value, the full configuration will be written to file.
71 */ 69 */
72static int rewrite = 0; 70static int rewrite;
71
72/**
73 * Should the generated configuration file contain the whole configuration?
74 */
75static int full;
73 76
74 77
75/** 78/**
@@ -144,8 +147,6 @@ run (void *cls,
144 const struct GNUNET_CONFIGURATION_Handle *cfg) 147 const struct GNUNET_CONFIGURATION_Handle *cfg)
145{ 148{
146 struct GNUNET_CONFIGURATION_Handle *out = NULL; 149 struct GNUNET_CONFIGURATION_Handle *out = NULL;
147 struct GNUNET_CONFIGURATION_Handle *diff = NULL;
148 char *cfg_fn;
149 150
150 (void) cls; 151 (void) cls;
151 (void) args; 152 (void) args;
@@ -153,44 +154,38 @@ run (void *cls,
153 { 154 {
154 char *name; 155 char *name;
155 156
156 GNUNET_asprintf (&name, "libgnunet_plugin_%s", backend_check); 157 GNUNET_asprintf (&name,
157 global_ret = (GNUNET_OK == GNUNET_PLUGIN_test (name)) ? 0 : 77; 158 "libgnunet_plugin_%s",
159 backend_check);
160 global_ret = (GNUNET_OK ==
161 GNUNET_PLUGIN_test (name)) ? 0 : 77;
158 GNUNET_free (name); 162 GNUNET_free (name);
159 return; 163 return;
160 } 164 }
161 if (!rewrite) 165 if (full)
166 rewrite = GNUNET_YES;
167 if (list_sections)
162 { 168 {
163 struct GNUNET_CONFIGURATION_Handle *def; 169 fprintf (stderr,
164 170 _ ("The following sections are available:\n"));
165 def = GNUNET_CONFIGURATION_create (); 171 GNUNET_CONFIGURATION_iterate_sections (cfg,
166 if (GNUNET_OK != GNUNET_CONFIGURATION_load (def, NULL)) 172 &print_section_name,
167 { 173 NULL);
168 fprintf (stderr, _ ("failed to load configuration defaults")); 174 return;
169 global_ret = 1;
170 return;
171 }
172 diff = GNUNET_CONFIGURATION_get_diff (def, cfg);
173 cfg = diff;
174 } 175 }
175 if (((! rewrite) && (NULL == section)) || list_sections) 176 if ( (! rewrite) &&
177 (NULL == section) )
176 { 178 {
177 if (! list_sections) 179 fprintf (stderr,
178 { 180 _ ("%s or %s argument is required\n"),
179 fprintf (stderr, 181 "--section",
180 _ ("%s or %s argument is required\n"), 182 "--list-sections");
181 "--section", 183 global_ret = 1;
182 "--list-sections"); 184 return;
183 global_ret = 1;
184 }
185 else
186 {
187 fprintf (stderr, _ ("The following sections are available:\n"));
188 GNUNET_CONFIGURATION_iterate_sections (cfg, &print_section_name, NULL);
189 }
190 goto cleanup;
191 } 185 }
192 186
193 if ((NULL != section) && (NULL == value)) 187 if ( (NULL != section) &&
188 (NULL == value) )
194 { 189 {
195 if (NULL == option) 190 if (NULL == option)
196 { 191 {
@@ -203,68 +198,108 @@ run (void *cls,
203 { 198 {
204 if (is_filename) 199 if (is_filename)
205 { 200 {
206 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, 201 if (GNUNET_OK !=
207 section, 202 GNUNET_CONFIGURATION_get_value_filename (cfg,
208 option, 203 section,
209 &value)) 204 option,
205 &value))
210 { 206 {
211 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option); 207 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
208 section,
209 option);
212 global_ret = 3; 210 global_ret = 3;
213 goto cleanup; 211 return;
214 } 212 }
215 } 213 }
216 else 214 else
217 { 215 {
218 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_string (cfg, 216 if (GNUNET_OK !=
219 section, 217 GNUNET_CONFIGURATION_get_value_string (cfg,
220 option, 218 section,
221 &value)) 219 option,
220 &value))
222 { 221 {
223 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, section, option); 222 GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
223 section,
224 option);
224 global_ret = 3; 225 global_ret = 3;
225 goto cleanup; 226 return;
226 } 227 }
227 } 228 }
228 fprintf (stdout, "%s\n", value); 229 fprintf (stdout,
230 "%s\n",
231 value);
229 } 232 }
230 } 233 }
231 else if (NULL != section) 234 else if (NULL != section)
232 { 235 {
233 if (NULL == option) 236 if (NULL == option)
234 { 237 {
235 fprintf (stderr, _ ("--option argument required to set value\n")); 238 fprintf (stderr,
239 _ ("--option argument required to set value\n"));
236 global_ret = 1; 240 global_ret = 1;
237 goto cleanup; 241 return;
238 } 242 }
239 out = GNUNET_CONFIGURATION_dup (cfg); 243 out = GNUNET_CONFIGURATION_dup (cfg);
240 GNUNET_CONFIGURATION_set_value_string (out, section, option, value); 244 GNUNET_CONFIGURATION_set_value_string (out,
245 section,
246 option,
247 value);
248 rewrite = GNUNET_YES;
241 } 249 }
242 cfg_fn = NULL; 250 if (rewrite)
243 if (NULL == cfgfile)
244 { 251 {
245 const char *xdg = getenv ("XDG_CONFIG_HOME"); 252 char *cfg_fn = NULL;
246 if (NULL != xdg) 253
247 GNUNET_asprintf (&cfg_fn, 254 if (NULL == cfgfile)
248 "%s%s%s", 255 {
249 xdg, 256 const char *xdg = getenv ("XDG_CONFIG_HOME");
250 DIR_SEPARATOR_STR, 257 if (NULL != xdg)
251 GNUNET_OS_project_data_get ()->config_file); 258 GNUNET_asprintf (&cfg_fn,
259 "%s%s%s",
260 xdg,
261 DIR_SEPARATOR_STR,
262 GNUNET_OS_project_data_get ()->config_file);
263 else
264 cfg_fn = GNUNET_strdup (
265 GNUNET_OS_project_data_get ()->user_config_file);
266 cfgfile = cfg_fn;
267 }
268
269 if (! full)
270 {
271 struct GNUNET_CONFIGURATION_Handle *def;
272
273 def = GNUNET_CONFIGURATION_create ();
274 if (GNUNET_OK !=
275 GNUNET_CONFIGURATION_load (def,
276 NULL))
277 {
278 fprintf (stderr,
279 _ ("failed to load configuration defaults"));
280 global_ret = 1;
281 GNUNET_CONFIGURATION_destroy (def);
282 GNUNET_CONFIGURATION_destroy (out);
283 GNUNET_free (cfg_fn);
284 return;
285 }
286 if (GNUNET_OK !=
287 GNUNET_CONFIGURATION_write_diffs (def,
288 out,
289 cfgfile))
290 global_ret = 2;
291 GNUNET_CONFIGURATION_destroy (def);
292 }
252 else 293 else
253 cfg_fn = GNUNET_strdup (GNUNET_OS_project_data_get ()->user_config_file); 294 {
254 cfgfile = cfg_fn; 295 if (GNUNET_OK !=
255 } 296 GNUNET_CONFIGURATION_write (out,
256 if ((NULL != diff) || (NULL != out)) 297 cfgfile))
257 { 298 global_ret = 2;
258 if (GNUNET_OK != 299 }
259 GNUNET_CONFIGURATION_write ((NULL == out) ? diff : out, cfgfile)) 300 GNUNET_free (cfg_fn);
260 global_ret = 2;
261 } 301 }
262 GNUNET_free (cfg_fn); 302 GNUNET_CONFIGURATION_destroy (out);
263 if (NULL != out)
264 GNUNET_CONFIGURATION_destroy (out);
265cleanup:
266 if (NULL != diff)
267 GNUNET_CONFIGURATION_destroy (diff);
268} 303}
269 304
270 305
@@ -278,50 +313,60 @@ cleanup:
278int 313int
279main (int argc, char *const *argv) 314main (int argc, char *const *argv)
280{ 315{
281 struct GNUNET_GETOPT_CommandLineOption options[] = 316 struct GNUNET_GETOPT_CommandLineOption options[] = {
282 { GNUNET_GETOPT_option_flag ( 317 GNUNET_GETOPT_option_exclusive (
318 GNUNET_GETOPT_option_string (
319 'b',
320 "supported-backend",
321 "BACKEND",
322 gettext_noop (
323 "test if the current installation supports the specified BACKEND"),
324 &backend_check)),
325 GNUNET_GETOPT_option_flag (
326 'F',
327 "full",
328 gettext_noop (
329 "write the full configuration file, including default values"),
330 &full),
331 GNUNET_GETOPT_option_flag (
283 'f', 332 'f',
284 "filename", 333 "filename",
285 gettext_noop ("interpret option value as a filename (with $-expansion)"), 334 gettext_noop ("interpret option value as a filename (with $-expansion)"),
286 &is_filename), 335 &is_filename),
287 GNUNET_GETOPT_option_exclusive (GNUNET_GETOPT_option_string ( 336 GNUNET_GETOPT_option_string ('o',
288 'b', 337 "option",
289 "supported-backend", 338 "OPTION",
290 "BACKEND", 339 gettext_noop ("name of the option to access"),
291 gettext_noop ( 340 &option),
292 "test if the current installation supports the specified BACKEND"), 341 GNUNET_GETOPT_option_flag (
293 &backend_check)), 342 'r',
343 "rewrite",
344 gettext_noop (
345 "rewrite the configuration file, even if nothing changed"),
346 &rewrite),
347 GNUNET_GETOPT_option_flag ('S',
348 "list-sections",
349 gettext_noop (
350 "print available configuration sections"),
351 &list_sections),
294 GNUNET_GETOPT_option_string ('s', 352 GNUNET_GETOPT_option_string ('s',
295 "section", 353 "section",
296 "SECTION", 354 "SECTION",
297 gettext_noop ( 355 gettext_noop (
298 "name of the section to access"), 356 "name of the section to access"),
299 &section), 357 &section),
300 GNUNET_GETOPT_option_string ('o',
301 "option",
302 "OPTION",
303 gettext_noop ("name of the option to access"),
304 &option),
305 GNUNET_GETOPT_option_string ('V', 358 GNUNET_GETOPT_option_string ('V',
306 "value", 359 "value",
307 "VALUE", 360 "VALUE",
308 gettext_noop ("value to set"), 361 gettext_noop ("value to set"),
309 &value), 362 &value),
310 GNUNET_GETOPT_option_flag ('S', 363 GNUNET_GETOPT_OPTION_END
311 "list-sections", 364 };
312 gettext_noop (
313 "print available configuration sections"),
314 &list_sections),
315 GNUNET_GETOPT_option_flag (
316 'w',
317 "rewrite",
318 gettext_noop (
319 "write the full configuration file, including default values"),
320 &rewrite),
321 GNUNET_GETOPT_OPTION_END };
322 int ret; 365 int ret;
323 366
324 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 367 if (GNUNET_OK !=
368 GNUNET_STRINGS_get_utf8_args (argc, argv,
369 &argc, &argv))
325 return 2; 370 return 2;
326 371
327 ret = 372 ret =