diff options
Diffstat (limited to 'src/exchange-tools/taler-exchange-keycheck.c')
-rw-r--r-- | src/exchange-tools/taler-exchange-keycheck.c | 85 |
1 files changed, 48 insertions, 37 deletions
diff --git a/src/exchange-tools/taler-exchange-keycheck.c b/src/exchange-tools/taler-exchange-keycheck.c index 064f2249e..eaca7cd61 100644 --- a/src/exchange-tools/taler-exchange-keycheck.c +++ b/src/exchange-tools/taler-exchange-keycheck.c @@ -34,8 +34,12 @@ static char *exchange_directory; /** * Our configuration. */ -static struct GNUNET_CONFIGURATION_Handle *kcfg; +static const struct GNUNET_CONFIGURATION_Handle *kcfg; +/** + * Return value from main(). + */ +static int global_ret; /** * Function called on each signing key. @@ -194,6 +198,43 @@ exchange_denomkeys_check () /** + * Main function that will be run. + * + * @param cls closure + * @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) +{ + kcfg = cfg; + if (GNUNET_OK != + GNUNET_CONFIGURATION_get_value_filename (kcfg, + "exchange", + "KEYDIR", + &exchange_directory)) + { + GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + "exchange", + "KEYDIR"); + global_ret = 1; + return; + } + + if ( (GNUNET_OK != exchange_signkeys_check ()) || + (GNUNET_OK != exchange_denomkeys_check ()) ) + { + global_ret = 1; + return; + } +} + + +/** * The main function of the keyup tool * * @param argc number of arguments from the command line @@ -203,10 +244,7 @@ exchange_denomkeys_check () int main (int argc, char *const *argv) { - char *cfgfile; const struct GNUNET_GETOPT_CommandLineOption options[] = { - GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile), - GNUNET_GETOPT_OPTION_HELP ("gnunet-exchange-keycheck OPTIONS"), GNUNET_GETOPT_OPTION_END }; @@ -214,42 +252,15 @@ main (int argc, char *const *argv) GNUNET_log_setup ("taler-exchange-keycheck", "WARNING", NULL)); - - if (GNUNET_GETOPT_run ("taler-exchange-keycheck", - options, - argc, argv) < 0) - return 1; - kcfg = GNUNET_CONFIGURATION_create (); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (kcfg, - cfgfile)) - { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, - _("Malformed configuration file `%s', exit ...\n"), - cfgfile); - GNUNET_free_non_null (cfgfile); - return 1; - } - GNUNET_free_non_null (cfgfile); if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_filename (kcfg, - "exchange", - "KEYDIR", - &exchange_directory)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "exchange", - "KEYDIR"); + GNUNET_PROGRAM_run (argc, argv, + "taler-exchange-keycheck", + "Check keys of the exchange for validity", + options, + &run, NULL)) return 1; - } + return global_ret; - if ( (GNUNET_OK != exchange_signkeys_check ()) || - (GNUNET_OK != exchange_denomkeys_check ()) ) - { - GNUNET_CONFIGURATION_destroy (kcfg); - return 1; - } - GNUNET_CONFIGURATION_destroy (kcfg); - return 0; } /* end of taler-exchange-keycheck.c */ |