diff options
Diffstat (limited to 'src/backend/taler-merchant-httpd_helper.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_helper.c | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c new file mode 100644 index 00000000..30ff4a90 --- /dev/null +++ b/src/backend/taler-merchant-httpd_helper.c @@ -0,0 +1,106 @@ +/* + This file is part of TALER + (C) 2014--2020 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU Lesser 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 taler-merchant-httpd_helper.c + * @brief shared logic for various handlers + * @author Christian Grothoff + */ +#include "platform.h" +#include <gnunet/gnunet_util_lib.h> +#include <taler/taler_util.h> +#include <taler/taler_json_lib.h> +#include "taler-merchant-httpd_helper.h" + +/** + * check @a payto_uris for well-formedness + * + * @param payto_uris JSON array of payto URIs (presumably) + * @return true if they are all valid URIs (and this is an array of strings) + */ +bool +TMH_payto_uri_array_valid (const json_t *payto_uris) +{ + bool payto_ok = true; + + if (! json_is_array (payto_uris)) + { + GNUNET_break_op (0); + payto_ok = false; + } + else + { + unsigned int len = json_array_size (payto_uris); + + for (unsigned int i = 0; i<len; i++) + { + json_t *payto_uri = json_array_get (payto_uris, + i); + const char *uri; + + if (! json_is_string (payto_uri)) + payto_ok = false; + uri = json_string_value (payto_uri); + /* Test for the same payto:// URI being given twice */ + for (unsigned int j = 0; j<i; j++) + { + json_t *old_uri = json_array_get (payto_uris, + j); + if (json_equal (payto_uri, + old_uri)) + { + GNUNET_break_op (0); + payto_ok = false; + break; + } + } + if (! payto_ok) + break; + if (GNUNET_SYSERR == + TALER_JSON_validate_payto (uri)) + { + payto_ok = false; + break; + } + } + } + return payto_ok; +} + + +struct TMH_WireMethod * +TMH_setup_wire_account (const char *payto_uri) +{ + struct GNUNET_HashCode salt; + struct TMH_WireMethod *wm; + + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + &salt, + sizeof (salt)); + wm = GNUNET_new (struct TMH_WireMethod); + wm->j_wire = json_pack ("{s:s, s:o}", + "payto_uri", payto_uri, + "salt", GNUNET_JSON_from_data_auto (&salt)); + GNUNET_assert (NULL != wm->j_wire); + /* This also tests for things like the IBAN being malformed */ + GNUNET_assert (GNUNET_OK == + TALER_JSON_merchant_wire_signature_hash (wm->j_wire, + &wm->h_wire)); + wm->wire_method + = TALER_payto_get_method (payto_uri); + GNUNET_assert (NULL != wm->wire_method); /* checked earlier */ + wm->active = true; + return wm; +} |