diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-09-05 13:54:26 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-09-05 13:54:26 +0200 |
commit | 30f6c8326c9c8e1c8e9449247a1b3d4c4de633b6 (patch) | |
tree | f99d034d08c39d2e428a51463a73f2214b339992 | |
parent | 2ce46ab26b60b6b6a5bb724943ea22304e51c36a (diff) |
fix #9170
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 89 | ||||
-rw-r--r-- | src/backenddb/merchantdb_plugin.c | 8 | ||||
-rwxr-xr-x | src/testing/test_merchant_order_creation.sh | 2 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_orders.c | 40 |
4 files changed, 82 insertions, 57 deletions
diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index a2e3b493..4761fbdc 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -698,9 +698,11 @@ clean_order (void *cls) GNUNET_free (oc->parse_choices.token_families[i].name); GNUNET_free (oc->parse_choices.token_families[i].description); json_decref (oc->parse_choices.token_families[i].description_i18n); - for (unsigned int j = 0; j<oc->parse_choices.token_families[i].keys_len; j++) + for (unsigned int j = 0; j<oc->parse_choices.token_families[i].keys_len; j++ + ) { - GNUNET_CRYPTO_blind_sign_pub_decref(oc->parse_choices.token_families[i].keys[j].pub.public_key); + GNUNET_CRYPTO_blind_sign_pub_decref (oc->parse_choices.token_families[i]. + keys[j].pub.public_key); } GNUNET_array_grow (oc->parse_choices.token_families[i].keys, oc->parse_choices.token_families[i].keys_len, @@ -1361,7 +1363,7 @@ get_rounded_time_interval (struct GNUNET_TIME_Relative precision, struct GNUNET_TIME_Timestamp *start, struct GNUNET_TIME_Timestamp *end) { - struct tm* timeinfo; + struct tm*timeinfo; time_t seconds; seconds = GNUNET_TIME_timestamp_to_s (ts); @@ -1433,6 +1435,7 @@ get_rounded_time_interval (struct GNUNET_TIME_Relative precision, return GNUNET_OK; } + /** * Check if the token family with the given @a slug is already present in * the list of token families for this order. If not, fetch its details and @@ -1460,10 +1463,10 @@ set_token_family (struct OrderContext *oc, struct GNUNET_TIME_Timestamp min_valid_after; struct GNUNET_TIME_Timestamp max_valid_after; - if ( GNUNET_OK != get_rounded_time_interval (precision, - *valid_after, - &min_valid_after, - &max_valid_after)) + if (GNUNET_OK != get_rounded_time_interval (precision, + *valid_after, + &min_valid_after, + &max_valid_after)) { GNUNET_break (0); reply_with_error (oc, @@ -1544,8 +1547,10 @@ set_token_family (struct OrderContext *oc, struct GNUNET_TIME_Timestamp now = GNUNET_TIME_timestamp_get (); /* Verify that the token family is valid right now. */ - if (GNUNET_TIME_timestamp_cmp (key_details.token_family.valid_after, >, now) || - GNUNET_TIME_timestamp_cmp (key_details.token_family.valid_before, <=, now)) + if (GNUNET_TIME_timestamp_cmp (key_details.token_family.valid_after, >, now) + || + GNUNET_TIME_timestamp_cmp (key_details.token_family.valid_before, <=, now) + ) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Token family expired or not yet valid\n"); @@ -1575,7 +1580,8 @@ set_token_family (struct OrderContext *oc, .keys_len = 0, }; - switch (key_details.token_family.kind) { + switch (key_details.token_family.kind) + { case TALER_MERCHANTDB_TFK_Subscription: new_family.kind = TALER_MCTK_SUBSCRIPTION; new_family.critical = true; @@ -1589,10 +1595,11 @@ set_token_family (struct OrderContext *oc, } GNUNET_array_append (oc->parse_choices.token_families, - oc->parse_choices.token_families_len, - new_family); + oc->parse_choices.token_families_len, + new_family); - family = &oc->parse_choices.token_families[oc->parse_choices.token_families_len - 1]; + family = &oc->parse_choices.token_families[oc->parse_choices. + token_families_len - 1]; } if (NULL == key_details.pub.public_key) @@ -1682,7 +1689,9 @@ set_token_family (struct OrderContext *oc, key.pub = token_pub; key.valid_after = min_valid_after; key.valid_before = valid_before; - } else { + } + else + { key.pub = key_details.pub; key.valid_after = key_details.valid_after; key.valid_before = key_details.valid_before; @@ -1761,8 +1770,9 @@ serialize_order (struct OrderContext *oc) for (unsigned int i = 0; i<oc->parse_choices.token_families_len; i++) { - json_t *keys = json_array(); - struct TALER_MerchantContractTokenFamily *family = &oc->parse_choices.token_families[i]; + json_t *keys = json_array (); + struct TALER_MerchantContractTokenFamily *family = &oc->parse_choices. + token_families[i]; for (unsigned int j = 0; j<family->keys_len; j++) { @@ -1772,9 +1782,10 @@ serialize_order (struct OrderContext *oc) /* TODO: Remove h_pub. */ GNUNET_JSON_pack_data_auto ("h_pub", &key.pub.public_key->pub_key_hash), - GNUNET_JSON_pack_allow_null( + GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_rsa_public_key ("rsa_pub", - key.pub.public_key->details.rsa_public_key)), + key.pub.public_key->details. + rsa_public_key)), // GNUNET_JSON_pack_allow_null( // GNUNET_JSON_pack_data_auto ("cs_pub", // &key.pub.public_key->details.cs_public_key)), @@ -1784,7 +1795,7 @@ serialize_order (struct OrderContext *oc) key.valid_after), GNUNET_JSON_pack_timestamp ("valid_before", key.valid_before) - ); + ); GNUNET_assert (0 == json_array_append_new (keys, jkey)); } @@ -1802,7 +1813,7 @@ serialize_order (struct OrderContext *oc) keys), GNUNET_JSON_pack_bool ("critical", family->critical) - ); + ); GNUNET_assert (0 == json_object_set_new (token_families, family->slug, @@ -1825,14 +1836,15 @@ serialize_order (struct OrderContext *oc) json_t *jinput = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("kind", - TMH_string_from_contract_input_type (input->type)), + TMH_string_from_contract_input_type (input-> + type)), GNUNET_JSON_pack_string ("token_family_slug", input->details.token.token_family_slug), GNUNET_JSON_pack_int64 ("number", input->details.token.count), GNUNET_JSON_pack_timestamp ("valid_after", input->details.token.valid_after) - ); + ); GNUNET_assert (0 == json_array_append_new (inputs, jinput)); } @@ -1846,14 +1858,15 @@ serialize_order (struct OrderContext *oc) json_t *joutput = GNUNET_JSON_PACK ( GNUNET_JSON_pack_string ("kind", - TMH_string_from_contract_output_type (output->type)), + TMH_string_from_contract_output_type (output-> + type)), GNUNET_JSON_pack_string ("token_family_slug", output->details.token.token_family_slug), GNUNET_JSON_pack_int64 ("number", output->details.token.count), GNUNET_JSON_pack_timestamp ("valid_after", output->details.token.valid_after) - ); + ); GNUNET_assert (0 == json_array_append (outputs, joutput)); } @@ -1926,12 +1939,12 @@ serialize_order (struct OrderContext *oc) &oc->parse_order.brutto), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_array_steal ("choices", - choices) - ), + choices) + ), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_object_steal ("token_families", - token_families) - ), + token_families) + ), GNUNET_JSON_pack_allow_null ( GNUNET_JSON_pack_object_incref ("extra", (json_t *) oc->parse_order.extra)) @@ -2080,7 +2093,7 @@ parse_order (struct OrderContext *oc) const struct TALER_MERCHANTDB_InstanceSettings *settings = &oc->hc->instance->settings; const char *merchant_base_url = NULL; - const char *version = NULL; + uint64_t version = 0; const json_t *jmerchant = NULL; /* auto_refund only needs to be type-checked, * mostly because in GNUnet relative times can't @@ -2090,7 +2103,7 @@ parse_order (struct OrderContext *oc) stefan-base fee calculation to the parse_choices phase. */ struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_mark_optional ( - GNUNET_JSON_spec_string ("version", + GNUNET_JSON_spec_uint64 ("version", &version), NULL), TALER_JSON_spec_amount_any ("amount", @@ -2193,7 +2206,7 @@ parse_order (struct OrderContext *oc) ret); return; } - if (NULL == version || 0 == strcmp ("0", version)) + if (0 == version) { oc->parse_order.version = TALER_MCV_V0; @@ -2208,7 +2221,7 @@ parse_order (struct OrderContext *oc) return; } } - else if (0 == strcmp ("1", version)) + else if (1 == version) { oc->parse_order.version = TALER_MCV_V1; @@ -2579,7 +2592,7 @@ parse_choices (struct OrderContext *oc) return; } - if (0 == json_array_size(jinputs) && 0 == json_array_size(joutputs)) + if (0 == json_array_size (jinputs) && 0 == json_array_size (joutputs)) { GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Choice #%u must have at least one input or output\n", @@ -2656,8 +2669,9 @@ parse_choices (struct OrderContext *oc) } if (GNUNET_OK != set_token_family (oc, - input.details.token.token_family_slug, - &input.details.token.valid_after)) + input.details.token.token_family_slug + , + &input.details.token.valid_after)) { /* error is already scheduled, return. */ return; @@ -2737,8 +2751,9 @@ parse_choices (struct OrderContext *oc) } if (GNUNET_OK != set_token_family (oc, - output.details.token.token_family_slug, - &output.details.token.valid_after)) + output.details.token. + token_family_slug, + &output.details.token.valid_after)) { /* Error is already scheduled, return. */ return; diff --git a/src/backenddb/merchantdb_plugin.c b/src/backenddb/merchantdb_plugin.c index 7dfb44e8..1207d499 100644 --- a/src/backenddb/merchantdb_plugin.c +++ b/src/backenddb/merchantdb_plugin.c @@ -84,6 +84,10 @@ static char *old_dlsearchpath; * Setup libtool paths. */ void __attribute__ ((constructor)) +plugin_init (void); + +/* Declaration to avoid compiler warning */ +void __attribute__ ((constructor)) plugin_init (void) { int err; @@ -125,6 +129,10 @@ plugin_init (void) * Shutdown libtool. */ void __attribute__ ((destructor)) +plugin_fini (void); + +/* Declaration to avoid compiler warning */ +void __attribute__ ((destructor)) plugin_fini (void) { lt_dlsetsearchpath (old_dlsearchpath); diff --git a/src/testing/test_merchant_order_creation.sh b/src/testing/test_merchant_order_creation.sh index 244dacdc..2fe069af 100755 --- a/src/testing/test_merchant_order_creation.sh +++ b/src/testing/test_merchant_order_creation.sh @@ -263,7 +263,7 @@ echo " OK" echo -n "Creating v1 order with token family ..." STATUS=$(curl 'http://localhost:9966/private/orders' \ - -d '{"order":{"version":"1","amount":"TESTKUDOS:7","summary":"with_subscription","fulfillment_message":"Paid successfully","choices":[{"inputs":[{"kind":"token","count":1,"token_family_slug":"test-sub","valid_after":{"t_s":'$NOW'}}],"outputs":[{"kind":"token","count":1,"token_family_slug":"test-sub","valid_after":{"t_s":'$NOW'}}]}]}}' \ + -d '{"order":{"version":1,"amount":"TESTKUDOS:7","summary":"with_subscription","fulfillment_message":"Paid successfully","choices":[{"inputs":[{"kind":"token","count":1,"token_family_slug":"test-sub","valid_after":{"t_s":'$NOW'}}],"outputs":[{"kind":"token","count":1,"token_family_slug":"test-sub","valid_after":{"t_s":'$NOW'}}]}]}}' \ -w "%{http_code}" -s -o "$LAST_RESPONSE") if [ "$STATUS" != "200" ] diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index a1df1259..04b258eb 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -612,17 +612,19 @@ make_choices_json ( /* FIXME: ugly code should return c, use GNUNET_JSON_PACK() for more type-safety */ json_t *c; - c = json_pack("[{s:o, s:o}]", - "inputs", json_pack("[{s:s, s:i, s:s, s:o}]", - "kind", "token", - "count", input_count, - "token_family_slug", input_slug, - "valid_after", GNUNET_JSON_from_timestamp(input_valid_after)), - "outputs", json_pack("[{s:s, s:i, s:s, s:o}]", - "kind", "token", - "count", output_count, - "token_family_slug", output_slug, - "valid_after", GNUNET_JSON_from_timestamp(output_valid_after))); + c = json_pack ("[{s:o, s:o}]", + "inputs", json_pack ("[{s:s, s:i, s:s, s:o}]", + "kind", "token", + "count", input_count, + "token_family_slug", input_slug, + "valid_after", GNUNET_JSON_from_timestamp + (input_valid_after)), + "outputs", json_pack ("[{s:s, s:i, s:s, s:o}]", + "kind", "token", + "count", output_count, + "token_family_slug", output_slug, + "valid_after", GNUNET_JSON_from_timestamp + (output_valid_after))); *choices = c; } @@ -637,15 +639,15 @@ make_choices_json ( */ static void orders_run3 (void *cls, - const struct TALER_TESTING_Command *cmd, - struct TALER_TESTING_Interpreter *is) + const struct TALER_TESTING_Command *cmd, + struct TALER_TESTING_Interpreter *is) { struct OrdersState *ps = cls; struct GNUNET_TIME_Absolute now; const char *slug; ps->is = is; - now = GNUNET_TIME_absolute_get_monotonic (ps->cfg); + now = GNUNET_TIME_absolute_get_monotonic (ps->cfg); if (NULL == json_object_get (ps->order_terms, "order_id")) { @@ -669,8 +671,8 @@ orders_run3 (void *cls, if (NULL == token_family_cmd) TALER_TESTING_FAIL (is); if (GNUNET_OK != - TALER_TESTING_get_trait_token_family_slug (token_family_cmd, - &slug)) + TALER_TESTING_get_trait_token_family_slug (token_family_cmd, + &slug)) TALER_TESTING_FAIL (is); } make_choices_json (slug, slug, @@ -684,12 +686,12 @@ orders_run3 (void *cls, json_object_set_new (ps->order_terms, "choices", ps->choices) - ); + ); GNUNET_assert (0 == json_object_set_new (ps->order_terms, "version", - json_string ("1")) - ); + json_integer (1)) + ); GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, |