diff options
Diffstat (limited to 'src/extensions')
-rw-r--r-- | src/extensions/age_restriction/age_restriction.c | 4 | ||||
-rw-r--r-- | src/extensions/extensions.c | 49 | ||||
-rw-r--r-- | src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c | 72 |
3 files changed, 111 insertions, 14 deletions
diff --git a/src/extensions/age_restriction/age_restriction.c b/src/extensions/age_restriction/age_restriction.c index a1a11e4f..576a6039 100644 --- a/src/extensions/age_restriction/age_restriction.c +++ b/src/extensions/age_restriction/age_restriction.c @@ -151,7 +151,9 @@ struct TALER_Extension TE_age_restriction = { .disable = &age_restriction_disable, .load_config = &age_restriction_load_config, .manifest = &age_restriction_manifest, - .deposit_handler = NULL, + + /* This extension is not a policy extension */ + .parse_policy_details = NULL, .http_get_handler = NULL, .http_post_handler = NULL, }; diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c index 02137d31..64574fc2 100644 --- a/src/extensions/extensions.c +++ b/src/extensions/extensions.c @@ -353,4 +353,53 @@ TALER_extensions_load_manifests ( } +enum GNUNET_GenericReturnValue +TALER_extensions_from_policy_details ( + const json_t *policy_details, + const struct TALER_Extension **extension, + char **error_hint) +{ + const json_t *jtype; + const char *type; + + *extension = NULL; + *error_hint = NULL; + + if ((NULL == policy_details) || + (! json_is_object (policy_details))) + { + *error_hint = "invalid policy object"; + return GNUNET_SYSERR; + } + + jtype = json_object_get (policy_details, "type"); + if (NULL == jtype) + { + *error_hint = "no type in policy object"; + return GNUNET_SYSERR; + } + + type = json_string_value (jtype); + if (NULL == type) + { + *error_hint = "invalid type in policy object"; + return GNUNET_SYSERR; + } + + *extension = TALER_extensions_get_by_name (type); + if ((NULL == *extension) || + (NULL == (*extension)->parse_policy_details)) + { + GNUNET_break (0); + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unsupported extension policy '%s' requested\n", + type); + *extension = NULL; + return GNUNET_NO; + } + + return GNUNET_OK; +} + + /* end of extensions.c */ diff --git a/src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c b/src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c index 160250a6..e00f810f 100644 --- a/src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c +++ b/src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2021-2022 Taler Systems SA + Copyright (C) 2022 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 @@ -32,7 +32,7 @@ /* (public) configuration of this extension */ /* TODO: these fields need to be set in the init handler */ -static struct TALER_BrandtVickreyAuction BV_config = { +static struct TALER_ExtensionPolicyBrandtVickreyAuctionConfig BV_config = { .max_bidders = 10, .max_prices = 10, .auction_fee = { @@ -497,7 +497,7 @@ static json_t * auction_manifest ( const struct TALER_Extension *ext) { - struct TALER_BrandtVickreyAuction *conf = ext->config; + struct TALER_ExtensionPolicyBrandtVickreyAuctionConfig *conf = ext->config; GNUNET_assert (conf); json_t *config = GNUNET_JSON_PACK ( @@ -589,20 +589,66 @@ auction_http_post_handler ( /** - * @brief implements the TALER_Extensions.deposit_handler interface. + * @brief implements the TALER_Extensions.parse_policy_details interface. * - * @param[in] input JSON input from the client during a deposit request - * @param[out] output by this extension + * @param[in] input The policy_details for this handler during deposit + * @param[out] serial On success will contain the serial-ID under which the + * @param[out] deadline On success will contain a deadline, might be "forever" + * exchange should store the policy_details in the policy_details table. * @return GNUNET_OK if the request was OK */ enum GNUNET_GenericReturnValue -auction_deposit_handler ( - json_t *input, - json_t **output) +auction_parse_policy_details ( + const json_t *input, + struct TALER_ExtensionsPolicySerialID *serial, + struct GNUNET_TIME_Timestamp *deadline) { - /* TODO */ - *output = NULL; - return GNUNET_OK; + enum GNUNET_GenericReturnValue ret = GNUNET_NO; + struct GNUNET_CRYPTO_EddsaPublicKey pub; + struct GNUNET_HashCode hc; + struct GNUNET_JSON_Specification spec[] = { + /* We ignore the "type" field as it must have been parsed already upstream + * - or this handler wouldn't have been called in first place. */ + GNUNET_JSON_spec_fixed_auto ("bidder_pub", &pub), + GNUNET_JSON_spec_fixed_auto ("h_auction", &hc), + GNUNET_JSON_spec_timestamp ("deadline", deadline), + GNUNET_JSON_spec_end (), + }; + + GNUNET_assert (serial); + GNUNET_assert (deadline); + + do { + ret = GNUNET_JSON_parse (input, + spec, + NULL, + NULL); + + if (GNUNET_OK != ret) + break; + + /* FIXME: check the deadline */ + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + LOG_PREFIX "check of deadline %ld not implemented!\n", + deadline->abs_time.abs_value_us); + + /* Create serial as H(bidder_pub, h_auction) */ + { + struct GNUNET_HashContext *hc = GNUNET_CRYPTO_hash_context_start (); + GNUNET_CRYPTO_hash_context_read (hc, + &pub, + sizeof(pub)); + GNUNET_CRYPTO_hash_context_read (hc, + &hc, + sizeof(hc)); + GNUNET_CRYPTO_hash_context_finish (hc, + &serial->hash); + } + + ret = GNUNET_OK; + } while(0); + + return ret; } @@ -617,7 +663,7 @@ struct TALER_Extension TE_auction_brandt = { .disable = &auction_disable, .load_config = &auction_load_config, .manifest = &auction_manifest, - .deposit_handler = &auction_deposit_handler, + .parse_policy_details = &auction_parse_policy_details, .http_get_handler = &auction_http_get_handler, .http_post_handler = &auction_http_post_handler, }; |