update getopt config parsing style to match 'getopt' GNUnet branch API change

This commit is contained in:
Christian Grothoff 2017-03-15 12:01:06 +01:00
parent 296f919ce4
commit ae3e850c94
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
13 changed files with 302 additions and 288 deletions

View File

@ -26,18 +26,13 @@
/** /**
* Are we running in verbose mode? * Are we running in verbose mode?
*/ */
static int verbose; static unsigned int verbose;
/** /**
* Filename of the auditor's private key. * Filename of the auditor's private key.
*/ */
static char *auditor_key_file; static char *auditor_key_file;
/**
* Exchange's public key (in Crockford base32 encoding).
*/
static char *exchange_public_key;
/** /**
* File with the Exchange's denomination keys to sign, itself * File with the Exchange's denomination keys to sign, itself
* signed by the Exchange's public key. * signed by the Exchange's public key.
@ -144,23 +139,35 @@ main (int argc,
{ {
char *cfgfile = NULL; char *cfgfile = NULL;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'a', "auditor-key", "FILENAME", GNUNET_GETOPT_OPTION_FILENAME ('a',
"file containing the private key of the auditor", 1, "auditor-key",
&GNUNET_GETOPT_set_filename, &auditor_key_file}, "FILENAME",
"file containing the private key of the auditor",
&auditor_key_file),
GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile), GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile),
GNUNET_GETOPT_OPTION_HELP ("Private key of the auditor to use for signing"), GNUNET_GETOPT_OPTION_HELP ("Private key of the auditor to use for signing"),
{'m', "exchange-key", "KEY", GNUNET_GETOPT_OPTION_MANDATORY
"public key of the exchange (Crockford base32 encoded)", 1, (GNUNET_GETOPT_OPTION_SET_BASE32_AUTO ('m',
&GNUNET_GETOPT_set_string, &exchange_public_key}, "exchange-key",
{'u', "auditor-url", "URL", "KEY",
"URL of the auditor (informative link for the user)", 1, "public key of the exchange (Crockford base32 encoded)",
&GNUNET_GETOPT_set_string, &auditor_url}, &master_public_key)),
{'r', "exchange-request", "FILENAME", GNUNET_GETOPT_OPTION_STRING ('u',
"set of keys the exchange requested the auditor to sign", 1, "auditor-url",
&GNUNET_GETOPT_set_string, &exchange_request_file}, "URL",
{'o', "output", "FILENAME", "URL of the auditor (informative link for the user)",
"where to write our signature", 1, &auditor_url),
&GNUNET_GETOPT_set_string, &output_file}, GNUNET_GETOPT_OPTION_MANDATORY
(GNUNET_GETOPT_OPTION_FILENAME ('r',
"exchange-request",
"FILENAME",
"set of keys the exchange requested the auditor to sign",
&exchange_request_file)),
GNUNET_GETOPT_OPTION_FILENAME ('o',
"output",
"FILENAME",
"where to write our signature",
&output_file),
GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION), GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_VERBOSE (&verbose), GNUNET_GETOPT_OPTION_VERBOSE (&verbose),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
@ -213,7 +220,7 @@ main (int argc,
&auditor_url)) ) &auditor_url)) )
{ {
fprintf (stderr, fprintf (stderr,
"Auditor URL not given\n"); "Auditor URL not given in neither configuration nor command-line\n");
return 1; return 1;
} }
if (GNUNET_YES != GNUNET_DISK_file_test (auditor_key_file)) if (GNUNET_YES != GNUNET_DISK_file_test (auditor_key_file))
@ -230,32 +237,6 @@ main (int argc,
} }
GNUNET_CRYPTO_eddsa_key_get_public (eddsa_priv, GNUNET_CRYPTO_eddsa_key_get_public (eddsa_priv,
&apub.eddsa_pub); &apub.eddsa_pub);
if (NULL == exchange_public_key)
{
fprintf (stderr,
"Exchange public key not given\n");
GNUNET_free (eddsa_priv);
return 1;
}
if (GNUNET_OK !=
GNUNET_STRINGS_string_to_data (exchange_public_key,
strlen (exchange_public_key),
&master_public_key,
sizeof (master_public_key)))
{
fprintf (stderr,
"Public key `%s' malformed\n",
exchange_public_key);
GNUNET_free (eddsa_priv);
return 1;
}
if (NULL == exchange_request_file)
{
fprintf (stderr,
"Exchange signing request not given\n");
GNUNET_free (eddsa_priv);
return 1;
}
fh = GNUNET_DISK_file_open (exchange_request_file, fh = GNUNET_DISK_file_open (exchange_request_file,
GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE); GNUNET_DISK_PERM_NONE);

View File

@ -268,7 +268,7 @@ static int run_exchange;
* every 50 iterations. Also includes how long the iteration took, * every 50 iterations. Also includes how long the iteration took,
* so we can see if it is stable. * so we can see if it is stable.
*/ */
static int be_verbose; static unsigned int be_verbose;
/** /**
* How many coins the benchmark should operate on * How many coins the benchmark should operate on
@ -1442,16 +1442,11 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"gotten pool_size of %d\n", "gotten pool_size of %d\n",
pool_size); pool_size);
if (NULL == config_file)
{
fail ("-c option is mandatory");
return;
}
cfg = GNUNET_CONFIGURATION_create (); cfg = GNUNET_CONFIGURATION_create ();
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL); NULL);
if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg, if (GNUNET_SYSERR ==
GNUNET_CONFIGURATION_parse (cfg,
config_file)) config_file))
{ {
fail ("Failed to parse configuration file"); fail ("Failed to parse configuration file");
@ -1567,23 +1562,33 @@ main (int argc,
struct GNUNET_OS_Process *proc; struct GNUNET_OS_Process *proc;
unsigned int cnt; unsigned int cnt;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'a', "automate", NULL, GNUNET_GETOPT_OPTION_SET_ONE ('a',
"Initialize and start the bank and exchange", GNUNET_NO, "automate",
&GNUNET_GETOPT_set_one, &run_exchange}, "Initialize and start the bank and exchange",
GNUNET_GETOPT_OPTION_CFG_FILE (&config_file), &run_exchange),
{'e', "exchange-uri", "URI", GNUNET_GETOPT_OPTION_MANDATORY
"URI of the exchange", GNUNET_YES, (GNUNET_GETOPT_OPTION_CFG_FILE (&config_file)),
&GNUNET_GETOPT_set_string, &exchange_uri}, GNUNET_GETOPT_OPTION_STRING ('e',
{'E', "exchange-admin-uri", "URI", "exchange-uri",
"URI of the administrative interface of the exchange", GNUNET_YES, "URI",
&GNUNET_GETOPT_set_string, &exchange_admin_uri}, "URI of the exchange",
&exchange_uri),
GNUNET_GETOPT_OPTION_STRING ('E',
"exchange-admin-uri",
"URI",
"URI of the administrative interface of the exchange",
&exchange_admin_uri),
GNUNET_GETOPT_OPTION_HELP ("tool to benchmark the Taler exchange"), GNUNET_GETOPT_OPTION_HELP ("tool to benchmark the Taler exchange"),
{'s', "pool-size", "SIZE", GNUNET_GETOPT_OPTION_SET_UINT ('s',
"How many coins this benchmark should instantiate", GNUNET_YES, "pool-size",
&GNUNET_GETOPT_set_uint, &pool_size}, "SIZE",
{'l', "limit", "LIMIT", "How many coins this benchmark should instantiate",
"Terminate the benchmark after LIMIT operations", GNUNET_YES, &pool_size),
&GNUNET_GETOPT_set_uint, &num_iterations}, GNUNET_GETOPT_OPTION_SET_UINT ('l',
"limit",
"LIMIT",
"Terminate the benchmark after LIMIT operations",
&num_iterations),
GNUNET_GETOPT_OPTION_VERBOSE (&be_verbose), GNUNET_GETOPT_OPTION_VERBOSE (&be_verbose),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };
@ -1687,7 +1692,8 @@ main (int argc,
GNUNET_free (wget); GNUNET_free (wget);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
} }
GNUNET_SCHEDULER_run (&run, NULL); GNUNET_SCHEDULER_run (&run,
NULL);
if (run_exchange) if (run_exchange)
{ {
GNUNET_OS_process_kill (exchanged, GNUNET_OS_process_kill (exchanged,

View File

@ -58,7 +58,9 @@ taler_exchange_reservemod_LDADD = \
$(top_builddir)/src/util/libtalerutil.la \ $(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/pq/libtalerpq.la \ $(top_builddir)/src/pq/libtalerpq.la \
$(top_builddir)/src/exchangedb/libtalerexchangedb.la \ $(top_builddir)/src/exchangedb/libtalerexchangedb.la \
-lgnunetutil -ljansson $(XLIB) -lgnunetjson \
-lgnunetutil \
-ljansson $(XLIB)
taler_exchange_reservemod_LDFLAGS = \ taler_exchange_reservemod_LDFLAGS = \
$(POSTGRESQL_LDFLAGS) $(POSTGRESQL_LDFLAGS)
taler_exchange_reservemod_CPPFLAGS = \ taler_exchange_reservemod_CPPFLAGS = \

View File

@ -96,12 +96,14 @@ main (int argc,
char *const *argv) char *const *argv)
{ {
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'r', "reset", NULL, GNUNET_GETOPT_OPTION_SET_ONE ('r',
"reset database (DANGEROUS: all existing data is lost!)", 0, "reset",
&GNUNET_GETOPT_set_one, &reset_db}, "reset database (DANGEROUS: all existing data is lost!)",
{'g', "gc", NULL, &reset_db),
"garbage collect database", 0, GNUNET_GETOPT_OPTION_SET_ONE ('g',
&GNUNET_GETOPT_set_one, &gc_db}, "gc",
"garbage collect database",
&gc_db),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };

View File

@ -184,11 +184,6 @@ static FILE *auditor_output_file;
*/ */
static char *exchange_directory; static char *exchange_directory;
/**
* Time to pretend when the key update is executed.
*/
static char *pretend_time_str;
/** /**
* Directory where we should write the wire transfer fee structure. * Directory where we should write the wire transfer fee structure.
*/ */
@ -1041,23 +1036,6 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv; struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
kcfg = cfg; kcfg = cfg;
if (NULL != pretend_time_str)
{
if (GNUNET_OK !=
GNUNET_STRINGS_fancy_time_to_absolute (pretend_time_str,
&now))
{
fprintf (stderr,
"timestamp `%s' invalid\n",
pretend_time_str);
global_ret = 1;
return;
}
}
else
{
now = GNUNET_TIME_absolute_get ();
}
if (NULL == feedir) if (NULL == feedir)
{ {
if (GNUNET_OK != if (GNUNET_OK !=
@ -1232,19 +1210,27 @@ int
main (int argc, main (int argc,
char *const *argv) char *const *argv)
{ {
const struct GNUNET_GETOPT_CommandLineOption options[] = { struct GNUNET_GETOPT_CommandLineOption options[] = {
{'m', "master-key", "FILE", GNUNET_GETOPT_OPTION_FILENAME ('m',
"master key file (private key)", 1, "master-key",
&GNUNET_GETOPT_set_filename, &masterkeyfile}, "FILENAME",
{'f', "feedir", "DIRNAME", "master key file (private key)",
"directory where to write wire transfer fee structure", 1, &masterkeyfile),
&GNUNET_GETOPT_set_filename, &feedir}, GNUNET_GETOPT_OPTION_FILENAME ('f',
{'o', "output", "FILE", "feedir",
"auditor denomination key signing request file to create", 1, "DIRNAME",
&GNUNET_GETOPT_set_filename, &auditorrequestfile}, "directory where to write wire transfer fee structure",
{'t', "time", "TIMESTAMP", &feedir),
"pretend it is a different time for the update", 0, GNUNET_GETOPT_OPTION_FILENAME ('o',
&GNUNET_GETOPT_set_string, &pretend_time_str}, "output",
"FILENAME",
"auditor denomination key signing request file to create",
&auditorrequestfile),
GNUNET_GETOPT_OPTION_SET_ABSOLUTE_TIME ('t',
"time",
"TIMESTAMP",
"pretend it is a different time for the update",
&now),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };
@ -1252,7 +1238,7 @@ main (int argc,
GNUNET_log_setup ("taler-exchange-keyup", GNUNET_log_setup ("taler-exchange-keyup",
"WARNING", "WARNING",
NULL)); NULL));
now = GNUNET_TIME_absolute_get ();
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc, argv, GNUNET_PROGRAM_run (argc, argv,
"taler-exchange-keyup", "taler-exchange-keyup",

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2014, 2015 GNUnet e.V. Copyright (C) 2014-2017 GNUnet e.V.
TALER is free software; you can redistribute it and/or modify it under the TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -21,6 +21,7 @@
*/ */
#include "platform.h" #include "platform.h"
#include <gnunet/gnunet_util_lib.h> #include <gnunet/gnunet_util_lib.h>
#include <gnunet/gnunet_json_lib.h>
#include <libpq-fe.h> #include <libpq-fe.h>
#include <jansson.h> #include <jansson.h>
#include "taler_exchangedb_plugin.h" #include "taler_exchangedb_plugin.h"
@ -36,24 +37,24 @@ static char *exchange_directory;
static struct TALER_EXCHANGEDB_Plugin *plugin; static struct TALER_EXCHANGEDB_Plugin *plugin;
/** /**
* Public key of the reserve as a string. * Public key of the reserve.
*/ */
static char *reserve_pub_str; static struct TALER_ReservePublicKeyP reserve_pub;
/** /**
* Amount to add as a string. * Amount to add. Invalid if not initialized.
*/ */
static char *add_str; static struct TALER_Amount add_value;
/** /**
* Details about the sender account in JSON format. * Details about the sender account in JSON format.
*/ */
static char *sender_details; static json_t *sender_details;
/** /**
* Details about the wire transfer in JSON format. * Details about the wire transfer in JSON format.
*/ */
static char *transfer_details; static json_t *transfer_details;
/** /**
* Return value from main(). * Return value from main().
@ -123,12 +124,6 @@ run (void *cls,
const char *cfgfile, const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg) const struct GNUNET_CONFIGURATION_Handle *cfg)
{ {
struct TALER_Amount add_value;
json_t *jdetails;
json_t *tdetails;
json_error_t error;
struct TALER_ReservePublicKeyP reserve_pub;
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_filename (cfg, GNUNET_CONFIGURATION_get_value_filename (cfg,
"exchange", "exchange",
@ -141,72 +136,6 @@ run (void *cls,
global_ret = 1; global_ret = 1;
return; return;
} }
if ((NULL == reserve_pub_str) ||
(GNUNET_OK !=
GNUNET_STRINGS_string_to_data (reserve_pub_str,
strlen (reserve_pub_str),
&reserve_pub,
sizeof (struct TALER_ReservePublicKeyP))))
{
fprintf (stderr,
"Parsing reserve key invalid\n");
global_ret = 1;
return;
}
if ( (NULL == add_str) ||
(GNUNET_OK !=
TALER_string_to_amount (add_str,
&add_value)) )
{
fprintf (stderr,
"Failed to parse currency amount `%s'\n",
add_str);
global_ret = 1;
return;
}
if (NULL == sender_details)
{
fprintf (stderr,
"No sender details given (sender required)\n");
global_ret = 1;
return;
}
jdetails = json_loads (sender_details,
JSON_REJECT_DUPLICATES,
&error);
if (NULL == jdetails)
{
fprintf (stderr,
"Failed to parse JSON transaction details `%s': %s (%s)\n",
sender_details,
error.text,
error.source);
global_ret = 1;
return;
}
if (NULL == transfer_details)
{
fprintf (stderr,
"No transfer details given (justification required)\n");
global_ret = 1;
json_decref (jdetails);
return;
}
tdetails = json_loads (transfer_details,
JSON_REJECT_DUPLICATES,
&error);
if (NULL == tdetails)
{
fprintf (stderr,
"Failed to parse JSON transaction details `%s': %s (%s)\n",
transfer_details,
error.text,
error.source);
global_ret = 1;
json_decref (jdetails);
return;
}
if (NULL == if (NULL ==
(plugin = TALER_EXCHANGEDB_plugin_load (cfg))) (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{ {
@ -218,12 +147,12 @@ run (void *cls,
if (GNUNET_SYSERR == if (GNUNET_SYSERR ==
run_transaction (&reserve_pub, run_transaction (&reserve_pub,
&add_value, &add_value,
jdetails, sender_details,
tdetails)) transfer_details))
global_ret = 1; global_ret = 1;
TALER_EXCHANGEDB_plugin_unload (plugin); TALER_EXCHANGEDB_plugin_unload (plugin);
json_decref (jdetails); json_decref (transfer_details);
json_decref (tdetails); json_decref (sender_details);
} }
@ -238,19 +167,31 @@ int
main (int argc, char *const *argv) main (int argc, char *const *argv)
{ {
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'a', "add", "DENOM", GNUNET_GETOPT_OPTION_MANDATORY
"value to add", 1, (TALER_getopt_get_amount ('a',
&GNUNET_GETOPT_set_string, &add_str}, "add",
{'s', "sender", "JSON", "DENOM",
"details about the sender's bank account", 1, "value to add",
&GNUNET_GETOPT_set_string, &sender_details}, &add_value)),
{'t', "transfer", "JSON", GNUNET_GETOPT_OPTION_MANDATORY
"details that uniquely identify the bank transfer", 1, (GNUNET_JSON_getopt ('s',
&GNUNET_GETOPT_set_string, &transfer_details}, "sender",
"JSON",
"details about the sender's bank account",
&sender_details)),
GNUNET_GETOPT_OPTION_MANDATORY
(GNUNET_JSON_getopt ('t',
"transfer",
"JSON",
"details that uniquely identify the bank transfer",
&transfer_details)),
GNUNET_GETOPT_OPTION_HELP ("Deposit funds into a Taler reserve"), GNUNET_GETOPT_OPTION_HELP ("Deposit funds into a Taler reserve"),
{'R', "reserve", "KEY", GNUNET_GETOPT_OPTION_MANDATORY
"reserve (public key) to modify", 1, (GNUNET_GETOPT_OPTION_SET_BASE32_AUTO ('R',
&GNUNET_GETOPT_set_string, &reserve_pub_str}, "reserve",
"KEY",
"reserve (public key) to modify",
&reserve_pub)),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };

View File

@ -1,6 +1,6 @@
/* /*
This file is part of TALER This file is part of TALER
Copyright (C) 2015, 2016 Inria Copyright (C) 2015, 2016, 2017 Inria
TALER is free software; you can redistribute it and/or modify it under the TALER is free software; you can redistribute it and/or modify it under the
terms of the GNU General Public License as published by the Free Software terms of the GNU General Public License as published by the Free Software
@ -35,12 +35,12 @@ static char *masterkeyfile;
/** /**
* Account holder information in JSON format. * Account holder information in JSON format.
*/ */
static char *json_in; static json_t *account_holder;
/** /**
* Which wire method is this for? * Which wire method is this for?
*/ */
static const char *method; static char *method;
/** /**
* Where to write the result. * Where to write the result.
@ -70,8 +70,6 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv; struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
struct TALER_MasterPrivateKeyP key; struct TALER_MasterPrivateKeyP key;
struct TALER_MasterSignatureP sig; struct TALER_MasterSignatureP sig;
json_t *j;
json_error_t err;
char *json_out; char *json_out;
struct GNUNET_HashCode salt; struct GNUNET_HashCode salt;
struct TALER_WIRE_Plugin *plugin; struct TALER_WIRE_Plugin *plugin;
@ -101,40 +99,26 @@ run (void *cls,
global_ret = 1; global_ret = 1;
return; return;
} }
if (NULL == json_in)
{
fprintf (stderr,
"Required -j argument missing\n");
global_ret = 1;
return;
}
j = json_loads (json_in,
JSON_REJECT_DUPLICATES,
&err);
if (NULL == j)
{
fprintf (stderr,
"Failed to parse JSON: %s (at offset %u)\n",
err.text,
(unsigned int) err.position);
global_ret = 1;
return;
}
if (NULL == method) if (NULL == method)
{ {
json_t *test; json_t *test;
test = json_object_get(j, "type"); const char *m;
if (NULL == test || (NULL == (method = json_string_value (test))))
test = json_object_get(account_holder,
"type");
if ( (NULL == test) ||
(NULL == (m = json_string_value (test))))
{ {
fprintf (stderr, fprintf (stderr,
"Required -t argument missing\n"); "Required -t argument missing\n");
global_ret = 1; global_ret = 1;
return; return;
} }
method = GNUNET_strdup (m);
} }
else else
{ {
json_object_set_new (j, json_object_set_new (account_holder,
"type", "type",
json_string (method)); json_string (method));
} }
@ -149,18 +133,20 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Wire transfer method `%s' not supported\n", "Wire transfer method `%s' not supported\n",
method); method);
GNUNET_free (method);
global_ret = 1; global_ret = 1;
return; return;
} }
GNUNET_free (method);
if (GNUNET_OK != if (GNUNET_OK !=
plugin->sign_wire_details (plugin->cls, plugin->sign_wire_details (plugin->cls,
j, account_holder,
&key, &key,
&salt, &salt,
&sig)) &sig))
{ {
/* sign function should have logged applicable errors */ /* sign function should have logged applicable errors */
json_decref (j); json_decref (account_holder);
TALER_WIRE_plugin_unload (plugin); TALER_WIRE_plugin_unload (plugin);
global_ret = 1; global_ret = 1;
return; return;
@ -169,18 +155,19 @@ run (void *cls,
GNUNET_free (eddsa_priv); GNUNET_free (eddsa_priv);
/* add signature and salt to JSON message */ /* add signature and salt to JSON message */
json_object_set_new (j, json_object_set_new (account_holder,
"salt", "salt",
GNUNET_JSON_from_data (&salt, GNUNET_JSON_from_data (&salt,
sizeof (salt))); sizeof (salt)));
json_object_set_new (j, json_object_set_new (account_holder,
"sig", "sig",
GNUNET_JSON_from_data (&sig, GNUNET_JSON_from_data (&sig,
sizeof (sig))); sizeof (sig)));
/* dump result to stdout */ /* dump result to stdout */
json_out = json_dumps (j, JSON_INDENT(2)); json_out = json_dumps (account_holder,
json_decref (j); JSON_INDENT(2));
json_decref (account_holder);
GNUNET_assert (NULL != json_out); GNUNET_assert (NULL != json_out);
if (NULL != output_filename) if (NULL != output_filename)
@ -219,18 +206,27 @@ main (int argc,
char *const *argv) char *const *argv)
{ {
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'j', "json", "JSON", GNUNET_GETOPT_OPTION_MANDATORY
"account information in JSON format", 1, (GNUNET_JSON_getopt ('j',
&GNUNET_GETOPT_set_string, &json_in}, "json",
{'m', "master-key", "FILE", "JSON",
"master key file (private key)", 1, "account information in JSON format",
&GNUNET_GETOPT_set_filename, &masterkeyfile}, &account_holder)),
{'t', "type", "METHOD", GNUNET_GETOPT_OPTION_FILENAME ('m',
"which wire transfer method (i.e. 'test' or 'sepa') is this for?", 1, "master-key",
&GNUNET_GETOPT_set_string, &method}, "FILENAME",
{'o', "output", "FILE", "master key file (private key)",
"where to write the result", 1, &masterkeyfile),
&GNUNET_GETOPT_set_filename, &output_filename}, GNUNET_GETOPT_OPTION_STRING ('t',
"type",
"METHOD",
"which wire transfer method (i.e. 'test' or 'sepa') is this for?",
&method),
GNUNET_GETOPT_OPTION_FILENAME ('o',
"output",
"FILENAME",
"where to write the result",
&output_filename),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };

View File

@ -1198,10 +1198,11 @@ int
main (int argc, main (int argc,
char *const *argv) char *const *argv)
{ {
static const struct GNUNET_GETOPT_CommandLineOption options[] = { struct GNUNET_GETOPT_CommandLineOption options[] = {
{'t', "test", NULL, GNUNET_GETOPT_OPTION_SET_ONE ('t',
"run in test mode and exit when idle", 0, "test",
&GNUNET_GETOPT_set_one, &test_mode}, "run in test mode and exit when idle",
&test_mode),
GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION), GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END GNUNET_GETOPT_OPTION_END
}; };

View File

@ -934,23 +934,30 @@ main (int argc,
char *loglev = NULL; char *loglev = NULL;
char *logfile = NULL; char *logfile = NULL;
const struct GNUNET_GETOPT_CommandLineOption options[] = { const struct GNUNET_GETOPT_CommandLineOption options[] = {
{'C', "connection-close", NULL, GNUNET_GETOPT_OPTION_SET_ONE ('C',
"force HTTP connections to be closed after each request", 0, "connection-close",
&GNUNET_GETOPT_set_one, &TEH_exchange_connection_close}, "force HTTP connections to be closed after each request",
&TEH_exchange_connection_close),
GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile), GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile),
{'D', "disable-admin", NULL, GNUNET_GETOPT_OPTION_SET_ONE ('D',
"do not run the /admin-HTTP server", 0, "disable-admin",
&GNUNET_GETOPT_set_one, &no_admin}, "do not run the /admin-HTTP server",
{'i', "init-db", NULL, &no_admin),
"create database tables and indicies if necessary", 0, GNUNET_GETOPT_OPTION_SET_ONE ('i',
&GNUNET_GETOPT_set_one, &init_db}, "init-db",
{'t', "timeout", "SECONDS", "create database tables and indicies if necessary",
"after how long do connections timeout by default (in seconds)", 1, &init_db),
&GNUNET_GETOPT_set_uint, &connection_timeout}, GNUNET_GETOPT_OPTION_SET_UINT ('t',
"timeout",
"SECONDS",
"after how long do connections timeout by default (in seconds)",
&connection_timeout),
#if HAVE_DEVELOPER #if HAVE_DEVELOPER
{'f', "file-input", "FILENAME", GNUNET_GETOPT_OPTION_FILENAME ('f',
"run in test-mode using FILENAME as the HTTP request to process", 1, "file-input",
&GNUNET_GETOPT_set_filename, &input_filename}, "FILENAME",
"run in test-mode using FILENAME as the HTTP request to process",
&input_filename),
#endif #endif
GNUNET_GETOPT_OPTION_HELP ("HTTP server providing a RESTful API to access a Taler exchange"), GNUNET_GETOPT_OPTION_HELP ("HTTP server providing a RESTful API to access a Taler exchange"),
GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev), GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev),

View File

@ -151,6 +151,16 @@ TALER_amount_get_zero (const char *cur,
struct TALER_Amount *denom); struct TALER_Amount *denom);
/**
* Test if the given amount is valid.
*
* @param amount amount to check
* @return #GNUNET_OK if @a amount is valid
*/
int
TALER_amount_is_valid (const struct TALER_Amount *amount);
/** /**
* Convert amount from host to network representation. * Convert amount from host to network representation.
* *

View File

@ -110,6 +110,23 @@ TALER_config_get_denom (const struct GNUNET_CONFIGURATION_Handle *cfg,
struct TALER_Amount *denom); struct TALER_Amount *denom);
/**
* Allow user to specify an amount on the command line.
*
* @param shortName short name of the option
* @param name long name of the option
* @param argumentHelp help text for the option argument
* @param description long help text for the option
* @param[out] amount set to the amount specified at the command line
*/
struct GNUNET_GETOPT_CommandLineOption
TALER_getopt_get_amount (char shortName,
const char *name,
const char *argumentHelp,
const char *description,
struct TALER_Amount *amount);
/** /**
* Return default project data used by Taler. * Return default project data used by Taler.
*/ */

View File

@ -252,16 +252,15 @@ invalidate (struct TALER_Amount *a)
/** /**
* Test if @a a is valid * Test if the given amount is valid.
* *
* @param a amount to test * @param amount amount to check
* @return #GNUNET_YES if valid, * @return #GNUNET_OK if @a amount is valid
* #GNUNET_NO if invalid
*/ */
static int int
test_valid (const struct TALER_Amount *a) TALER_amount_is_valid (const struct TALER_Amount *amount)
{ {
return ('\0' != a->currency[0]); return ('\0' != amount->currency[0]);
} }
@ -292,8 +291,8 @@ int
TALER_amount_cmp_currency (const struct TALER_Amount *a1, TALER_amount_cmp_currency (const struct TALER_Amount *a1,
const struct TALER_Amount *a2) const struct TALER_Amount *a2)
{ {
if ( (GNUNET_NO == test_valid (a1)) || if ( (GNUNET_NO == TALER_amount_is_valid (a1)) ||
(GNUNET_NO == test_valid (a2)) ) (GNUNET_NO == TALER_amount_is_valid (a2)) )
return GNUNET_SYSERR; return GNUNET_SYSERR;
if (0 == strcasecmp (a1->currency, if (0 == strcasecmp (a1->currency,
a2->currency)) a2->currency))
@ -499,7 +498,7 @@ TALER_amount_normalize (struct TALER_Amount *amount)
{ {
int ret; int ret;
if (GNUNET_YES != test_valid (amount)) if (GNUNET_YES != TALER_amount_is_valid (amount))
return GNUNET_SYSERR; return GNUNET_SYSERR;
ret = GNUNET_NO; ret = GNUNET_NO;
while ( (amount->value != UINT64_MAX) && while ( (amount->value != UINT64_MAX) &&
@ -535,7 +534,7 @@ TALER_amount_to_string (const struct TALER_Amount *amount)
unsigned int i; unsigned int i;
struct TALER_Amount norm; struct TALER_Amount norm;
if (GNUNET_YES != test_valid (amount)) if (GNUNET_YES != TALER_amount_is_valid (amount))
return NULL; return NULL;
norm = *amount; norm = *amount;
GNUNET_break (GNUNET_SYSERR != GNUNET_break (GNUNET_SYSERR !=

View File

@ -93,4 +93,70 @@ TALER_config_get_denom (const struct GNUNET_CONFIGURATION_Handle *cfg,
} }
/**
* Set an option with an amount from the command line. A pointer to
* this function should be passed as part of the 'struct
* GNUNET_GETOPT_CommandLineOption' array to initialize options of
* this type.
*
* @param ctx command line processing context
* @param scls additional closure (will point to the `struct TALER_Amount`)
* @param option name of the option
* @param value actual value of the option as a string.
* @return #GNUNET_OK if parsing the value worked
*/
static int
set_amount (struct GNUNET_GETOPT_CommandLineProcessorContext *ctx,
void *scls,
const char *option,
const char *value)
{
struct TALER_Amount *amount = scls;
if (GNUNET_OK !=
TALER_string_to_amount (value,
amount))
{
FPRINTF (stderr,
_("Failed to parse amount in option `%s'\n"),
option);
return GNUNET_SYSERR;
}
return GNUNET_OK;
}
/**
* Allow user to specify an amount on the command line.
*
* @param shortName short name of the option
* @param name long name of the option
* @param argumentHelp help text for the option argument
* @param description long help text for the option
* @param[out] amount set to the amount specified at the command line
*/
struct GNUNET_GETOPT_CommandLineOption
TALER_getopt_get_amount (char shortName,
const char *name,
const char *argumentHelp,
const char *description,
struct TALER_Amount *amount)
{
struct GNUNET_GETOPT_CommandLineOption clo = {
.shortName = shortName,
.name = name,
.argumentHelp = argumentHelp,
.description = description,
.require_argument = 1,
.processor = &set_amount,
.scls = (void *) amount
};
return clo;
}
/* end of util.c */ /* end of util.c */