gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] 98/130: fix payto:// construction routine and move it t


From: gnunet
Subject: [taler-exchange] 98/130: fix payto:// construction routine and move it to libtalerutil
Date: Wed, 17 Nov 2021 12:25:46 +0100

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

grothoff pushed a commit to branch master
in repository exchange.

commit 98c30bee88762acfc236c918fd2fa6151c0808ff
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sun Nov 7 19:22:12 2021 +0100

    fix payto:// construction routine and move it to libtalerutil
---
 src/exchangedb/plugin_exchangedb_postgres.c | 43 ++++-------------
 src/include/taler_util.h                    | 13 +++++
 src/util/payto.c                            | 74 ++++++++++++++++-------------
 3 files changed, 63 insertions(+), 67 deletions(-)

diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index d7cfd871..fbd168a8 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -3979,42 +3979,15 @@ postgres_inselect_wallet_kyc_status (
 {
   struct PostgresClosure *pg = cls;
   char *payto_uri;
-  char *rps;
-  unsigned int skip;
-  const char *extra = "";
-  int url_len;
-
-  rps = GNUNET_STRINGS_data_to_string_alloc (reserve_pub,
-                                             sizeof (*reserve_pub));
-  skip = 0;
-  if (0 == strncasecmp (pg->exchange_url,
-                        "http://";,
-                        strlen ("http://";)))
-    skip = strlen ("http://";);
-  if (0 == strncasecmp (pg->exchange_url,
-                        "https://";,
-                        strlen ("https://";)))
-    skip = strlen ("https://";);
-  url_len = strlen (pg->exchange_url);
-  if ('/' == pg->exchange_url[url_len - 1])
-    url_len--;
-  url_len -= skip;
-  GNUNET_asprintf (&payto_uri,
-                   "taler%s://reserve/%.*s/%s",
-                   extra,
-                   url_len,
-                   pg->exchange_url + skip,
-                   rps);
-  GNUNET_free (rps);
-  {
-    enum GNUNET_DB_QueryStatus qs;
+  enum GNUNET_DB_QueryStatus qs;
 
-    qs = inselect_account_kyc_status (pg,
-                                      payto_uri,
-                                      kyc);
-    GNUNET_free (payto_uri);
-    return qs;
-  }
+  payto_uri = TALER_payto_from_reserve (pg->exchange_url,
+                                        reserve_pub);
+  qs = inselect_account_kyc_status (pg,
+                                    payto_uri,
+                                    kyc);
+  GNUNET_free (payto_uri);
+  return qs;
 }
 
 
diff --git a/src/include/taler_util.h b/src/include/taler_util.h
index 4faa75c4..8d7f5f75 100644
--- a/src/include/taler_util.h
+++ b/src/include/taler_util.h
@@ -327,6 +327,19 @@ char *
 TALER_payto_get_method (const char *payto_uri);
 
 
+/**
+ * Construct a payto://-URI from a Taler @a reserve_pub at
+ * a @exchange_base_url
+ *
+ * @param exchange_base_url the URL of the exchange
+ * @param reserve_pub public key of the reserve
+ * @return payto:// URI encoding the reserve's address
+ */
+char *
+TALER_payto_from_reserve (const char *exchange_base_url,
+                          const struct TALER_ReservePublicKeyP *reserve_pub);
+
+
 /**
  * Obtain the account name from a payto URL.
  *
diff --git a/src/util/payto.c b/src/util/payto.c
index 26872f1e..746b2624 100644
--- a/src/util/payto.c
+++ b/src/util/payto.c
@@ -70,13 +70,6 @@ payto_get_key (const char *payto_uri,
 }
 
 
-/**
- * Extract the subject value from the URI parameters.
- *
- * @param payto_uri the URL to parse
- * @return NULL if the subject parameter is not found.
- *         The caller should free the returned value.
- */
 char *
 TALER_payto_get_subject (const char *payto_uri)
 {
@@ -85,14 +78,6 @@ TALER_payto_get_subject (const char *payto_uri)
 }
 
 
-/**
- * Obtain the payment method from a @a payto_uri. The
- * format of a payto URI is 'payto://$METHOD/$SOMETHING'.
- * We return $METHOD.
- *
- * @param payto_uri the URL to parse
- * @return NULL on error (malformed @a payto_uri)
- */
 char *
 TALER_payto_get_method (const char *payto_uri)
 {
@@ -113,16 +98,6 @@ TALER_payto_get_method (const char *payto_uri)
 }
 
 
-/**
- * Obtain the account name from a payto URL.  The format
- * of the @a payto URL is 'payto://x-taler-bank/$HOSTNAME/$ACCOUNT[?PARAMS]'.
- * We check the first part matches, skip over the $HOSTNAME
- * and return the $ACCOUNT portion.
- *
- * @param payto an x-taler-bank payto URL
- * @return only the account name from the @a payto URL, NULL if not an 
x-taler-bank
- *   payto URL
- */
 char *
 TALER_xtalerbank_account_from_payto (const char *payto)
 {
@@ -202,13 +177,6 @@ validate_payto_iban (const char *account_url)
 }
 
 
-/**
- * Check that a payto:// URI is well-formed.
- *
- * @param payto_uri the URL to check
- * @return NULL on success, otherwise an error
- *         message to be freed by the caller!
- */
 char *
 TALER_payto_validate (const char *payto_uri)
 {
@@ -264,3 +232,45 @@ TALER_payto_hash (const char *payto,
                       strlen (payto) + 1,
                       &h_payto->hash);
 }
+
+
+char *
+TALER_payto_from_reserve (const char *exchange_base_url,
+                          const struct TALER_ReservePublicKeyP *reserve_pub)
+{
+  char *payto_uri;
+  char *rps;
+  unsigned int skip;
+  const char *extra = "";
+  int url_len;
+
+  rps = GNUNET_STRINGS_data_to_string_alloc (reserve_pub,
+                                             sizeof (*reserve_pub));
+  skip = 0;
+  if (0 == strncasecmp (exchange_base_url,
+                        "http://";,
+                        strlen ("http://";)))
+  {
+    skip = strlen ("http://";);
+    extra = "+http";
+  }
+  if (0 == strncasecmp (exchange_base_url,
+                        "https://";,
+                        strlen ("https://";)))
+    skip = strlen ("https://";);
+  url_len = strlen (exchange_base_url);
+  if ('/' == exchange_base_url[url_len - 1])
+    url_len--;
+  url_len -= skip;
+  GNUNET_asprintf (&payto_uri,
+                   "taler%s://reserve/%.*s/%s",
+                   extra,
+                   url_len,
+                   exchange_base_url + skip,
+                   rps);
+  GNUNET_free (rps);
+  return payto_uri;
+}
+
+
+/* end of payto.c */

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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