gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 01/03: pass h_contract separate from URI, that is clean


From: gnunet
Subject: [taler-merchant] 01/03: pass h_contract separate from URI, that is cleaner
Date: Sat, 22 Aug 2020 19:22:08 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 97b02a22a9904c42d26e7973a82b9751e60f2135
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Sat Aug 22 19:20:51 2020 +0200

    pass h_contract separate from URI, that is cleaner
---
 ...-merchant-httpd_private-post-orders-ID-refund.c | 18 +++------
 src/lib/merchant_api_common.c                      | 46 +++++++++++++++++++++-
 2 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c 
b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
index b5ef07b..d308bf4 100644
--- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
+++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c
@@ -40,14 +40,12 @@
  * @param connection MHD connection to take host and path from
  * @param instance_id merchant's instance ID, must not be NULL
  * @param order_id order ID to show a refund for, must not be NULL
- * @param h_contract hash of the contract to pass for authorization
  * @returns the URI, must be freed with #GNUNET_free
  */
 static char *
 make_taler_refund_uri (struct MHD_Connection *connection,
                        const char *instance_id,
-                       const char *order_id,
-                       const struct GNUNET_HashCode *h_contract)
+                       const char *order_id)
 {
   const char *host;
   const char *forwarded_host;
@@ -89,11 +87,6 @@ make_taler_refund_uri (struct MHD_Connection *connection,
   GNUNET_buffer_write_path (&buf, order_id);
   GNUNET_buffer_write_path (&buf,
                             ""); // Trailing slash
-  GNUNET_buffer_write_str (&buf,
-                           "?h_contract=");
-  GNUNET_buffer_write_data_encoded (&buf,
-                                    &h_contract,
-                                    sizeof (*h_contract));
   return GNUNET_buffer_reap_str (&buf);
 }
 
@@ -294,13 +287,14 @@ TMH_private_post_orders_ID_refund (const struct 
TMH_RequestHandler *rh,
 
     taler_refund_uri = make_taler_refund_uri (connection,
                                               hc->instance->settings.id,
-                                              hc->infix,
-                                              &h_contract);
+                                              hc->infix);
     ret = TALER_MHD_reply_json_pack (connection,
                                      MHD_HTTP_OK,
-                                     "{s:s}",
+                                     "{s:s, s:o}",
                                      "taler_refund_uri",
-                                     taler_refund_uri);
+                                     taler_refund_uri,
+                                     "h_contract",
+                                     GNUNET_JSON_from_data_auto (&h_contract));
     GNUNET_free (taler_refund_uri);
     return ret;
   }
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
index 55d4209..8e5c896 100644
--- a/src/lib/merchant_api_common.c
+++ b/src/lib/merchant_api_common.c
@@ -159,7 +159,7 @@ TALER_MERCHANT_baseurl_add_instance (const char *base_url,
  * @param uri the uri to parse.
  * @param[out] action the action the URI is indicating.
  * @param[out] rest the substring of the URI following the action.
- * @return GNUNET_SYSERR if the URI is malformed, GNUNET_OK otherwise.
+ * @return #GNUNET_SYSERR if the URI is malformed, #GNUNET_OK otherwise.
  */
 static int
 parse_taler_uri_scheme_action (const char *uri,
@@ -170,6 +170,7 @@ parse_taler_uri_scheme_action (const char *uri,
   /* Check that the uri starts with "taler://pay" or "taler+http://pay"; and
      then remove it */
   char *path = strchr (scheme, ':');
+
   if ((NULL == path) ||
       (strlen (path) < 3))
   {
@@ -414,6 +415,49 @@ TALER_MERCHANT_parse_refund_uri (
     *order_id = '\0';
     ++order_id;
 
+
+    {
+      char *ct_str = strchr (last_seg,
+                             '?');
+      char *ct_data;
+
+      if (NULL != ct_str)
+      {
+        *ct_str = '\0';
+        ++ct_str;
+
+        ct_data = strchr (ct_str,
+                          '=');
+        if (NULL == ct_data)
+        {
+          GNUNET_break_op (0);
+          GNUNET_free (path);
+          return GNUNET_SYSERR;
+        }
+        *ct_data = '\0';
+        ++ct_data;
+        if ((0 != strcmp ("h_contract",
+                          ct_str)) ||
+            (GNUNET_OK !=
+             GNUNET_STRINGS_string_to_data (ct_data,
+                                            strlen (ct_data),
+                                            &parse_data->h_contract,
+                                            sizeof (struct GNUNET_HashCode))))
+        {
+          GNUNET_break_op (0);
+          GNUNET_free (path);
+          return GNUNET_SYSERR;
+        }
+      }
+      else
+      {
+        memset (&parse_data->h_contract,
+                0,
+                sizeof (struct GNUNET_HashCode));
+      }
+    }
+
+
     ssid = strchr (last_seg,
                    '#');
     if (NULL != ssid)

-- 
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]