gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-exchange] branch master updated: refactor uri parsing logic, prep


From: gnunet
Subject: [taler-exchange] branch master updated: refactor uri parsing logic, prepare for unit test
Date: Tue, 14 Jan 2020 15:58:32 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new 2edee5ac refactor uri parsing logic, prepare for unit test
2edee5ac is described below

commit 2edee5ac4a4886e71db6e28314334cd24c6d3a55
Author: Christian Grothoff <address@hidden>
AuthorDate: Tue Jan 14 15:57:36 2020 +0100

    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(-)

diff --git a/src/bank-lib/bank_api_credit.c b/src/bank-lib/bank_api_credit.c
index 4bb6e7cb..161da876 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 1d5f6eae..ea3ddeeb 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 5b03648f..b99b7881 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 57782380..40801269 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 fb2602c6..97e687ea 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 b6fed3f1..48c10048 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 abb95816..6b51519f 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; i<kd_old.num_denom_keys; i++)
       kd.denom_keys[i].key.rsa_public_key
         = GNUNET_CRYPTO_rsa_public_key_dup (
-            kd_old.denom_keys[i].key.rsa_public_key);
+        kd_old.denom_keys[i].key.rsa_public_key);
 
     kd.num_auditors = kd_old.num_auditors;
     kd.auditors = GNUNET_new_array (kd.num_auditors,
diff --git a/src/lib/testing_api_helpers_bank.c 
b/src/lib/testing_api_helpers_bank.c
index 5147034a..91aaba9e 100644
--- a/src/lib/testing_api_helpers_bank.c
+++ b/src/lib/testing_api_helpers_bank.c
@@ -374,9 +374,6 @@ TALER_TESTING_prepare_fakebank (const char *config_filename,
 {
   struct GNUNET_CONFIGURATION_Handle *cfg;
   char *payto_url;
-  char *fakebank_url;
-  const char *start;
-  const char *end;
 
   cfg = GNUNET_CONFIGURATION_create ();
   if (GNUNET_OK != GNUNET_CONFIGURATION_load (cfg,
@@ -395,38 +392,30 @@ TALER_TESTING_prepare_fakebank (const char 
*config_filename,
     return GNUNET_SYSERR;
   }
   GNUNET_CONFIGURATION_destroy (cfg);
-  if (0 != strncasecmp (payto_url,
-                        "payto://x-taler-bank/",
-                        strlen ("payto://x-taler-bank/")))
+  bc->bank_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 89b31ebb..35abe4a1 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 00000000..80bf652e
--- /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 <http://www.gnu.org/licenses/>
+*/
+/**
+ * @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 5fc47137..4be1e730 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 50ac5c1a..62f733a1 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 */

-- 
To stop receiving notification emails like this one, please contact
address@hidden.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]