merchant

Merchant backend to process payments, run by merchants
Log | Files | Refs | Submodules | README | LICENSE

commit 61c6cb27442aed0b45cf31f8a69183b1c39e9a13
parent 39e6ebbc169a250b6ae11928f5ce58696f09f19f
Author: Christian Grothoff <christian@grothoff.org>
Date:   Fri, 19 Nov 2021 11:43:40 +0100

-fix misc bugs

Diffstat:
Msrc/backend/taler-merchant-httpd_post-orders-ID-claim.c | 22+++++++++++++++++++---
Msrc/backend/taler-merchant-httpd_spa.c | 8++++++--
Msrc/lib/merchant_api_lock_product.c | 2++
Msrc/lib/merchant_api_patch_instance.c | 2++
Msrc/lib/merchant_api_patch_order_forget.c | 2++
Msrc/lib/merchant_api_patch_product.c | 2++
Msrc/lib/merchant_api_post_instance_auth.c | 1+
Msrc/lib/merchant_api_post_instances.c | 2++
Msrc/lib/merchant_api_post_order_abort.c | 1+
Msrc/lib/merchant_api_post_order_paid.c | 2++
Msrc/lib/merchant_api_post_order_pay.c | 1+
Msrc/lib/merchant_api_post_order_refund.c | 1+
Msrc/lib/merchant_api_post_orders.c | 8+++++---
Msrc/lib/merchant_api_post_reserves.c | 8+++++---
Msrc/lib/merchant_api_post_transfers.c | 8+++++---
Msrc/lib/merchant_api_tip_authorize.c | 9++++++---
Msrc/lib/merchant_api_wallet_post_order_refund.c | 1+
Msrc/testing/testing_api_cmd_post_orders.c | 16+++++++---------
18 files changed, 70 insertions(+), 26 deletions(-)

diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-claim.c b/src/backend/taler-merchant-httpd_post-orders-ID-claim.c @@ -62,7 +62,6 @@ claim_order (const char *instance_id, struct TALER_ClaimTokenP order_ct; enum GNUNET_DB_QueryStatus qs; uint64_t order_serial; - struct GNUNET_TIME_Absolute timestamp; if (GNUNET_OK != TMH_db->start (TMH_db->cls, @@ -90,8 +89,6 @@ claim_order (const char *instance_id, struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("nonce", &stored_nonce), - TALER_JSON_spec_absolute_time ("timestamp", - &timestamp), GNUNET_JSON_spec_end () }; @@ -126,6 +123,12 @@ claim_order (const char *instance_id, { struct GNUNET_HashCode unused; + struct GNUNET_TIME_Absolute timestamp; + struct GNUNET_JSON_Specification spec[] = { + TALER_JSON_spec_absolute_time ("timestamp", + &timestamp), + GNUNET_JSON_spec_end () + }; /* see if we have this order in our table of unclaimed orders */ qs = TMH_db->lookup_order (TMH_db->cls, @@ -140,6 +143,19 @@ claim_order (const char *instance_id, return qs; } GNUNET_assert (NULL != *contract_terms); + if (GNUNET_OK != + GNUNET_JSON_parse (*contract_terms, + spec, + NULL, + NULL)) + { + /* this should not be possible: contract_terms should always + have a timestamp! */ + GNUNET_break (0); + TMH_db->rollback (TMH_db->cls); + return GNUNET_DB_STATUS_HARD_ERROR; + } + GNUNET_assert (0 == json_object_set_new (*contract_terms, "nonce", diff --git a/src/backend/taler-merchant-httpd_spa.c b/src/backend/taler-merchant-httpd_spa.c @@ -39,8 +39,8 @@ static struct MHD_Response *spa; MHD_RESULT TMH_return_spa (const struct TMH_RequestHandler *rh, - struct MHD_Connection *connection, - struct TMH_HandlerContext *hc) + struct MHD_Connection *connection, + struct TMH_HandlerContext *hc) { if ( (MHD_YES == TALER_MHD_can_compress (connection)) && @@ -152,6 +152,10 @@ TMH_spa_init () "text/html")); } } + else + { + GNUNET_free (in); + } } spa = MHD_create_response_from_fd (sb.st_size, diff --git a/src/lib/merchant_api_lock_product.c b/src/lib/merchant_api_lock_product.c @@ -202,12 +202,14 @@ TALER_MERCHANT_product_lock ( CURL *eh; eh = curl_easy_init (); + GNUNET_assert (NULL != eh); if (GNUNET_OK != TALER_curl_easy_post (&plh->post_ctx, eh, req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (plh); return NULL; diff --git a/src/lib/merchant_api_patch_instance.c b/src/lib/merchant_api_patch_instance.c @@ -243,12 +243,14 @@ TALER_MERCHANT_instance_patch ( CURL *eh; eh = curl_easy_init (); + GNUNET_assert (NULL != eh); if (GNUNET_OK != TALER_curl_easy_post (&iph->post_ctx, eh, req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (iph->url); GNUNET_free (iph); diff --git a/src/lib/merchant_api_patch_order_forget.c b/src/lib/merchant_api_patch_order_forget.c @@ -207,12 +207,14 @@ TALER_MERCHANT_order_forget (struct GNUNET_CURL_Context *ctx, CURL *eh; eh = curl_easy_init (); + GNUNET_assert (NULL != eh); if (GNUNET_OK != TALER_curl_easy_post (&ofh->post_ctx, eh, req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (ofh); return NULL; diff --git a/src/lib/merchant_api_patch_product.c b/src/lib/merchant_api_patch_product.c @@ -224,12 +224,14 @@ TALER_MERCHANT_product_patch ( CURL *eh; eh = curl_easy_init (); + GNUNET_assert (NULL != eh); if (GNUNET_OK != TALER_curl_easy_post (&pph->post_ctx, eh, req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (pph); return NULL; diff --git a/src/lib/merchant_api_post_instance_auth.c b/src/lib/merchant_api_post_instance_auth.c @@ -194,6 +194,7 @@ TALER_MERCHANT_instance_auth_post ( req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (iaph->url); GNUNET_free (iaph); diff --git a/src/lib/merchant_api_post_instances.c b/src/lib/merchant_api_post_instances.c @@ -269,12 +269,14 @@ TALER_MERCHANT_instances_post ( CURL *eh; eh = curl_easy_init (); + GNUNET_assert (NULL != eh); if (GNUNET_OK != TALER_curl_easy_post (&iph->post_ctx, eh, req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (iph); return NULL; diff --git a/src/lib/merchant_api_post_order_abort.c b/src/lib/merchant_api_post_order_abort.c @@ -411,6 +411,7 @@ TALER_MERCHANT_order_abort (struct GNUNET_CURL_Context *ctx, abort_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (abort_obj); GNUNET_free (oah); return NULL; diff --git a/src/lib/merchant_api_post_order_paid.c b/src/lib/merchant_api_post_order_paid.c @@ -207,12 +207,14 @@ TALER_MERCHANT_order_paid ( CURL *eh; eh = curl_easy_init (); + GNUNET_assert (NULL != eh); if (GNUNET_OK != TALER_curl_easy_post (&oph->post_ctx, eh, req_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req_obj); GNUNET_free (oph); return NULL; diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c @@ -548,6 +548,7 @@ TALER_MERCHANT_order_pay_frontend ( pay_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (pay_obj); GNUNET_free (oph); return NULL; diff --git a/src/lib/merchant_api_post_order_refund.c b/src/lib/merchant_api_post_order_refund.c @@ -229,6 +229,7 @@ TALER_MERCHANT_post_order_refund (struct GNUNET_CURL_Context *ctx, req)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req); GNUNET_free (orh->url); GNUNET_free (orh); diff --git a/src/lib/merchant_api_post_orders.c b/src/lib/merchant_api_post_orders.c @@ -329,11 +329,13 @@ TALER_MERCHANT_orders_post2 ( } eh = curl_easy_init (); GNUNET_assert (NULL != eh); - if (GNUNET_OK != TALER_curl_easy_post (&po->post_ctx, - eh, - req)) + if (GNUNET_OK != + TALER_curl_easy_post (&po->post_ctx, + eh, + req)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req); GNUNET_free (po); return NULL; diff --git a/src/lib/merchant_api_post_reserves.c b/src/lib/merchant_api_post_reserves.c @@ -206,11 +206,13 @@ TALER_MERCHANT_reserves_post ( exchange_url)); eh = curl_easy_init (); GNUNET_assert (NULL != eh); - if (GNUNET_OK != TALER_curl_easy_post (&prh->post_ctx, - eh, - req)) + if (GNUNET_OK != + TALER_curl_easy_post (&prh->post_ctx, + eh, + req)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req); GNUNET_free (prh); return NULL; diff --git a/src/lib/merchant_api_post_transfers.c b/src/lib/merchant_api_post_transfers.c @@ -311,11 +311,13 @@ TALER_MERCHANT_transfers_post ( exchange_url)); eh = curl_easy_init (); GNUNET_assert (NULL != eh); - if (GNUNET_OK != TALER_curl_easy_post (&pth->post_ctx, - eh, - req)) + if (GNUNET_OK != + TALER_curl_easy_post (&pth->post_ctx, + eh, + req)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (req); GNUNET_free (pth); return NULL; diff --git a/src/lib/merchant_api_tip_authorize.c b/src/lib/merchant_api_tip_authorize.c @@ -271,6 +271,7 @@ TALER_MERCHANT_tip_authorize2 ( te_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (te_obj); GNUNET_free (tao->url); GNUNET_free (tao); @@ -331,11 +332,13 @@ TALER_MERCHANT_tip_authorize (struct GNUNET_CURL_Context *ctx, next_url)); eh = curl_easy_init (); GNUNET_assert (NULL != eh); - if (GNUNET_OK != TALER_curl_easy_post (&tao->post_ctx, - eh, - te_obj)) + if (GNUNET_OK != + TALER_curl_easy_post (&tao->post_ctx, + eh, + te_obj)) { GNUNET_break (0); + curl_easy_cleanup (eh); json_decref (te_obj); GNUNET_free (tao->url); GNUNET_free (tao); diff --git a/src/lib/merchant_api_wallet_post_order_refund.c b/src/lib/merchant_api_wallet_post_order_refund.c @@ -390,6 +390,7 @@ TALER_MERCHANT_wallet_post_order_refund ( { GNUNET_break (0); json_decref (req); + curl_easy_cleanup (eh); GNUNET_free (orh->url); GNUNET_free (orh); return NULL; diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c @@ -415,7 +415,6 @@ orders_run2 (void *cls, { struct OrdersState *ps = cls; const json_t *order; - json_error_t error; char *products_string = GNUNET_strdup (ps->products); char *locks_string = GNUNET_strdup (ps->locks); char *token; @@ -454,21 +453,20 @@ orders_run2 (void *cls, // FIXME: should probably use get_monotone() to ensure uniqueness! now = GNUNET_TIME_absolute_get (); - order_id = GNUNET_STRINGS_data_to_string_alloc - (&now.abs_value_us, - sizeof (now.abs_value_us)); - json_object_set_new (ps->order_terms, - "order_id", - json_string (order_id)); + order_id = GNUNET_STRINGS_data_to_string_alloc ( + &now.abs_value_us, + sizeof (now.abs_value_us)); + GNUNET_assert (0 == + json_object_set_new (ps->order_terms, + "order_id", + json_string (order_id))); GNUNET_free (order_id); } order = ps->order_terms; } if (NULL == order) { - // human error here. GNUNET_break (0); - fprintf (stderr, "%s\n", error.text); TALER_TESTING_interpreter_fail (is); return; }