fix taler-exchange-wire way of loading configuration
This commit is contained in:
parent
ecc5b6791f
commit
fe36ba0062
@ -47,42 +47,24 @@ static char *method;
|
||||
static char *output_filename;
|
||||
|
||||
/**
|
||||
* Our configuration.
|
||||
* Return value from main().
|
||||
*/
|
||||
static struct GNUNET_CONFIGURATION_Handle *cfg;
|
||||
|
||||
static int global_ret;
|
||||
|
||||
/**
|
||||
* The main function of the taler-exchange-sepa tool. This tool is used
|
||||
* to sign the SEPA bank account details using the master key.
|
||||
* Main function that will be run.
|
||||
*
|
||||
* @param argc number of arguments from the command line
|
||||
* @param argv command line arguments
|
||||
* @return 0 ok, 1 on error
|
||||
* @param cls closure
|
||||
* @param args remaining command-line arguments
|
||||
* @param cfgfile name of the configuration file used (for saving, can be NULL!)
|
||||
* @param c configuration
|
||||
*/
|
||||
int
|
||||
main (int argc,
|
||||
char *const *argv)
|
||||
static void
|
||||
run (void *cls,
|
||||
char *const *args,
|
||||
const char *cfgfile,
|
||||
const struct GNUNET_CONFIGURATION_Handle *cfg)
|
||||
{
|
||||
char *cfgfile = NULL;
|
||||
const struct GNUNET_GETOPT_CommandLineOption options[] = {
|
||||
GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile),
|
||||
{'j', "json", "JSON",
|
||||
"account information in JSON format", 1,
|
||||
&GNUNET_GETOPT_set_string, &json_in},
|
||||
{'m', "master-key", "FILE",
|
||||
"master key file (private key)", 1,
|
||||
&GNUNET_GETOPT_set_filename, &masterkeyfile},
|
||||
{'t', "type", "METHOD",
|
||||
"which wire transfer method (i.e. 'test' or 'sepa') is this for?", 1,
|
||||
&GNUNET_GETOPT_set_string, &method},
|
||||
{'o', "output", "FILE",
|
||||
"where to write the result", 1,
|
||||
&GNUNET_GETOPT_set_filename, &output_filename},
|
||||
GNUNET_GETOPT_OPTION_HELP ("Setup /wire response"),
|
||||
GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
|
||||
GNUNET_GETOPT_OPTION_END
|
||||
};
|
||||
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
|
||||
struct TALER_MasterPrivateKeyP key;
|
||||
struct TALER_MasterSignatureP sig;
|
||||
@ -92,26 +74,6 @@ main (int argc,
|
||||
struct GNUNET_HashCode salt;
|
||||
struct TALER_WIRE_Plugin *plugin;
|
||||
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_log_setup ("taler-exchange-wire",
|
||||
"WARNING",
|
||||
NULL));
|
||||
|
||||
if (GNUNET_GETOPT_run ("taler-exchange-wire",
|
||||
options,
|
||||
argc, argv) < 0)
|
||||
return 1;
|
||||
cfg = GNUNET_CONFIGURATION_create ();
|
||||
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg,
|
||||
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 ( (NULL == masterkeyfile) &&
|
||||
(GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_get_value_filename (cfg,
|
||||
@ -121,7 +83,8 @@ main (int argc,
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Master key file not given in neither configuration nor command-line\n");
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
eddsa_priv = GNUNET_CRYPTO_eddsa_key_create_from_file (masterkeyfile);
|
||||
if (NULL == eddsa_priv)
|
||||
@ -129,19 +92,22 @@ main (int argc,
|
||||
fprintf (stderr,
|
||||
"Failed to initialize master key from file `%s'\n",
|
||||
masterkeyfile);
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
if (NULL == json_in)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Required -j argument missing\n");
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
if (NULL == method)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"Required -t argument missing\n");
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
j = json_loads (json_in,
|
||||
JSON_REJECT_DUPLICATES,
|
||||
@ -152,7 +118,8 @@ main (int argc,
|
||||
"Failed to parse JSON: %s (at offset %u)\n",
|
||||
err.text,
|
||||
(unsigned int) err.position);
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
json_object_set_new (j,
|
||||
"type",
|
||||
@ -168,7 +135,8 @@ main (int argc,
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
|
||||
"Wire transfer method `%s' not supported\n",
|
||||
method);
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
if (GNUNET_OK !=
|
||||
plugin->sign_wire_details (plugin->cls,
|
||||
@ -180,7 +148,8 @@ main (int argc,
|
||||
/* sign function should have logged applicable errors */
|
||||
json_decref (j);
|
||||
TALER_WIRE_plugin_unload (plugin);
|
||||
return 1;
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
TALER_WIRE_plugin_unload (plugin);
|
||||
GNUNET_free (eddsa_priv);
|
||||
@ -211,7 +180,50 @@ main (int argc,
|
||||
json_out);
|
||||
fflush (stdout);
|
||||
free (json_out);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The main function of the taler-exchange-wire tool. This tool is
|
||||
* used to sign the bank account details using the master key.
|
||||
*
|
||||
* @param argc number of arguments from the command line
|
||||
* @param argv command line arguments
|
||||
* @return 0 ok, 1 on error
|
||||
*/
|
||||
int
|
||||
main (int argc,
|
||||
char *const *argv)
|
||||
{
|
||||
const struct GNUNET_GETOPT_CommandLineOption options[] = {
|
||||
{'j', "json", "JSON",
|
||||
"account information in JSON format", 1,
|
||||
&GNUNET_GETOPT_set_string, &json_in},
|
||||
{'m', "master-key", "FILE",
|
||||
"master key file (private key)", 1,
|
||||
&GNUNET_GETOPT_set_filename, &masterkeyfile},
|
||||
{'t', "type", "METHOD",
|
||||
"which wire transfer method (i.e. 'test' or 'sepa') is this for?", 1,
|
||||
&GNUNET_GETOPT_set_string, &method},
|
||||
{'o', "output", "FILE",
|
||||
"where to write the result", 1,
|
||||
&GNUNET_GETOPT_set_filename, &output_filename},
|
||||
GNUNET_GETOPT_OPTION_END
|
||||
};
|
||||
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
GNUNET_log_setup ("taler-exchange-wire",
|
||||
"WARNING",
|
||||
NULL));
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_PROGRAM_run (argc, argv,
|
||||
"taler-exchange-wire",
|
||||
"Setup /wire response",
|
||||
options,
|
||||
&run, NULL))
|
||||
return 1;
|
||||
return global_ret;
|
||||
}
|
||||
|
||||
|
||||
/* end of taler-exchange-wire.c */
|
||||
|
Loading…
Reference in New Issue
Block a user