summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/taler_merchant_service.h45
-rw-r--r--src/lib/merchant_api_get_webhooks.c91
-rw-r--r--src/testing/testing_api_cmd_get_webhooks.c24
3 files changed, 84 insertions, 76 deletions
diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h
index a91e991e..b1b4d003 100644
--- a/src/include/taler_merchant_service.h
+++ b/src/include/taler_merchant_service.h
@@ -5332,21 +5332,52 @@ struct TALER_MERCHANT_WebhookEntry
};
-// FIXME: change signature!
+/**
+ * Response to a GET /webhooks operation.
+ */
+struct TALER_MERCHANT_WebhooksGetResponse
+{
+ /**
+ * HTTP response details
+ */
+ struct TALER_MERCHANT_HttpResponse hr;
+
+ /**
+ * Details depending on status.
+ */
+ union
+ {
+ /**
+ * Details if status is #MHD_HTTP_OK.
+ */
+ struct
+ {
+ /**
+ * length of the @e webhooks array
+ */
+ unsigned int webhooks_length;
+
+ /**
+ * array of templates the requested instance offers
+ */
+ const struct TALER_MERCHANT_WebhookEntry *webhooks;
+
+ } ok;
+
+ } details;
+};
+
+
/**
* Function called with the result of the GET /webhooks operation.
*
* @param cls closure
- * @param hr HTTP response details
- * @param webhooks_length length of the @a webhooks array
- * @param webhooks array of webhooks the requested instance offers
+ * @param wgr response details
*/
typedef void
(*TALER_MERCHANT_WebhooksGetCallback)(
void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr,
- unsigned int webhooks_length,
- const struct TALER_MERCHANT_WebhookEntry webhooks[]);
+ const struct TALER_MERCHANT_WebhooksGetResponse *wgr);
/**
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);
}
diff --git a/src/testing/testing_api_cmd_get_webhooks.c b/src/testing/testing_api_cmd_get_webhooks.c
index 536512aa..cbcd11c6 100644
--- a/src/testing/testing_api_cmd_get_webhooks.c
+++ b/src/testing/testing_api_cmd_get_webhooks.c
@@ -71,33 +71,29 @@ struct GetWebhooksState
* Callback for a GET /webhooks operation.
*
* @param cls closure for this function
- * @param hr HTTP response details
- * @param webhooks_length length of the @a webhooks array
- * @param webhooks array of webhooks the requested instance offers
+ * @param wgr response details
*/
static void
get_webhooks_cb (void *cls,
- const struct TALER_MERCHANT_HttpResponse *hr,
- unsigned int webhooks_length,
- const struct TALER_MERCHANT_WebhookEntry webhooks[])
+ const struct TALER_MERCHANT_WebhooksGetResponse *wgr)
{
struct GetWebhooksState *gis = cls;
gis->igh = NULL;
- if (gis->http_status != hr->http_status)
+ if (gis->http_status != wgr->hr.http_status)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Unexpected response code %u (%d) to command %s\n",
- hr->http_status,
- (int) hr->ec,
+ wgr->hr.http_status,
+ (int) wgr->hr.ec,
TALER_TESTING_interpreter_get_current_label (gis->is));
TALER_TESTING_interpreter_fail (gis->is);
return;
}
- switch (hr->http_status)
+ switch (wgr->hr.http_status)
{
case MHD_HTTP_OK:
- if (webhooks_length != gis->webhooks_length)
+ if (wgr->details.ok.webhooks_length != gis->webhooks_length)
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Length of webhooks found does not match\n");
@@ -124,7 +120,7 @@ get_webhooks_cb (void *cls,
TALER_TESTING_interpreter_fail (gis->is);
return;
}
- if (0 != strcmp (webhooks[i].webhook_id,
+ if (0 != strcmp (wgr->details.ok.webhooks[i].webhook_id,
*webhook_id))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -143,8 +139,8 @@ get_webhooks_cb (void *cls,
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Unhandled HTTP status %u (%d).\n",
- hr->http_status,
- hr->ec);
+ wgr->hr.http_status,
+ wgr->hr.ec);
}
TALER_TESTING_interpreter_next (gis->is);
}