gnunet-svn
[Top][All Lists]
Advanced

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

[taler-anastasis] 01/03: fix policy payment url


From: gnunet
Subject: [taler-anastasis] 01/03: fix policy payment url
Date: Thu, 10 Dec 2020 11:29:34 +0100

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

dennis-neufeld pushed a commit to branch master
in repository anastasis.

commit fca0da2861b1e64a19b0832530c9c2c32f3028a3
Author: Dennis Neufeld <dennis.neufeld@students.bfh.ch>
AuthorDate: Wed Dec 9 17:23:35 2020 +0100

    fix policy payment url
---
 src/backend/anastasis-httpd_policy_upload.c | 41 ++++++++++++++++++++++++-----
 src/lib/Makefile.am                         |  2 ++
 src/lib/anastasis.c                         | 33 +++++------------------
 src/lib/anastasis_api_backup_redux.c        | 27 +++++++++----------
 src/lib/testing_api_cmd_policy_store.c      | 38 +++++++-------------------
 src/lib/testing_cmd_secret_share.c          | 39 +++++++--------------------
 6 files changed, 74 insertions(+), 106 deletions(-)

diff --git a/src/backend/anastasis-httpd_policy_upload.c 
b/src/backend/anastasis-httpd_policy_upload.c
index 4c077ec..07ceb51 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -244,18 +244,45 @@ make_payment_request (const char *order_id)
   resp = MHD_create_response_from_buffer (0,
                                           NULL,
                                           MHD_RESPMEM_PERSISTENT);
-  GNUNET_break (MHD_YES ==
-                MHD_add_response_header (resp,
-                                         
MHD_HTTP_HEADER_ACCESS_CONTROL_ALLOW_ORIGIN,
-                                         "*"));
+  TALER_MHD_add_global_headers (resp);
   {
     char *hdr;
+    char *pfx;
+    char *hn;
+
+    if (0 == strncasecmp ("https://";,
+                          AH_backend_url,
+                          strlen ("https://";)))
+    {
+      pfx = "taler://";
+      hn = &AH_backend_url[strlen ("https://";)];
+    }
+    else if (0 == strncasecmp ("http://";,
+                               AH_backend_url,
+                               strlen ("http://";)))
+    {
+      pfx = "taler+http://";;
+      hn = &AH_backend_url[strlen ("http://";)];
+    }
+    else
+    {
+      GNUNET_break (0);
+      MHD_destroy_response (resp);
+      return NULL;
+    }
+    if (0 == strlen (hn))
+    {
+      GNUNET_break (0);
+      MHD_destroy_response (resp);
+      return NULL;
+    }
 
-    /* TODO: support instances? */
     GNUNET_asprintf (&hdr,
-                     "taler://pay/%s/-/-/%s",
-                     AH_backend_url,
+                     "%spay/%s/%s/",
+                     pfx,
+                     hn,
                      order_id);
+
     GNUNET_break (MHD_YES ==
                   MHD_add_response_header (resp,
                                            "Taler",
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am
index c254cae..44fae35 100644
--- a/src/lib/Makefile.am
+++ b/src/lib/Makefile.am
@@ -55,6 +55,7 @@ libanastasis_la_LIBADD = \
   -lgnunetutil \
   -ljansson \
   -ltalerutil \
+  -ltalermerchant \
   $(XLIB)
 
 libanastasistesting_la_LDFLAGS = \
@@ -117,6 +118,7 @@ libanastasisredux_la_LIBADD = \
   -lgnunetutil \
   -ltalermhd \
   -ltalerutil \
+  -ltalermerchant \
   -ltalerjson \
   -ljansson \
   $(XLIB)
diff --git a/src/lib/anastasis.c b/src/lib/anastasis.c
index cb2b4a5..f1f5c01 100644
--- a/src/lib/anastasis.c
+++ b/src/lib/anastasis.c
@@ -23,6 +23,7 @@
 #include "anastasis.h"
 #include <taler/taler_json_lib.h>
 #include <gnunet/gnunet_util_lib.h>
+#include <taler/taler_merchant_service.h>
 
 
 /**
@@ -1683,45 +1684,25 @@ policy_store_cb (void *cls,
       break;
     case ANASTASIS_US_PAYMENT_REQUIRED:
       {
-        /* FIXME: Payment required handling */
-
-        const char *m;
+        struct TALER_MERCHANT_PayUriData pd;
 
-        if (0 != strncmp (ud->details.payment_request,
-                          "taler://pay/http",
-                          strlen ("taler://pay/http")))
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Did not find `%s' in `%s'\n",
-                      "/-/-/",
-                      ud->details.payment_request);
-          GNUNET_break (0);
-          return;
-        }
-        m = strstr (ud->details.payment_request, "/-/-/");
-        if (NULL == m)
+        if (GNUNET_OK !=
+            TALER_MERCHANT_parse_pay_uri (ud->details.payment_request,
+                                          &pd))
         {
           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                       "Did not find `%s' in `%s'\n",
                       "/-/-/",
                       ud->details.payment_request);
-          /* NOTE: The above is a simplifying assumption for the
-             test-logic, hitting this code merely means that
-             the assumptions for the test (i.e. no instance) are
-             not satisfied, it is not inherently the case that
-             the above token must appear in the payment request!
-
-             So if you hit this, you might just want to modify
-             the code here to handle this better! */
           GNUNET_break (0);
           return;
         }
-        pss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+        pss->payment_order_id = GNUNET_strdup (pd.order_id);
+        TALER_MERCHANT_parse_pay_uri_free (&pd);
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                     "At %s:%d Order ID from Anastasis service is %s\n",
                     __FILE__, __LINE__,
                     pss->payment_order_id);
-
         memset (&pss->curr_hash,
                 0,
                 sizeof (struct GNUNET_HashCode));
diff --git a/src/lib/anastasis_api_backup_redux.c 
b/src/lib/anastasis_api_backup_redux.c
index 23deab8..5e3efe9 100644
--- a/src/lib/anastasis_api_backup_redux.c
+++ b/src/lib/anastasis_api_backup_redux.c
@@ -25,6 +25,7 @@
 #include <jansson.h>
 #include <taler/taler_json_lib.h>
 #include <taler/taler_util.h>
+#include <taler/taler_merchant_service.h>
 #include "anastasis_redux.h"
 #include "anastasis_error_codes.h"
 #include "anastasis_api_redux.h"
@@ -1325,7 +1326,6 @@ secret_share_payment_cb (void *cls,
               __FILE__, __LINE__,
               taler_pay_url);
 
-  const char *m;
   size_t index;
   json_t *upload;
   struct SecretShareState *sss = cls;
@@ -1349,32 +1349,29 @@ secret_share_payment_cb (void *cls,
       GNUNET_assert (0 ==
                      json_object_set (upload,
                                       "pay_url",
-                                      json_string (strcat (taler_pay_url,
-                                                           "/"))));
+                                      json_string (taler_pay_url)));
       break;
     }
   }
 
-  m = strstr (taler_pay_url, "/-/-/");
-  if (NULL == m)
+  struct TALER_MERCHANT_PayUriData pd;
+
+  if (GNUNET_OK !=
+      TALER_MERCHANT_parse_pay_uri (taler_pay_url,
+                                    &pd))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "Did not find `%s' in `%s'\n",
                 "/-/-/",
                 taler_pay_url);
     GNUNET_break (0);
-    /* NOTE: The above is a simplifying assumption for the
-        test-logic, hitting this code merely means that
-        the assumptions for the test (i.e. no instance) are
-        not satisfied, it is not inherently the case that
-        the above token must appear in the payment request!
-
-        So if you hit this, you might just want to modify
-        the code here to handle this better! */
     return;
   }
-  sss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
-
+  sss->payment_order_id = GNUNET_strdup (pd.order_id);
+  TALER_MERCHANT_parse_pay_uri_free (&pd);
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              "Order ID from Anastasis service is `%s'\n",
+              sss->payment_order_id);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
               "At %s:%d Order ID from Anastasis service is %s\n",
               __FILE__, __LINE__,
diff --git a/src/lib/testing_api_cmd_policy_store.c 
b/src/lib/testing_api_cmd_policy_store.c
index 0b3216b..3934662 100644
--- a/src/lib/testing_api_cmd_policy_store.c
+++ b/src/lib/testing_api_cmd_policy_store.c
@@ -29,6 +29,8 @@
 #include "anastasis_testing_lib.h"
 #include <taler/taler_util.h>
 #include <taler/taler_testing_lib.h>
+#include <taler/taler_merchant_service.h>
+
 
 /**
  * State for a "policy store" CMD.
@@ -178,43 +180,21 @@ policy_store_cb (void *cls,
       break;
     case ANASTASIS_US_PAYMENT_REQUIRED:
       {
-        /* FIXME: Payment required handling */
-        const char *m;
+        struct TALER_MERCHANT_PayUriData pd;
 
-        if (0 != strncmp (ud->details.payment_request,
-                          "taler://pay/http",
-                          strlen ("taler://pay/http")))
+        if (GNUNET_OK !=
+            TALER_MERCHANT_parse_pay_uri (ud->details.payment_request,
+                                          &pd))
         {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Did not find `%s' in `%s'\n",
-                      "/-/-/",
-                      ud->details.payment_request);
-          TALER_TESTING_interpreter_fail (pss->is);
-          return;
-        }
-        m = strstr (ud->details.payment_request, "/-/-/");
-        if (NULL == m)
-        {
-          GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                      "Did not find `%s' in `%s'\n",
-                      "/-/-/",
-                      ud->details.payment_request);
+          GNUNET_break (0);
           TALER_TESTING_interpreter_fail (pss->is);
-          /* NOTE: The above is a simplifying assumption for the
-             test-logic, hitting this code merely means that
-             the assumptions for the test (i.e. no instance) are
-             not satisfied, it is not inherently the case that
-             the above token must appear in the payment request!
-
-             So if you hit this, you might just want to modify
-             the code here to handle this better! */
           return;
         }
-        pss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+        pss->payment_order_id = GNUNET_strdup (pd.order_id);
+        TALER_MERCHANT_parse_pay_uri_free (&pd);
         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
                     "Order ID from Anastasis service is `%s'\n",
                     pss->payment_order_id);
-
         memset (&pss->curr_hash,
                 0,
                 sizeof (struct GNUNET_HashCode));
diff --git a/src/lib/testing_cmd_secret_share.c 
b/src/lib/testing_cmd_secret_share.c
index 253efcd..5a6b6c5 100644
--- a/src/lib/testing_cmd_secret_share.c
+++ b/src/lib/testing_cmd_secret_share.c
@@ -25,6 +25,7 @@
 #include "anastasis_testing_lib.h"
 #include <taler/taler_util.h>
 #include <taler/taler_testing_lib.h>
+#include <taler/taler_merchant_service.h>
 
 
 /**
@@ -128,7 +129,6 @@ secret_share_payment_cb (void *cls,
                          const char *server_url,
                          enum TALER_ErrorCode ec)
 {
-  const char *m;
   struct SecretShareState *sss = cls;
   sss->sso = NULL;
 
@@ -152,39 +152,20 @@ secret_share_payment_cb (void *cls,
     return;
   }
 
-  if (0 != strncmp (taler_pay_url,
-                    "taler://pay/http",
-                    strlen ("taler://pay/http")))
-  {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Did not find `%s' in `%s'\n",
-                "/-/-/",
-                taler_pay_url);
-    TALER_TESTING_interpreter_fail (sss->is);
-    return;
-  }
-  m = strstr (taler_pay_url, "/-/-/");
-  if (NULL == m)
+  struct TALER_MERCHANT_PayUriData pd;
+
+  if (GNUNET_OK !=
+      TALER_MERCHANT_parse_pay_uri (taler_pay_url,
+                                    &pd))
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
-                "Did not find `%s' in `%s'\n",
-                "/-/-/",
-                taler_pay_url);
+    GNUNET_break (0);
     TALER_TESTING_interpreter_fail (sss->is);
-    /* NOTE: The above is a simplifying assumption for the
-        test-logic, hitting this code merely means that
-        the assumptions for the test (i.e. no instance) are
-        not satisfied, it is not inherently the case that
-        the above token must appear in the payment request!
-
-        So if you hit this, you might just want to modify
-        the code here to handle this better! */
     return;
   }
-  sss->payment_order_id = GNUNET_strdup (&m[strlen ("/-/-/")]);
+  sss->payment_order_id = GNUNET_strdup (pd.order_id);
+  TALER_MERCHANT_parse_pay_uri_free (&pd);
   GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-              "At %s:%d Order ID from Anastasis service is %s\n",
-              __FILE__, __LINE__,
+              "Order ID from Anastasis service is `%s'\n",
               sss->payment_order_id);
 
   TALER_TESTING_interpreter_next (sss->is);

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