From 2edee5ac4a4886e71db6e28314334cd24c6d3a55 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Tue, 14 Jan 2020 15:57:36 +0100 Subject: refactor uri parsing logic, prepare for unit test --- src/bank-lib/bank_api_credit.c | 2 +- src/bank-lib/bank_api_debit.c | 2 +- src/bank-lib/fakebank.c | 5 +- src/exchange-tools/taler-exchange-keyup.c | 2 +- src/exchange/taler-exchange-httpd_refresh_reveal.c | 6 +-- src/include/taler_util.h | 23 +++++++++ src/lib/exchange_api_handle.c | 2 +- src/lib/testing_api_helpers_bank.c | 33 ++++-------- src/util/Makefile.am | 14 ++++-- src/util/test_payto.c | 35 +++++++++++++ src/util/test_url.c | 3 +- src/util/util.c | 58 ++++++++++++++++++++++ 12 files changed, 149 insertions(+), 36 deletions(-) create mode 100644 src/util/test_payto.c diff --git a/src/bank-lib/bank_api_credit.c b/src/bank-lib/bank_api_credit.c index 4bb6e7cb2..161da876f 100644 --- a/src/bank-lib/bank_api_credit.c +++ b/src/bank-lib/bank_api_credit.c @@ -270,7 +270,7 @@ TALER_BANK_credit_history (struct GNUNET_CURL_Context *ctx, hh->bank_base_url = GNUNET_strdup (bank_base_url); hh->request_url = TALER_BANK_path_to_url_ (bank_base_url, url); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting history at `%s'\n", hh->request_url); eh = curl_easy_init (); diff --git a/src/bank-lib/bank_api_debit.c b/src/bank-lib/bank_api_debit.c index 1d5f6eaeb..ea3ddeebc 100644 --- a/src/bank-lib/bank_api_debit.c +++ b/src/bank-lib/bank_api_debit.c @@ -273,7 +273,7 @@ TALER_BANK_debit_history (struct GNUNET_CURL_Context *ctx, hh->request_url = TALER_BANK_path_to_url_ (bank_base_url, url); - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Requesting history at `%s'\n", hh->request_url); eh = curl_easy_init (); diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index 5b03648f6..b99b78816 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -1111,7 +1111,7 @@ serve (struct TALER_FAKEBANK_Handle *h, size_t *upload_data_size, void **con_cls) { - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Fakebank, serving URL `%s' for account `%s'\n", url, account); @@ -1198,6 +1198,9 @@ handle_mhd_request (void *cls, int ret; (void) version; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Handling request for `%s'\n", + url); if ( (strlen (url) > 1) && (NULL != (end = strchr (url + 1, '/'))) ) { diff --git a/src/exchange-tools/taler-exchange-keyup.c b/src/exchange-tools/taler-exchange-keyup.c index 577823804..408012697 100644 --- a/src/exchange-tools/taler-exchange-keyup.c +++ b/src/exchange-tools/taler-exchange-keyup.c @@ -765,7 +765,7 @@ create_denomkey_issue (const struct CoinTypeParams *params, 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; diff --git a/src/exchange/taler-exchange-httpd_refresh_reveal.c b/src/exchange/taler-exchange-httpd_refresh_reveal.c index fb2602c61..97e687ea9 100644 --- a/src/exchange/taler-exchange-httpd_refresh_reveal.c +++ b/src/exchange/taler-exchange-httpd_refresh_reveal.c @@ -771,9 +771,9 @@ handle_refresh_reveal_json (struct MHD_Connection *connection, { rctx->ev_sigs[i].rsa_signature = GNUNET_CRYPTO_rsa_sign_blinded ( - rctx->dkis[i]->denom_priv.rsa_private_key, - rctx->rcds[i].coin_ev, - rctx->rcds[i].coin_ev_size); + rctx->dkis[i]->denom_priv.rsa_private_key, + rctx->rcds[i].coin_ev, + rctx->rcds[i].coin_ev_size); if (NULL == rctx->ev_sigs[i].rsa_signature) { GNUNET_break (0); diff --git a/src/include/taler_util.h b/src/include/taler_util.h index b6fed3f12..48c10048e 100644 --- a/src/include/taler_util.h +++ b/src/include/taler_util.h @@ -403,4 +403,27 @@ char * TALER_payto_xtalerbank_make (const char *bank_url, const char *account_name); + +/** + * Given an x-taler-bank payto:// URL, compute + * the HTTP(S) base URL of the account. + * + * @param payto the payto URL + * @return bank URL of the account, NULL if not x-taler-bak payto URL + */ +char * +TALER_xtalerbank_base_url_from_payto (const char *payto); + + +/** + * Given an x-taler-bank payto:// URL, compute + * the HTTP(S) base URL of the account. + * + * @param payto the payto URL + * @return bank URL of the account, NULL if not x-taler-bak payto URL + */ +char * +TALER_xtalerbank_account_url_from_payto (const char *payto); + + #endif diff --git a/src/lib/exchange_api_handle.c b/src/lib/exchange_api_handle.c index abb95816c..6b51519fd 100644 --- a/src/lib/exchange_api_handle.c +++ b/src/lib/exchange_api_handle.c @@ -1262,7 +1262,7 @@ keys_completed_cb (void *cls, for (unsigned int i = 0; ibank_url + = TALER_xtalerbank_base_url_from_payto (payto_url); + if (NULL == bc->bank_url) { GNUNET_log_config_invalid (GNUNET_ERROR_TYPE_WARNING, config_section, "URL", "expected `x-taler-bank' payto://-URL"); - GNUNET_CONFIGURATION_destroy (cfg); GNUNET_free (payto_url); return GNUNET_SYSERR; } - start = &payto_url [strlen ("payto://x-taler-bank/")]; - end = strchr (start, - (unsigned char) '/'); - if (NULL == end) - end = &start[strlen (start)]; - fakebank_url = GNUNET_strndup (start, - end - start); - GNUNET_free (payto_url); if (GNUNET_OK != - TALER_TESTING_url_port_free (fakebank_url)) + TALER_TESTING_url_port_free (bc->bank_url)) { - GNUNET_free (fakebank_url); + GNUNET_free (bc->bank_url); + bc->bank_url = NULL; + GNUNET_free (payto_url); return GNUNET_SYSERR; } - bc->bank_url = fakebank_url; - GNUNET_asprintf (&bc->exchange_account_url, - "%s/%s", - bc->bank_url, - EXCHANGE_ACCOUNT_NAME); + bc->exchange_account_url + = TALER_xtalerbank_account_url_from_payto (payto_url); + GNUNET_assert (NULL != bc->exchange_account_url); + GNUNET_free (payto_url); bc->exchange_auth.method = TALER_BANK_AUTH_NONE; bc->exchange_payto = TALER_payto_xtalerbank_make (bc->bank_url, "2"); bc->user42_payto = TALER_payto_xtalerbank_make (bc->bank_url, "42"); diff --git a/src/util/Makefile.am b/src/util/Makefile.am index 89b31ebba..35abe4a1b 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -56,16 +56,16 @@ libtalerutil_la_LDFLAGS = \ -version-info 0:0:0 \ -export-dynamic -no-undefined -TESTS = \ - test_amount \ - test_crypto \ - test_url check_PROGRAMS = \ test_amount \ test_crypto \ + test_payto \ test_url +TESTS = \ + $(check_PROGRAMS) + test_amount_SOURCES = \ test_amount.c @@ -79,6 +79,12 @@ test_crypto_LDADD = \ -lgnunetutil \ libtalerutil.la +test_payto_SOURCES = \ + test_payto.c +test_payto_LDADD = \ + -lgnunetutil \ + libtalerutil.la + test_url_SOURCES = \ test_url.c test_url_LDADD = \ diff --git a/src/util/test_payto.c b/src/util/test_payto.c new file mode 100644 index 000000000..80bf652e0 --- /dev/null +++ b/src/util/test_payto.c @@ -0,0 +1,35 @@ +/* + This file is part of TALER + (C) 2020 Taler Systems SA + + 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 +*/ +/** + * @file util/test_payto.c + * @brief Tests for payto helpers + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_util.h" + + +int +main (int argc, + const char *const argv[]) +{ + + + return 0; +} + + +/* end of test_payto.c */ diff --git a/src/util/test_url.c b/src/util/test_url.c index 5fc47137c..4be1e7307 100644 --- a/src/util/test_url.c +++ b/src/util/test_url.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2015 GNUnet e.V. + (C) 2015-2020 Taler Systems SA 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 @@ -45,7 +45,6 @@ int main (int argc, const char *const argv[]) { - cf (TALER_urlencode (""), ""); cf (TALER_urlencode ("abc"), "abc"); cf (TALER_urlencode ("~~"), "~~"); diff --git a/src/util/util.c b/src/util/util.c index 50ac5c1a7..62f733a17 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -805,4 +805,62 @@ TALER_payto_xtalerbank_make (const char *bank_url, } +/** + * Given an x-taler-bank payto:// URL, compute + * the HTTP(S) base URL of the account. + * + * @param payto the payto URL + * @return bank URL of the account, NULL if not x-taler-bak payto URL + */ +char * +TALER_xtalerbank_base_url_from_payto (const char *payto) +{ + const char *start; + const char *end; + + if (0 != strncasecmp (payto, + "payto://x-taler-bank/", + strlen ("payto://x-taler-bank/"))) + { + return NULL; + } + start = &payto [strlen ("payto://x-taler-bank/")]; + end = strchr (start, + (unsigned char) '/'); + if (NULL == end) + end = &start[strlen (start)]; + return GNUNET_strndup (start, + end - start); +} + + +/** + * Given an x-taler-bank payto:// URL, compute + * the HTTP(S) base URL of the account. + * + * @param payto the payto URL + * @return bank URL of the account, NULL if not x-taler-bak payto URL + */ +char * +TALER_xtalerbank_account_url_from_payto (const char *payto) +{ + const char *start; + const char *end; + + if (0 != strncasecmp (payto, + "payto://x-taler-bank/", + strlen ("payto://x-taler-bank/"))) + { + return NULL; + } + start = &payto [strlen ("payto://x-taler-bank/")]; + end = strchr (start, + (unsigned char) '?'); + if (NULL == end) + end = &start[strlen (start)]; + return GNUNET_strndup (start, + end - start); +} + + /* end of util.c */ -- cgit v1.2.3