merchant

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

commit e1cb7a087c986d8ce3d23dc2767e82fa5c72b11c
parent 9a395a36f47eb9569e3a157bef0e8684ebb5ee4b
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sun, 24 May 2026 23:17:41 +0200

fix utility library build

Diffstat:
Msrc/include/taler/taler_merchant_util.h | 21+++++++++++++++------
Msrc/util/base_terms_parse.c | 26++------------------------
Msrc/util/contract_parse.c | 24+++++++++++++++---------
Msrc/util/contract_serialize.c | 28++++++++++++++--------------
Msrc/util/merchant_parse.c | 21+++++++++++++++++++++
Msrc/util/order_choice_parse.c | 30------------------------------
Msrc/util/order_parse.c | 17++++++-----------
Msrc/util/product_parse.c | 4+++-
8 files changed, 76 insertions(+), 95 deletions(-)

diff --git a/src/include/taler/taler_merchant_util.h b/src/include/taler/taler_merchant_util.h @@ -968,7 +968,7 @@ struct TALER_MERCHANT_TemplateContractPaivana * from by selecting the respective index when signing the deposit * confirmation. */ - struct TALER_MERCHANT_TemplateChoice *choices; + struct TALER_MERCHANT_OrderChoice *choices; /** * Length of the @e choices array. @@ -1773,6 +1773,16 @@ TALER_MERCHANT_metadata_to_json ( /** + * Free representation of merchant details. + * + * @param[in,out] merchant metadata to release, excluding the pointer itself + */ +void +TALER_MERCHANT_metadata_free ( + struct TALER_MERCHANT_MetaData *merchant); + + +/** * Provide specification to parse given JSON array to order * choices. All fields from @a choices elements are copied. * @@ -2105,13 +2115,11 @@ TALER_MERCHANT_order_free ( * Parse JSON proto contract terms in @a input. * * @param[in] input JSON object containing contract terms - * @param[out] pc proto contract to initialize - * @return true on success, false on failure + * @return NULL on failure */ -bool +struct TALER_MERCHANT_ProtoContract * TALER_MERCHANT_proto_contract_parse ( - json_t *input, - struct TALER_MERCHANT_ProtoContract *pc); + json_t *input); /** @@ -2124,6 +2132,7 @@ json_t * TALER_MERCHANT_proto_contract_serialize ( const struct TALER_MERCHANT_ProtoContract *pc); + /** * Free the proto-contract at @a pc * diff --git a/src/util/base_terms_parse.c b/src/util/base_terms_parse.c @@ -36,7 +36,6 @@ TALER_MERCHANT_base_terms_parse ( { struct TALER_MERCHANT_ContractBaseTerms *ct = GNUNET_new (struct TALER_MERCHANT_ContractBaseTerms); - const json_t *products = NULL; struct GNUNET_JSON_Specification espec[] = { TALER_MERCHANT_spec_contract_version ("version", &ct->version), @@ -121,11 +120,11 @@ TALER_MERCHANT_base_terms_parse ( "Failed to parse contract\n"); goto cleanup; } - return true; + return ct; cleanup: TALER_MERCHANT_base_terms_free (ct); - return false; + return NULL; } @@ -137,21 +136,6 @@ TALER_MERCHANT_base_terms_free ( return; GNUNET_free (ct->public_reorder_url); GNUNET_free (ct->order_id); - GNUNET_free (ct->merchant_base_url); - GNUNET_free (ct->merchant.name); - GNUNET_free (ct->merchant.website); - GNUNET_free (ct->merchant.email); - GNUNET_free (ct->merchant.logo); - if (NULL != ct->merchant.address) - { - json_decref (ct->merchant.address); - ct->merchant.address = NULL; - } - if (NULL != ct->merchant.jurisdiction) - { - json_decref (ct->merchant.jurisdiction); - ct->merchant.jurisdiction = NULL; - } GNUNET_free (ct->summary); GNUNET_free (ct->fulfillment_url); GNUNET_free (ct->fulfillment_message); @@ -160,12 +144,6 @@ TALER_MERCHANT_base_terms_free ( json_decref (ct->fulfillment_message_i18n); ct->fulfillment_message_i18n = NULL; } - GNUNET_free (ct->wire_method); - if (NULL != ct->exchanges) - { - json_decref (ct->exchanges); - ct->exchanges = NULL; - } if (NULL != ct->delivery_location) { json_decref (ct->delivery_location); diff --git a/src/util/contract_parse.c b/src/util/contract_parse.c @@ -40,7 +40,7 @@ static enum GNUNET_GenericReturnValue parse_contract_v0 ( json_t *input, - struct TALER_MERCHANT_Contract *contract) + struct TALER_MERCHANT_ProtoContract *contract) { struct GNUNET_JSON_Specification espec[] = { TALER_JSON_spec_amount_any ("amount", @@ -156,7 +156,7 @@ TALER_MERCHANT_proto_contract_parse ( pc = GNUNET_new (struct TALER_MERCHANT_ProtoContract); pc->base = base; { - json_t *products; + const json_t *products = NULL; struct GNUNET_JSON_Specification espec[] = { GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_array_const ("products", @@ -260,11 +260,11 @@ void TALER_MERCHANT_proto_contract_free ( struct TALER_MERCHANT_ProtoContract *pc) { - switch (pc->common.version) + switch (pc->base->version) { - case TALER_MERCHANT_PC_VERSION_0: + case TALER_MERCHANT_CONTRACT_VERSION_0: break; - case TALER_MERCHANT_PC_VERSION_1: + case TALER_MERCHANT_CONTRACT_VERSION_1: for (unsigned int i = 0; i < pc->details.v1.choices_len; i++) @@ -279,17 +279,23 @@ TALER_MERCHANT_proto_contract_free ( GNUNET_free (pc->details.v1.token_authorities); break; } - if (NULL != ct->products) + if (NULL != pc->products) { - for (size_t i = 0; i<ct->products_len; i++) - TALER_MERCHANT_product_sold_free (&ct->products[i]); - GNUNET_free (ct->products); + for (size_t i = 0; i<pc->products_len; i++) + TALER_MERCHANT_product_sold_free (&pc->products[i]); + GNUNET_free (pc->products); } if (NULL != pc->base) { TALER_MERCHANT_base_terms_free (pc->base); pc->base = NULL; } + GNUNET_free (pc->wire_method); + if (NULL != pc->exchanges) + { + json_decref (pc->exchanges); + pc->exchanges = NULL; + } GNUNET_free (pc); } diff --git a/src/util/contract_serialize.c b/src/util/contract_serialize.c @@ -104,7 +104,7 @@ TALER_MERCHANT_proto_contract_serialize ( json_t *products; bj = TALER_MERCHANT_base_terms_serialize (pc->base); - switch (base->version) + switch (pc->base->version) { case TALER_MERCHANT_CONTRACT_VERSION_0: details = json_from_contract_v0 (pc); @@ -116,49 +116,49 @@ TALER_MERCHANT_proto_contract_serialize ( GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "unknown contract type version %d", - ct->version); + pc->base->version); GNUNET_assert (0); return NULL; success: products = json_array (); GNUNET_assert (NULL != products); - for (size_t i = 0; i<ct->products_len; i++) + for (size_t i = 0; i<pc->products_len; i++) { GNUNET_assert ( 0 == json_array_append_new (products, TALER_MERCHANT_product_sold_serialize ( - &ct->products[i]))); + &pc->products[i]))); } return GNUNET_JSON_PACK ( GNUNET_JSON_pack_object_steal (NULL, bj), GNUNET_JSON_pack_timestamp ("timestamp", - ct->timestamp), + pc->timestamp), GNUNET_JSON_pack_timestamp ("refund_deadline", - ct->refund_deadline), + pc->refund_deadline), GNUNET_JSON_pack_timestamp ("pay_deadline", - ct->pay_deadline), + pc->pay_deadline), GNUNET_JSON_pack_timestamp ("wire_transfer_deadline", - ct->wire_deadline), + pc->wire_deadline), GNUNET_JSON_pack_data_auto ("merchant_pub", - &ct->merchant_pub.eddsa_pub), + &pc->merchant_pub.eddsa_pub), GNUNET_JSON_pack_string ("merchant_base_url", - ct->merchant_base_url), + pc->merchant_base_url), GNUNET_JSON_pack_object_steal ( "merchant", TALER_MERCHANT_metadata_to_json ( - &input->common.merchant)), + &pc->merchant)), GNUNET_JSON_pack_array_steal ("products", products), GNUNET_JSON_pack_data_auto ("h_wire", - &ct->h_wire), + &pc->h_wire), GNUNET_JSON_pack_string ("wire_method", - ct->wire_method), + pc->wire_method), GNUNET_JSON_pack_array_steal ("exchanges", - ct->exchanges), + pc->exchanges), GNUNET_JSON_pack_object_steal (NULL, details)); } diff --git a/src/util/merchant_parse.c b/src/util/merchant_parse.c @@ -129,3 +129,24 @@ TALER_MERCHANT_spec_merchant_details ( return ret; } + + +void +TALER_MERCHANT_metadata_free ( + struct TALER_MERCHANT_MetaData *merchant) +{ + GNUNET_free (merchant->name); + GNUNET_free (merchant->website); + GNUNET_free (merchant->email); + GNUNET_free (merchant->logo); + if (NULL != merchant->address) + { + json_decref (merchant->address); + merchant->address = NULL; + } + if (NULL != merchant->jurisdiction) + { + json_decref (merchant->jurisdiction); + merchant->jurisdiction = NULL; + } +} diff --git a/src/util/order_choice_parse.c b/src/util/order_choice_parse.c @@ -172,7 +172,6 @@ TALER_MERCHANT_parse_order_choice_output ( } case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: { - const json_t *donau_urls = NULL; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_mark_optional ( TALER_JSON_spec_amount_any ("amount", @@ -195,28 +194,6 @@ TALER_MERCHANT_parse_order_choice_output ( GNUNET_break_op (0); return GNUNET_SYSERR; } - - GNUNET_array_grow (output->details.donation_receipt.donau_urls, - output->details.donation_receipt.donau_urls_len, - json_array_size (donau_urls)); - - for (unsigned int i = 0; - i < output->details.donation_receipt.donau_urls_len; - i++) - { - const json_t *jurl; - - jurl = json_array_get (donau_urls, - i); - if (! json_is_string (jurl)) - { - GNUNET_break_op (0); - return GNUNET_SYSERR; - } - output->details.donation_receipt.donau_urls[i] = - GNUNET_strdup (json_string_value (jurl)); - } - return GNUNET_OK; } } @@ -437,13 +414,6 @@ TALER_MERCHANT_order_choice_free ( case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_TOKEN: break; case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_DONATION_RECEIPT: - for (unsigned int j = 0; - j<output->details.donation_receipt.donau_urls_len; - j++) - GNUNET_free (output->details.donation_receipt.donau_urls[j]); - GNUNET_array_grow (output->details.donation_receipt.donau_urls, - output->details.donation_receipt.donau_urls_len, - 0); break; #if FUTURE case TALER_MERCHANT_CONTRACT_OUTPUT_TYPE_COIN: diff --git a/src/util/order_parse.c b/src/util/order_parse.c @@ -155,9 +155,9 @@ TALER_MERCHANT_order_parse (json_t *input) return NULL; } order->refund_deadline = GNUNET_TIME_UNIT_FOREVER_TS; - order->wire_deadline = GNUNET_TIME_UNIT_FOREVER_TS; + order->wire_transfer_deadline = GNUNET_TIME_UNIT_FOREVER_TS; { - json_t *products; + const json_t *products; struct GNUNET_JSON_Specification espec[] = { GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_array_const ("products", @@ -177,7 +177,7 @@ TALER_MERCHANT_order_parse (json_t *input) NULL), GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_timestamp ("wire_transfer_deadline", - &order->wire_deadline), + &order->wire_transfer_deadline), NULL), GNUNET_JSON_spec_end () }; @@ -224,7 +224,7 @@ TALER_MERCHANT_order_parse (json_t *input) } } } - switch (order->base.version) + switch (order->base->version) { case TALER_MERCHANT_CONTRACT_VERSION_0: res = parse_order_v0 (input, @@ -257,7 +257,7 @@ TALER_MERCHANT_order_free ( { if (NULL == order) return; - switch (order->common.version) + switch (order->base->version) { case TALER_MERCHANT_CONTRACT_VERSION_0: break; @@ -267,11 +267,6 @@ TALER_MERCHANT_order_free ( i++) TALER_MERCHANT_order_choice_free (&order->details.v1.choices[i]); GNUNET_free (order->details.v1.choices); - for (unsigned int i = 0; - i < order->details.v1.token_authorities_len; - i++) - TALER_MERCHANT_contract_token_family_free (&order->details.v1.token_authorities[i]); - GNUNET_free (order->details.v1.token_authorities); break; } if (NULL != order->products) @@ -279,7 +274,7 @@ TALER_MERCHANT_order_free ( for (size_t i = 0; i<order->products_len; i++) TALER_MERCHANT_product_sold_free (&order->products[i]); GNUNET_free (order->products); - order->products_len = NULL; + order->products_len = 0; } if (NULL != order->base) { diff --git a/src/util/product_parse.c b/src/util/product_parse.c @@ -115,8 +115,10 @@ parse_unit_quantity (const char *s, enum GNUNET_GenericReturnValue TALER_MERCHANT_parse_product_sold (const json_t *pj, - struct TALER_MERCHANT_ProductSold *r) + struct TALER_MERCHANT_ProductSold *r, + bool allow_mip) { + // FIXME: properly implement distinction between MIP and non-MIP! bool no_quantity; bool no_unit_quantity; bool no_price;