summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-15 20:08:38 +0100
committerChristian Grothoff <christian@grothoff.org>2020-03-15 20:08:38 +0100
commit4322bbf2f1722b4c53114901768772dabdb7e822 (patch)
treee2193282c2d179f2d3bdf32eb7aca7a6ba161f25 /src
parentd7cfb11fc6a171ece9c233d67ec849ac391bc818 (diff)
downloadexchange-4322bbf2f1722b4c53114901768772dabdb7e822.tar.gz
exchange-4322bbf2f1722b4c53114901768772dabdb7e822.tar.bz2
exchange-4322bbf2f1722b4c53114901768772dabdb7e822.zip
move common logic to parse currency into libtalerutil
Diffstat (limited to 'src')
-rw-r--r--src/auditor/taler-auditor-httpd.c9
-rw-r--r--src/auditor/taler-auditor.c9
-rw-r--r--src/auditor/taler-wire-auditor.c9
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c9
-rw-r--r--src/bank-lib/Makefile.am1
-rw-r--r--src/bank-lib/taler-fakebank-run.c20
-rw-r--r--src/benchmark/taler-exchange-benchmark.c20
-rw-r--r--src/exchange-tools/taler-exchange-keyup.c11
-rw-r--r--src/exchange/taler-exchange-httpd.c25
-rw-r--r--src/exchange/taler-exchange-wirewatch.c47
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c9
-rw-r--r--src/include/taler_util.h13
-rw-r--r--src/testing/testing_api_loop.c19
-rw-r--r--src/util/config.c37
14 files changed, 82 insertions, 156 deletions
diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c
index ff069f2aa..d7d8c4e5f 100644
--- a/src/auditor/taler-auditor-httpd.c
+++ b/src/auditor/taler-auditor-httpd.c
@@ -455,14 +455,9 @@ auditor_serve_process_config ()
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "TALER",
- "CURRENCY",
- &currency))
+ TALER_config_get_currency (cfg,
+ &currency))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "TALER",
- "CURRENCY");
return GNUNET_SYSERR;
}
if (GNUNET_OK !=
diff --git a/src/auditor/taler-auditor.c b/src/auditor/taler-auditor.c
index aad7cf175..d9d91fcfb 100644
--- a/src/auditor/taler-auditor.c
+++ b/src/auditor/taler-auditor.c
@@ -5291,14 +5291,9 @@ run (void *cls,
TALER_B2S (&master_pub));
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &currency))
+ TALER_config_get_currency (cfg,
+ &currency))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
global_ret = 1;
return;
}
diff --git a/src/auditor/taler-wire-auditor.c b/src/auditor/taler-wire-auditor.c
index 51c1ba815..fb8e52f7b 100644
--- a/src/auditor/taler-wire-auditor.c
+++ b/src/auditor/taler-wire-auditor.c
@@ -2178,14 +2178,9 @@ run (void *cls,
} /* end of -m not given */
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &currency))
+ TALER_config_get_currency (cfg,
+ &currency))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
global_ret = 1;
return;
}
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 2f1b5234d..d48defb15 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -3197,14 +3197,9 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
return NULL;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &pg->currency))
+ TALER_config_get_currency (cfg,
+ &pg->currency))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
GNUNET_free (pg);
return NULL;
}
diff --git a/src/bank-lib/Makefile.am b/src/bank-lib/Makefile.am
index 729f96e15..282c9db7e 100644
--- a/src/bank-lib/Makefile.am
+++ b/src/bank-lib/Makefile.am
@@ -16,6 +16,7 @@ taler_fakebank_run_SOURCES = \
taler-fakebank-run.c
taler_fakebank_run_LDADD = \
libtalerfakebank.la \
+ $(top_builddir)/src/util/libtalerutil.la \
-lgnunetutil
taler_bank_transfer_SOURCES = \
diff --git a/src/bank-lib/taler-fakebank-run.c b/src/bank-lib/taler-fakebank-run.c
index 588777c94..4b94a4bd9 100644
--- a/src/bank-lib/taler-fakebank-run.c
+++ b/src/bank-lib/taler-fakebank-run.c
@@ -48,26 +48,10 @@ run (void *cls,
(void) cls;
(void) args;
(void) cfgfile;
- (void) cfg;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &currency_string))
+ TALER_config_get_currency (cfg,
+ &currency_string))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
- ret = 1;
- return;
- }
- if (strlen (currency_string) >= TALER_CURRENCY_LEN)
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY",
- "Value is too long");
- GNUNET_free (currency_string);
ret = 1;
return;
}
diff --git a/src/benchmark/taler-exchange-benchmark.c b/src/benchmark/taler-exchange-benchmark.c
index 3ea2b0bba..b1f2bc578 100644
--- a/src/benchmark/taler-exchange-benchmark.c
+++ b/src/benchmark/taler-exchange-benchmark.c
@@ -831,25 +831,9 @@ main (int argc,
return BAD_CONFIG_FILE;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "currency",
- &currency))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "currency");
- GNUNET_CONFIGURATION_destroy (cfg);
- GNUNET_free (cfg_filename);
- return BAD_CONFIG_FILE;
- }
-
- if (strlen (currency) >= TALER_CURRENCY_LEN)
+ TALER_config_get_currency (cfg,
+ &currency))
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY",
- "Value is too long");
GNUNET_CONFIGURATION_destroy (cfg);
GNUNET_free (cfg_filename);
return BAD_CONFIG_FILE;
diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c
index b10a139a7..4513934bf 100644
--- a/src/exchange-tools/taler-exchange-keyup.c
+++ b/src/exchange-tools/taler-exchange-keyup.c
@@ -772,7 +772,7 @@ create_denomkey_issue (
GNUNET_assert (NULL != dki->denom_priv.rsa_private_key);
dki->denom_pub.rsa_public_key
= GNUNET_CRYPTO_rsa_private_key_get_public (
- dki->denom_priv.rsa_private_key);
+ dki->denom_priv.rsa_private_key);
GNUNET_CRYPTO_rsa_public_key_hash (dki->denom_pub.rsa_public_key,
&dki->issue.properties.denom_hash);
dki->issue.properties.master = master_public_key;
@@ -1174,14 +1174,9 @@ run (void *cls,
(void) cfgfile;
kcfg = cfg;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &currency))
+ TALER_config_get_currency (cfg,
+ &currency))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
global_ret = 1;
return;
}
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c
index 98d6a9ba5..9524c2cbf 100644
--- a/src/exchange/taler-exchange-httpd.c
+++ b/src/exchange/taler-exchange-httpd.c
@@ -759,31 +759,6 @@ exchange_serve_process_config ()
return GNUNET_SYSERR;
}
{
- char *currency_string;
-
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &currency_string))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
- return GNUNET_SYSERR;
- }
- if (strlen (currency_string) >= TALER_CURRENCY_LEN)
- {
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY",
- "Value is too long");
- GNUNET_free (currency_string);
- return GNUNET_SYSERR;
- }
- GNUNET_free (currency_string);
- }
- {
char *master_public_key_str;
if (GNUNET_OK !=
diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c
index 69929e127..3731f6633 100644
--- a/src/exchange/taler-exchange-wirewatch.c
+++ b/src/exchange/taler-exchange-wirewatch.c
@@ -101,11 +101,6 @@ static struct GNUNET_CURL_Context *ctx;
static struct GNUNET_CURL_RescheduleContext *rc;
/**
- * Which currency is used by this exchange?
- */
-static char *exchange_currency_string;
-
-/**
* The exchange's configuration (global)
*/
static const struct GNUNET_CONFIGURATION_Handle *cfg;
@@ -177,8 +172,6 @@ static struct TALER_BANK_CreditHistoryHandle *hh;
static void
shutdown_task (void *cls)
{
- struct WireAccount *wa;
-
(void) cls;
if (NULL != hh)
{
@@ -202,14 +195,18 @@ shutdown_task (void *cls)
}
TALER_EXCHANGEDB_plugin_unload (db_plugin);
db_plugin = NULL;
- while (NULL != (wa = wa_head))
{
- GNUNET_CONTAINER_DLL_remove (wa_head,
- wa_tail,
- wa);
- TALER_BANK_auth_free (&wa->auth);
- GNUNET_free (wa->section_name);
- GNUNET_free (wa);
+ struct WireAccount *wa;
+
+ while (NULL != (wa = wa_head))
+ {
+ GNUNET_CONTAINER_DLL_remove (wa_head,
+ wa_tail,
+ wa);
+ TALER_BANK_auth_free (&wa->auth);
+ GNUNET_free (wa->section_name);
+ GNUNET_free (wa);
+ }
}
wa_pos = NULL;
last_row_off = 0;
@@ -259,28 +256,8 @@ add_account_cb (void *cls,
* @return #GNUNET_OK on success
*/
static int
-exchange_serve_process_config ()
+exchange_serve_process_config (void)
{
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &exchange_currency_string))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
- return GNUNET_SYSERR;
- }
- if (strlen (exchange_currency_string) >= TALER_CURRENCY_LEN)
- {
- fprintf (stderr,
- "Currency `%s' longer than the allowed limit of %u characters.",
- exchange_currency_string,
- (unsigned int) TALER_CURRENCY_LEN);
- return GNUNET_SYSERR;
- }
-
if (NULL ==
(db_plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
{
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index dfa05fb8c..e333c1dfc 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -7230,14 +7230,9 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
return NULL;
}
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "taler",
- "CURRENCY",
- &pg->currency))
+ TALER_config_get_currency (cfg,
+ &pg->currency))
{
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
GNUNET_free (pg->sql_dir);
GNUNET_free (pg);
return NULL;
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index cf44f0238..c7bf9c02a 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -138,6 +138,19 @@ TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
/**
+ * Load our currency from the @a cfg (in section [taler]
+ * the option "CURRENCY").
+ *
+ * @param cfg configuration to use
+ * @param[out] currency where to write the result
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+int
+TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char **currency);
+
+
+/**
* Allow user to specify an amount on the command line.
*
* @param shortName short name of the option
diff --git a/src/testing/testing_api_loop.c b/src/testing/testing_api_loop.c
index 5f30f71e9..1053e6f78 100644
--- a/src/testing/testing_api_loop.c
+++ b/src/testing/testing_api_loop.c
@@ -127,24 +127,9 @@ TALER_TESTING_run_with_fakebank (struct TALER_TESTING_Interpreter *is,
char *currency;
if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (is->cfg,
- "taler",
- "CURRENCY",
- &currency))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY");
- is->result = GNUNET_SYSERR;
- return;
- }
- if (strlen (currency) >= TALER_CURRENCY_LEN)
+ TALER_config_get_currency (is->cfg,
+ &currency))
{
- GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
- "taler",
- "CURRENCY",
- "Value is too long");
- GNUNET_free (currency);
is->result = GNUNET_SYSERR;
return;
}
diff --git a/src/util/config.c b/src/util/config.c
index ee74fe8ff..160d541f0 100644
--- a/src/util/config.c
+++ b/src/util/config.c
@@ -55,3 +55,40 @@ TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
GNUNET_free (str);
return GNUNET_OK;
}
+
+
+/**
+ * Load our currency from the @a cfg (in section [taler]
+ * the option "CURRENCY").
+ *
+ * @param cfg configuration to use
+ * @param[out] currency where to write the result
+ * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
+ */
+int
+TALER_config_get_currency (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ char **currency)
+{
+ if (GNUNET_OK !=
+ GNUNET_CONFIGURATION_get_value_string (cfg,
+ "taler",
+ "CURRENCY",
+ currency))
+ {
+ GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
+ "taler",
+ "CURRENCY");
+ return GNUNET_SYSERR;
+ }
+ if (strlen (*currency) >= TALER_CURRENCY_LEN)
+ {
+ fprintf (stderr,
+ "Currency `%s' longer than the allowed limit of %u characters.",
+ *currency,
+ (unsigned int) TALER_CURRENCY_LEN);
+ GNUNET_free (*currency);
+ *currency = NULL;
+ return GNUNET_SYSERR;
+ }
+ return GNUNET_OK;
+}