summaryrefslogtreecommitdiff
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
parent812423c3872dce704ce9161127c7ebfbb7034fbe (diff)
downloadanastasis-1db139a7f3b74b2dc4135ab8b42d625415705d63.tar.gz
anastasis-1db139a7f3b74b2dc4135ab8b42d625415705d63.tar.bz2
anastasis-1db139a7f3b74b2dc4135ab8b42d625415705d63.zip
-eliminating some legacy json_pack calls from Anastasis
-rw-r--r--src/authorization/anastasis_authorization_plugin_email.c19
-rw-r--r--src/authorization/anastasis_authorization_plugin_file.c10
-rw-r--r--src/authorization/anastasis_authorization_plugin_post.c20
-rw-r--r--src/authorization/anastasis_authorization_plugin_sms.c20
-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
-rw-r--r--src/lib/anastasis_backup.c140
-rw-r--r--src/lib/anastasis_recovery.c106
-rw-r--r--src/reducer/anastasis_api_redux.c100
-rw-r--r--src/restclient/anastasis_api_truth_store.c33
-rw-r--r--src/testing/testing_cmd_truth_upload.c9
13 files changed, 316 insertions, 359 deletions
diff --git a/src/authorization/anastasis_authorization_plugin_email.c b/src/authorization/anastasis_authorization_plugin_email.c
index 33c400b..5448b7d 100644
--- a/src/authorization/anastasis_authorization_plugin_email.c
+++ b/src/authorization/anastasis_authorization_plugin_email.c
@@ -436,22 +436,19 @@ email_process (struct ANASTASIS_AUTHORIZATION_State *as,
if (TALER_MHD_xmime_matches (mime,
"application/json"))
{
- json_t *body;
char *user;
user = GNUNET_strndup (as->email,
len);
- body = json_pack ("{s:I, s:s, s:s}",
- "code",
- TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED,
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED),
- "detail",
- user);
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED),
+ GNUNET_JSON_pack_string ("hint",
+ TALER_ErrorCode_get_hint (
+ TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED)),
+ GNUNET_JSON_pack_string ("detail",
+ user));
GNUNET_free (user);
- GNUNET_break (NULL != body);
- resp = TALER_MHD_make_json (body);
}
else
{
diff --git a/src/authorization/anastasis_authorization_plugin_file.c b/src/authorization/anastasis_authorization_plugin_file.c
index 210ade7..15c22a1 100644
--- a/src/authorization/anastasis_authorization_plugin_file.c
+++ b/src/authorization/anastasis_authorization_plugin_file.c
@@ -209,13 +209,9 @@ file_process (struct ANASTASIS_AUTHORIZATION_State *as,
if (TALER_MHD_xmime_matches (mime,
"application/json"))
{
- json_t *body;
-
- body = json_pack ("{s:s}",
- "filename",
- as->filename);
- GNUNET_break (NULL != body);
- resp = TALER_MHD_make_json (body);
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_string ("filename",
+ as->filename));
}
else
{
diff --git a/src/authorization/anastasis_authorization_plugin_post.c b/src/authorization/anastasis_authorization_plugin_post.c
index 1f20ff3..1240316 100644
--- a/src/authorization/anastasis_authorization_plugin_post.c
+++ b/src/authorization/anastasis_authorization_plugin_post.c
@@ -500,18 +500,14 @@ post_process (struct ANASTASIS_AUTHORIZATION_State *as,
if (TALER_MHD_xmime_matches (mime,
"application/json"))
{
- json_t *body;
-
- body = json_pack ("{s:I, s:s, s:s}",
- "code",
- TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED,
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED),
- "detail",
- zip);
- GNUNET_break (NULL != body);
- resp = TALER_MHD_make_json (body);
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED),
+ GNUNET_JSON_pack_string ("hint",
+ TALER_ErrorCode_get_hint (
+ TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED)),
+ GNUNET_JSON_pack_string ("detail",
+ zip));
}
else
{
diff --git a/src/authorization/anastasis_authorization_plugin_sms.c b/src/authorization/anastasis_authorization_plugin_sms.c
index 01b5f73..0cd36c5 100644
--- a/src/authorization/anastasis_authorization_plugin_sms.c
+++ b/src/authorization/anastasis_authorization_plugin_sms.c
@@ -433,18 +433,14 @@ sms_process (struct ANASTASIS_AUTHORIZATION_State *as,
if (TALER_MHD_xmime_matches (mime,
"application/json"))
{
- json_t *body;
-
- body = json_pack ("{s:I, s:s, s:s}",
- "code",
- TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED,
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED),
- "detail",
- end);
- GNUNET_break (NULL != body);
- resp = TALER_MHD_make_json (body);
+ resp = TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_uint64 ("code",
+ TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED),
+ GNUNET_JSON_pack_string ("hint",
+ TALER_ErrorCode_get_hint (
+ TALER_EC_ANASTASIS_TRUTH_CHALLENGE_RESPONSE_REQUIRED)),
+ GNUNET_JSON_pack_string ("detail",
+ end));
}
else
{
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,
diff --git a/src/lib/anastasis_backup.c b/src/lib/anastasis_backup.c
index ea55e6a..d97bdae 100644
--- a/src/lib/anastasis_backup.c
+++ b/src/lib/anastasis_backup.c
@@ -134,29 +134,28 @@ ANASTASIS_truth_from_json (const json_t *json)
json_t *
ANASTASIS_truth_to_json (const struct ANASTASIS_Truth *t)
{
- return json_pack (
- "{s:o,s:o,s:o,s:o,s:o"
- ",s:o,s:s,s:s,s:s,s:s?}",
- "uuid",
- GNUNET_JSON_from_data_auto (&t->uuid),
- "key_share",
- GNUNET_JSON_from_data_auto (&t->key_share),
- "truth_key",
- GNUNET_JSON_from_data_auto (&t->truth_key),
- "salt",
- GNUNET_JSON_from_data_auto (&t->salt),
- "nonce",
- GNUNET_JSON_from_data_auto (&t->nonce),
- "provider_salt",
- GNUNET_JSON_from_data_auto (&t->provider_salt),
- "url",
- t->url,
- "type",
- t->type,
- "instructions",
- t->instructions,
- "mime_type",
- t->mime_type);
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("uuid",
+ &t->uuid),
+ GNUNET_JSON_pack_data_auto ("key_share",
+ &t->key_share),
+ GNUNET_JSON_pack_data_auto ("truth_key",
+ &t->truth_key),
+ GNUNET_JSON_pack_data_auto ("salt",
+ &t->salt),
+ GNUNET_JSON_pack_data_auto ("nonce",
+ &t->nonce),
+ GNUNET_JSON_pack_data_auto ("provider_salt",
+ &t->provider_salt),
+ GNUNET_JSON_pack_string ("url",
+ t->url),
+ GNUNET_JSON_pack_string ("type",
+ t->type),
+ GNUNET_JSON_pack_string ("instructions",
+ t->instructions),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("mime_type",
+ t->mime_type)));
}
@@ -778,23 +777,16 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
uuids,
GNUNET_JSON_from_data_auto (
&policy->truths[b]->uuid)));
- if (0 !=
- json_array_append_new (
- dec_policies,
- json_pack ("{s:o, s:o, s:o}",
- "master_key",
- GNUNET_JSON_from_data_auto (
- &encrypted_master_keys[k]),
- "uuids",
- uuids,
- "salt",
- GNUNET_JSON_from_data_auto (&policy->salt))))
- {
- GNUNET_break (0);
- json_decref (dec_policies);
- ANASTASIS_secret_share_cancel (ss);
- return NULL;
- }
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ dec_policies,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("master_key",
+ &encrypted_master_keys[k]),
+ GNUNET_JSON_pack_array_steal ("uuids",
+ uuids),
+ GNUNET_JSON_pack_data_auto ("salt",
+ &policy->salt))));
}
esc_methods = json_array ();
@@ -825,38 +817,24 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
if (! unique)
continue;
- if (0 !=
- json_array_append_new (
- esc_methods,
- json_pack ("{s:o," /* truth uuid */
- " s:s," /* provider url */
- " s:s," /* instructions */
- " s:o," /* truth key */
- " s:o," /* truth salt */
- " s:o," /* provider salt */
- " s:s}", /* escrow method */
- "uuid",
- GNUNET_JSON_from_data_auto (
- &pt->uuid),
- "url",
- pt->url,
- "instructions",
- pt->instructions,
- "truth_key", GNUNET_JSON_from_data_auto (
- &pt->truth_key),
- "salt", GNUNET_JSON_from_data_auto (
- &pt->salt),
- "provider_salt", GNUNET_JSON_from_data_auto (
- &pt->provider_salt),
- "escrow_type",
- pt->type)))
- {
- GNUNET_break (0);
- json_decref (esc_methods);
- json_decref (dec_policies);
- ANASTASIS_secret_share_cancel (ss);
- return NULL;
- }
+ GNUNET_assert (0 ==
+ json_array_append_new (
+ esc_methods,
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("uuid",
+ &pt->uuid),
+ GNUNET_JSON_pack_string ("url",
+ pt->url),
+ GNUNET_JSON_pack_string ("instructions",
+ pt->instructions),
+ GNUNET_JSON_pack_data_auto ("truth_key",
+ &pt->truth_key),
+ GNUNET_JSON_pack_data_auto ("salt",
+ &pt->salt),
+ GNUNET_JSON_pack_data_auto ("provider_salt",
+ &pt->provider_salt),
+ GNUNET_JSON_pack_string ("escrow_type",
+ pt->type))));
}
}
@@ -869,13 +847,17 @@ ANASTASIS_secret_share (struct GNUNET_CURL_Context *ctx,
int ret;
uint32_t be_size;
- recovery_document = json_pack (
- "{s:s?, s:o, s:o, s:o}",
- "secret_name", secret_name,
- "policies", dec_policies,
- "escrow_methods", esc_methods,
- "encrypted_core_secret", GNUNET_JSON_from_data (encrypted_core_secret,
- core_secret_size));
+ recovery_document = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("secret_name",
+ secret_name)),
+ GNUNET_JSON_pack_array_steal ("policies",
+ dec_policies),
+ GNUNET_JSON_pack_array_steal ("escrow_methods",
+ esc_methods),
+ GNUNET_JSON_pack_data_varsize ("encrypted_core_secret",
+ encrypted_core_secret,
+ core_secret_size));
GNUNET_assert (NULL != recovery_document);
GNUNET_free (encrypted_core_secret);
diff --git a/src/lib/anastasis_recovery.c b/src/lib/anastasis_recovery.c
index 5b0726f..2a606d2 100644
--- a/src/lib/anastasis_recovery.c
+++ b/src/lib/anastasis_recovery.c
@@ -963,22 +963,20 @@ ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r)
const struct ANASTASIS_Challenge *c = dp->pub_details.challenges[j];
json_t *cs;
- cs = json_pack ("{s:o}",
- "uuid",
- GNUNET_JSON_from_data_auto (&c->ci.uuid));
- GNUNET_assert (NULL != cs);
+ cs = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("uuid",
+ &c->ci.uuid));
GNUNET_assert (0 ==
json_array_append_new (c_arr,
cs));
}
- dps = json_pack ("{s:o, s:o, s:o}",
- "emk",
- GNUNET_JSON_from_data_auto (&dp->emk),
- "salt",
- GNUNET_JSON_from_data_auto (&dp->salt),
- "challenges",
- c_arr);
- GNUNET_assert (NULL != dps);
+ dps = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("emk",
+ &dp->emk),
+ GNUNET_JSON_pack_data_auto ("salt",
+ &dp->salt),
+ GNUNET_JSON_pack_array_steal ("challenges",
+ c_arr));
GNUNET_assert (0 ==
json_array_append_new (dps_arr,
dps));
@@ -990,53 +988,53 @@ ANASTASIS_recovery_serialize (const struct ANASTASIS_Recovery *r)
const struct ANASTASIS_Challenge *c = &r->cs[i];
json_t *cs;
- cs = json_pack ("{s:o,s:o,s:o,s:o,s:o?,"
- " s:s,s:s,s:s,s:b}",
- "uuid",
- GNUNET_JSON_from_data_auto (&c->ci.uuid),
- "truth_key",
- GNUNET_JSON_from_data_auto (&c->truth_key),
- "salt",
- GNUNET_JSON_from_data_auto (&c->salt),
- "provider_salt",
- GNUNET_JSON_from_data_auto (&c->provider_salt),
- "key_share",
- c->ci.solved
- ? GNUNET_JSON_from_data_auto (&c->key_share)
- : NULL,
- "url",
- c->url,
- "type",
- c->type,
- "instructions",
- c->instructions,
- "solved",
- c->ci.solved);
- GNUNET_assert (NULL != cs);
+ cs = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("uuid",
+ &c->ci.uuid),
+ GNUNET_JSON_pack_data_auto ("truth_key",
+ &c->truth_key),
+ GNUNET_JSON_pack_data_auto ("salt",
+ &c->salt),
+ GNUNET_JSON_pack_data_auto ("provider_salt",
+ &c->provider_salt),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_data_varsize ("key_share",
+ c->ci.solved
+ ? &c->key_share
+ : NULL,
+ sizeof (c->key_share))),
+ GNUNET_JSON_pack_string ("url",
+ c->url),
+ GNUNET_JSON_pack_string ("type",
+ c->type),
+ GNUNET_JSON_pack_string ("instructions",
+ c->instructions),
+ GNUNET_JSON_pack_bool ("solved",
+ c->ci.solved));
GNUNET_assert (0 ==
json_array_append_new (cs_arr,
cs));
}
- return json_pack ("{s:o, s:o, s:o, s:I, s:O, "
- " s:s, s:s?, s:o}",
- "id",
- GNUNET_JSON_from_data_auto (&r->id),
- "dps",
- dps_arr,
- "cs",
- cs_arr,
- "version",
- (json_int_t) r->ri.version,
- "id_data",
- r->id_data,
- "provider_url",
- r->provider_url,
- "secret_name",
- r->secret_name,
- "core_secret",
- GNUNET_JSON_from_data (r->enc_core_secret,
- r->enc_core_secret_size));
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("id",
+ &r->id),
+ GNUNET_JSON_pack_array_steal ("dps",
+ dps_arr),
+ GNUNET_JSON_pack_array_steal ("cs",
+ cs_arr),
+ GNUNET_JSON_pack_uint64 ("version",
+ r->ri.version),
+ GNUNET_JSON_pack_object_incref ("id_data",
+ (json_t *) r->id_data),
+ GNUNET_JSON_pack_string ("provider_url",
+ r->provider_url),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_string ("secret_name",
+ r->secret_name)),
+ GNUNET_JSON_pack_data_varsize ("core_secret",
+ r->enc_core_secret,
+ r->enc_core_secret_size));
}
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; i<cr->methods_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));
}
diff --git a/src/restclient/anastasis_api_truth_store.c b/src/restclient/anastasis_api_truth_store.c
index ef6a642..3311bc4 100644
--- a/src/restclient/anastasis_api_truth_store.c
+++ b/src/restclient/anastasis_api_truth_store.c
@@ -295,25 +295,20 @@ ANASTASIS_truth_store (
{
json_t *truth_data;
- truth_data = json_pack ("{s:o," /* encrypted KeyShare */
- " s:s," /* type */
- " s:o," /* nonce */
- " s:s," /* truth_mime */
- " s:I}", /* payment years */
- "keyshare_data",
- GNUNET_JSON_from_data_auto (encrypted_keyshare),
- "type",
- type,
- "encrypted_truth",
- GNUNET_JSON_from_data (encrypted_truth,
- encrypted_truth_size),
- "truth_mime",
- (NULL != truth_mime)
- ? truth_mime
- : "",
- "storage_duration_years",
- (json_int_t) payment_years_requested);
- GNUNET_assert (NULL != truth_data);
+ truth_data = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_data_auto ("keyshare_data",
+ encrypted_keyshare),
+ GNUNET_JSON_pack_string ("type",
+ type),
+ GNUNET_JSON_pack_data_varsize ("encrypted_truth",
+ encrypted_truth,
+ encrypted_truth_size),
+ GNUNET_JSON_pack_string ("truth_mime",
+ (NULL != truth_mime)
+ ? truth_mime
+ : ""),
+ GNUNET_JSON_pack_uint64 ("storage_duration_years",
+ payment_years_requested));
json_str = json_dumps (truth_data,
JSON_COMPACT);
GNUNET_assert (NULL != json_str);
diff --git a/src/testing/testing_cmd_truth_upload.c b/src/testing/testing_cmd_truth_upload.c
index f9149d5..a9a3161 100644
--- a/src/testing/testing_cmd_truth_upload.c
+++ b/src/testing/testing_cmd_truth_upload.c
@@ -302,12 +302,9 @@ truth_upload_traits (void *cls,
json_t *
ANASTASIS_TESTING_make_id_data_example (const char *id_data)
{
- json_t *id;
-
- id = json_pack ("{s:s}",
- "id_data", id_data);
- GNUNET_assert (NULL != id);
- return id;
+ return GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("id_data",
+ id_data));
}