diff options
author | Christian Grothoff <grothoff@gnunet.org> | 2023-10-13 21:06:58 +0200 |
---|---|---|
committer | Christian Grothoff <grothoff@gnunet.org> | 2023-10-13 21:16:51 +0200 |
commit | 28b80ac78306bfa216ab9638f40f65bd86eef716 (patch) | |
tree | 056c1e06cc893666212682935d8714d2bc96587f | |
parent | 0f3490dc022620c7e42b86426e14198a04c2e17f (diff) |
add currency specification parsing to /config logic in libtalermerchant
-rw-r--r-- | src/include/taler_merchant_service.h | 17 | ||||
-rw-r--r-- | src/lib/merchant_api_common.c | 2 | ||||
-rw-r--r-- | 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; } |