From f9f3cbe9fcedfb8ca95275d5e406b1270062d7ea Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 Sep 2021 18:27:53 +0200 Subject: make backend-check a gnunet-only gnunet-config option --- src/include/gnunet_configuration_lib.h | 23 +++++--------- src/util/configuration_helper.c | 14 --------- src/util/gnunet-config.c | 57 +++++++++++++++++++++++++++++++++- 3 files changed, 64 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/include/gnunet_configuration_lib.h b/src/include/gnunet_configuration_lib.h index 46b745541..234f66e61 100644 --- a/src/include/gnunet_configuration_lib.h +++ b/src/include/gnunet_configuration_lib.h @@ -641,6 +641,14 @@ GNUNET_CONFIGURATION_append_value_filename (struct struct GNUNET_CONFIGURATION_ConfigSettings { + /** + * Must be set to the API version, i.e. + * #GNUNET_UTIL_VERSION. Used to detect + * which version of the struct the client + * is using. + */ + unsigned int api_version; + /** * Name of the section */ @@ -656,13 +664,6 @@ struct GNUNET_CONFIGURATION_ConfigSettings */ char *value; - /** - * Backend to check if the respective plugin is - * loadable. NULL if no check is to be performed. - * The value is the "basename" of the plugin to load. - */ - char *backend_check; - /** * Treat option as a filename. */ @@ -706,14 +707,6 @@ struct GNUNET_CONFIGURATION_ConfigSettings * @param cs configuration settings to initialize */ #define GNUNET_CONFIGURATION_CONFIG_OPTIONS(cs) \ - GNUNET_GETOPT_option_exclusive ( \ - GNUNET_GETOPT_option_string ( \ - 'b', \ - "supported-backend", \ - "BACKEND", \ - gettext_noop ( \ - "test if the current installation supports the specified BACKEND"), \ - &(cs)->backend_check)), \ GNUNET_GETOPT_option_flag ( \ 'F', \ "full", \ diff --git a/src/util/configuration_helper.c b/src/util/configuration_helper.c index eb8b543d1..8f995ec03 100644 --- a/src/util/configuration_helper.c +++ b/src/util/configuration_helper.c @@ -115,19 +115,6 @@ GNUNET_CONFIGURATION_config_tool_run ( struct GNUNET_CONFIGURATION_Handle *ncfg = NULL; (void) args; - if (NULL != cs->backend_check) - { - char *name; - - GNUNET_asprintf (&name, - "libgnunet_plugin_%s", - cs->backend_check); - cs->global_ret = (GNUNET_OK == - GNUNET_PLUGIN_test (name)) ? 0 : 77; - GNUNET_free (name); - return; - } - if (cs->diagnostics) { /* Re-parse the configuration with diagnostics enabled. */ @@ -309,7 +296,6 @@ GNUNET_CONFIGURATION_config_settings_free ( GNUNET_free (cs->option); GNUNET_free (cs->section); GNUNET_free (cs->value); - GNUNET_free (cs->backend_check); } diff --git a/src/util/gnunet-config.c b/src/util/gnunet-config.c index 202ef7866..797de0b0d 100644 --- a/src/util/gnunet-config.c +++ b/src/util/gnunet-config.c @@ -27,6 +27,52 @@ #include "gnunet_util_lib.h" +/** + * Backend to check if the respective plugin is + * loadable. NULL if no check is to be performed. + * The value is the "basename" of the plugin to load. + */ +static char *backend_check; + + +/** + * Main task to run to perform operations typical for + * gnunet-config as per the configuration settings + * given in @a cls. + * + * @param cls closure with the `struct GNUNET_CONFIGURATION_ConfigSettings` + * @param args remaining command-line arguments + * @param cfgfile name of the configuration file used (for saving, + * can be NULL!) + * @param cfg configuration + */ +static void +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) +{ + struct GNUNET_CONFIGURATION_ConfigSettings *cs = cls; + + if (NULL != backend_check) + { + char *name; + + GNUNET_asprintf (&name, + "libgnunet_plugin_%s", + backend_check); + cs->global_ret = (GNUNET_OK == + GNUNET_PLUGIN_test (name)) ? 0 : 77; + GNUNET_free (name); + return; + } + GNUNET_CONFIGURATION_config_tool_run (cs, + args, + cfgfile, + cfg); +} + + /** * Program to manipulate configuration files. * @@ -39,9 +85,18 @@ main (int argc, char *const *argv) { struct GNUNET_CONFIGURATION_ConfigSettings cs = { + .api_version = GNUNET_UTIL_VERSION, .global_ret = EXIT_SUCCESS }; struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_exclusive ( + GNUNET_GETOPT_option_string ( + 'b', + "supported-backend", + "BACKEND", + gettext_noop ( + "test if the current installation supports the specified BACKEND"), + &backend_check)), GNUNET_CONFIGURATION_CONFIG_OPTIONS (&cs), GNUNET_GETOPT_OPTION_END }; @@ -57,7 +112,7 @@ main (int argc, "gnunet-config [OPTIONS]", gettext_noop ("Manipulate GNUnet configuration files"), options, - &GNUNET_CONFIGURATION_config_tool_run, + &run, &cs); GNUNET_free_nz ((void *) argv); GNUNET_CONFIGURATION_config_settings_free (&cs); -- cgit v1.2.3