From bcf5863eb45523615540ac99ab81fd131bd2f413 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 1 Aug 2021 19:59:40 +0200 Subject: -more json_pack fixes --- .../taler-merchant-httpd_private-get-orders-ID.c | 206 ++++++++++----------- 1 file changed, 96 insertions(+), 110 deletions(-) (limited to 'src/backend/taler-merchant-httpd_private-get-orders-ID.c') diff --git a/src/backend/taler-merchant-httpd_private-get-orders-ID.c b/src/backend/taler-merchant-httpd_private-get-orders-ID.c index abcf64e2..8f9dce35 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -25,6 +25,7 @@ #include #include "taler-merchant-httpd_mhd.h" #include "taler-merchant-httpd_exchanges.h" +#include "taler-merchant-httpd_helper.h" #include "taler-merchant-httpd_private-get-orders.h" @@ -337,28 +338,19 @@ gorc_report (struct GetOrderRequestContext *gorc, GNUNET_assert (0 == json_array_append_new ( gorc->wire_reports, - json_pack ("{s:I, s:s, s:I, s:I, s:o }", - "code", - (json_int_t) ec, - "hint", - TALER_ErrorCode_get_hint (ec), - "exchange_ec", - (json_int_t) exchange_hr->ec, - "exchange_hc", - (json_int_t) exchange_hr->http_status, - "coin_pub", - GNUNET_JSON_from_data_auto (coin_pub)))); + GNUNET_JSON_PACK ( + TALER_JSON_pack_ec (ec), + TMH_pack_exchange_reply (exchange_hr), + GNUNET_JSON_pack_data_auto ("coin_pub", + coin_pub)))); else GNUNET_assert (0 == json_array_append_new ( gorc->wire_reports, - json_pack ("{s:I, s:s, s:o }", - "code", - (json_int_t) ec, - "hint", - TALER_ErrorCode_get_hint (ec), - "coin_pub", - GNUNET_JSON_from_data_auto (coin_pub)))); + GNUNET_JSON_PACK ( + TALER_JSON_pack_ec (ec), + GNUNET_JSON_pack_data_auto ("coin_pub", + coin_pub)))); } @@ -657,13 +649,13 @@ process_refunds_cb (void *cls, GNUNET_assert (0 == json_array_append_new ( gorc->refund_details, - json_pack ("{s:o, s:o, s:s}", - "amount", - TALER_JSON_from_amount (refund_amount), - "timestamp", - GNUNET_JSON_from_time_abs (timestamp), - "reason", - reason))); + GNUNET_JSON_PACK ( + TALER_JSON_pack_amount ("amount", + refund_amount), + GNUNET_JSON_pack_time_abs ("timestamp", + timestamp), + GNUNET_JSON_pack_string ("reason", + reason)))); /* For refunded coins, we are not charged deposit fees, so subtract those again */ for (struct TransferQuery *tq = gorc->tq_head; @@ -734,17 +726,17 @@ process_transfer_details (void *cls, GNUNET_assert (0 == json_array_append_new ( wire_details, - json_pack ("{s:o, s:s, s:o, s:o, s:b}", - "wtid", - GNUNET_JSON_from_data_auto (wtid), - "exchange_url", - exchange_url, - "amount", - TALER_JSON_from_amount (&wired), - "execution_time", - GNUNET_JSON_from_time_abs (execution_time_round), - "confirmed", - transfer_confirmed))); + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("wtid", + wtid), + GNUNET_JSON_pack_string ("exchange_url", + exchange_url), + TALER_JSON_pack_amount ("amount", + &wired), + GNUNET_JSON_pack_time_abs ("execution_time", + execution_time_round), + GNUNET_JSON_pack_bool ("confirmed", + transfer_confirmed)))); } @@ -1044,27 +1036,25 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_HTTP_HEADERS_MALFORMED, "host"); } - ret = TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s, s:s, s:s, s:s, s:s" - " s:o, s:s, s:o}", - "taler_pay_uri", - taler_pay_uri, - "order_status_url", - order_status_url, - "order_status", - "unpaid", - "already_paid_order_id", - already_paid_order_id, - "already_paid_fulfillment_url", - gorc->fulfillment_url, - "total_amount", - TALER_JSON_from_amount ( - &gorc->contract_amount), - "summary", - summary, - "creation_time", - GNUNET_JSON_from_time_abs (timestamp)); + ret = TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("taler_pay_uri", + taler_pay_uri), + GNUNET_JSON_pack_string ("order_status_url", + order_status_url), + GNUNET_JSON_pack_string ("order_status", + "unpaid"), + GNUNET_JSON_pack_string ("already_paid_order_id", + already_paid_order_id), + GNUNET_JSON_pack_string ("already_paid_fulfillment_url", + gorc->fulfillment_url), + TALER_JSON_pack_amount ("total_amount", + &gorc->contract_amount), + GNUNET_JSON_pack_string ("summary", + summary), + GNUNET_JSON_pack_time_abs ("creation_time", + timestamp)); GNUNET_free (taler_pay_uri); GNUNET_free (already_paid_order_id); return ret; @@ -1094,13 +1084,13 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Order %s claimed but not paid yet\n", hc->infix); - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:O, s:s}", - "contract_terms", - gorc->contract_terms, - "order_status", - "claimed"); + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_object_incref ("contract_terms", + gorc->contract_terms), + GNUNET_JSON_pack_string ("order_status", + "claimed")); } if (paid && (! wired) && @@ -1165,22 +1155,21 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, hc->instance->settings.id, &claim_token, NULL); - ret = TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s, s:s, s:s, s:o, s:s, s:o}", - "taler_pay_uri", - taler_pay_uri, - "order_status_url", - order_status_url, - "order_status", - "unpaid", - "total_amount", - TALER_JSON_from_amount ( - &gorc->contract_amount), - "summary", - summary, - "creation_time", - GNUNET_JSON_from_time_abs (timestamp)); + ret = TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("taler_pay_uri", + taler_pay_uri), + GNUNET_JSON_pack_string ("order_status_url", + order_status_url), + GNUNET_JSON_pack_string ("order_status", + "unpaid"), + TALER_JSON_pack_amount ("total_amount", + &gorc->contract_amount), + GNUNET_JSON_pack_string ("summary", + summary), + GNUNET_JSON_pack_time_abs ("creation_time", + timestamp)); GNUNET_free (taler_pay_uri); GNUNET_free (order_status_url); return ret; @@ -1302,38 +1291,35 @@ TMH_private_get_orders_ID (const struct TMH_RequestHandler *rh, h_contract); } - ret = TALER_MHD_reply_json_pack ( + ret = TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - "{s:o, s:I, s:I, s:o, s:O," - " s:s, s:b, s:b, s:b, s:o," - " s:o, s:o, s:s}", - "wire_reports", - gorc->wire_reports, - "exchange_ec", - (json_int_t) gorc->exchange_ec, - "exchange_hc", - (json_int_t) gorc->exchange_hc, - "deposit_total", - TALER_JSON_from_amount (&gorc->deposits_total), - "contract_terms", - gorc->contract_terms, - "order_status", - "paid", - "refunded", - gorc->refunded, - "wired", - wired, - "refund_pending", - gorc->refund_pending, - "refund_amount", - TALER_JSON_from_amount (&gorc->refund_amount), - "wire_details", - gorc->wire_details, - "refund_details", - gorc->refund_details, - "order_status_url", - order_status_url); + GNUNET_JSON_pack_array_steal ("wire_reports", + gorc->wire_reports), + GNUNET_JSON_pack_uint64 ("exchange_code", + gorc->exchange_ec), + GNUNET_JSON_pack_uint64 ("exchange_http_status", + gorc->exchange_hc), + TALER_JSON_pack_amount ("deposit_total", + &gorc->deposits_total), + GNUNET_JSON_pack_object_incref ("contract_terms", + gorc->contract_terms), + GNUNET_JSON_pack_string ("order_status", + "paid"), + GNUNET_JSON_pack_bool ("refunded", + gorc->refunded), + GNUNET_JSON_pack_bool ("wired", + wired), + GNUNET_JSON_pack_bool ("refund_pending", + gorc->refund_pending), + TALER_JSON_pack_amount ("refund_amount", + &gorc->refund_amount), + GNUNET_JSON_pack_array_steal ("wire_details", + gorc->wire_details), + GNUNET_JSON_pack_array_steal ("refund_details", + gorc->refund_details), + GNUNET_JSON_pack_string ("order_status_url", + order_status_url)); GNUNET_free (order_status_url); gorc->wire_details = NULL; gorc->wire_reports = NULL; -- cgit v1.2.3