diff options
Diffstat (limited to 'src/lib/merchant_api_get_orders.c')
-rw-r--r-- | src/lib/merchant_api_get_orders.c | 66 |
1 files changed, 26 insertions, 40 deletions
diff --git a/src/lib/merchant_api_get_orders.c b/src/lib/merchant_api_get_orders.c index 0a0ba3f0..5bad47e0 100644 --- a/src/lib/merchant_api_get_orders.c +++ b/src/lib/merchant_api_get_orders.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2014-2018, 2020, 2021 Taler Systems SA + Copyright (C) 2014-2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -68,20 +68,20 @@ struct TALER_MERCHANT_OrdersGetHandle * Parse order information from @a ia. * * @param ia JSON array (or NULL!) with order data + * @param[in] ogr response to fill * @param ogh operation handle * @return #GNUNET_OK on success */ static enum GNUNET_GenericReturnValue parse_orders (const json_t *ia, + struct TALER_MERCHANT_OrdersGetResponse *ogr, struct TALER_MERCHANT_OrdersGetHandle *ogh) { unsigned int oes_len = json_array_size (ia); struct TALER_MERCHANT_OrderEntry oes[GNUNET_NZL (oes_len)]; size_t index; json_t *value; - int ret; - ret = GNUNET_OK; json_array_foreach (ia, index, value) { struct TALER_MERCHANT_OrderEntry *ie = &oes[index]; struct GNUNET_JSON_Specification spec[] = { @@ -108,25 +108,15 @@ parse_orders (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 - }; - - ogh->cb (ogh->cb_cls, - &hr, - oes_len, - oes); - ogh->cb = NULL; /* just to be sure */ } - return ret; + ogr->details.ok.orders_length = oes_len; + ogr->details.ok.orders = oes; + ogh->cb (ogh->cb_cls, + ogr); + ogh->cb = NULL; /* just to be sure */ + return GNUNET_OK; } @@ -145,9 +135,9 @@ handle_get_orders_finished (void *cls, { struct TALER_MERCHANT_OrdersGetHandle *ogh = cls; const json_t *json = response; - struct TALER_MERCHANT_HttpResponse hr = { - .http_status = (unsigned int) response_code, - .reply = json + struct TALER_MERCHANT_OrdersGetResponse ogr = { + .hr.http_status = (unsigned int) response_code, + .hr.reply = json }; ogh->job = NULL; @@ -170,52 +160,48 @@ handle_get_orders_finished (void *cls, spec, NULL, NULL)) { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + ogr.hr.http_status = 0; + ogr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; } else { if ( (! json_is_array (orders)) || (GNUNET_OK == parse_orders (orders, + &ogr, ogh)) ) { GNUNET_JSON_parse_free (spec); TALER_MERCHANT_orders_get_cancel (ogh); return; } - else - { - hr.http_status = 0; - hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - } + ogr.hr.http_status = 0; + ogr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; } GNUNET_JSON_parse_free (spec); break; } case MHD_HTTP_UNAUTHORIZED: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + ogr.hr.ec = TALER_JSON_get_error_code (json); + ogr.hr.hint = TALER_JSON_get_error_hint (json); /* Nothing really to verify, merchant says we need to authenticate. */ break; case MHD_HTTP_NOT_FOUND: - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + ogr.hr.ec = TALER_JSON_get_error_code (json); + ogr.hr.hint = TALER_JSON_get_error_hint (json); break; default: /* unexpected response code */ - hr.ec = TALER_JSON_get_error_code (json); - hr.hint = TALER_JSON_get_error_hint (json); + ogr.hr.ec = TALER_JSON_get_error_code (json); + ogr.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) ogr.hr.ec); break; } ogh->cb (ogh->cb_cls, - &hr, - 0, - NULL); + &ogr); TALER_MERCHANT_orders_get_cancel (ogh); } |