From 0e2148d63b85025c37d4212162a522e47445acab Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 4 Jun 2023 12:28:55 +0200 Subject: -code cleanup --- src/backend/taler-merchant-httpd_helper.c | 42 ++++-------- .../taler-merchant-httpd_post-orders-ID-abort.c | 10 ++- .../taler-merchant-httpd_post-orders-ID-pay.c | 26 +------- .../taler-merchant-httpd_post-tips-ID-pickup.c | 18 +---- ...ler-merchant-httpd_private-patch-instances-ID.c | 13 ++-- ...merchant-httpd_private-patch-orders-ID-forget.c | 22 +------ .../taler-merchant-httpd_private-post-account.c | 6 +- .../taler-merchant-httpd_private-post-instances.c | 30 +++------ src/include/taler_merchant_service.h | 2 +- src/lib/merchant_api_get_instance.c | 36 +++++----- src/lib/merchant_api_get_instances.c | 77 +++++++--------------- src/lib/merchant_api_get_kyc.c | 31 ++++----- src/lib/merchant_api_get_orders.c | 29 ++++---- src/lib/merchant_api_get_products.c | 32 ++++----- src/lib/merchant_api_get_template.c | 8 +-- src/lib/merchant_api_merchant_get_order.c | 46 ++++--------- src/lib/merchant_api_post_order_abort.c | 16 +---- src/lib/merchant_api_post_order_pay.c | 8 +-- 18 files changed, 144 insertions(+), 308 deletions(-) diff --git a/src/backend/taler-merchant-httpd_helper.c b/src/backend/taler-merchant-httpd_helper.c index 75639af6..48a42f40 100644 --- a/src/backend/taler-merchant-httpd_helper.c +++ b/src/backend/taler-merchant-httpd_helper.c @@ -34,7 +34,7 @@ TMH_cmp_wire_account ( const struct TMH_WireMethod *wm) { const char *credit_facade_url = NULL; - json_t *credit_facade_credentials = NULL; + const json_t *credit_facade_credentials = NULL; const char *uri; struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_string ("payto_uri", @@ -44,8 +44,8 @@ TMH_cmp_wire_account ( &credit_facade_url), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("credit_facade_credentials", - &credit_facade_credentials), + GNUNET_JSON_spec_object_const ("credit_facade_credentials", + &credit_facade_credentials), NULL), GNUNET_JSON_spec_end () }; @@ -69,7 +69,6 @@ TMH_cmp_wire_account ( strcmp (wm->payto_uri, uri)) { - GNUNET_JSON_parse_free (ispec); return GNUNET_SYSERR; } if ( (NULL == credit_facade_url) != @@ -77,24 +76,20 @@ TMH_cmp_wire_account ( (NULL == credit_facade_credentials) != (NULL == wm->credit_facade_credentials) ) { - GNUNET_JSON_parse_free (ispec); return GNUNET_NO; } if ( (NULL != credit_facade_url) && (0 != strcmp (credit_facade_url, wm->credit_facade_url)) ) { - GNUNET_JSON_parse_free (ispec); return GNUNET_NO; } if ( (NULL != credit_facade_credentials) && (0 != json_equal (credit_facade_credentials, wm->credit_facade_credentials)) ) { - GNUNET_JSON_parse_free (ispec); return GNUNET_NO; } - GNUNET_JSON_parse_free (ispec); return GNUNET_YES; } @@ -115,7 +110,7 @@ TMH_accounts_array_valid (const json_t *accounts) json_t *payto_uri = json_array_get (accounts, i); const char *credit_facade_url = NULL; - json_t *credit_facade_credentials = NULL; + const json_t *credit_facade_credentials = NULL; const char *uri; struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_string ("payto_uri", @@ -125,8 +120,8 @@ TMH_accounts_array_valid (const json_t *accounts) &credit_facade_url), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("credit_facade_credentials", - &credit_facade_credentials), + GNUNET_JSON_spec_object_const ("credit_facade_credentials", + &credit_facade_credentials), NULL), GNUNET_JSON_spec_end () }; @@ -158,7 +153,6 @@ TMH_accounts_array_valid (const json_t *accounts) "payto_uri")))) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (ispec); return false; } } @@ -173,7 +167,6 @@ TMH_accounts_array_valid (const json_t *accounts) uri, err); GNUNET_free (err); - GNUNET_JSON_parse_free (ispec); return false; } } @@ -198,13 +191,11 @@ TMH_accounts_array_valid (const json_t *accounts) GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Invalid credit facade URL or credentials `%s'\n", credit_facade_url); - GNUNET_JSON_parse_free (ispec); return false; } TALER_MERCHANT_BANK_auth_free (&auth); } - GNUNET_JSON_parse_free (ispec); - } + } /* end for all accounts */ return true; } @@ -221,7 +212,7 @@ TMH_location_object_valid (const json_t *location) const char *street = NULL; const char *building = NULL; const char *building_no = NULL; - json_t *lines = NULL; + const json_t *lines = NULL; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_string ("country", @@ -260,8 +251,8 @@ TMH_location_object_valid (const json_t *location) &building_no), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("address_lines", - &lines), + GNUNET_JSON_spec_array_const ("address_lines", + &lines), NULL), GNUNET_JSON_spec_end () }; @@ -284,13 +275,6 @@ TMH_location_object_valid (const json_t *location) size_t idx; json_t *line; - if (! json_is_array (lines)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Invalid location for field %s\n", - "lines"); - return false; - } json_array_foreach (lines, idx, line) { if (! json_is_string (line)) @@ -326,7 +310,7 @@ TMH_products_array_valid (const json_t *products) const char *unit = NULL; struct TALER_Amount price = { .value = 0 }; const char *image_data_url = NULL; - json_t *taxes = NULL; + const json_t *taxes = NULL; struct GNUNET_TIME_Timestamp delivery_date = { 0 }; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_mark_optional ( @@ -353,8 +337,8 @@ TMH_products_array_valid (const json_t *products) &image_data_url), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("taxes", - &taxes), + GNUNET_JSON_spec_array_const ("taxes", + &taxes), NULL), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_timestamp ("delivery_date", 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 1853e88a..5361496d 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-abort.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-abort.c @@ -856,10 +856,10 @@ parse_abort (struct MHD_Connection *connection, struct TMH_HandlerContext *hc, struct AbortContext *ac) { - json_t *coins; + const json_t *coins; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("coins", - &coins), + GNUNET_JSON_spec_array_const ("coins", + &coins), GNUNET_JSON_spec_fixed_auto ("h_contract", &ac->h_contract_terms), @@ -878,7 +878,7 @@ parse_abort (struct MHD_Connection *connection, ac->coins_cnt = json_array_size (coins); if (0 == ac->coins_cnt) { - GNUNET_JSON_parse_free (spec); + GNUNET_break_op (0); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_POST_ORDERS_ID_ABORT_COINS_ARRAY_EMPTY, @@ -912,7 +912,6 @@ parse_abort (struct MHD_Connection *connection, ispec); if (GNUNET_YES != res) { - GNUNET_JSON_parse_free (spec); GNUNET_break_op (0); return res; } @@ -921,7 +920,6 @@ parse_abort (struct MHD_Connection *connection, rd->ac = ac; } } - GNUNET_JSON_parse_free (spec); GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Handling /abort for order `%s' with contract hash `%s'\n", ac->hc->infix, diff --git a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c index bd68278c..04224ac5 100644 --- a/src/backend/taler-merchant-httpd_post-orders-ID-pay.c +++ b/src/backend/taler-merchant-httpd_post-orders-ID-pay.c @@ -2219,10 +2219,10 @@ static enum GNUNET_GenericReturnValue parse_pay (struct PayContext *pc) { const char *session_id = NULL; - json_t *coins; + const json_t *coins; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("coins", - &coins), + GNUNET_JSON_spec_array_const ("coins", + &coins), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_string ("session_id", &session_id), @@ -2253,25 +2253,10 @@ parse_pay (struct PayContext *pc) /* use empty string as default if client didn't specify it */ pc->session_id = GNUNET_strdup (""); } - - if (! json_is_array (coins)) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - return (MHD_YES == - TALER_MHD_reply_with_error (pc->connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MISSING, - "'coins' must be an array")) - ? GNUNET_NO - : GNUNET_SYSERR; - } - pc->coins_cnt = json_array_size (coins); if (pc->coins_cnt > MAX_COIN_ALLOWED_COINS) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return (MHD_YES == TALER_MHD_reply_with_error ( pc->connection, @@ -2336,7 +2321,6 @@ parse_pay (struct PayContext *pc) if (GNUNET_YES != res) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return res; } @@ -2347,7 +2331,6 @@ parse_pay (struct PayContext *pc) &pc->dc[j].cdd.coin_pub)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return (MHD_YES == TALER_MHD_reply_with_error (pc->connection, MHD_HTTP_BAD_REQUEST, @@ -2367,7 +2350,6 @@ parse_pay (struct PayContext *pc) TMH_currency)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return (MHD_YES == TALER_MHD_reply_with_error (pc->connection, MHD_HTTP_CONFLICT, @@ -2382,7 +2364,6 @@ parse_pay (struct PayContext *pc) if (dc->no_age_commitment != dc->no_minimum_age_sig) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return (MHD_YES == TALER_MHD_reply_with_error ( pc->connection, @@ -2419,7 +2400,6 @@ parse_pay (struct PayContext *pc) } } } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } 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 da482cda..7cfc4beb 100644 --- a/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c +++ b/src/backend/taler-merchant-httpd_post-tips-ID-pickup.c @@ -655,7 +655,7 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, if (NULL == pc) { - json_t *planchets; + const json_t *planchets; json_t *planchet; size_t index; @@ -678,8 +678,8 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, { struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("planchets", - &planchets), + GNUNET_JSON_spec_array_const ("planchets", + &planchets), GNUNET_JSON_spec_end () }; { @@ -694,16 +694,6 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, : MHD_NO; } } - if (! json_is_array (planchets)) - { - GNUNET_break_op (0); - json_decref (planchets); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "planchets"); - } - GNUNET_array_grow (pc->planchets, pc->planchets_length, json_array_size (planchets)); @@ -724,14 +714,12 @@ TMH_post_tips_ID_pickup (const struct TMH_RequestHandler *rh, spec); if (GNUNET_OK != res) { - json_decref (planchets); return (GNUNET_NO == res) ? MHD_YES : MHD_NO; } } } - json_decref (planchets); { struct GNUNET_HashContext *hc; diff --git a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c index 9241d069..5fa66e1f 100644 --- a/src/backend/taler-merchant-httpd_private-patch-instances-ID.c +++ b/src/backend/taler-merchant-httpd_private-patch-instances-ID.c @@ -63,14 +63,14 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, struct TMH_HandlerContext *hc) { struct TALER_MERCHANTDB_InstanceSettings is; - json_t *accounts; + const json_t *accounts; const char *name; const char *uts = "business"; struct TMH_WireMethod *wm_head = NULL; struct TMH_WireMethod *wm_tail = NULL; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("accounts", - &accounts), + GNUNET_JSON_spec_array_const ("accounts", + &accounts), GNUNET_JSON_spec_string ("name", &name), GNUNET_JSON_spec_mark_optional ( @@ -387,7 +387,7 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, { const char *credit_facade_url = NULL; - json_t *credit_facade_credentials = NULL; + const json_t *credit_facade_credentials = NULL; const char *uri; struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_string ("payto_uri", @@ -397,8 +397,8 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, &credit_facade_url), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("credit_facade_credentials", - &credit_facade_credentials), + GNUNET_JSON_spec_object_const ("credit_facade_credentials", + &credit_facade_credentials), NULL), GNUNET_JSON_spec_end () }; @@ -421,7 +421,6 @@ patch_instances_ID (struct TMH_MerchantInstance *mi, GNUNET_CONTAINER_DLL_insert (wm_head, wm_tail, wm); - GNUNET_JSON_parse_free (ispec); } /* ispec scope */ { diff --git a/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c b/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c index 798d610a..78d2189a 100644 --- a/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c +++ b/src/backend/taler-merchant-httpd_private-patch-orders-ID-forget.c @@ -93,7 +93,7 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, for (unsigned int i = 0; irollback (TMH_db->cls); - json_decref (contract_terms); - json_decref (fields); - return TALER_MHD_reply_with_error (connection, - MHD_HTTP_BAD_REQUEST, - TALER_EC_GENERIC_PARAMETER_MALFORMED, - "fields"); - } - { size_t index; json_t *value; @@ -179,7 +168,6 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, { TMH_db->rollback (TMH_db->cls); json_decref (contract_terms); - json_decref (fields); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_PRIVATE_PATCH_ORDERS_ID_FORGET_PATH_SYNTAX_INCORRECT, @@ -194,7 +182,6 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, /* We tried to forget a field that isn't forgettable */ TMH_db->rollback (TMH_db->cls); json_decref (contract_terms); - json_decref (fields); return TALER_MHD_reply_with_error (connection, MHD_HTTP_CONFLICT, TALER_EC_MERCHANT_PRIVATE_PATCH_ORDERS_ID_FORGET_PATH_NOT_FORGETTABLE, @@ -207,7 +194,6 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, /* One of the paths was malformed and couldn't be expanded */ TMH_db->rollback (TMH_db->cls); json_decref (contract_terms); - json_decref (fields); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_MERCHANT_PRIVATE_PATCH_ORDERS_ID_FORGET_PATH_SYNTAX_INCORRECT, @@ -220,7 +206,6 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, { TMH_db->rollback (TMH_db->cls); json_decref (contract_terms); - json_decref (fields); return TALER_MHD_reply_static (connection, MHD_HTTP_NO_CONTENT, NULL, @@ -232,7 +217,6 @@ TMH_private_patch_orders_ID_forget (const struct TMH_RequestHandler *rh, order_id, contract_terms); json_decref (contract_terms); - json_decref (fields); if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) { TMH_db->rollback (TMH_db->cls); diff --git a/src/backend/taler-merchant-httpd_private-post-account.c b/src/backend/taler-merchant-httpd_private-post-account.c index 8e93203b..f9be253c 100644 --- a/src/backend/taler-merchant-httpd_private-post-account.c +++ b/src/backend/taler-merchant-httpd_private-post-account.c @@ -37,7 +37,7 @@ TMH_private_post_account (const struct TMH_RequestHandler *rh, { struct TMH_MerchantInstance *mi = hc->instance; const char *credit_facade_url = NULL; - json_t *credit_facade_credentials = NULL; + const json_t *credit_facade_credentials = NULL; const char *uri; struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_string ("payto_uri", @@ -47,8 +47,8 @@ TMH_private_post_account (const struct TMH_RequestHandler *rh, &credit_facade_url), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("credit_facade_credentials", - &credit_facade_credentials), + GNUNET_JSON_spec_object_const ("credit_facade_credentials", + &credit_facade_credentials), NULL), GNUNET_JSON_spec_end () }; diff --git a/src/backend/taler-merchant-httpd_private-post-instances.c b/src/backend/taler-merchant-httpd_private-post-instances.c index c8f443cd..97b096d6 100644 --- a/src/backend/taler-merchant-httpd_private-post-instances.c +++ b/src/backend/taler-merchant-httpd_private-post-instances.c @@ -101,15 +101,15 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, { struct TALER_MERCHANTDB_InstanceSettings is; struct TALER_MERCHANTDB_InstanceAuthSettings ias; - json_t *accounts; + const json_t *accounts; const char *auth_token = NULL; const char *uts = "business"; struct TMH_WireMethod *wm_head = NULL; struct TMH_WireMethod *wm_tail = NULL; - json_t *jauth; + const json_t *jauth; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("accounts", - &accounts), + GNUNET_JSON_spec_array_const ("accounts", + &accounts), GNUNET_JSON_spec_string ("id", (const char **) &is.id), GNUNET_JSON_spec_string ("name", @@ -130,8 +130,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, GNUNET_JSON_spec_string ("logo", (const char **) &is.logo), NULL), - GNUNET_JSON_spec_json ("auth", - &jauth), + GNUNET_JSON_spec_object_const ("auth", + &jauth), GNUNET_JSON_spec_json ("address", &is.address), GNUNET_JSON_spec_json ("jurisdiction", @@ -169,7 +169,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, &is.ut)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -222,7 +221,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, if (! TMH_location_object_valid (is.address)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -232,7 +230,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, if (! TMH_location_object_valid (is.jurisdiction)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -243,7 +240,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, (! TMH_image_data_url_valid (is.logo)) ) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_BAD_REQUEST, TALER_EC_GENERIC_PARAMETER_MALFORMED, @@ -259,7 +255,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, { if (mi->deleted) { - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_CONFLICT, TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_PURGE_REQUIRED, @@ -317,7 +312,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, (accounts_equal (mi, accounts)) ) { - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_static (connection, MHD_HTTP_NO_CONTENT, NULL, @@ -326,7 +320,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, } else { - GNUNET_JSON_parse_free (spec); return TALER_MHD_reply_with_error (connection, MHD_HTTP_CONFLICT, TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS, @@ -344,7 +337,7 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, json_t *account = json_array_get (accounts, i); const char *credit_facade_url = NULL; - json_t *credit_facade_credentials = NULL; + const json_t *credit_facade_credentials = NULL; const char *uri; struct TMH_WireMethod *wm; struct GNUNET_JSON_Specification ispec[] = { @@ -355,8 +348,8 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, &credit_facade_url), NULL), GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_json ("credit_facade_credentials", - &credit_facade_credentials), + GNUNET_JSON_spec_object_const ("credit_facade_credentials", + &credit_facade_credentials), NULL), GNUNET_JSON_spec_end () }; @@ -376,7 +369,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, GNUNET_CONTAINER_DLL_insert (wm_head, wm_tail, wm); - GNUNET_JSON_parse_free (ispec); } } @@ -428,7 +420,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, TMH_db->start (TMH_db->cls, "post /instances")) { - GNUNET_JSON_parse_free (spec); mi->rc = 1; TMH_instance_decref (mi); return TALER_MHD_reply_with_error (connection, @@ -452,7 +443,6 @@ TMH_private_post_instances (const struct TMH_RequestHandler *rh, MHD_HTTP_CONFLICT, TALER_EC_MERCHANT_PRIVATE_POST_INSTANCES_ALREADY_EXISTS, is.id); - GNUNET_JSON_parse_free (spec); mi->rc = 1; TMH_instance_decref (mi); return ret; @@ -504,7 +494,6 @@ retry: } /* for .. MAX_RETRIES */ if (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != qs) { - GNUNET_JSON_parse_free (spec); mi->rc = 1; TMH_instance_decref (mi); return TALER_MHD_reply_with_error (connection, @@ -517,7 +506,6 @@ retry: TMH_add_instance (mi)); TMH_reload_instances (mi->settings.id); } - GNUNET_JSON_parse_free (spec); if (0 == strcmp (is.id, "default")) { diff --git a/src/include/taler_merchant_service.h b/src/include/taler_merchant_service.h index b1b4d003..3d64833f 100644 --- a/src/include/taler_merchant_service.h +++ b/src/include/taler_merchant_service.h @@ -413,7 +413,7 @@ struct TALER_MERCHANT_InstanceInformation * JSON array of payment targets (strings) supported by this backend * instance. */ - json_t *payment_targets; + const json_t *payment_targets; /** * User type for the instance. diff --git a/src/lib/merchant_api_get_instance.c b/src/lib/merchant_api_get_instance.c index 6224e1b4..cf58f828 100644 --- a/src/lib/merchant_api_get_instance.c +++ b/src/lib/merchant_api_get_instance.c @@ -93,13 +93,13 @@ handle_get_instance_finished (void *cls, { case MHD_HTTP_OK: { - json_t *accounts; + const json_t *accounts; const char *uts; - json_t *address; - json_t *jurisdiction; + const json_t *address; + const json_t *jurisdiction; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("accounts", - &accounts), + GNUNET_JSON_spec_array_const ("accounts", + &accounts), GNUNET_JSON_spec_string ("name", &igr.details.ok.details.name), GNUNET_JSON_spec_string ("user_type", @@ -107,10 +107,10 @@ handle_get_instance_finished (void *cls, GNUNET_JSON_spec_fixed_auto ( "merchant_pub", &igr.details.ok.details.merchant_pub), - GNUNET_JSON_spec_json ("address", - &address), - GNUNET_JSON_spec_json ("jurisdiction", - &jurisdiction), + GNUNET_JSON_spec_object_const ("address", + &address), + GNUNET_JSON_spec_object_const ("jurisdiction", + &jurisdiction), TALER_JSON_spec_amount_any ( "default_max_wire_fee", &igr.details.ok.details.default_max_wire_fee), @@ -129,14 +129,13 @@ handle_get_instance_finished (void *cls, GNUNET_JSON_spec_end () }; - if ( (GNUNET_OK == - GNUNET_JSON_parse (json, - spec, - NULL, NULL)) && - (json_is_array (accounts)) ) + if (GNUNET_OK == + GNUNET_JSON_parse (json, + spec, + NULL, NULL)) { unsigned int accounts_length = json_array_size (accounts); - struct TALER_MERCHANT_Account aa[accounts_length]; + struct TALER_MERCHANT_Account aa[GNUNET_NZL (accounts_length)]; size_t index; json_t *value; int ret = GNUNET_OK; @@ -146,7 +145,7 @@ handle_get_instance_finished (void *cls, sizeof (aa)); json_array_foreach (accounts, index, value) { - struct GNUNET_JSON_Specification spec[] = { + struct GNUNET_JSON_Specification ispec[] = { GNUNET_JSON_spec_fixed_auto ("salt", &aa[index].salt), GNUNET_JSON_spec_mark_optional ( @@ -164,7 +163,7 @@ handle_get_instance_finished (void *cls, if (GNUNET_OK != GNUNET_JSON_parse (value, - spec, + ispec, NULL, NULL)) { GNUNET_break_op (0); @@ -188,14 +187,12 @@ handle_get_instance_finished (void *cls, ret = GNUNET_SYSERR; igr.hr.http_status = 0; igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - GNUNET_JSON_parse_free (spec); break; } igr.details.ok.accounts_length = accounts_length; igr.details.ok.accounts = aa; igh->cb (igh->cb_cls, &igr); - GNUNET_JSON_parse_free (spec); TALER_MERCHANT_instance_get_cancel (igh); return; } @@ -203,7 +200,6 @@ handle_get_instance_finished (void *cls, GNUNET_break_op (0); igr.hr.http_status = 0; igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - GNUNET_JSON_parse_free (spec); break; } case MHD_HTTP_UNAUTHORIZED: diff --git a/src/lib/merchant_api_get_instances.c b/src/lib/merchant_api_get_instances.c index 5f26eb48..c0553941 100644 --- a/src/lib/merchant_api_get_instances.c +++ b/src/lib/merchant_api_get_instances.c @@ -81,7 +81,6 @@ parse_instances (const json_t *json, struct TALER_MERCHANT_InstanceInformation iis[GNUNET_NZL (iis_len)]; size_t index; json_t *value; - enum GNUNET_GenericReturnValue ret; struct TALER_MERCHANT_InstancesGetResponse igr = { .hr.http_status = MHD_HTTP_OK, .hr.reply = json, @@ -89,7 +88,6 @@ parse_instances (const json_t *json, .details.ok.iis = iis }; - ret = GNUNET_OK; json_array_foreach (ia, index, value) { struct TALER_MERCHANT_InstanceInformation *ii = &iis[index]; const char *uts; @@ -102,8 +100,8 @@ parse_instances (const json_t *json, &ii->id), GNUNET_JSON_spec_fixed_auto ("merchant_pub", &ii->merchant_pub), - GNUNET_JSON_spec_json ("payment_targets", - &ii->payment_targets), + GNUNET_JSON_spec_array_const ("payment_targets", + &ii->payment_targets), GNUNET_JSON_spec_end () }; @@ -113,24 +111,14 @@ parse_instances (const json_t *json, NULL, NULL)) { GNUNET_break_op (0); - ret = GNUNET_SYSERR; - continue; + return GNUNET_SYSERR; } if (GNUNET_OK != TALER_KYCLOGIC_kyc_user_type_from_string (uts, &ii->ut)) { GNUNET_break_op (0); - ret = GNUNET_SYSERR; - GNUNET_JSON_parse_free (spec); - break; - } - if (! json_is_array (ii->payment_targets)) - { - GNUNET_break_op (0); - ret = GNUNET_SYSERR; - GNUNET_JSON_parse_free (spec); - break; + return GNUNET_SYSERR; } for (unsigned int i = 0; ipayment_targets); i++) { @@ -138,27 +126,14 @@ parse_instances (const json_t *json, i))) { GNUNET_break_op (0); - ret = GNUNET_SYSERR; - GNUNET_JSON_parse_free (spec); - break; + return GNUNET_SYSERR; } } - if (GNUNET_SYSERR == ret) - { - GNUNET_JSON_parse_free (spec); - break; - } - } - if (GNUNET_OK == ret) - { - igh->cb (igh->cb_cls, - &igr); - igh->cb = NULL; /* just to be sure */ - } - for (unsigned int i = 0; icb (igh->cb_cls, + &igr); + igh->cb = NULL; /* just to be sure */ + return GNUNET_OK; } @@ -190,10 +165,10 @@ handle_instances_finished (void *cls, { case MHD_HTTP_OK: { - json_t *instances; + const json_t *instances; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("instances", - &instances), + GNUNET_JSON_spec_array_const ("instances", + &instances), GNUNET_JSON_spec_end () }; @@ -204,26 +179,18 @@ handle_instances_finished (void *cls, { igr.hr.http_status = 0; igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; } - else + if (GNUNET_OK == + parse_instances (json, + instances, + igh)) { - if ( (! json_is_array (instances)) || - (GNUNET_OK == - parse_instances (json, - instances, - igh)) ) - { - GNUNET_JSON_parse_free (spec); - TALER_MERCHANT_instances_get_cancel (igh); - return; - } - else - { - igr.hr.http_status = 0; - igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - } + TALER_MERCHANT_instances_get_cancel (igh); + return; } - GNUNET_JSON_parse_free (spec); + igr.hr.http_status = 0; + igr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } case MHD_HTTP_UNAUTHORIZED: diff --git a/src/lib/merchant_api_get_kyc.c b/src/lib/merchant_api_get_kyc.c index 0b62d2cf..c394590a 100644 --- a/src/lib/merchant_api_get_kyc.c +++ b/src/lib/merchant_api_get_kyc.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2021 Taler Systems SA + Copyright (C) 2023 Taler Systems SA TALER 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 @@ -76,8 +76,8 @@ struct TALER_MERCHANT_KycGetHandle static enum GNUNET_GenericReturnValue parse_kyc (struct TALER_MERCHANT_KycGetHandle *kyc, struct TALER_MERCHANT_KycResponse *kr, - json_t *pends, - json_t *touts) + const json_t *pends, + const json_t *touts) { unsigned int num_pends = json_array_size (pends); unsigned int num_touts = json_array_size (touts); @@ -186,13 +186,13 @@ handle_get_kyc_finished (void *cls, case MHD_HTTP_BAD_GATEWAY: case MHD_HTTP_GATEWAY_TIMEOUT: { - json_t *pends; - json_t *touts; + const json_t *pends; + const json_t *touts; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("pending_kycs", - &pends), - GNUNET_JSON_spec_json ("timeout_kycs", - &touts), + GNUNET_JSON_spec_array_const ("pending_kycs", + &pends), + GNUNET_JSON_spec_array_const ("timeout_kycs", + &touts), GNUNET_JSON_spec_end () }; @@ -205,20 +205,17 @@ handle_get_kyc_finished (void *cls, kr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } - if ( (! json_is_array (pends)) || - (! json_is_array (touts)) || - (GNUNET_OK != - parse_kyc (kyc, - &kr, - pends, - touts)) ) + if (GNUNET_OK != + parse_kyc (kyc, + &kr, + pends, + touts)) { kr.hr.http_status = 0; kr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } /* parse_kyc called the continuation already */ - GNUNET_JSON_parse_free (spec); TALER_MERCHANT_kyc_get_cancel (kyc); return; } diff --git a/src/lib/merchant_api_get_orders.c b/src/lib/merchant_api_get_orders.c index 5bad47e0..966ecb15 100644 --- a/src/lib/merchant_api_get_orders.c +++ b/src/lib/merchant_api_get_orders.c @@ -148,10 +148,10 @@ handle_get_orders_finished (void *cls, { case MHD_HTTP_OK: { - json_t *orders; + const json_t *orders; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("orders", - &orders), + GNUNET_JSON_spec_array_const ("orders", + &orders), GNUNET_JSON_spec_end () }; @@ -162,23 +162,18 @@ handle_get_orders_finished (void *cls, { ogr.hr.http_status = 0; ogr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; } - else + if (GNUNET_OK == + parse_orders (orders, + &ogr, + ogh)) { - if ( (! json_is_array (orders)) || - (GNUNET_OK == - parse_orders (orders, - &ogr, - ogh)) ) - { - GNUNET_JSON_parse_free (spec); - TALER_MERCHANT_orders_get_cancel (ogh); - return; - } - ogr.hr.http_status = 0; - ogr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + TALER_MERCHANT_orders_get_cancel (ogh); + return; } - GNUNET_JSON_parse_free (spec); + ogr.hr.http_status = 0; + ogr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } case MHD_HTTP_UNAUTHORIZED: diff --git a/src/lib/merchant_api_get_products.c b/src/lib/merchant_api_get_products.c index 98976237..01115094 100644 --- a/src/lib/merchant_api_get_products.c +++ b/src/lib/merchant_api_get_products.c @@ -149,10 +149,10 @@ handle_get_products_finished (void *cls, { case MHD_HTTP_OK: { - json_t *products; + const json_t *products; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("products", - &products), + GNUNET_JSON_spec_array_const ("products", + &products), GNUNET_JSON_spec_end () }; @@ -163,26 +163,18 @@ handle_get_products_finished (void *cls, { gpr.hr.http_status = 0; gpr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; + break; } - else + if (GNUNET_OK == + parse_products (json, + products, + pgh)) { - if ( (! json_is_array (products)) || - (GNUNET_OK == - parse_products (json, - products, - pgh)) ) - { - GNUNET_JSON_parse_free (spec); - TALER_MERCHANT_products_get_cancel (pgh); - return; - } - else - { - gpr.hr.http_status = 0; - gpr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - } + TALER_MERCHANT_products_get_cancel (pgh); + return; } - GNUNET_JSON_parse_free (spec); + gpr.hr.http_status = 0; + gpr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; break; } case MHD_HTTP_UNAUTHORIZED: diff --git a/src/lib/merchant_api_get_template.c b/src/lib/merchant_api_get_template.c index 386026cf..3e4a23a8 100644 --- a/src/lib/merchant_api_get_template.c +++ b/src/lib/merchant_api_get_template.c @@ -93,7 +93,7 @@ handle_get_template_finished (void *cls, case MHD_HTTP_OK: { uint32_t alg32; - json_t *contract; + const json_t *contract; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("template_description", &tgr.details.ok.template_description), @@ -103,8 +103,8 @@ handle_get_template_finished (void *cls, GNUNET_JSON_spec_string ("pos_key", &tgr.details.ok.pos_key), NULL), - GNUNET_JSON_spec_json ("template_contract", - &contract), + GNUNET_JSON_spec_object_const ("template_contract", + &contract), GNUNET_JSON_spec_end () }; @@ -118,13 +118,11 @@ handle_get_template_finished (void *cls, tgr.details.ok.template_contract = contract; tgh->cb (tgh->cb_cls, &tgr); - GNUNET_JSON_parse_free (spec); TALER_MERCHANT_template_get_cancel (tgh); return; } tgr.hr.http_status = 0; tgr.hr.ec = TALER_EC_GENERIC_INVALID_RESPONSE; - GNUNET_JSON_parse_free (spec); break; } case MHD_HTTP_UNAUTHORIZED: diff --git a/src/lib/merchant_api_merchant_get_order.c b/src/lib/merchant_api_merchant_get_order.c index a0c1995b..a8a50738 100644 --- a/src/lib/merchant_api_merchant_get_order.c +++ b/src/lib/merchant_api_merchant_get_order.c @@ -130,9 +130,9 @@ handle_claimed (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, struct TALER_MERCHANT_OrderStatusResponse *osr) { struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("contract_terms", - (json_t **) &osr->details.ok.details.claimed. - contract_terms), + GNUNET_JSON_spec_object_const ( + "contract_terms", + &osr->details.ok.details.claimed.contract_terms), GNUNET_JSON_spec_end () }; @@ -151,7 +151,6 @@ handle_claimed (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, osr->details.ok.status = TALER_MERCHANT_OSC_CLAIMED; omgh->cb (omgh->cb_cls, osr); - GNUNET_JSON_parse_free (spec); } @@ -169,9 +168,9 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, { uint32_t ec32; uint32_t hc32; - json_t *wire_details; - json_t *wire_reports; - json_t *refund_details; + const json_t *wire_details; + const json_t *wire_reports; + const json_t *refund_details; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_bool ("refunded", &osr->details.ok.details.paid.refunded), @@ -187,15 +186,15 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, &hc32), TALER_JSON_spec_amount_any ("refund_amount", &osr->details.ok.details.paid.refund_amount), - GNUNET_JSON_spec_json ( + GNUNET_JSON_spec_object_const ( "contract_terms", - (json_t **) &osr->details.ok.details.paid.contract_terms), - GNUNET_JSON_spec_json ("wire_details", - &wire_details), - GNUNET_JSON_spec_json ("wire_reports", - &wire_reports), - GNUNET_JSON_spec_json ("refund_details", - &refund_details), + &osr->details.ok.details.paid.contract_terms), + GNUNET_JSON_spec_array_const ("wire_details", + &wire_details), + GNUNET_JSON_spec_array_const ("wire_reports", + &wire_reports), + GNUNET_JSON_spec_array_const ("refund_details", + &refund_details), GNUNET_JSON_spec_end () }; @@ -211,19 +210,6 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, osr); return; } - if (! (json_is_array (wire_details) && - json_is_array (wire_reports) && - json_is_array (refund_details) && - json_is_object (osr->details.ok.details.paid.contract_terms)) ) - { - GNUNET_break_op (0); - osr->hr.http_status = 0; - osr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; - omgh->cb (omgh->cb_cls, - osr); - GNUNET_JSON_parse_free (spec); - return; - } osr->details.ok.status = TALER_MERCHANT_OSC_PAID; osr->details.ok.details.paid.exchange_ec = (enum TALER_ErrorCode) ec32; osr->details.ok.details.paid.exchange_hc = (unsigned int) hc32; @@ -264,7 +250,6 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, osr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; omgh->cb (omgh->cb_cls, osr); - GNUNET_JSON_parse_free (spec); return; } } @@ -300,7 +285,6 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, osr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; omgh->cb (omgh->cb_cls, osr); - GNUNET_JSON_parse_free (spec); return; } wr->code = (enum TALER_ErrorCode) c32; @@ -333,7 +317,6 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, osr->hr.ec = TALER_EC_GENERIC_REPLY_MALFORMED; omgh->cb (omgh->cb_cls, osr); - GNUNET_JSON_parse_free (spec); return; } } @@ -347,7 +330,6 @@ handle_paid (struct TALER_MERCHANT_OrderMerchantGetHandle *omgh, omgh->cb (omgh->cb_cls, osr); } - GNUNET_JSON_parse_free (spec); } diff --git a/src/lib/merchant_api_post_order_abort.c b/src/lib/merchant_api_post_order_abort.c index a924119b..3c9665c6 100644 --- a/src/lib/merchant_api_post_order_abort.c +++ b/src/lib/merchant_api_post_order_abort.c @@ -111,11 +111,11 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, struct TALER_MERCHANT_AbortResponse *ar, const json_t *json) { - json_t *refunds; + const json_t *refunds; unsigned int num_refunds; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("refunds", - &refunds), + GNUNET_JSON_spec_array_const ("refunds", + &refunds), GNUNET_JSON_spec_end () }; @@ -127,12 +127,6 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, GNUNET_break_op (0); return GNUNET_SYSERR; } - if (! json_is_array (refunds)) - { - GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); - return GNUNET_SYSERR; - } num_refunds = json_array_size (refunds); { struct TALER_MERCHANT_AbortedCoin res[GNUNET_NZL (num_refunds)]; @@ -153,7 +147,6 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } if (MHD_HTTP_OK == exchange_status) @@ -172,7 +165,6 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } @@ -187,7 +179,6 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, &res[i].exchange_sig)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } } @@ -199,7 +190,6 @@ check_abort_refund (struct TALER_MERCHANT_OrderAbortHandle *oah, ar); oah->abort_cb = NULL; } - GNUNET_JSON_parse_free (spec); return GNUNET_OK; } diff --git a/src/lib/merchant_api_post_order_pay.c b/src/lib/merchant_api_post_order_pay.c index 6cfeb846..4b674337 100644 --- a/src/lib/merchant_api_post_order_pay.c +++ b/src/lib/merchant_api_post_order_pay.c @@ -281,11 +281,11 @@ parse_conflict (struct TALER_MERCHANT_OrderPayHandle *oph, struct TALER_MERCHANT_PayResponse *pr, const json_t *json) { - json_t *ereply; + const json_t *ereply; const char *exchange_url; struct GNUNET_JSON_Specification spec[] = { - GNUNET_JSON_spec_json ("exchange_reply", - &ereply), + GNUNET_JSON_spec_object_const ("exchange_reply", + &ereply), GNUNET_JSON_spec_string ("exchange_url", &exchange_url), GNUNET_JSON_spec_end () @@ -339,10 +339,8 @@ parse_conflict (struct TALER_MERCHANT_OrderPayHandle *oph, NULL, NULL)) { GNUNET_break_op (0); - GNUNET_JSON_parse_free (spec); return GNUNET_SYSERR; } - GNUNET_JSON_parse_free (spec); for (unsigned int i = 0; inum_coins; i++) { -- cgit v1.2.3