From c1853b3942273d05dbdf6d7501a89ce5f7f8beba Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 11:47:48 +0200 Subject: another FIXME done --- src/lib/merchant_api_get_templates.c | 90 ++++++++++++++---------------------- 1 file changed, 35 insertions(+), 55 deletions(-) (limited to 'src/lib') diff --git a/src/lib/merchant_api_get_templates.c b/src/lib/merchant_api_get_templates.c index 4af6846e..a9807ae7 100644 --- a/src/lib/merchant_api_get_templates.c +++ b/src/lib/merchant_api_get_templates.c @@ -71,19 +71,18 @@ struct TALER_MERCHANT_TemplatesGetHandle * @param tgh operation handle * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue parse_templates (const json_t *ia, + struct TALER_MERCHANT_TemplatesGetResponse *tgr, struct TALER_MERCHANT_TemplatesGetHandle *tgh) { - unsigned int ies_len = json_array_size (ia); - struct TALER_MERCHANT_TemplateEntry ies[GNUNET_NZL (ies_len)]; + unsigned int tmpl_len = json_array_size (ia); + struct TALER_MERCHANT_TemplateEntry tmpl[GNUNET_NZL (tmpl_len)]; size_t index; json_t *value; - int ret; - ret = GNUNET_OK; json_array_foreach (ia, index, value) { - struct TALER_MERCHANT_TemplateEntry *ie = &ies[index]; + struct TALER_MERCHANT_TemplateEntry *ie = &tmpl[index]; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_id", &ie->template_id), @@ -96,25 +95,15 @@ parse_templates (const json_t *ia, NULL, NULL)) { GNUNET_break_op (0); - ret = GNUNET_SYSERR; - continue; + return GNUNET_SYSERR; } - if (GNUNET_SYSERR == ret) - break; - } - if (GNUNET_OK == ret) - { - struct TALER_MERCHANT_HttpResponse hr = { - .http_status = MHD_HTTP_OK - }; - - tgh->cb (tgh->cb_cls, - &hr, - ies_len, - ies); - tgh->cb = NULL; /* just to be sure */ } - return ret; + tgr->details.ok.templates_length = tmpl_len; + tgr->details.ok.templates = tmpl; + tgh->cb (tgh->cb_cls, + tgr); + tgh->cb = NULL; /* just to be sure */ + return GNUNET_OK; } @@ -133,9 +122,9 @@ handle_get_templates_finished (void *cls, { struct TALER_MERCHANT_TemplatesGetHandle *tgh = cls; const json_t *json = response; - struct TALER_MERCHANT_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_MERCHANT_TemplatesGetResponse tgr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; tgh->job = NULL; @@ -146,10 +135,10 @@ handle_get_templates_finished (void *cls, { case MHD_HTTP_OK: { - json_t *templates; + const json_t *templates; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("templates", - &templates), + GNUNET_JSON_spec_array_const ("templates", + &templates), GNUNET_JSON_spec_end () }; @@ -158,48 +147,39 @@ handle_get_templates_finished (void *cls, spec, NULL, NULL)) { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + tgr.hr.http_status = 0; + tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; } - else + if (GNUNET_OK == + parse_templates (templates, + &tgr, + tgh)) { - if ( (! json_is_array (templates)) || - (GNUNET_OK == - parse_templates (templates, - tgh)) ) - { - GNUNET_JSON_parse_free (spec); - TALER_MERCHANT_templates_get_cancel (tgh); - return; - } - else - { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - } + TALER_MERCHANT_templates_get_cancel (tgh); + return; } - GNUNET_JSON_parse_free (spec); + tgr.hr.http_status = 0; + tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } case MHD_HTTP_UNAUTHORIZED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); /* Nothing really to verify, merchant says we need to authenticate. */ break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + tgr.hr.ec = TALER_JSON_get_error_code (json); + tgr.hr.hint = TALER_JSON_get_error_hint (json); GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Unexpected response code %u/%d\n", (unsigned int) response_code, - (int) hr.ec); + (int) tgr.hr.ec); break; } tgh->cb (tgh->cb_cls, - &hr, - 0, - NULL); + &tgr); TALER_MERCHANT_templates_get_cancel (tgh); } -- cgit v1.2.3