diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-01 18:57:26 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-01 18:57:30 +0200 |
commit | 41bbc3b3d8cf2ac9d90cd41b584aea8dac11a9e5 (patch) | |
tree | f447f94f018dff506a3c5a1f6042df3964520c1a /src/backend | |
parent | 1dede2835d0b7305794a68cd6cc6740e4d05d4e9 (diff) | |
download | merchant-41bbc3b3d8cf2ac9d90cd41b584aea8dac11a9e5.tar.gz merchant-41bbc3b3d8cf2ac9d90cd41b584aea8dac11a9e5.tar.bz2 merchant-41bbc3b3d8cf2ac9d90cd41b584aea8dac11a9e5.zip |
-more json_pack fixes
Diffstat (limited to 'src/backend')
10 files changed, 100 insertions, 97 deletions
diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index 75121207..ffe7657a 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -612,8 +612,9 @@ send_pay_request (struct GetOrderData *god, GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_string ("fulfillment_url", god->fulfillment_url)), - GNUNET_JSON_pack_string ("already_paid_order_id", - already_paid_order_id)); + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("already_paid_order_id", + already_paid_order_id))); } GNUNET_free (taler_pay_uri); GNUNET_free (order_status_url); 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 ed162826..abcf64e2 100644 --- a/src/backend/taler-merchant-httpd_private-get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-orders-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2017, 2019, 2020 Taler Systems SA + (C) 2017-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software diff --git a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c index bb4da531..8ad6e8de 100644 --- a/src/backend/taler-merchant-httpd_private-get-reserves-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-reserves-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2018, 2020 Taler Systems SA + (C) 2018, 2020, 2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software diff --git a/src/backend/taler-merchant-httpd_private-get-tips-ID.c b/src/backend/taler-merchant-httpd_private-get-tips-ID.c index 7ebe6b9c..ee26f9e5 100644 --- a/src/backend/taler-merchant-httpd_private-get-tips-ID.c +++ b/src/backend/taler-merchant-httpd_private-get-tips-ID.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2017-2020 Taler Systems SA + (C) 2017-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -118,15 +118,13 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh, GNUNET_assert (0 == json_array_append_new ( pickups_json, - json_pack ("{s:o,s:I,s:o}", - "pickup_id", - GNUNET_JSON_from_data_auto ( - &pickups[i].pickup_id), - "num_planchets", - (json_int_t) pickups[i].num_planchets, - "requested_amount", - TALER_JSON_from_amount ( - &pickups[i].requested_amount)))); + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("pickup_id", + &pickups[i].pickup_id), + GNUNET_JSON_pack_uint64 ("num_planchets", + pickups[i].num_planchets), + TALER_JSON_pack_amount ("requested_amount", + &pickups[i].requested_amount)))); } } GNUNET_array_grow (pickups, @@ -138,16 +136,22 @@ TMH_private_get_tips_ID (const struct TMH_RequestHandler *rh, GNUNET_TIME_round_abs (&expiration_round); - ret = TALER_MHD_reply_json_pack ( + ret = TALER_MHD_REPLY_JSON_PACK ( connection, MHD_HTTP_OK, - "{s:o, s:o, s:s, s:o, s:o, s:o?}", - "total_authorized", TALER_JSON_from_amount (&total_authorized), - "total_picked_up", TALER_JSON_from_amount (&total_picked_up), - "reason", reason, - "expiration", GNUNET_JSON_from_time_abs (expiration_round), - "reserve_pub", GNUNET_JSON_from_data_auto (&reserve_pub), - "pickups", pickups_json); + TALER_JSON_pack_amount ("total_authorized", + &total_authorized), + TALER_JSON_pack_amount ("total_picked_up", + &total_picked_up), + GNUNET_JSON_pack_string ("reason", + reason), + GNUNET_JSON_pack_time_abs ("expiration", + expiration_round), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &reserve_pub), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_array_steal ("pickups", + pickups_json))); GNUNET_free (reason); return ret; } diff --git a/src/backend/taler-merchant-httpd_private-get-tips.c b/src/backend/taler-merchant-httpd_private-get-tips.c index 60e4900e..e222daae 100644 --- a/src/backend/taler-merchant-httpd_private-get-tips.c +++ b/src/backend/taler-merchant-httpd_private-get-tips.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2020 Taler Systems SA + (C) 2020-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software @@ -41,14 +41,13 @@ add_tip (void *cls, GNUNET_assert (0 == json_array_append_new ( pa, - json_pack ( - "{s:I, s:o, s:o}", - "row_id", - row_id, - "tip_id", - GNUNET_JSON_from_data_auto (&tip_id), - "tip_amount", - TALER_JSON_from_amount (&amount)))); + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("row_id", + row_id), + GNUNET_JSON_pack_data_auto ("tip_id", + &tip_id), + TALER_JSON_pack_amount ("tip_amount", + &amount)))); } @@ -149,8 +148,9 @@ TMH_private_get_tips (const struct TMH_RequestHandler *rh, "tips"); } - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o}", - "tips", pa); + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("tips", + pa)); } diff --git a/src/backend/taler-merchant-httpd_private-get-transfers.c b/src/backend/taler-merchant-httpd_private-get-transfers.c index 3ac15d01..82ff2882 100644 --- a/src/backend/taler-merchant-httpd_private-get-transfers.c +++ b/src/backend/taler-merchant-httpd_private-get-transfers.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014-2020 Taler Systems SA + (C) 2014-2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -56,30 +56,27 @@ transfer_cb (void *cls, json_t *ja = cls; json_t *r; - r = json_pack ("{s:o, s:o, s:s, s:s, s:I}", - "credit_amount", TALER_JSON_from_amount (credit_amount), - "wtid", GNUNET_JSON_from_data_auto (wtid), - "payto_uri", payto_uri, - "exchange_url", exchange_url, - "transfer_serial_id", (json_int_t) transfer_serial_id); - GNUNET_assert (NULL != r); - if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us != - execution_time.abs_value_us) - GNUNET_assert (0 == - json_object_set_new ( - r, - "execution_time", - GNUNET_JSON_from_time_abs (execution_time))); - GNUNET_assert (0 == - json_object_set_new ( - r, - "verified", - json_boolean (verified ? 1 : 0))); - GNUNET_assert (0 == - json_object_set_new ( - r, - "confirmed", - json_boolean (confirmed ? 1 : 0))); + r = GNUNET_JSON_PACK ( + TALER_JSON_pack_amount ("credit_amount", + credit_amount), + GNUNET_JSON_pack_data_auto ("wtid", + wtid), + GNUNET_JSON_pack_string ("payto_uri", + payto_uri), + GNUNET_JSON_pack_string ("exchange_url", + exchange_url), + GNUNET_JSON_pack_uint64 ("transfer_serial_id", + transfer_serial_id), + GNUNET_JSON_pack_bool ("verified", + verified), + GNUNET_JSON_pack_bool ("confirmed", + confirmed), + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_time_abs ( + "execution_time", + GNUNET_TIME_absolute_is_never (execution_time) + ? GNUNET_TIME_UNIT_ZERO_ABS /* => field ommitted */ + : execution_time) )); GNUNET_assert (0 == json_array_append_new (ja, r)); @@ -229,10 +226,11 @@ TMH_private_get_transfers (const struct TMH_RequestHandler *rh, TALER_EC_GENERIC_DB_FETCH_FAILED, "transfers"); } - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o}", - "transfers", ja); + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ("transfers", + ja)); } } diff --git a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c index c0e4afb5..39c8c180 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c +++ b/src/backend/taler-merchant-httpd_private-post-orders-ID-refund.c @@ -339,13 +339,13 @@ TMH_private_post_orders_ID_refund (const struct TMH_RequestHandler *rh, taler_refund_uri = make_taler_refund_uri (connection, hc->instance->settings.id, hc->infix); - ret = TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s, s:o}", - "taler_refund_uri", - taler_refund_uri, - "h_contract", - GNUNET_JSON_from_data_auto (&h_contract)); + ret = TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("taler_refund_uri", + taler_refund_uri), + GNUNET_JSON_pack_data_auto ("h_contract", + &h_contract)); GNUNET_free (taler_refund_uri); return ret; } diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index 10f97944..403036af 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -429,9 +429,9 @@ execute_order (struct MHD_Connection *connection, GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_data_varsize ( "token", - (GNUNET_YES == GNUNET_is_zero (&token)) + GNUNET_is_zero (&token) ? NULL - : GNUNET_JSON_from_data_auto (&token), + : &token, sizeof (token)))); } else @@ -578,10 +578,10 @@ execute_order (struct MHD_Connection *connection, GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_data_varsize ( "token", - (GNUNET_YES == GNUNET_is_zero (&claim_token)) - ? NULL - : GNUNET_JSON_from_data_auto (&claim_token), - sizeof (claim_token)))); + GNUNET_is_zero (claim_token) + ? NULL + : claim_token, + sizeof (*claim_token)))); GNUNET_JSON_parse_free (spec); return ret; } @@ -1234,8 +1234,8 @@ merge_inventory (struct MHD_Connection *connection, pd.unit), TALER_JSON_pack_amount ("price", &pd.price), - GNUNET_JSON_pack_object_steal ("taxes", - pd.taxes), + GNUNET_JSON_pack_array_steal ("taxes", + pd.taxes), GNUNET_JSON_pack_string ("image", pd.image), GNUNET_JSON_pack_uint64 ("quantity", diff --git a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c index f49b9b1d..f9ceede3 100644 --- a/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves-ID-authorize-tip.c @@ -128,17 +128,17 @@ authorize_tip (const struct TMH_RequestHandler *rh, &tip_id, hc->instance->settings.id); GNUNET_TIME_round_abs (&expiration); - res = TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:s, s:s, s:s, s:o}", - "tip_id", - hash_enc.encoding, - "taler_tip_uri", - taler_tip_uri, - "tip_status_url", - tip_status_url, - "tip_expiration", - GNUNET_JSON_from_time_abs (expiration)); + res = TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_string ("tip_id", + (const char *) hash_enc.encoding), + GNUNET_JSON_pack_string ("taler_tip_uri", + taler_tip_uri), + GNUNET_JSON_pack_string ("tip_status_url", + tip_status_url), + GNUNET_JSON_pack_time_abs ("tip_expiration", + expiration)); GNUNET_free (taler_tip_uri); GNUNET_free (tip_status_url); return res; diff --git a/src/backend/taler-merchant-httpd_private-post-reserves.c b/src/backend/taler-merchant-httpd_private-post-reserves.c index a720f6c6..c509b9c2 100644 --- a/src/backend/taler-merchant-httpd_private-post-reserves.c +++ b/src/backend/taler-merchant-httpd_private-post-reserves.c @@ -376,13 +376,13 @@ TMH_private_post_reserves (const struct TMH_RequestHandler *rh, MHD_HTTP_INTERNAL_SERVER_ERROR, TALER_EC_GENERIC_DB_STORE_FAILED, "reserve"); - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o,s:s}", - "reserve_pub", - GNUNET_JSON_from_data_auto (&reserve_pub), - "payto_uri", - rc->payto_uri); + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_data_auto ("reserve_pub", + &reserve_pub), + GNUNET_JSON_pack_string ("payto_uri", + rc->payto_uri)); } } |