diff options
Diffstat (limited to 'src/wire')
-rw-r--r-- | src/wire/Makefile.am | 1 | ||||
-rw-r--r-- | src/wire/payto.c | 104 | ||||
-rw-r--r-- | src/wire/wire.c | 149 | ||||
-rw-r--r-- | src/wire/wire_helper.c | 56 |
4 files changed, 56 insertions, 254 deletions
diff --git a/src/wire/Makefile.am b/src/wire/Makefile.am index 6bf38aa2a..2a82282a3 100644 --- a/src/wire/Makefile.am +++ b/src/wire/Makefile.am @@ -13,7 +13,6 @@ lib_LTLIBRARIES = \ libtalerwire_la_SOURCES = \ payto.c \ - wire.c \ wire_helper.c libtalerwire_la_LIBADD = \ -lgnunetutil \ diff --git a/src/wire/payto.c b/src/wire/payto.c index 741549772..0c3fce957 100644 --- a/src/wire/payto.c +++ b/src/wire/payto.c @@ -20,6 +20,7 @@ */ #include "platform.h" #include "taler_util.h" +#include "taler_bank_service.h" #include "taler_wire_lib.h" /** @@ -43,8 +44,8 @@ TALER_WIRE_account_free (struct TALER_Account *acc) case TALER_PAC_X_TALER_BANK: GNUNET_free (acc->details.x_taler_bank.hostname); acc->details.x_taler_bank.hostname = NULL; - GNUNET_free (acc->details.x_taler_bank.bank_base_url); - acc->details.x_taler_bank.bank_base_url = NULL; + GNUNET_free (acc->details.x_taler_bank.account_base_url); + acc->details.x_taler_bank.account_base_url = NULL; break; case TALER_PAC_IBAN: GNUNET_free (acc->details.iban.number); @@ -410,7 +411,8 @@ parse_payto_x_taler_bank (const char *account_url, const char *hostname; const char *account; const char *q; - unsigned long long no; + unsigned int port; + char *p; #define PREFIX "payto://x-taler-bank/" if (0 != strncasecmp (account_url, @@ -422,74 +424,52 @@ parse_payto_x_taler_bank (const char *account_url, (unsigned char) '/'))) return TALER_EC_PAYTO_MALFORMED; account++; - if (NULL != (q = strchr (account, - (unsigned char) '?'))) + if (NULL == r_account) + return TALER_EC_NONE; + q = strchr (account, + (unsigned char) '?'); + if (0 == q) + q = account + strlen (account); + r_account->details.x_taler_bank.hostname + = GNUNET_strndup (hostname, + account - hostname); + port = 443; /* if non given, equals 443. */ + if (NULL != (p = strchr (r_account->details.x_taler_bank.hostname, + (unsigned char) ':'))) { - char *s; - - s = GNUNET_strndup (account, - q - account); - if (1 != sscanf (s, - "%llu", - &no)) + p++; + if (1 != sscanf (p, + "%u", + &port)) { - GNUNET_free (s); + GNUNET_break (0); + TALER_LOG_ERROR ("Malformed host from payto:// URI\n"); + GNUNET_free (r_account->details.x_taler_bank.hostname); + r_account->details.x_taler_bank.hostname = NULL; return TALER_EC_PAYTO_MALFORMED; } - GNUNET_free (s); } - else if (1 != sscanf (account, - "%llu", - &no)) + if (443 != port) { - return TALER_EC_PAYTO_MALFORMED; + GNUNET_assert + (GNUNET_SYSERR != GNUNET_asprintf + (&r_account->details.x_taler_bank.account_base_url, + "http://%s/%.*s", + r_account->details.x_taler_bank.hostname, + (int) (q - account), + account)); } - if (no > MAX_ACCOUNT_NO) - return TALER_EC_PAYTO_MALFORMED; - - if (NULL != r_account) + else { - long long unsigned port; - char *p; - - r_account->details.x_taler_bank.hostname - = GNUNET_strndup (hostname, - account - hostname); - r_account->details.x_taler_bank.no = no; - port = 443; /* if non given, equals 443. */ - if (NULL != (p = strchr (r_account->details.x_taler_bank.hostname, - (unsigned char) ':'))) - { - p++; - if (1 != sscanf (p, - "%llu", - &port)) - { - GNUNET_break (0); - TALER_LOG_ERROR ("Malformed host from payto:// URI\n"); - GNUNET_free (r_account->details.x_taler_bank.hostname); - r_account->details.x_taler_bank.hostname = NULL; - return TALER_EC_PAYTO_MALFORMED; - } - } - if (443 != port) - { - GNUNET_assert - (GNUNET_SYSERR != GNUNET_asprintf - (&r_account->details.x_taler_bank.bank_base_url, - "http://%s", - r_account->details.x_taler_bank.hostname)); - } - else - { - GNUNET_assert - (GNUNET_SYSERR != GNUNET_asprintf - (&r_account->details.x_taler_bank.bank_base_url, - "https://%s", - r_account->details.x_taler_bank.hostname)); - } - r_account->type = TALER_PAC_X_TALER_BANK; + GNUNET_assert + (GNUNET_SYSERR != GNUNET_asprintf + (&r_account->details.x_taler_bank.account_base_url, + "https://%s/%.*s", + r_account->details.x_taler_bank.hostname, + (int) (q - account), + account)); } + r_account->type = TALER_PAC_X_TALER_BANK; return TALER_EC_NONE; } diff --git a/src/wire/wire.c b/src/wire/wire.c deleted file mode 100644 index 60ae9e6ed..000000000 --- a/src/wire/wire.c +++ /dev/null @@ -1,149 +0,0 @@ -/* - This file is part of TALER - (C) 2015, 2016, 2017, 2018 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 - 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 wire/wire.c - * @brief Functions for loading wire plugins - * @author Christian Grothoff <christian@grothoff.org> - */ -#include "platform.h" -#include "taler_util.h" -#include "taler_wire_lib.h" - - -/** - * A wire plugin that we have loaded. - */ -struct WirePlugin -{ - /** - * We keep these in a DLL. - */ - struct WirePlugin *next; - - /** - * We keep these in a DLL. - */ - struct WirePlugin *prev; - - /** - * Type of this wire plugin. - */ - char *type; - - /** - * Wire plugin - */ - struct TALER_WIRE_Plugin *plugin; - - /** - * Reference counter for the plugin. - */ - unsigned int rc; -}; - - -/** - * Head of the DLL of loaded wire plugins. - */ -static struct WirePlugin *wp_head; - -/** - * Tail of the DLL of loaded wire plugins. - */ -static struct WirePlugin *wp_tail; - - -/** - * Load a WIRE plugin. - * - * @param cfg configuration to use - * @param plugin_name name of the plugin to load - * @return the plugin object pointer, or NULL upon errors. - */ -struct TALER_WIRE_Plugin * -TALER_WIRE_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg, - const char *plugin_name) -{ - char *lib_name; - struct TALER_WIRE_Plugin *plugin; - struct WirePlugin *wp; - - for (wp = wp_head; NULL != wp; wp = wp->next) - if (0 == strcasecmp (plugin_name, - wp->type)) - { - wp->rc++; - return wp->plugin; - } - (void) GNUNET_asprintf (&lib_name, - "libtaler_plugin_wire_%s", - plugin_name); - plugin = GNUNET_PLUGIN_load (lib_name, - (void *) cfg); - if (NULL != plugin) - plugin->library_name = lib_name; - else - GNUNET_free (lib_name); - if (NULL == plugin) - return NULL; - wp = GNUNET_new (struct WirePlugin); - wp->plugin = plugin; - wp->type = GNUNET_strdup (plugin_name); - GNUNET_CONTAINER_DLL_insert (wp_head, - wp_tail, - wp); - wp->rc = 1; - return plugin; -} - - -/** - * Unload a WIRE plugin. - * - * @param plugin the plugin to unload - */ -void -TALER_WIRE_plugin_unload (struct TALER_WIRE_Plugin *plugin) -{ - struct WirePlugin *wp; - char *lib_name; - - if (NULL == plugin) - return; - for (wp = wp_head; NULL != wp; wp = wp->next) - { - if (plugin == wp->plugin) - { - wp->rc--; - if (0 < wp->rc) - return; - GNUNET_CONTAINER_DLL_remove (wp_head, - wp_tail, - wp); - GNUNET_free (wp->type); - GNUNET_free (wp); - break; - } - } - lib_name = plugin->library_name; - GNUNET_assert (NULL == GNUNET_PLUGIN_unload (lib_name, - plugin)); - GNUNET_free (lib_name); -} - - -/* end of wire.c */ diff --git a/src/wire/wire_helper.c b/src/wire/wire_helper.c index e62539832..4b7f092a2 100644 --- a/src/wire/wire_helper.c +++ b/src/wire/wire_helper.c @@ -20,6 +20,7 @@ /** * @file wire/wire_helper.c * @brief Helper functions for dealing with wire formats + * @author Christian Grothoff <christian@grothoff.org> */ #include "platform.h" @@ -33,23 +34,6 @@ /** - * Maps wire methods to plugin names. - */ -struct ConversionTable -{ - - /** - * Wire method (e.g. 'iban', 'x-taler-bank', ..) - */ - const char *method; - - /** - * Plugin name, e.g. 'taler_bank', .. - */ - const char *plugin_name; -}; - -/** * Obtain the payment method from a @a payto_url * * @param payto_url the URL to parse @@ -76,35 +60,23 @@ TALER_WIRE_payto_get_method (const char *payto_url) /** - * Get the plugin name from the payment method. + * Round the amount to something that can be + * transferred on the wire. * - * FIXME: this is ugly, would be better to have - * a way to iterate over all plugins and interrogate - * them as to what wire method(s) they support! - * - * @param method the method implemented by the plugin (for - * simplicity, we assume 1 method is implemented by 1 plugin). - * @return the plugin name, NULL if not found. + * @param[in,out] amount amount to round down + * @return #GNUNET_OK on success, #GNUNET_NO if rounding was unnecessary, + * #GNUNET_SYSERR if the amount or currency was invalid */ -const char * -TALER_WIRE_get_plugin_from_method (const char *method) +int +TALER_WIRE_amount_round (struct TALER_Amount *amount) { - static const struct ConversionTable ct[] = { - {"x-taler-bank", "taler_bank"}, - {"iban", "taler_bank"}, - {NULL, NULL} - }; - - for (unsigned int i = 0; - NULL != ct[i].method; - i++) - { - if (0 == strcmp (method, - ct[i].method)) - return ct[i].plugin_name; - } + uint32_t delta; - return NULL; + delta = amount->fraction % (TALER_AMOUNT_FRAC_BASE / 100); + if (0 == delta) + return GNUNET_NO; + amount->fraction -= delta; + return GNUNET_OK; } |