summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2023-06-04 11:54:22 +0200
committerChristian Grothoff <christian@grothoff.org>2023-06-04 11:54:22 +0200
commitee36b6d2d5a695e2ae685924b4c59db562833577 (patch)
tree197b49555a4cadf3c40a5965b681d43084506cda /src/lib
parentc1853b3942273d05dbdf6d7501a89ce5f7f8beba (diff)
downloadmerchant-ee36b6d2d5a695e2ae685924b4c59db562833577.tar.gz
merchant-ee36b6d2d5a695e2ae685924b4c59db562833577.tar.bz2
merchant-ee36b6d2d5a695e2ae685924b4c59db562833577.zip
another FIXME done
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/merchant_api_get_webhooks.c91
1 files changed, 36 insertions, 55 deletions
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);
}