summaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-08-01 22:49:04 +0200
committerChristian Grothoff <christian@grothoff.org>2021-08-01 22:49:04 +0200
commit92b86cc5a7277de1a3b3ab55aaf37c83a649930e (patch)
treeeef73525a65c6fe6825559f050b8ea971ca8302a /src/backend
parent4e18bf19dfed52aa448a0b0d8547c0be182ba36a (diff)
downloadmerchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.tar.gz
merchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.tar.bz2
merchant-92b86cc5a7277de1a3b3ab55aaf37c83a649930e.zip
finish implementing #6935
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/taler-merchant-httpd_get-tips-ID.c42
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-abort.c98
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-claim.c9
-rw-r--r--src/backend/taler-merchant-httpd_post-orders-ID-refund.c111
-rw-r--r--src/backend/taler-merchant-httpd_post-tips-ID-pickup.c82
5 files changed, 152 insertions, 190 deletions
diff --git a/src/backend/taler-merchant-httpd_get-tips-ID.c b/src/backend/taler-merchant-httpd_get-tips-ID.c
index 09640bde..5b0abd89 100644
--- a/src/backend/taler-merchant-httpd_get-tips-ID.c
+++ b/src/backend/taler-merchant-httpd_get-tips-ID.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
@@ -244,15 +244,14 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
else
{
json_t *context;
- context = json_pack ("{s:s, s:s, s:s}",
- "remaining_tip",
- TALER_amount2s (&remaining),
- "taler_tip_uri",
- uri,
- "taler_tip_qrcode_svg",
- qr);
- GNUNET_assert (NULL != context);
+ context = GNUNET_JSON_PACK (
+ TALER_JSON_pack_amount ("remaining_tip",
+ &remaining),
+ GNUNET_JSON_pack_string ("taler_tip_uri",
+ uri),
+ GNUNET_JSON_pack_string ("taler_tip_qrcode_svg",
+ qr));
ret = TMH_return_from_template (connection,
( (0 == remaining.value) &&
(0 == remaining.fraction) )
@@ -273,19 +272,18 @@ TMH_get_tips_ID (const struct TMH_RequestHandler *rh,
}
else
{
- ret = TALER_MHD_reply_json_pack (connection,
- ( (0 == remaining.value) &&
- (0 == remaining.fraction) )
- ? MHD_HTTP_GONE
- : MHD_HTTP_OK,
- "{s:s, s:o, s:o}",
- "exchange_url",
- exchange_url,
- "tip_amount",
- TALER_JSON_from_amount (&remaining),
- "expiration",
- GNUNET_JSON_from_time_abs (
- expiration_round));
+ ret = TALER_MHD_REPLY_JSON_PACK (
+ connection,
+ ( (0 == remaining.value) &&
+ (0 == remaining.fraction) )
+ ? MHD_HTTP_GONE
+ : MHD_HTTP_OK,
+ GNUNET_JSON_pack_string ("exchange_url",
+ exchange_url),
+ TALER_JSON_pack_amount ("tip_amount",
+ &remaining),
+ GNUNET_JSON_pack_time_abs ("expiration",
+ expiration_round));
}
GNUNET_free (exchange_url);
return ret;
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
index 759c3ba5..f0b2a0c2 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.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
@@ -27,6 +27,7 @@
#include <taler/taler_json_lib.h>
#include <taler/taler_exchange_service.h>
#include "taler-merchant-httpd_exchanges.h"
+#include "taler-merchant-httpd_helper.h"
/**
@@ -366,49 +367,44 @@ generate_success_response (struct AbortContext *ac)
(0 == rdi->http_status) ||
(NULL == rdi->exchange_reply) )
hc = MHD_HTTP_BAD_GATEWAY;
- detail = (MHD_HTTP_OK != rdi->http_status)
- ? json_pack ("{s:s, s:I, s:I, s:O?}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) rdi->http_status,
- "exchange_code",
- (json_int_t)
- (NULL != rdi->exchange_reply)
- ? TALER_JSON_get_error_code (
- rdi->exchange_reply)
- : TALER_EC_GENERIC_INVALID_RESPONSE,
- "exchange_reply",
- rdi->exchange_reply)
- : json_pack ("{s:s, s:I, s:o, s:o}",
- "type",
- "success",
- "exchange_status",
- (json_int_t) rdi->http_status,
- "exchange_sig",
- GNUNET_JSON_from_data_auto (&rdi->exchange_sig),
- "exchange_pub",
- GNUNET_JSON_from_data_auto (&rdi->exchange_pub));
- if ( (NULL == detail) ||
- (0 != json_array_append_new (refunds,
- detail)) )
- {
- json_decref (refunds);
- GNUNET_break (0);
- resume_abort_with_error (ac,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_JSON_ALLOCATION_FAILURE,
- "could not create JSON array");
- return;
- }
+ if (MHD_HTTP_OK != rdi->http_status)
+ detail = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ rdi->http_status),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ (NULL != rdi->exchange_reply)
+ ?
+ TALER_JSON_get_error_code (
+ rdi->exchange_reply)
+ :
+ TALER_EC_GENERIC_INVALID_RESPONSE),
+ GNUNET_JSON_pack_allow_null (
+ GNUNET_JSON_pack_object_incref ("exchange_reply",
+ rdi->exchange_reply)));
+ else
+ detail = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "success"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ rdi->http_status),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &rdi->exchange_sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &rdi->exchange_pub));
+ GNUNET_assert (0 ==
+ json_array_append_new (refunds,
+ detail));
}
/* Resume and send back the response. */
- resume_abort_with_response (ac,
- hc,
- TALER_MHD_make_json_pack ("{s:o}",
- "refunds",
- refunds));
+ resume_abort_with_response (
+ ac,
+ hc,
+ TALER_MHD_MAKE_JSON_PACK (
+ GNUNET_JSON_pack_array_steal ("refunds",
+ refunds)));
}
@@ -534,13 +530,9 @@ process_abort_with_exchange (void *cls,
resume_abort_with_response (
ac,
MHD_HTTP_GATEWAY_TIMEOUT,
- TALER_MHD_make_json_pack (
- "{s:s, s:I}",
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
- "code",
- (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
+ TALER_MHD_make_error (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
+ NULL));
return;
}
if (NULL == exchange_handle)
@@ -550,14 +542,10 @@ process_abort_with_exchange (void *cls,
resume_abort_with_response (
ac,
MHD_HTTP_BAD_GATEWAY,
- TALER_MHD_make_json_pack (
- "{s:s, s:I, s:I, s:I, s:O?}",
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_reply", hr->reply));
+ TMH_pack_exchange_reply (hr)));
return;
}
/* Initiate refund operation for all coins of
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
index 8b3b80ea..537ea0e1 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c
@@ -267,12 +267,13 @@ TMH_post_orders_ID_claim (const struct TMH_RequestHandler *rh,
GNUNET_CRYPTO_eddsa_sign (&hc->instance->merchant_priv.eddsa_priv,
&pdps,
&merchant_sig);
- return TALER_MHD_reply_json_pack (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{ s:o, s:o }",
- "contract_terms", contract_terms,
- "sig", GNUNET_JSON_from_data_auto (&merchant_sig));
+ GNUNET_JSON_pack_object_steal ("contract_terms",
+ contract_terms),
+ GNUNET_JSON_pack_data_auto ("sig",
+ &merchant_sig));
}
}
diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-refund.c b/src/backend/taler-merchant-httpd_post-orders-ID-refund.c
index 22c9f717..27622d63 100644
--- a/src/backend/taler-merchant-httpd_post-orders-ID-refund.c
+++ b/src/backend/taler-merchant-httpd_post-orders-ID-refund.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 Affero General Public License as
@@ -738,60 +738,60 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
{
if (NULL == cr->exchange_reply)
{
- refund = json_pack ("{s:s,s:I,s:I,s:o,s:o,s:o}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) cr->exchange_status,
- "rtransaction_id",
- (json_int_t) cr->rtransaction_id,
- "coin_pub",
- GNUNET_JSON_from_data_auto (&cr->coin_pub),
- "refund_amount",
- TALER_JSON_from_amount (&cr->refund_amount),
- "execution_time",
- GNUNET_JSON_from_time_abs (cr->execution_time));
+ refund = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ cr->exchange_status),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ cr->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cr->coin_pub),
+ TALER_JSON_pack_amount ("refund_amount",
+ &cr->refund_amount),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ cr->execution_time));
}
else
{
- refund = json_pack ("{s:s,s:I,s:I,s:O,s:I,s:o,s:o,s:o}",
- "type",
- "failure",
- "exchange_status",
- (json_int_t) cr->exchange_status,
- "exchange_code",
- (json_int_t) cr->exchange_code,
- "exchange_reply",
- cr->exchange_reply,
- "rtransaction_id",
- (json_int_t) cr->rtransaction_id,
- "coin_pub",
- GNUNET_JSON_from_data_auto (&cr->coin_pub),
- "refund_amount",
- TALER_JSON_from_amount (&cr->refund_amount),
- "execution_time",
- GNUNET_JSON_from_time_abs (cr->execution_time));
+ refund = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "failure"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ cr->exchange_status),
+ GNUNET_JSON_pack_uint64 ("exchange_code",
+ cr->exchange_code),
+ GNUNET_JSON_pack_object_incref ("exchange_reply",
+ cr->exchange_reply),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ cr->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cr->coin_pub),
+ TALER_JSON_pack_amount ("refund_amount",
+ &cr->refund_amount),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ cr->execution_time));
}
}
else
{
- refund = json_pack ("{s:s,s:I,s:o,s:o,s:I,s:o,s:o,s:o}",
- "type",
- "success",
- "exchange_status",
- (json_int_t) cr->exchange_status,
- "exchange_sig",
- GNUNET_JSON_from_data_auto (&cr->exchange_sig),
- "exchange_pub",
- GNUNET_JSON_from_data_auto (&cr->exchange_pub),
- "rtransaction_id",
- (json_int_t) cr->rtransaction_id,
- "coin_pub",
- GNUNET_JSON_from_data_auto (&cr->coin_pub),
- "refund_amount",
- TALER_JSON_from_amount (&cr->refund_amount),
- "execution_time",
- GNUNET_JSON_from_time_abs (cr->execution_time));
+ refund = GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_string ("type",
+ "success"),
+ GNUNET_JSON_pack_uint64 ("exchange_status",
+ cr->exchange_status),
+ GNUNET_JSON_pack_data_auto ("exchange_sig",
+ &cr->exchange_sig),
+ GNUNET_JSON_pack_data_auto ("exchange_pub",
+ &cr->exchange_pub),
+ GNUNET_JSON_pack_uint64 ("rtransaction_id",
+ cr->rtransaction_id),
+ GNUNET_JSON_pack_data_auto ("coin_pub",
+ &cr->coin_pub),
+ TALER_JSON_pack_amount ("refund_amount",
+ &cr->refund_amount),
+ GNUNET_JSON_pack_time_abs ("execution_time",
+ cr->execution_time));
}
GNUNET_assert (
0 ==
@@ -799,16 +799,15 @@ TMH_post_orders_ID_refund (const struct TMH_RequestHandler *rh,
refund));
}
- return TALER_MHD_reply_json_pack (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{s:o, s:o, s:o}",
- "refund_amount",
- TALER_JSON_from_amount (&prd->refund_amount),
- "refunds",
- ra,
- "merchant_pub",
- GNUNET_JSON_from_data_auto (&hc->instance->merchant_pub));
+ TALER_JSON_pack_amount ("refund_amount",
+ &prd->refund_amount),
+ GNUNET_JSON_pack_array_steal ("refunds",
+ ra),
+ GNUNET_JSON_pack_data_auto ("merchant_pub",
+ &hc->instance->merchant_pub));
}
return MHD_YES;
diff --git a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
index 2bdef2bc..bd327b56 100644
--- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c
+++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.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
@@ -25,6 +25,7 @@
#include <taler/taler_signatures.h>
#include "taler-merchant-httpd.h"
#include "taler-merchant-httpd_mhd.h"
+#include "taler-merchant-httpd_helper.h"
#include "taler-merchant-httpd_exchanges.h"
#include "taler-merchant-httpd_post-tips-ID-pickup.h"
@@ -292,12 +293,9 @@ withdraw_cb (void *cls,
stop_operations (pc);
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_MERCHANT_TIP_PICKUP_EXCHANGE_ERROR,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (TALER_EC_MERCHANT_TIP_PICKUP_EXCHANGE_ERROR),
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -359,13 +357,9 @@ do_withdraw (void *cls,
po);
GNUNET_free (po);
pc->http_status = MHD_HTTP_GATEWAY_TIMEOUT;
- pc->response = TALER_MHD_make_json_pack (
- "{s:s, s:I}",
- "hint",
- TALER_ErrorCode_get_hint (
- TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT),
- "code",
- (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT);
+ pc->response = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -379,14 +373,10 @@ do_withdraw (void *cls,
GNUNET_free (po);
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:s, s:I, s:I, s:I, s:O?}",
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -485,10 +475,8 @@ compute_total_requested (void *cls,
if (NULL == hr)
{
pc->http_status = MHD_HTTP_GATEWAY_TIMEOUT;
- pc->response = TALER_MHD_make_json_pack (
- "{s:I, s:s}",
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT,
- "hint", TALER_ErrorCode_get_hint (
+ pc->response = TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_TIMEOUT));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
@@ -498,14 +486,10 @@ compute_total_requested (void *cls,
{
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE,
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_CONNECT_FAILURE),
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -514,14 +498,10 @@ compute_total_requested (void *cls,
{
pc->http_status = MHD_HTTP_BAD_GATEWAY;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:s, s:I, s:I, s:O}",
- "code", (json_int_t) TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE,
- "hint", TALER_ErrorCode_get_hint (
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
TALER_EC_MERCHANT_GENERIC_EXCHANGE_KEYS_FAILURE),
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -540,13 +520,10 @@ compute_total_requested (void *cls,
{
pc->http_status = MHD_HTTP_CONFLICT;
pc->response =
- TALER_MHD_make_json_pack (
- "{s:I, s:I, s:I, s:O}",
- "code",
- (json_int_t) TALER_EC_MERCHANT_TIP_PICKUP_DENOMINATION_UNKNOWN,
- "exchange_code", (json_int_t) hr->ec,
- "exchange_http_status", (json_int_t) hr->http_status,
- "exchange_reply", hr->reply);
+ TALER_MHD_MAKE_JSON_PACK (
+ TALER_JSON_pack_ec (
+ TALER_EC_MERCHANT_TIP_PICKUP_DENOMINATION_UNKNOWN),
+ TMH_pack_exchange_reply (hr));
MHD_resume_connection (pc->connection);
TMH_trigger_daemon (); /* we resumed, kick MHD */
return;
@@ -869,17 +846,16 @@ RETRY:
GNUNET_assert (0 ==
json_array_append_new (
blind_sigs,
- json_pack ("{s:o}",
- "blind_sig",
- GNUNET_JSON_from_rsa_signature (
- sigs[i]))));
+ GNUNET_JSON_PACK (
+ GNUNET_JSON_pack_rsa_signature ("blind_sig",
+ sigs[i]))));
GNUNET_CRYPTO_rsa_signature_free (sigs[i]);
}
- return TALER_MHD_reply_json_pack (
+ return TALER_MHD_REPLY_JSON_PACK (
connection,
MHD_HTTP_OK,
- "{s:o}",
- "blind_sigs", blind_sigs);
+ GNUNET_JSON_pack_array_steal ("blind_sigs",
+ blind_sigs));
}
break;
case GNUNET_DB_STATUS_SOFT_ERROR: