summaryrefslogtreecommitdiff
path: root/src/exchange-tools
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-03-15 12:01:06 +0100
committerChristian Grothoff <christian@grothoff.org>2017-03-15 12:01:06 +0100
commitae3e850c946947cead6b9330f7c8e9764bd5f934 (patch)
treec031aeb264149454869f1ace7bf8db0a04d3002b /src/exchange-tools
parent296f919ce4dcd9123c402d52d18afae7e353b11a (diff)
downloadexchange-ae3e850c946947cead6b9330f7c8e9764bd5f934.tar.gz
exchange-ae3e850c946947cead6b9330f7c8e9764bd5f934.tar.bz2
exchange-ae3e850c946947cead6b9330f7c8e9764bd5f934.zip
update getopt config parsing style to match 'getopt' GNUnet branch API change
Diffstat (limited to 'src/exchange-tools')
-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
5 files changed, 111 insertions, 184 deletions
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
};