From ee36b6d2d5a695e2ae685924b4c59db562833577 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 11:54:22 +0200 Subject: another FIXME done --- src/lib/merchant_api_get_webhooks.c | 91 +++++++++++++++---------------------- 1 file changed, 36 insertions(+), 55 deletions(-) (limited to 'src/lib') diff --git a/src/lib/merchant_api_get_webhooks.c b/src/lib/merchant_api_get_webhooks.c index c176eff7..521230e6 100644 --- a/src/lib/merchant_api_get_webhooks.c +++ b/src/lib/merchant_api_get_webhooks.c @@ -68,22 +68,22 @@ struct TALER_MERCHANT_WebhooksGetHandle * Parse webhook information from @a ia. * * @param ia JSON array (or NULL!) with webhook data + * @param[in] wgr partially filled webhook response * @param wgh operation handle * @return #GNUNET_OK on success */ -static int +static enum GNUNET_GenericReturnValue parse_webhooks (const json_t *ia, + struct TALER_MERCHANT_WebhooksGetResponse *wgr, struct TALER_MERCHANT_WebhooksGetHandle *wgh) { - unsigned int ies_len = json_array_size (ia); - struct TALER_MERCHANT_WebhookEntry ies[GNUNET_NZL (ies_len)]; + unsigned int whook_len = json_array_size (ia); + struct TALER_MERCHANT_WebhookEntry whook[GNUNET_NZL (whook_len)]; size_t index; json_t *value; - int ret; - ret = GNUNET_OK; json_array_foreach (ia, index, value) { - struct TALER_MERCHANT_WebhookEntry *ie = &ies[index]; + struct TALER_MERCHANT_WebhookEntry *ie = &whook[index]; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("webhook_id", &ie->webhook_id), @@ -96,25 +96,15 @@ parse_webhooks (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 - }; - - wgh->cb (wgh->cb_cls, - &hr, - ies_len, - ies); - wgh->cb = NULL; /* just to be sure */ } - return ret; + wgr->details.ok.webhooks_length = whook_len; + wgr->details.ok.webhooks = whook; + wgh->cb (wgh->cb_cls, + wgr); + wgh->cb = NULL; /* just to be sure */ + return GNUNET_OK; } @@ -133,9 +123,9 @@ handle_get_webhooks_finished (void *cls, { struct TALER_MERCHANT_WebhooksGetHandle *wgh = cls; const json_t *json = response; - struct TALER_MERCHANT_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_MERCHANT_WebhooksGetResponse wgr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; wgh->job = NULL; @@ -146,10 +136,10 @@ handle_get_webhooks_finished (void *cls, { case MHD_HTTP_OK: { - json_t *webhooks; + const json_t *webhooks; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("webhooks", - &webhooks), + GNUNET_JSON_spec_array_const ("webhooks", + &webhooks), GNUNET_JSON_spec_end () }; @@ -158,48 +148,39 @@ handle_get_webhooks_finished (void *cls, spec, NULL, NULL)) { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + wgr.hr.http_status = 0; + wgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; } - else + if (GNUNET_OK == + parse_webhooks (webhooks, + &wgr, + wgh)) { - if ( (! json_is_array (webhooks)) || - (GNUNET_OK == - parse_webhooks (webhooks, - wgh)) ) - { - GNUNET_JSON_parse_free (spec); - TALER_MERCHANT_webhooks_get_cancel (wgh); - return; - } - else - { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - } + TALER_MERCHANT_webhooks_get_cancel (wgh); + return; } - GNUNET_JSON_parse_free (spec); + wgr.hr.http_status = 0; + wgr.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); + wgr.hr.ec = TALER_JSON_get_error_code (json); + wgr.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); + wgr.hr.ec = TALER_JSON_get_error_code (json); + wgr.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) wgr.hr.ec); break; } wgh->cb (wgh->cb_cls, - &hr, - 0, - NULL); + &wgr); TALER_MERCHANT_webhooks_get_cancel (wgh); } -- cgit v1.2.3