diff options
-rw-r--r-- | src/bank-lib/bank_api_admin.c | 14 | ||||
-rw-r--r-- | src/bank-lib/bank_api_transfer.c | 18 | ||||
-rw-r--r-- | src/bank-lib/fakebank.c | 110 | ||||
-rw-r--r-- | src/exchange-tools/taler-auditor-offline.c | 53 |
4 files changed, 111 insertions, 84 deletions
diff --git a/src/bank-lib/bank_api_admin.c b/src/bank-lib/bank_api_admin.c index a0d68de2d..56828efa9 100644 --- a/src/bank-lib/bank_api_admin.c +++ b/src/bank-lib/bank_api_admin.c @@ -184,13 +184,13 @@ TALER_BANK_admin_add_incoming ( json_t *admin_obj; CURL *eh; - admin_obj = json_pack ("{s:o, s:o, s:s}", - "reserve_pub", - GNUNET_JSON_from_data_auto (reserve_pub), - "amount", - TALER_JSON_from_amount (amount), - "debit_account", - debit_account); + admin_obj = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("reserve_pub", + reserve_pub), + TALER_JSON_pack_amount ("amount", + amount), + GNUNET_JSON_pack_string ("debit_account", + debit_account)); if (NULL == admin_obj) { GNUNET_break (0); diff --git a/src/bank-lib/bank_api_transfer.c b/src/bank-lib/bank_api_transfer.c index 3f482e8c4..da9ff4f55 100644 --- a/src/bank-lib/bank_api_transfer.c +++ b/src/bank-lib/bank_api_transfer.c @@ -319,13 +319,17 @@ TALER_BANK_transfer ( GNUNET_break (0); return NULL; } - transfer_obj = json_pack ("{s:o, s:o, s:s, s:o, s:s}", - "request_uid", GNUNET_JSON_from_data_auto ( - &wp->request_uid), - "amount", TALER_JSON_from_amount (&amount), - "exchange_base_url", exchange_base_url, - "wtid", GNUNET_JSON_from_data_auto (&wp->wtid), - "credit_account", destination_account_uri); + transfer_obj = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("request_uid", + &wp->request_uid), + TALER_JSON_pack_amount ("amount", + &amount), + GNUNET_JSON_pack_string ("exchange_base_url", + exchange_base_url), + GNUNET_JSON_pack_data_auto ("wtid", + &wp->wtid), + GNUNET_JSON_pack_string ("credit_account", + destination_account_uri)); if (NULL == transfer_obj) { GNUNET_break (0); diff --git a/src/bank-lib/fakebank.c b/src/bank-lib/fakebank.c index c6871938b..1fac5e1b6 100644 --- a/src/bank-lib/fakebank.c +++ b/src/bank-lib/fakebank.c @@ -1083,13 +1083,12 @@ handle_admin_add_incoming (struct TALER_FAKEBANK_Handle *h, json_decref (json); /* Finally build response object */ - return TALER_MHD_reply_json_pack (connection, + return TALER_MHD_REPLY_JSON_PACK (connection, MHD_HTTP_OK, - "{s:I, s:o}", - "row_id", - (json_int_t) row_id, - "timestamp", - GNUNET_JSON_from_time_abs (timestamp)); + GNUNET_JSON_pack_uint64 ("row_id", + row_id), + GNUNET_JSON_pack_time_abs ("timestamp", + timestamp)); } @@ -1211,14 +1210,14 @@ handle_transfer (struct TALER_FAKEBANK_Handle *h, json_decref (json); /* Finally build response object */ - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:I, s:o}", - "row_id", - (json_int_t) row_id, - /* dummy timestamp */ - "timestamp", GNUNET_JSON_from_time_abs ( - GNUNET_TIME_UNIT_ZERO_ABS)); + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_uint64 ("row_id", + row_id), + /* dummy timestamp */ + GNUNET_JSON_pack_time_abs ("timestamp", + GNUNET_TIME_UNIT_ZERO_ABS)); } @@ -1438,11 +1437,12 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, pthread_mutex_unlock (&h->big_lock)); GNUNET_free (debit_payto); /* FIXME: suspend for long-polling instead */ - return TALER_MHD_reply_json_pack (connection, - MHD_HTTP_OK, - "{s:o}", - "outgoing_transactions", - history); + return TALER_MHD_REPLY_JSON_PACK ( + connection, + MHD_HTTP_OK, + GNUNET_JSON_pack_array_steal ( + "outgoing_transactions", + history)); } if (t->debit_account != acc) { @@ -1487,17 +1487,21 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, GNUNET_asprintf (&credit_payto, "payto://x-taler-bank/localhost/%s", pos->credit_account->account_name); - trans = json_pack ( - "{s:I, s:o, s:o, s:s, s:s, s:s, s:o}", - "row_id", (json_int_t) pos->row_id, - "date", GNUNET_JSON_from_time_abs (pos->date), - "amount", TALER_JSON_from_amount (&pos->amount), - "credit_account", credit_payto, - "debit_account", debit_payto, // FIXME: inefficient to return this here always! - "exchange_base_url", - pos->subject.debit.exchange_base_url, - "wtid", GNUNET_JSON_from_data_auto ( - &pos->subject.debit.wtid)); + trans = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("row_id", + pos->row_id), + GNUNET_JSON_pack_time_abs ("date", + pos->date), + TALER_JSON_pack_amount ("amount", + &pos->amount), + GNUNET_JSON_pack_string ("credit_account", + credit_payto), + GNUNET_JSON_pack_string ("debit_account", + debit_payto), // FIXME: inefficient to return this here always! + GNUNET_JSON_pack_string ("exchange_base_url", + pos->subject.debit.exchange_base_url), + GNUNET_JSON_pack_data_auto ("wtid", + &pos->subject.debit.wtid)); GNUNET_assert (NULL != trans); GNUNET_free (credit_payto); GNUNET_assert (0 == @@ -1515,11 +1519,11 @@ handle_debit_history (struct TALER_FAKEBANK_Handle *h, GNUNET_assert (0 == pthread_mutex_unlock (&h->big_lock)); GNUNET_free (debit_payto); - return TALER_MHD_reply_json_pack (connection, + return TALER_MHD_REPLY_JSON_PACK (connection, MHD_HTTP_OK, - "{s:o}", - "outgoing_transactions", - history); + GNUNET_JSON_pack_array_steal ( + "outgoing_transactions", + history)); } @@ -1593,11 +1597,11 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, pthread_mutex_unlock (&h->big_lock)); GNUNET_free (credit_payto); /* FIXME: suspend for long-polling instead */ - return TALER_MHD_reply_json_pack (connection, + return TALER_MHD_REPLY_JSON_PACK (connection, MHD_HTTP_OK, - "{s:o}", - "incoming_transactions", - history); + GNUNET_JSON_pack_array_steal ( + "incoming_transactions", + history)); } if (skip) { @@ -1631,15 +1635,19 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, GNUNET_asprintf (&debit_payto, "payto://x-taler-bank/localhost/%s", pos->debit_account->account_name); - trans = json_pack ( - "{s:I, s:o, s:o, s:s, s:s, s:o}", - "row_id", (json_int_t) pos->row_id, - "date", GNUNET_JSON_from_time_abs (pos->date), - "amount", TALER_JSON_from_amount (&pos->amount), - "credit_account", credit_payto, // FIXME: inefficient to repeat this always here! - "debit_account", debit_payto, - "reserve_pub", GNUNET_JSON_from_data_auto ( - &pos->subject.credit.reserve_pub)); + trans = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("row_id", + pos->row_id), + GNUNET_JSON_pack_time_abs ("date", + pos->date), + TALER_JSON_pack_amount ("amount", + &pos->amount), + GNUNET_JSON_pack_string ("credit_account", + credit_payto), // FIXME: inefficient to repeat this always here! + GNUNET_JSON_pack_string ("debit_account", + debit_payto), + GNUNET_JSON_pack_data_auto ("reserve_pub", + &pos->subject.credit.reserve_pub)); GNUNET_assert (NULL != trans); GNUNET_free (debit_payto); GNUNET_assert (0 == @@ -1657,11 +1665,11 @@ handle_credit_history (struct TALER_FAKEBANK_Handle *h, GNUNET_assert (0 == pthread_mutex_unlock (&h->big_lock)); GNUNET_free (credit_payto); - return TALER_MHD_reply_json_pack (connection, + return TALER_MHD_REPLY_JSON_PACK (connection, MHD_HTTP_OK, - "{s:o}", - "incoming_transactions", - history); + GNUNET_JSON_pack_array_steal ( + "incoming_transactions", + history)); } diff --git a/src/exchange-tools/taler-auditor-offline.c b/src/exchange-tools/taler-auditor-offline.c index cc7278e54..0fbd82baa 100644 --- a/src/exchange-tools/taler-auditor-offline.c +++ b/src/exchange-tools/taler-auditor-offline.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2020 Taler Systems SA + Copyright (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 @@ -295,11 +295,11 @@ output_operation (const char *op_name, json_t *action; GNUNET_assert (NULL != out); - action = json_pack ("{ s:s, s:o }", - "operation", - op_name, - "arguments", - op_value); + action = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("operation", + op_name), + GNUNET_JSON_pack_object_steal ("arguments", + op_value)); GNUNET_break (0 == json_array_append_new (out, action)); @@ -660,6 +660,15 @@ keys_cb ( switch (hr->http_status) { case MHD_HTTP_OK: + if (! json_is_object (hr->reply)) + { + GNUNET_break (0); + TALER_EXCHANGE_disconnect (exchange); + exchange = NULL; + test_shutdown (); + global_ret = EXIT_FAILURE; + return; + } break; default: fprintf (stderr, @@ -673,11 +682,11 @@ keys_cb ( global_ret = EXIT_FAILURE; return; } - in = json_pack ("{s:s,s:O}", - "operation", - OP_INPUT_KEYS, - "arguments", - hr->reply); + in = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("operation", + OP_INPUT_KEYS), + GNUNET_JSON_pack_object_incref ("arguments", + (json_t *) hr->reply)); if (NULL == args[0]) { json_dumpf (in, @@ -1141,11 +1150,11 @@ sign_denomkeys (const json_t *denomkeys) &auditor_priv, &auditor_sig); output_operation (OP_SIGN_DENOMINATION, - json_pack ("{s:o, s:o}", - "h_denom_pub", - GNUNET_JSON_from_data_auto (&h_denom_pub), - "auditor_sig", - GNUNET_JSON_from_data_auto (&auditor_sig))); + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("h_denom_pub", + &h_denom_pub), + GNUNET_JSON_pack_data_auto ("auditor_sig", + &auditor_sig))); } GNUNET_JSON_parse_free (spec); } @@ -1214,7 +1223,10 @@ do_sign (char *const *args) return; } if (NULL == out) + { out = json_array (); + GNUNET_assert (NULL != out); + } if (GNUNET_OK != sign_denomkeys (denomkeys)) { @@ -1247,11 +1259,14 @@ do_setup (char *const *args) if (NULL != *args) { if (NULL == out) + { out = json_array (); + GNUNET_assert (NULL != out); + } output_operation (OP_SETUP, - json_pack ("{s:o}", - "auditor_pub", - GNUNET_JSON_from_data_auto (&auditor_pub))); + GNUNET_JSON_PACK ( + GNUNET_JSON_pack_data_auto ("auditor_pub", + &auditor_pub))); } else |