summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/auditor/taler-auditor-sign.c77
-rw-r--r--src/benchmark/taler-exchange-benchmark.c58
-rw-r--r--src/exchange-tools/Makefile.am4
-rw-r--r--src/exchange-tools/taler-exchange-dbinit.c14
-rw-r--r--src/exchange-tools/taler-exchange-keyup.c60
-rw-r--r--src/exchange-tools/taler-exchange-reservemod.c131
-rw-r--r--src/exchange-tools/taler-exchange-wire.c86
-rw-r--r--src/exchange/taler-exchange-aggregator.c9
-rw-r--r--src/exchange/taler-exchange-httpd.c37
-rw-r--r--src/include/taler_amount_lib.h10
-rw-r--r--src/include/taler_util.h17
-rw-r--r--src/util/amount.c21
-rw-r--r--src/util/util.c66
13 files changed, 302 insertions, 288 deletions
diff --git a/src/auditor/taler-auditor-sign.c b/src/auditor/taler-auditor-sign.c
index 90888da33..5d73eccaf 100644
--- a/src/auditor/taler-auditor-sign.c
+++ b/src/auditor/taler-auditor-sign.c
@@ -26,7 +26,7 @@
/**
* Are we running in verbose mode?
*/
-static int verbose;
+static unsigned int verbose;
/**
* Filename of the auditor's private key.
@@ -34,11 +34,6 @@ static int verbose;
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
* signed by the Exchange's public key.
*/
@@ -144,23 +139,35 @@ main (int argc,
{
char *cfgfile = NULL;
const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'a', "auditor-key", "FILENAME",
- "file containing the private key of the auditor", 1,
- &GNUNET_GETOPT_set_filename, &auditor_key_file},
+ GNUNET_GETOPT_OPTION_FILENAME ('a',
+ "auditor-key",
+ "FILENAME",
+ "file containing the private key of the auditor",
+ &auditor_key_file),
GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile),
GNUNET_GETOPT_OPTION_HELP ("Private key of the auditor to use for signing"),
- {'m', "exchange-key", "KEY",
- "public key of the exchange (Crockford base32 encoded)", 1,
- &GNUNET_GETOPT_set_string, &exchange_public_key},
- {'u', "auditor-url", "URL",
- "URL of the auditor (informative link for the user)", 1,
- &GNUNET_GETOPT_set_string, &auditor_url},
- {'r', "exchange-request", "FILENAME",
- "set of keys the exchange requested the auditor to sign", 1,
- &GNUNET_GETOPT_set_string, &exchange_request_file},
- {'o', "output", "FILENAME",
- "where to write our signature", 1,
- &GNUNET_GETOPT_set_string, &output_file},
+ GNUNET_GETOPT_OPTION_MANDATORY
+ (GNUNET_GETOPT_OPTION_SET_BASE32_AUTO ('m',
+ "exchange-key",
+ "KEY",
+ "public key of the exchange (Crockford base32 encoded)",
+ &master_public_key)),
+ GNUNET_GETOPT_OPTION_STRING ('u',
+ "auditor-url",
+ "URL",
+ "URL of the auditor (informative link for the user)",
+ &auditor_url),
+ 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_VERBOSE (&verbose),
GNUNET_GETOPT_OPTION_END
@@ -213,7 +220,7 @@ main (int argc,
&auditor_url)) )
{
fprintf (stderr,
- "Auditor URL not given\n");
+ "Auditor URL not given in neither configuration nor command-line\n");
return 1;
}
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,
&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,
GNUNET_DISK_OPEN_READ,
GNUNET_DISK_PERM_NONE);
diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c
index 62a7fb684..39236c648 100644
--- a/src/benchmark/taler-exchange-benchmark.c
+++ b/src/benchmark/taler-exchange-benchmark.c
@@ -268,7 +268,7 @@ static int run_exchange;
* every 50 iterations. Also includes how long the iteration took,
* 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
@@ -1442,17 +1442,12 @@ run (void *cls)
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"gotten pool_size of %d\n",
pool_size);
- if (NULL == config_file)
- {
- fail ("-c option is mandatory");
- return;
- }
-
cfg = GNUNET_CONFIGURATION_create ();
GNUNET_SCHEDULER_add_shutdown (&do_shutdown,
NULL);
- if (GNUNET_SYSERR == GNUNET_CONFIGURATION_parse (cfg,
- config_file))
+ if (GNUNET_SYSERR ==
+ GNUNET_CONFIGURATION_parse (cfg,
+ config_file))
{
fail ("Failed to parse configuration file");
return;
@@ -1567,23 +1562,33 @@ main (int argc,
struct GNUNET_OS_Process *proc;
unsigned int cnt;
const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'a', "automate", NULL,
- "Initialize and start the bank and exchange", GNUNET_NO,
- &GNUNET_GETOPT_set_one, &run_exchange},
- GNUNET_GETOPT_OPTION_CFG_FILE (&config_file),
- {'e', "exchange-uri", "URI",
- "URI of the exchange", GNUNET_YES,
- &GNUNET_GETOPT_set_string, &exchange_uri},
- {'E', "exchange-admin-uri", "URI",
- "URI of the administrative interface of the exchange", GNUNET_YES,
- &GNUNET_GETOPT_set_string, &exchange_admin_uri},
+ GNUNET_GETOPT_OPTION_SET_ONE ('a',
+ "automate",
+ "Initialize and start the bank and exchange",
+ &run_exchange),
+ GNUNET_GETOPT_OPTION_MANDATORY
+ (GNUNET_GETOPT_OPTION_CFG_FILE (&config_file)),
+ GNUNET_GETOPT_OPTION_STRING ('e',
+ "exchange-uri",
+ "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"),
- {'s', "pool-size", "SIZE",
- "How many coins this benchmark should instantiate", GNUNET_YES,
- &GNUNET_GETOPT_set_uint, &pool_size},
- {'l', "limit", "LIMIT",
- "Terminate the benchmark after LIMIT operations", GNUNET_YES,
- &GNUNET_GETOPT_set_uint, &num_iterations},
+ GNUNET_GETOPT_OPTION_SET_UINT ('s',
+ "pool-size",
+ "SIZE",
+ "How many coins this benchmark should instantiate",
+ &pool_size),
+ 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_END
};
@@ -1687,7 +1692,8 @@ main (int argc,
GNUNET_free (wget);
fprintf (stderr, "\n");
}
- GNUNET_SCHEDULER_run (&run, NULL);
+ GNUNET_SCHEDULER_run (&run,
+ NULL);
if (run_exchange)
{
GNUNET_OS_process_kill (exchanged,
diff --git a/src/exchange-tools/Makefile.am b/src/exchange-tools/Makefile.am
index 60b2cc2c5..8eb2ac210 100644
--- a/src/exchange-tools/Makefile.am
+++ b/src/exchange-tools/Makefile.am
@@ -58,7 +58,9 @@ taler_exchange_reservemod_LDADD = \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/pq/libtalerpq.la \
$(top_builddir)/src/exchangedb/libtalerexchangedb.la \
- -lgnunetutil -ljansson $(XLIB)
+ -lgnunetjson \
+ -lgnunetutil \
+ -ljansson $(XLIB)
taler_exchange_reservemod_LDFLAGS = \
$(POSTGRESQL_LDFLAGS)
taler_exchange_reservemod_CPPFLAGS = \
diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c
index b0f53d55a..23a31fad1 100644
--- a/src/exchange-tools/taler-exchange-dbinit.c
+++ b/src/exchange-tools/taler-exchange-dbinit.c
@@ -96,12 +96,14 @@ main (int argc,
char *const *argv)
{
const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'r', "reset", NULL,
- "reset database (DANGEROUS: all existing data is lost!)", 0,
- &GNUNET_GETOPT_set_one, &reset_db},
- {'g', "gc", NULL,
- "garbage collect database", 0,
- &GNUNET_GETOPT_set_one, &gc_db},
+ GNUNET_GETOPT_OPTION_SET_ONE ('r',
+ "reset",
+ "reset database (DANGEROUS: all existing data is lost!)",
+ &reset_db),
+ GNUNET_GETOPT_OPTION_SET_ONE ('g',
+ "gc",
+ "garbage collect database",
+ &gc_db),
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c
index f14e28b3c..679a3ff89 100644
--- a/src/exchange-tools/taler-exchange-keyup.c
+++ b/src/exchange-tools/taler-exchange-keyup.c
@@ -185,11 +185,6 @@ static FILE *auditor_output_file;
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.
*/
static char *feedir;
@@ -1041,23 +1036,6 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
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 (GNUNET_OK !=
@@ -1232,27 +1210,35 @@ int
main (int argc,
char *const *argv)
{
- const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'m', "master-key", "FILE",
- "master key file (private key)", 1,
- &GNUNET_GETOPT_set_filename, &masterkeyfile},
- {'f', "feedir", "DIRNAME",
- "directory where to write wire transfer fee structure", 1,
- &GNUNET_GETOPT_set_filename, &feedir},
- {'o', "output", "FILE",
- "auditor denomination key signing request file to create", 1,
- &GNUNET_GETOPT_set_filename, &auditorrequestfile},
- {'t', "time", "TIMESTAMP",
- "pretend it is a different time for the update", 0,
- &GNUNET_GETOPT_set_string, &pretend_time_str},
- GNUNET_GETOPT_OPTION_END
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_FILENAME ('m',
+ "master-key",
+ "FILENAME",
+ "master key file (private key)",
+ &masterkeyfile),
+ GNUNET_GETOPT_OPTION_FILENAME ('f',
+ "feedir",
+ "DIRNAME",
+ "directory where to write wire transfer fee structure",
+ &feedir),
+ GNUNET_GETOPT_OPTION_FILENAME ('o',
+ "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_assert (GNUNET_OK ==
GNUNET_log_setup ("taler-exchange-keyup",
"WARNING",
NULL));
-
+ now = GNUNET_TIME_absolute_get ();
if (GNUNET_OK !=
GNUNET_PROGRAM_run (argc, argv,
"taler-exchange-keyup",
diff --git a/src/exchange-tools/taler-exchange-reservemod.c b/src/exchange-tools/taler-exchange-reservemod.c
index ce3297f34..9bcc4e15b 100644
--- a/src/exchange-tools/taler-exchange-reservemod.c
+++ b/src/exchange-tools/taler-exchange-reservemod.c
@@ -1,6 +1,6 @@
/*
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
terms of the GNU General Public License as published by the Free Software
@@ -21,6 +21,7 @@
*/
#include "platform.h"
#include <gnunet/gnunet_util_lib.h>
+#include <gnunet/gnunet_json_lib.h>
#include <libpq-fe.h>
#include <jansson.h>
#include "taler_exchangedb_plugin.h"
@@ -36,24 +37,24 @@ static char *exchange_directory;
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.
*/
-static char *sender_details;
+static json_t *sender_details;
/**
* Details about the wire transfer in JSON format.
*/
-static char *transfer_details;
+static json_t *transfer_details;
/**
* Return value from main().
@@ -123,12 +124,6 @@ run (void *cls,
const char *cfgfile,
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 !=
GNUNET_CONFIGURATION_get_value_filename (cfg,
"exchange",
@@ -141,72 +136,6 @@ run (void *cls,
global_ret = 1;
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 ==
(plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{
@@ -218,12 +147,12 @@ run (void *cls,
if (GNUNET_SYSERR ==
run_transaction (&reserve_pub,
&add_value,
- jdetails,
- tdetails))
+ sender_details,
+ transfer_details))
global_ret = 1;
TALER_EXCHANGEDB_plugin_unload (plugin);
- json_decref (jdetails);
- json_decref (tdetails);
+ json_decref (transfer_details);
+ json_decref (sender_details);
}
@@ -238,19 +167,31 @@ int
main (int argc, char *const *argv)
{
const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'a', "add", "DENOM",
- "value to add", 1,
- &GNUNET_GETOPT_set_string, &add_str},
- {'s', "sender", "JSON",
- "details about the sender's bank account", 1,
- &GNUNET_GETOPT_set_string, &sender_details},
- {'t', "transfer", "JSON",
- "details that uniquely identify the bank transfer", 1,
- &GNUNET_GETOPT_set_string, &transfer_details},
+ GNUNET_GETOPT_OPTION_MANDATORY
+ (TALER_getopt_get_amount ('a',
+ "add",
+ "DENOM",
+ "value to add",
+ &add_value)),
+ GNUNET_GETOPT_OPTION_MANDATORY
+ (GNUNET_JSON_getopt ('s',
+ "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"),
- {'R', "reserve", "KEY",
- "reserve (public key) to modify", 1,
- &GNUNET_GETOPT_set_string, &reserve_pub_str},
+ GNUNET_GETOPT_OPTION_MANDATORY
+ (GNUNET_GETOPT_OPTION_SET_BASE32_AUTO ('R',
+ "reserve",
+ "KEY",
+ "reserve (public key) to modify",
+ &reserve_pub)),
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/exchange-tools/taler-exchange-wire.c b/src/exchange-tools/taler-exchange-wire.c
index 7249398d3..b7f6af89d 100644
--- a/src/exchange-tools/taler-exchange-wire.c
+++ b/src/exchange-tools/taler-exchange-wire.c
@@ -1,6 +1,6 @@
/*
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
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.
*/
-static char *json_in;
+static json_t *account_holder;
/**
* Which wire method is this for?
*/
-static const char *method;
+static char *method;
/**
* Where to write the result.
@@ -70,8 +70,6 @@ run (void *cls,
struct GNUNET_CRYPTO_EddsaPrivateKey *eddsa_priv;
struct TALER_MasterPrivateKeyP key;
struct TALER_MasterSignatureP sig;
- json_t *j;
- json_error_t err;
char *json_out;
struct GNUNET_HashCode salt;
struct TALER_WIRE_Plugin *plugin;
@@ -101,40 +99,26 @@ run (void *cls,
global_ret = 1;
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)
{
json_t *test;
- test = json_object_get(j, "type");
- if (NULL == test || (NULL == (method = json_string_value (test))))
+ const char *m;
+
+ test = json_object_get(account_holder,
+ "type");
+ if ( (NULL == test) ||
+ (NULL == (m = json_string_value (test))))
{
fprintf (stderr,
"Required -t argument missing\n");
global_ret = 1;
return;
}
+ method = GNUNET_strdup (m);
}
else
{
- json_object_set_new (j,
+ json_object_set_new (account_holder,
"type",
json_string (method));
}
@@ -149,18 +133,20 @@ run (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Wire transfer method `%s' not supported\n",
method);
+ GNUNET_free (method);
global_ret = 1;
return;
}
+ GNUNET_free (method);
if (GNUNET_OK !=
plugin->sign_wire_details (plugin->cls,
- j,
+ account_holder,
&key,
&salt,
&sig))
{
/* sign function should have logged applicable errors */
- json_decref (j);
+ json_decref (account_holder);
TALER_WIRE_plugin_unload (plugin);
global_ret = 1;
return;
@@ -169,18 +155,19 @@ run (void *cls,
GNUNET_free (eddsa_priv);
/* add signature and salt to JSON message */
- json_object_set_new (j,
+ json_object_set_new (account_holder,
"salt",
GNUNET_JSON_from_data (&salt,
sizeof (salt)));
- json_object_set_new (j,
+ json_object_set_new (account_holder,
"sig",
GNUNET_JSON_from_data (&sig,
sizeof (sig)));
/* dump result to stdout */
- json_out = json_dumps (j, JSON_INDENT(2));
- json_decref (j);
+ json_out = json_dumps (account_holder,
+ JSON_INDENT(2));
+ json_decref (account_holder);
GNUNET_assert (NULL != json_out);
if (NULL != output_filename)
@@ -219,18 +206,27 @@ 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_MANDATORY
+ (GNUNET_JSON_getopt ('j',
+ "json",
+ "JSON",
+ "account information in JSON format",
+ &account_holder)),
+ GNUNET_GETOPT_OPTION_FILENAME ('m',
+ "master-key",
+ "FILENAME",
+ "master key file (private key)",
+ &masterkeyfile),
+ 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
};
diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c
index cbf3fb5d3..ae4ee24fd 100644
--- a/src/exchange/taler-exchange-aggregator.c
+++ b/src/exchange/taler-exchange-aggregator.c
@@ -1198,10 +1198,11 @@ int
main (int argc,
char *const *argv)
{
- static const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'t', "test", NULL,
- "run in test mode and exit when idle", 0,
- &GNUNET_GETOPT_set_one, &test_mode},
+ struct GNUNET_GETOPT_CommandLineOption options[] = {
+ GNUNET_GETOPT_OPTION_SET_ONE ('t',
+ "test",
+ "run in test mode and exit when idle",
+ &test_mode),
GNUNET_GETOPT_OPTION_VERSION (VERSION "-" VCS_VERSION),
GNUNET_GETOPT_OPTION_END
};
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index fa000d06b..6b430d734 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -934,23 +934,30 @@ main (int argc,
char *loglev = NULL;
char *logfile = NULL;
const struct GNUNET_GETOPT_CommandLineOption options[] = {
- {'C', "connection-close", NULL,
- "force HTTP connections to be closed after each request", 0,
- &GNUNET_GETOPT_set_one, &TEH_exchange_connection_close},
+ GNUNET_GETOPT_OPTION_SET_ONE ('C',
+ "connection-close",
+ "force HTTP connections to be closed after each request",
+ &TEH_exchange_connection_close),
GNUNET_GETOPT_OPTION_CFG_FILE (&cfgfile),
- {'D', "disable-admin", NULL,
- "do not run the /admin-HTTP server", 0,
- &GNUNET_GETOPT_set_one, &no_admin},
- {'i', "init-db", NULL,
- "create database tables and indicies if necessary", 0,
- &GNUNET_GETOPT_set_one, &init_db},
- {'t', "timeout", "SECONDS",
- "after how long do connections timeout by default (in seconds)", 1,
- &GNUNET_GETOPT_set_uint, &connection_timeout},
+ GNUNET_GETOPT_OPTION_SET_ONE ('D',
+ "disable-admin",
+ "do not run the /admin-HTTP server",
+ &no_admin),
+ GNUNET_GETOPT_OPTION_SET_ONE ('i',
+ "init-db",
+ "create database tables and indicies if necessary",
+ &init_db),
+ GNUNET_GETOPT_OPTION_SET_UINT ('t',
+ "timeout",
+ "SECONDS",
+ "after how long do connections timeout by default (in seconds)",
+ &connection_timeout),
#if HAVE_DEVELOPER
- {'f', "file-input", "FILENAME",
- "run in test-mode using FILENAME as the HTTP request to process", 1,
- &GNUNET_GETOPT_set_filename, &input_filename},
+ GNUNET_GETOPT_OPTION_FILENAME ('f',
+ "file-input",
+ "FILENAME",
+ "run in test-mode using FILENAME as the HTTP request to process",
+ &input_filename),
#endif
GNUNET_GETOPT_OPTION_HELP ("HTTP server providing a RESTful API to access a Taler exchange"),
GNUNET_GETOPT_OPTION_LOGLEVEL (&loglev),
diff --git a/src/include/taler_amount_lib.h b/src/include/taler_amount_lib.h
index 555894f4b..e6c36fed8 100644
--- a/src/include/taler_amount_lib.h
+++ b/src/include/taler_amount_lib.h
@@ -152,6 +152,16 @@ TALER_amount_get_zero (const char *cur,
/**
+ * 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.
*
* @param res where to store amount in network representation
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index c115594f5..34e07a351 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -111,6 +111,23 @@ TALER_config_get_denom (const struct GNUNET_CONFIGURATION_Handle *cfg,
/**
+ * 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.
*/
const struct GNUNET_OS_ProjectData *
diff --git a/src/util/amount.c b/src/util/amount.c
index 7684ddf32..44eefe6a6 100644
--- a/src/util/amount.c
+++ b/src/util/amount.c
@@ -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
- * @return #GNUNET_YES if valid,
- * #GNUNET_NO if invalid
+ * @param amount amount to check
+ * @return #GNUNET_OK if @a amount is valid
*/
-static int
-test_valid (const struct TALER_Amount *a)
+int
+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,
const struct TALER_Amount *a2)
{
- if ( (GNUNET_NO == test_valid (a1)) ||
- (GNUNET_NO == test_valid (a2)) )
+ if ( (GNUNET_NO == TALER_amount_is_valid (a1)) ||
+ (GNUNET_NO == TALER_amount_is_valid (a2)) )
return GNUNET_SYSERR;
if (0 == strcasecmp (a1->currency,
a2->currency))
@@ -499,7 +498,7 @@ TALER_amount_normalize (struct TALER_Amount *amount)
{
int ret;
- if (GNUNET_YES != test_valid (amount))
+ if (GNUNET_YES != TALER_amount_is_valid (amount))
return GNUNET_SYSERR;
ret = GNUNET_NO;
while ( (amount->value != UINT64_MAX) &&
@@ -535,7 +534,7 @@ TALER_amount_to_string (const struct TALER_Amount *amount)
unsigned int i;
struct TALER_Amount norm;
- if (GNUNET_YES != test_valid (amount))
+ if (GNUNET_YES != TALER_amount_is_valid (amount))
return NULL;
norm = *amount;
GNUNET_break (GNUNET_SYSERR !=
diff --git a/src/util/util.c b/src/util/util.c
index e01a2cc02..8976b0a3d 100644
--- a/src/util/util.c
+++ b/src/util/util.c
@@ -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 */