move common logic to parse currency into libtalerutil
This commit is contained in:
parent
d7cfb11fc6
commit
4322bbf2f1
@ -455,14 +455,9 @@ auditor_serve_process_config ()
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||
"TALER",
|
||||
"CURRENCY",
|
||||
¤cy))
|
||||
TALER_config_get_currency (cfg,
|
||||
¤cy))
|
||||
{
|
||||
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
||||
"TALER",
|
||||
"CURRENCY");
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (GNUNET_OK !=
|
||||
|
@ -5291,14 +5291,9 @@ run (void *cls,
|
||||
TALER_B2S (&master_pub));
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||
"taler",
|
||||
"CURRENCY",
|
||||
¤cy))
|
||||
TALER_config_get_currency (cfg,
|
||||
¤cy))
|
||||
{
|
||||
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
||||
"taler",
|
||||
"CURRENCY");
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
|
@ -2178,14 +2178,9 @@ run (void *cls,
|
||||
} /* end of -m not given */
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||
"taler",
|
||||
"CURRENCY",
|
||||
¤cy))
|
||||
TALER_config_get_currency (cfg,
|
||||
¤cy))
|
||||
{
|
||||
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
||||
"taler",
|
||||
"CURRENCY");
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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 = \
|
||||
|
@ -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",
|
||||
¤cy_string))
|
||||
TALER_config_get_currency (cfg,
|
||||
¤cy_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;
|
||||
}
|
||||
|
@ -831,25 +831,9 @@ main (int argc,
|
||||
return BAD_CONFIG_FILE;
|
||||
}
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||
"taler",
|
||||
"currency",
|
||||
¤cy))
|
||||
TALER_config_get_currency (cfg,
|
||||
¤cy))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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;
|
||||
|
@ -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",
|
||||
¤cy))
|
||||
TALER_config_get_currency (cfg,
|
||||
¤cy))
|
||||
{
|
||||
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
||||
"taler",
|
||||
"CURRENCY");
|
||||
global_ret = 1;
|
||||
return;
|
||||
}
|
||||
|
@ -758,31 +758,6 @@ exchange_serve_process_config ()
|
||||
"REVOCATION_DIR");
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
{
|
||||
char *currency_string;
|
||||
|
||||
if (GNUNET_OK !=
|
||||
GNUNET_CONFIGURATION_get_value_string (cfg,
|
||||
"taler",
|
||||
"CURRENCY",
|
||||
¤cy_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;
|
||||
|
||||
|
@ -100,11 +100,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)
|
||||
*/
|
||||
@ -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)))
|
||||
{
|
||||
|
@ -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;
|
||||
|
@ -137,6 +137,19 @@ TALER_config_get_amount (const struct GNUNET_CONFIGURATION_Handle *cfg,
|
||||
struct TALER_Amount *denom);
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
|
@ -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",
|
||||
¤cy))
|
||||
TALER_config_get_currency (is->cfg,
|
||||
¤cy))
|
||||
{
|
||||
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
|
||||
"taler",
|
||||
"CURRENCY");
|
||||
is->result = GNUNET_SYSERR;
|
||||
return;
|
||||
}
|
||||
if (strlen (currency) >= TALER_CURRENCY_LEN)
|
||||
{
|
||||
GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_ERROR,
|
||||
"taler",
|
||||
"CURRENCY",
|
||||
"Value is too long");
|
||||
GNUNET_free (currency);
|
||||
is->result = GNUNET_SYSERR;
|
||||
return;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user