From 1db139a7f3b74b2dc4135ab8b42d625415705d63 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 31 Jul 2021 22:50:16 +0200 Subject: -eliminating some legacy json_pack calls from Anastasis --- src/reducer/anastasis_api_redux.c | 100 ++++++++++++++++++++------------------ 1 file changed, 52 insertions(+), 48 deletions(-) (limited to 'src/reducer') diff --git a/src/reducer/anastasis_api_redux.c b/src/reducer/anastasis_api_redux.c index eb7e362..7b7e5d5 100644 --- a/src/reducer/anastasis_api_redux.c +++ b/src/reducer/anastasis_api_redux.c @@ -287,10 +287,14 @@ ANASTASIS_redux_fail_ (ANASTASIS_ActionCallback cb, { json_t *estate; - estate = json_pack ("{s:s?, s:I, s:s}", - "detail", detail, - "code", (json_int_t) ec, - "hint", TALER_ErrorCode_get_hint (ec)); + estate = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_allow_null ( + GNUNET_JSON_pack_string ("detail", + detail)), + GNUNET_JSON_pack_uint64 ("code", + ec), + GNUNET_JSON_pack_string ("hint", + TALER_ErrorCode_get_hint (ec))); cb (cb_cls, ec, estate); @@ -473,11 +477,11 @@ notify_waiting (struct ConfigRequest *cr) if (TALER_EC_NONE != cr->ec) { - prov = json_pack ("{s:I, s:I}", - "error_code", - (json_int_t) cr->ec, - "http_status", - (json_int_t) cr->http_status); + prov = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_uint64 ("error_code", + cr->ec), + GNUNET_JSON_pack_uint64 ("http_status", + cr->http_status)); } else { @@ -488,38 +492,35 @@ notify_waiting (struct ConfigRequest *cr) for (unsigned int i = 0; imethods_length; i++) { struct AuthorizationMethodConfig *method = &cr->methods[i]; - json_t *mj = json_pack ("{s:s, s:o}", - "type", - method->type, - "usage_fee", - TALER_JSON_from_amount (&method->usage_fee)); + json_t *mj = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_string ("type", + method->type), + TALER_JSON_pack_amount ("usage_fee", + &method->usage_fee)); - GNUNET_assert (NULL != mj); GNUNET_assert (0 == json_array_append_new (methods_list, mj)); } - prov = json_pack ("{s:o, s:o, s:o, s:o, s:s," - " s:s, s:I, s:o, s:I}", - "methods", - methods_list, - "annual_fee", - TALER_JSON_from_amount (&cr->annual_fee), - "truth_upload_fee", - TALER_JSON_from_amount (&cr->truth_upload_fee), - "liability_limit", - TALER_JSON_from_amount (&cr->liability_limit), - "currency", - cr->currency, - /* 6 */ - "business_name", - cr->business_name, - "storage_limit_in_megabytes", - (json_int_t) cr->storage_limit_in_megabytes, - "salt", - GNUNET_JSON_from_data_auto (&cr->salt), - "http_status", - (json_int_t) cr->http_status); + prov = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_array_steal ("methods", + methods_list), + TALER_JSON_pack_amount ("annual_fee", + &cr->annual_fee), + TALER_JSON_pack_amount ("truth_upload_fee", + &cr->truth_upload_fee), + TALER_JSON_pack_amount ("liability_limit", + &cr->liability_limit), + GNUNET_JSON_pack_string ("currency", + cr->currency), + GNUNET_JSON_pack_string ("business_name", + cr->business_name), + GNUNET_JSON_pack_uint64 ("storage_limit_in_megabytes", + cr->storage_limit_in_megabytes), + GNUNET_JSON_pack_data_auto ("salt", + &cr->salt), + GNUNET_JSON_pack_uint64 ("http_status", + cr->http_status)); } GNUNET_assert (0 == json_object_set_new (provider_list, @@ -1682,9 +1683,9 @@ ANASTASIS_REDUX_load_continents_ () } if (NULL == ex) { - ex = json_pack ("{s:O}", - "name", - continent); + ex = GNUNET_JSON_PACK ( + GNUNET_JSON_pack_object_incref ("name", + (json_t *) continent)); GNUNET_assert (0 == json_array_append_new (continents, ex)); @@ -1708,23 +1709,26 @@ ANASTASIS_REDUX_load_continents_ () if (NULL == name_ex) { name_ex = json_object (); - json_object_set_new (ex, - "name_i18n", - name_ex); + GNUNET_assert (NULL != name_ex); + GNUNET_assert (0 == + json_object_set_new (ex, + "name_i18n", + name_ex)); } if (NULL == json_object_get (name_ex, lang)) { - json_object_set (name_ex, - lang, - trans); + GNUNET_assert (0 == + json_object_set (name_ex, + lang, + trans)); } } } } } } - return json_pack ("{s:o}", - "continents", - continents); + return GNUNET_JSON_PACK ( + GNUNET_JSON_pack_array_steal ("continents", + continents)); } -- cgit v1.2.3