summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-07-31 22:50:16 +0200
committerChristian Grothoff <christian@grothoff.org>2021-07-31 22:50:21 +0200
commit1db139a7f3b74b2dc4135ab8b42d625415705d63 (patch)
treedbbd66f083001bdefc9b029c1f45a5c2cf93697e /src/backend
parent812423c3872dce704ce9161127c7ebfbb7034fbe (diff)
downloadanastasis-1db139a7f3b74b2dc4135ab8b42d625415705d63.tar.gz
anastasis-1db139a7f3b74b2dc4135ab8b42d625415705d63.tar.bz2
anastasis-1db139a7f3b74b2dc4135ab8b42d625415705d63.zip
-eliminating some legacy json_pack calls from Anastasis
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/anastasis-httpd_config.c73
-rw-r--r--src/backend/anastasis-httpd_policy_upload.c25
-rw-r--r--src/backend/anastasis-httpd_truth.c44
-rw-r--r--src/backend/anastasis-httpd_truth_upload.c76
4 files changed, 107 insertions, 111 deletions
diff --git a/src/backend/anastasis-httpd_config.c b/src/backend/anastasis-httpd_config.c
index fff6bcb..14ed8db 100644
--- a/src/backend/anastasis-httpd_config.c
+++ b/src/backend/anastasis-httpd_config.c
@@ -1,6 +1,6 @@
/*
This file is part of Anastasis
- Copyright (C) 2020 Taler Systems SA
+ Copyright (C) 2020, 2021 Taler Systems SA
Anastasis 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
@@ -63,12 +63,11 @@ add_methods (void *cls,
section);
return;
}
- method = json_pack ("{s:s, s:o}",
- "type",
- section,
- "cost",
- TALER_JSON_from_amount (&cost));
- GNUNET_assert (NULL != method);
+ method = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ section),
+ TALER_JSON_pack_amount ("cost",
+ &cost));
GNUNET_assert (
0 ==
json_array_append_new (method_arr,
@@ -86,11 +85,11 @@ AH_handler_config (struct AH_RequestHandler *rh,
{
json_t *method;
- method = json_pack ("{s:s, s:o}",
- "type",
- "question",
- "cost",
- TALER_JSON_from_amount (&AH_question_cost));
+ method = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "question"),
+ TALER_JSON_pack_amount ("cost",
+ &AH_question_cost));
GNUNET_assert (
0 ==
json_array_append_new (method_arr,
@@ -99,33 +98,29 @@ AH_handler_config (struct AH_RequestHandler *rh,
GNUNET_CONFIGURATION_iterate_sections (AH_cfg,
&add_methods,
method_arr);
- return TALER_MHD_reply_json_pack (connection,
- MHD_HTTP_OK,
- "{s:s, s:s, s:s, s:s, s:o, s:I,"
- " s:o, s:o, s:o, s:o }",
- "name",
- "anastasis",
- "version",
- "0:0:0",
- "business_name",
- AH_business_name,
- "currency",
- (char *) AH_currency,
- "methods",
- method_arr,
- "storage_limit_in_megabytes",
- (json_int_t) AH_upload_limit_mb,
- /* 6 */
- "annual_fee",
- TALER_JSON_from_amount (&AH_annual_fee),
- "truth_upload_fee",
- TALER_JSON_from_amount (
- &AH_truth_upload_fee),
- "liability_limit",
- TALER_JSON_from_amount (&AH_insurance),
- "server_salt",
- GNUNET_JSON_from_data_auto (
- &AH_server_salt));
+ return TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("name",
+ "anastasis"),
+ GNUNET_JSON_pack_string ("version",
+ "0:0:0"),
+ GNUNET_JSON_pack_string ("business_name",
+ AH_business_name),
+ GNUNET_JSON_pack_string ("currency",
+ (char *) AH_currency),
+ GNUNET_JSON_pack_array_steal ("methods",
+ method_arr),
+ GNUNET_JSON_pack_uint64 ("storage_limit_in_megabytes",
+ AH_upload_limit_mb),
+ TALER_JSON_pack_amount ("annual_fee",
+ &AH_annual_fee),
+ TALER_JSON_pack_amount ("truth_upload_fee",
+ &AH_truth_upload_fee),
+ TALER_JSON_pack_amount ("liability_limit",
+ &AH_insurance),
+ GNUNET_JSON_pack_data_auto ("server_salt",
+ &AH_server_salt));
}
diff --git a/src/backend/anastasis-httpd_policy_upload.c b/src/backend/anastasis-httpd_policy_upload.c
index b8bd5ed..bff6028 100644
--- a/src/backend/anastasis-httpd_policy_upload.c
+++ b/src/backend/anastasis-httpd_policy_upload.c
@@ -329,19 +329,18 @@ proposal_cb (void *cls,
por->hr.http_status,
(int) por->hr.ec);
GNUNET_break (0);
- puc->resp = TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O?}",
- "code",
- (json_int_t) TALER_EC_SYNC_PAYMENT_CREATE_BACKEND_ERROR,
- "hint",
- "Failed to setup order with merchant backend",
- "backend-ec",
- (json_int_t) por->hr.ec,
- "backend-http-status",
- (json_int_t) por->hr.http_status,
- "backend-reply",
- por->hr.reply);
- GNUNET_assert (NULL != puc->resp);
+ puc->resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_SYNC_PAYMENT_CREATE_BACKEND_ERROR),
+ GNUNET_JSON_pack_string ("hint",
+ "Failed to setup order with merchant backend"),
+ GNUNET_JSON_pack_uint64 ("backend-ec",
+ por->hr.ec),
+ GNUNET_JSON_pack_uint64 ("backend-http-status",
+ por->hr.http_status),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("backend-reply",
+ (json_t *) por->hr.reply)));
puc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
return;
}
diff --git a/src/backend/anastasis-httpd_truth.c b/src/backend/anastasis-httpd_truth.c
index 164c33a..b0b6530 100644
--- a/src/backend/anastasis-httpd_truth.c
+++ b/src/backend/anastasis-httpd_truth.c
@@ -520,19 +520,18 @@ proposal_cb (void *cls,
por->hr.http_status,
(int) por->hr.ec);
GNUNET_break (0);
- gc->resp = TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O?}",
- "code",
- (json_int_t) TALER_EC_ANASTASIS_TRUTH_PAYMENT_CREATE_BACKEND_ERROR,
- "hint",
- "Failed to setup order with merchant backend",
- "backend-ec",
- (json_int_t) por->hr.ec,
- "backend-http-status",
- (json_int_t) por->hr.http_status,
- "backend-reply",
- por->hr.reply);
- GNUNET_assert (NULL != gc->resp);
+ gc->resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_TRUTH_PAYMENT_CREATE_BACKEND_ERROR),
+ GNUNET_JSON_pack_string ("hint",
+ "Failed to setup order with merchant backend"),
+ GNUNET_JSON_pack_uint64 ("backend-ec",
+ por->hr.ec),
+ GNUNET_JSON_pack_uint64 ("backend-http-status",
+ por->hr.http_status),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_steal ("backend-reply",
+ (json_t *) por->hr.reply)));
gc->response_code = MHD_HTTP_BAD_GATEWAY;
return;
}
@@ -727,14 +726,17 @@ begin_payment (struct GetContext *gc)
pay_deadline = GNUNET_TIME_relative_to_absolute (
ANASTASIS_CHALLENGE_OFFER_LIFETIME);
GNUNET_TIME_round_abs (&pay_deadline);
- order = json_pack ("{s:o, s:s, s:s, s:o, s:o}",
- "amount", TALER_JSON_from_amount (&gc->challenge_cost),
- "summary", "challenge fee for anastasis service",
- "order_id", order_id,
- "auto_refund", GNUNET_JSON_from_time_rel (
- AUTO_REFUND_TIMEOUT),
- "pay_deadline", GNUNET_JSON_from_time_abs (
- pay_deadline));
+ order = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("amount",
+ &gc->challenge_cost),
+ GNUNET_JSON_pack_string ("summary",
+ "challenge fee for anastasis service"),
+ GNUNET_JSON_pack_string ("order_id",
+ order_id),
+ GNUNET_JSON_pack_time_rel ("auto_refund",
+ AUTO_REFUND_TIMEOUT),
+ GNUNET_JSON_pack_time_abs ("pay_deadline",
+ pay_deadline));
gc->po = TALER_MERCHANT_orders_post2 (AH_ctx,
AH_backend_url,
order,
diff --git a/src/backend/anastasis-httpd_truth_upload.c b/src/backend/anastasis-httpd_truth_upload.c
index 9767087..130876f 100644
--- a/src/backend/anastasis-httpd_truth_upload.c
+++ b/src/backend/anastasis-httpd_truth_upload.c
@@ -264,19 +264,18 @@ proposal_cb (void *cls,
por->hr.http_status,
(int) por->hr.ec);
GNUNET_break (0);
- tuc->resp = TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O?}",
- "code",
- (json_int_t) TALER_EC_ANASTASIS_GENERIC_ORDER_CREATE_BACKEND_ERROR,
- "hint",
- "Failed to setup order with merchant backend",
- "backend-ec",
- (json_int_t) por->hr.ec,
- "backend-http-status",
- (json_int_t) por->hr.http_status,
- "backend-reply",
- por->hr.reply);
- GNUNET_assert (NULL != tuc->resp);
+ tuc->resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_GENERIC_ORDER_CREATE_BACKEND_ERROR),
+ GNUNET_JSON_pack_string ("hint",
+ "Failed to setup order with merchant backend"),
+ GNUNET_JSON_pack_uint64 ("backend-ec",
+ por->hr.ec),
+ GNUNET_JSON_pack_uint64 ("backend-http-status",
+ por->hr.http_status),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("backend-reply",
+ (json_t *) por->hr.reply)));
tuc->response_code = MHD_HTTP_BAD_GATEWAY;
return;
}
@@ -381,19 +380,19 @@ check_payment_cb (void *cls,
case MHD_HTTP_UNAUTHORIZED:
/* Configuration issue, complain! */
tuc->response_code = MHD_HTTP_INTERNAL_SERVER_ERROR;
- tuc->resp = TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O?}",
- "code",
- (json_int_t) TALER_EC_ANASTASIS_GENERIC_PAYMENT_CHECK_UNAUTHORIZED,
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_ANASTASIS_GENERIC_PAYMENT_CHECK_UNAUTHORIZED),
- "backend-ec",
- (json_int_t) hr->ec,
- "backend-http-status",
- (json_int_t) hr->http_status,
- "backend-reply",
- hr->reply);
+ tuc->resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_GENERIC_PAYMENT_CHECK_UNAUTHORIZED),
+ GNUNET_JSON_pack_string ("hint",
+ TALER_ErrorCode_get_hint (
+ TALER_EC_ANASTASIS_GENERIC_PAYMENT_CHECK_UNAUTHORIZED)),
+ GNUNET_JSON_pack_uint64 ("backend-ec",
+ hr->ec),
+ GNUNET_JSON_pack_uint64 ("backend-http-status",
+ hr->http_status),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("backend-reply",
+ (json_t *) hr->reply)));
GNUNET_assert (NULL != tuc->resp);
break;
case MHD_HTTP_NOT_FOUND:
@@ -441,18 +440,19 @@ check_payment_cb (void *cls,
default:
/* Unexpected backend response */
tuc->response_code = MHD_HTTP_BAD_GATEWAY;
- tuc->resp = TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O?}",
- "code",
- (json_int_t) TALER_EC_ANASTASIS_GENERIC_BACKEND_ERROR,
- "hint",
- TALER_ErrorCode_get_hint (TALER_EC_ANASTASIS_GENERIC_BACKEND_ERROR),
- "backend-ec",
- (json_int_t) hr->ec,
- "backend-http-status",
- (json_int_t) hr->http_status,
- "backend-reply",
- hr->reply);
+ tuc->resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_GENERIC_BACKEND_ERROR),
+ GNUNET_JSON_pack_string ("hint",
+ TALER_ErrorCode_get_hint (
+ TALER_EC_ANASTASIS_GENERIC_BACKEND_ERROR)),
+ GNUNET_JSON_pack_uint64 ("backend-ec",
+ (json_int_t) hr->ec),
+ GNUNET_JSON_pack_uint64 ("backend-http-status",
+ (json_int_t) hr->http_status),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("backend-reply",
+ (json_t *) hr->reply)));
break;
}
GNUNET_CONTAINER_DLL_remove (tuc_head,