gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 06/06: add currency specification parsing to /config lo


From: gnunet
Subject: [taler-merchant] 06/06: add currency specification parsing to /config logic in libtalermerchant
Date: Fri, 13 Oct 2023 21:17:01 +0200

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

grothoff pushed a commit to branch master
in repository merchant.

commit 28b80ac78306bfa216ab9638f40f65bd86eef716
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Fri Oct 13 21:06:58 2023 +0200

    add currency specification parsing to /config logic in libtalermerchant
---
 src/include/taler_merchant_service.h | 17 +++++++++++++--
 src/lib/merchant_api_common.c        |  2 +-
 src/lib/merchant_api_get_config.c    | 40 ++++++++++++++++++++++++++++++++++--
 3 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/src/include/taler_merchant_service.h 
b/src/include/taler_merchant_service.h
index 6d79d45e..b3e15025 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -211,7 +211,7 @@ struct TALER_MERCHANT_RefundUriData
  * @param[out] parse_data data extracted from the URI. Must be free'd.
  * @return #GNUNET_SYSERR if @e refund_uri is malformed, #GNUNET_OK otherwise.
  */
-int
+enum GNUNET_GenericReturnValue
 TALER_MERCHANT_parse_refund_uri (
   const char *refund_uri,
   struct TALER_MERCHANT_RefundUriData *parse_data);
@@ -288,7 +288,8 @@ enum TALER_MERCHANT_VersionCompatibility
 struct TALER_MERCHANT_ConfigInformation
 {
   /**
-   * Currency used/supported by the merchant.
+   * Default currency of the merchant.  See cspecs
+   * for all currencies supported by the merchant.
    */
   const char *currency;
 
@@ -333,6 +334,18 @@ struct TALER_MERCHANT_ConfigResponse
        * protocol compatibility information
        */
       enum TALER_MERCHANT_VersionCompatibility compat;
+
+      /**
+       * Length of the @e cspecs array.
+       */
+      unsigned int num_cspecs;
+
+      /**
+       * Array with rendering specifications for the currencies
+       * supported by this merchant backend.
+       */
+      const struct TALER_CurrencySpecification *cspecs;
+      
     } ok;
   } details;
 };
diff --git a/src/lib/merchant_api_common.c b/src/lib/merchant_api_common.c
index 00e0358d..f5569ce3 100644
--- a/src/lib/merchant_api_common.c
+++ b/src/lib/merchant_api_common.c
@@ -245,7 +245,7 @@ TALER_MERCHANT_parse_pay_uri_free (
 }
 
 
-int
+enum GNUNET_GenericReturnValue
 TALER_MERCHANT_parse_refund_uri (
   const char *refund_uri,
   struct TALER_MERCHANT_RefundUriData *parse_data)
diff --git a/src/lib/merchant_api_get_config.c 
b/src/lib/merchant_api_get_config.c
index 8eddf9d7..708b7907 100644
--- a/src/lib/merchant_api_get_config.c
+++ b/src/lib/merchant_api_get_config.c
@@ -104,7 +104,10 @@ handle_config_finished (void *cls,
   {
   case MHD_HTTP_OK:
     {
+      const json_t *jcs;
       struct GNUNET_JSON_Specification spec[] = {
+        GNUNET_JSON_spec_object_const ("currencies",
+                                       &jcs),
         GNUNET_JSON_spec_string ("currency",
                                  &cr.details.ok.ci.currency),
         GNUNET_JSON_spec_string ("version",
@@ -153,8 +156,41 @@ handle_config_finished (void *cls,
           }
         }
       }
-      vgh->cb (vgh->cb_cls,
-               &cr);
+      {
+        unsigned int nspec = json_object_size (jcs);
+        struct TALER_CurrencySpecification *cspecs;
+        unsigned int off = 0;
+        json_t *obj;
+        const char *curr;
+
+        cspecs = GNUNET_new_array (nspec,
+                                   struct TALER_CurrencySpecification);
+        cr.details.ok.num_cspecs = nspec;
+        cr.details.ok.cspecs = cspecs;
+        json_object_foreach ((json_t *) jcs, curr, obj)
+        {
+          struct TALER_CurrencySpecification *cs = &cspecs[off++];
+          struct GNUNET_JSON_Specification cspec[] = {
+            TALER_JSON_spec_currency_specification (curr,
+                                                    cs),
+            GNUNET_JSON_spec_end ()
+          };
+
+          if (GNUNET_OK !=
+              GNUNET_JSON_parse (jcs,
+                                 cspec,
+                                 NULL, NULL))
+          {
+            cr.hr.http_status = 0;
+            cr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE;
+            break;
+          }
+        }
+        vgh->cb (vgh->cb_cls,
+                 &cr);
+        TALER_CONFIG_free_currencies (nspec,
+                                      cspecs);
+      }
       TALER_MERCHANT_config_get_cancel (vgh);
       return;
     }

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