diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_deposit.c')
| -rw-r--r-- | src/exchange/taler-exchange-httpd_deposit.c | 56 |
1 files changed, 48 insertions, 8 deletions
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c index 0484ab07..033245f5 100644 --- a/src/exchange/taler-exchange-httpd_deposit.c +++ b/src/exchange/taler-exchange-httpd_deposit.c @@ -47,7 +47,7 @@ * @param connection connection to the client * @param coin_pub public key of the coin * @param h_wire hash of wire details - * @param h_extensions hash of applicable extensions + * @param h_policy hash of applicable extensions * @param h_contract_terms hash of contract details * @param exchange_timestamp exchange's timestamp * @param refund_deadline until when this deposit be refunded @@ -61,7 +61,7 @@ reply_deposit_success ( struct MHD_Connection *connection, const struct TALER_CoinSpendPublicKeyP *coin_pub, const struct TALER_MerchantWireHashP *h_wire, - const struct TALER_ExtensionContractHashP *h_extensions, + const struct TALER_ExtensionPolicyHashP *h_policy, const struct TALER_PrivateContractHashP *h_contract_terms, struct GNUNET_TIME_Timestamp exchange_timestamp, struct GNUNET_TIME_Timestamp refund_deadline, @@ -78,7 +78,7 @@ reply_deposit_success ( &TEH_keys_exchange_sign_, h_contract_terms, h_wire, - h_extensions, + h_policy, exchange_timestamp, wire_deadline, refund_deadline, @@ -115,6 +115,11 @@ struct DepositContext const struct TALER_EXCHANGEDB_Deposit *deposit; /** + * Extension handler for policy, maybe NULL. + */ + const struct TALER_Extension *policy_extension; + + /** * Our timestamp (when we received the request). * Possibly updated by the transaction if the * request is idempotent (was repeated). @@ -156,6 +161,7 @@ deposit_transaction (void *cls, enum GNUNET_DB_QueryStatus qs; bool balance_ok; bool in_conflict; + bool blocked_by_policy = false; qs = TEH_make_coin_known (&dc->deposit->coin, connection, @@ -163,11 +169,30 @@ deposit_transaction (void *cls, mhd_ret); if (qs < 0) return qs; + + /* Check and apply policies, if applicable */ + if (NULL != dc->policy_extension) + { + const struct TALER_Extension *ext = dc->policy_extension; + struct TALER_ExtensionsPolicySerialID serialID; + struct GNUNET_TIME_Timestamp deadline; + GNUNET_assert (ext->parse_policy_details); + + qs = ext->parse_policy_details (dc->deposit->policy_details, + &serialID, + &deadline); + + if (qs < 0) + return qs; + + blocked_by_policy = true; + } + qs = TEH_plugin->do_deposit (TEH_plugin->cls, dc->deposit, dc->known_coin_id, &dc->h_payto, - false, /* FIXME-OEC: extension blocked #7270 */ + blocked_by_policy, &dc->exchange_timestamp, &balance_ok, &in_conflict); @@ -216,6 +241,7 @@ TEH_handler_deposit (struct MHD_Connection *connection, struct DepositContext dc; struct TALER_EXCHANGEDB_Deposit deposit; const char *payto_uri; + struct TALER_ExtensionPolicyHashP *ph_policy = NULL; struct GNUNET_JSON_Specification spec[] = { GNUNET_JSON_spec_string ("merchant_payto_uri", &payto_uri), @@ -228,8 +254,6 @@ TEH_handler_deposit (struct MHD_Connection *connection, &deposit.coin.denom_pub_hash), TALER_JSON_spec_denom_sig ("ub_sig", &deposit.coin.denom_sig), - GNUNET_JSON_spec_fixed_auto ("merchant_pub", - &deposit.merchant_pub), GNUNET_JSON_spec_fixed_auto ("h_contract_terms", &deposit.h_contract_terms), GNUNET_JSON_spec_mark_optional ( @@ -240,12 +264,21 @@ TEH_handler_deposit (struct MHD_Connection *connection, &deposit.csig), GNUNET_JSON_spec_timestamp ("timestamp", &deposit.timestamp), + + /* TODO: refund_deadline and merchant_pub will move into the + * extension policy_merchant_refunds */ GNUNET_JSON_spec_mark_optional ( GNUNET_JSON_spec_timestamp ("refund_deadline", &deposit.refund_deadline), NULL), + GNUNET_JSON_spec_fixed_auto ("merchant_pub", + &deposit.merchant_pub), GNUNET_JSON_spec_timestamp ("wire_transfer_deadline", &deposit.wire_deadline), + GNUNET_JSON_spec_mark_optional ( + GNUNET_JSON_spec_json ("policy", + &deposit.policy_details), + &deposit.no_policy_details), GNUNET_JSON_spec_end () }; struct TALER_MerchantWireHashP h_wire; @@ -383,6 +416,13 @@ TEH_handler_deposit (struct MHD_Connection *connection, NULL); } + if (! deposit.no_policy_details) + { + TALER_deposit_policy_hash (deposit.policy_details, + &deposit.h_policy); + ph_policy = &deposit.h_policy; + } + deposit.deposit_fee = dk->meta.fees.deposit; /* check coin signature */ switch (dk->denom_pub.cipher) @@ -426,7 +466,7 @@ TEH_handler_deposit (struct MHD_Connection *connection, &h_wire, &deposit.h_contract_terms, &deposit.coin.h_age_commitment, - NULL /* FIXME: h_extensions! */, + ph_policy, &deposit.coin.denom_pub_hash, deposit.timestamp, &deposit.merchant_pub, @@ -481,7 +521,7 @@ TEH_handler_deposit (struct MHD_Connection *connection, res = reply_deposit_success (connection, &deposit.coin.coin_pub, &h_wire, - NULL /* FIXME: h_extensions! */, + ph_policy, &deposit.h_contract_terms, dc.exchange_timestamp, deposit.refund_deadline, |
