diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-07-20 19:33:59 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-07-20 19:33:59 +0200 |
commit | 362bf0c5bd2270ed6a54dfbdfd83702dca892797 (patch) | |
tree | 62dc70b9111810c1375fedfb75efff882bb5058d /src/backend/taler-merchant-httpd_private-post-instances.c | |
parent | 43dd7c8ae663fcb3db64fb7571c56144baa83a0e (diff) | |
download | merchant-362bf0c5bd2270ed6a54dfbdfd83702dca892797.tar.gz merchant-362bf0c5bd2270ed6a54dfbdfd83702dca892797.tar.bz2 merchant-362bf0c5bd2270ed6a54dfbdfd83702dca892797.zip |
-workshop refactoring
Diffstat (limited to 'src/backend/taler-merchant-httpd_private-post-instances.c')
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-instances.c | 76 |
1 files changed, 8 insertions, 68 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c b/src/backend/taler-merchant-httpd_private-post-instances.c index f9df3d39..71739c3d 100644 --- a/src/backend/taler-merchant-httpd_private-post-instances.c +++ b/src/backend/taler-merchant-httpd_private-post-instances.c @@ -24,6 +24,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_private-post-instances.h" +#include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> #include <regex.h> @@ -234,56 +235,11 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, } /* check payto_uris for well-formedness */ - { - 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; - } - } - } - if (! payto_ok) - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PAYTO_URI_MALFORMED, - NULL); - } + if (! TMH_payto_uri_array_valid (payto_uris)) + return TALER_MHD_reply_with_error (connection, + MHD_HTTP_BAD_REQUEST, + TALER_EC_GENERIC_PAYTO_URI_MALFORMED, + NULL); /* check 'id' well-formed */ { @@ -402,24 +358,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, json_t *payto_uri = json_array_get (payto_uris, i); struct TMH_WireMethod *wm; - struct GNUNET_HashCode salt; - - GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, - &salt, - sizeof (salt)); - wm = GNUNET_new (struct TMH_WireMethod); - wm->j_wire = json_pack ("{s:O, 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 (json_string_value (payto_uri)); - GNUNET_assert (NULL != wm->wire_method); /* checked earlier */ - wm->active = true; + + wm = TMH_setup_wire_account (json_string_value (payto_uri)); GNUNET_CONTAINER_DLL_insert (wm_head, wm_tail, wm); |