2018-04-02 14:24:45 +02:00
|
|
|
/*
|
|
|
|
This file is part of TALER
|
2021-08-03 21:58:36 +02:00
|
|
|
Copyright (C) 2018-2021 Taler Systems SA
|
2018-04-02 14:24:45 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
Foundation; either version 3, or (at your option) any later version.
|
|
|
|
|
|
|
|
TALER is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* @file exchangedb/exchangedb_accounts.c
|
|
|
|
* @brief Logic to parse account information from the configuration
|
|
|
|
* @author Christian Grothoff
|
|
|
|
*/
|
|
|
|
#include "platform.h"
|
|
|
|
#include "taler_exchangedb_lib.h"
|
|
|
|
|
|
|
|
|
2020-03-12 10:11:24 +01:00
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Information we keep for each supported account of the exchange.
|
2020-03-12 10:11:24 +01:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
struct WireAccount
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Accounts are kept in a DLL.
|
|
|
|
*/
|
|
|
|
struct WireAccount *next;
|
2020-03-12 10:11:24 +01:00
|
|
|
|
2021-08-03 21:58:36 +02:00
|
|
|
/**
|
|
|
|
* Plugins are kept in a DLL.
|
|
|
|
*/
|
|
|
|
struct WireAccount *prev;
|
2020-03-12 10:11:24 +01:00
|
|
|
|
2018-04-02 14:24:45 +02:00
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Externally visible account information.
|
2018-04-02 14:24:45 +02:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
struct TALER_EXCHANGEDB_AccountInfo ai;
|
2018-04-02 14:24:45 +02:00
|
|
|
|
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Authentication data. Only parsed if
|
|
|
|
* #TALER_EXCHANGEDB_ALO_AUTHDATA was set.
|
2018-04-02 14:24:45 +02:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
struct TALER_BANK_AuthenticationData auth;
|
2018-04-02 14:24:45 +02:00
|
|
|
|
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Name of the section that configures this account.
|
2018-04-02 14:24:45 +02:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
char *section_name;
|
2020-08-28 23:43:05 +02:00
|
|
|
|
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Name of the wire method underlying the account.
|
2020-08-28 23:43:05 +02:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
char *method;
|
|
|
|
|
2018-04-02 14:24:45 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Head of list of wire accounts of the exchange.
|
2018-04-02 14:24:45 +02:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
static struct WireAccount *wa_head;
|
2018-04-02 14:24:45 +02:00
|
|
|
|
|
|
|
/**
|
2021-08-03 21:58:36 +02:00
|
|
|
* Tail of list of wire accounts of the exchange.
|
2018-04-02 14:24:45 +02:00
|
|
|
*/
|
2021-08-03 21:58:36 +02:00
|
|
|
static struct WireAccount *wa_tail;
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TALER_EXCHANGEDB_find_accounts (TALER_EXCHANGEDB_AccountCallback cb,
|
2018-04-02 14:24:45 +02:00
|
|
|
void *cb_cls)
|
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
for (struct WireAccount *wa = wa_head;
|
|
|
|
NULL != wa;
|
|
|
|
wa = wa->next)
|
|
|
|
cb (cb_cls,
|
|
|
|
&wa->ai);
|
2018-04-02 14:24:45 +02:00
|
|
|
}
|
|
|
|
|
2019-10-31 12:59:50 +01:00
|
|
|
|
2021-08-03 21:58:36 +02:00
|
|
|
const struct TALER_EXCHANGEDB_AccountInfo *
|
2020-03-12 10:11:24 +01:00
|
|
|
TALER_EXCHANGEDB_find_account_by_method (const char *method)
|
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
for (struct WireAccount *wa = wa_head;
|
|
|
|
NULL != wa;
|
|
|
|
wa = wa->next)
|
2020-03-12 10:11:24 +01:00
|
|
|
if (0 == strcmp (method,
|
|
|
|
wa->method))
|
2021-08-03 21:58:36 +02:00
|
|
|
return &wa->ai;
|
2020-03-12 10:11:24 +01:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"No wire account known for method `%s'\n",
|
|
|
|
method);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-03 21:58:36 +02:00
|
|
|
const struct TALER_EXCHANGEDB_AccountInfo *
|
2020-03-12 10:11:24 +01:00
|
|
|
TALER_EXCHANGEDB_find_account_by_payto_uri (const char *url)
|
|
|
|
{
|
|
|
|
char *method;
|
2021-08-03 21:58:36 +02:00
|
|
|
const struct TALER_EXCHANGEDB_AccountInfo *ai;
|
2020-03-12 10:11:24 +01:00
|
|
|
|
|
|
|
method = TALER_payto_get_method (url);
|
|
|
|
if (NULL == method)
|
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"Invalid payto:// URL `%s'\n",
|
|
|
|
url);
|
|
|
|
return NULL;
|
|
|
|
}
|
2021-08-03 21:58:36 +02:00
|
|
|
ai = TALER_EXCHANGEDB_find_account_by_method (method);
|
2020-03-12 10:11:24 +01:00
|
|
|
GNUNET_free (method);
|
2021-08-03 21:58:36 +02:00
|
|
|
return ai;
|
2020-03-12 10:11:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-03 21:58:36 +02:00
|
|
|
/**
|
|
|
|
* Closure for #add_account_cb().
|
|
|
|
*/
|
|
|
|
struct LoaderContext
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Configuration to use.
|
|
|
|
*/
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* true if we are to load the authentication data
|
|
|
|
* for the access to the bank account.
|
|
|
|
*/
|
|
|
|
bool load_auth_data;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load accounts enabled for CREDIT.
|
|
|
|
*/
|
|
|
|
bool credit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load accounts enabled for DEBIT.
|
|
|
|
*/
|
|
|
|
bool debit;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loader status (set by callback).
|
|
|
|
*/
|
|
|
|
enum GNUNET_GenericReturnValue res;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-03-12 10:11:24 +01:00
|
|
|
/**
|
|
|
|
* Function called with information about a wire account. Adds
|
|
|
|
* the account to our list.
|
|
|
|
*
|
2021-08-03 21:58:36 +02:00
|
|
|
* @param cls closure, a `struct LoaderContext`
|
2021-08-04 08:39:19 +02:00
|
|
|
* @param section section to parse account information from
|
2020-03-12 10:11:24 +01:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
add_account_cb (void *cls,
|
2021-08-03 21:58:36 +02:00
|
|
|
const char *section)
|
2020-03-12 10:11:24 +01:00
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
struct LoaderContext *lc = cls;
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg = lc->cfg;
|
|
|
|
struct WireAccount *wa;
|
2020-03-12 10:11:24 +01:00
|
|
|
char *payto_uri;
|
2021-08-03 21:58:36 +02:00
|
|
|
char *method;
|
|
|
|
bool debit;
|
|
|
|
bool credit;
|
2020-03-12 10:11:24 +01:00
|
|
|
|
2021-08-03 21:58:36 +02:00
|
|
|
if (0 != strncasecmp (section,
|
|
|
|
"exchange-account-",
|
|
|
|
strlen ("exchange-account-")))
|
|
|
|
return;
|
|
|
|
|
|
|
|
debit = (GNUNET_YES ==
|
|
|
|
GNUNET_CONFIGURATION_get_value_yesno (lc->cfg,
|
|
|
|
section,
|
|
|
|
"ENABLE_DEBIT"));
|
|
|
|
credit = (GNUNET_YES ==
|
|
|
|
GNUNET_CONFIGURATION_get_value_yesno (lc->cfg,
|
|
|
|
section,
|
|
|
|
"ENABLE_CREDIT"));
|
|
|
|
if (! ( ( (debit) &&
|
|
|
|
(lc->debit) ) ||
|
|
|
|
( (credit) &&
|
|
|
|
(lc->credit) ) ) )
|
2020-03-12 10:11:24 +01:00
|
|
|
return; /* not enabled for us, skip */
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
GNUNET_CONFIGURATION_get_value_string (cfg,
|
2021-08-03 21:58:36 +02:00
|
|
|
section,
|
2020-03-12 10:11:24 +01:00
|
|
|
"PAYTO_URI",
|
|
|
|
&payto_uri))
|
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING,
|
|
|
|
section,
|
2020-03-12 10:11:24 +01:00
|
|
|
"PAYTO_URI");
|
2021-08-03 21:58:36 +02:00
|
|
|
lc->res = GNUNET_SYSERR;
|
2020-03-12 10:11:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-08-03 21:58:36 +02:00
|
|
|
method = TALER_payto_get_method (payto_uri);
|
|
|
|
GNUNET_free (payto_uri);
|
|
|
|
if (NULL == method)
|
2020-03-12 10:11:24 +01:00
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
|
|
|
"payto URI in config ([%s]/PAYTO_URI) malformed\n",
|
|
|
|
section);
|
|
|
|
lc->res = GNUNET_SYSERR;
|
2020-03-12 10:11:24 +01:00
|
|
|
return;
|
|
|
|
}
|
2021-08-03 21:58:36 +02:00
|
|
|
wa = GNUNET_new (struct WireAccount);
|
|
|
|
wa->section_name = GNUNET_strdup (section);
|
|
|
|
wa->method = method;
|
|
|
|
wa->ai.debit_enabled = debit;
|
|
|
|
wa->ai.credit_enabled = credit;
|
|
|
|
wa->ai.auth = NULL;
|
|
|
|
wa->ai.section_name = wa->section_name;
|
|
|
|
wa->ai.method = wa->method;
|
|
|
|
if (lc->load_auth_data)
|
2020-03-12 10:11:24 +01:00
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
char *csn;
|
|
|
|
|
|
|
|
GNUNET_asprintf (&csn,
|
|
|
|
"exchange-accountcredentials-%s",
|
|
|
|
§ion[strlen ("exchange-account-")]);
|
|
|
|
if (GNUNET_OK !=
|
|
|
|
TALER_BANK_auth_parse_cfg (cfg,
|
|
|
|
csn,
|
|
|
|
&wa->auth))
|
|
|
|
{
|
|
|
|
GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
|
|
|
|
"Failed to load exchange account credentials from section `%s'\n",
|
|
|
|
csn);
|
|
|
|
GNUNET_free (csn);
|
|
|
|
GNUNET_free (wa->section_name);
|
|
|
|
GNUNET_free (wa->method);
|
|
|
|
GNUNET_free (wa);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
wa->ai.auth = &wa->auth;
|
|
|
|
GNUNET_free (csn);
|
2020-03-12 10:11:24 +01:00
|
|
|
}
|
|
|
|
GNUNET_CONTAINER_DLL_insert (wa_head,
|
|
|
|
wa_tail,
|
|
|
|
wa);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-08-03 21:58:36 +02:00
|
|
|
enum GNUNET_GenericReturnValue
|
|
|
|
TALER_EXCHANGEDB_load_accounts (
|
|
|
|
const struct GNUNET_CONFIGURATION_Handle *cfg,
|
|
|
|
enum TALER_EXCHANGEDB_AccountLoaderOptions options)
|
2020-03-12 10:11:24 +01:00
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
struct LoaderContext lc = {
|
|
|
|
.cfg = cfg,
|
|
|
|
.debit = 0 != (options & TALER_EXCHANGEDB_ALO_DEBIT),
|
|
|
|
.credit = 0 != (options & TALER_EXCHANGEDB_ALO_CREDIT),
|
|
|
|
.load_auth_data = 0 != (options & TALER_EXCHANGEDB_ALO_AUTHDATA),
|
|
|
|
};
|
|
|
|
|
|
|
|
GNUNET_CONFIGURATION_iterate_sections (cfg,
|
|
|
|
&add_account_cb,
|
|
|
|
&lc);
|
|
|
|
if (GNUNET_SYSERR == lc.res)
|
|
|
|
return GNUNET_SYSERR;
|
2020-03-12 10:11:24 +01:00
|
|
|
if (NULL == wa_head)
|
|
|
|
return GNUNET_NO;
|
|
|
|
return GNUNET_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
TALER_EXCHANGEDB_unload_accounts (void)
|
|
|
|
{
|
2021-08-03 21:58:36 +02:00
|
|
|
struct WireAccount *wa;
|
2020-03-12 10:11:24 +01:00
|
|
|
|
|
|
|
while (NULL != (wa = wa_head))
|
|
|
|
{
|
|
|
|
GNUNET_CONTAINER_DLL_remove (wa_head,
|
|
|
|
wa_tail,
|
|
|
|
wa);
|
2021-08-03 21:58:36 +02:00
|
|
|
if (NULL != wa->ai.auth)
|
|
|
|
TALER_BANK_auth_free (&wa->auth);
|
2020-03-12 10:11:24 +01:00
|
|
|
GNUNET_free (wa->section_name);
|
|
|
|
GNUNET_free (wa->method);
|
|
|
|
GNUNET_free (wa);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-04-02 14:24:45 +02:00
|
|
|
/* end of exchangedb_accounts.c */
|