aboutsummaryrefslogtreecommitdiff
path: root/src/exchange/taler-exchange-httpd_deposit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/exchange/taler-exchange-httpd_deposit.c')
-rw-r--r--src/exchange/taler-exchange-httpd_deposit.c148
1 files changed, 37 insertions, 111 deletions
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c
index 0199802c..033245f5 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -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);
@@ -208,86 +233,6 @@ deposit_transaction (void *cls,
}
-/**
- * @brief check the provided policy
- *
- * @param[in] policy_details JSON object provided by the client with prolicy
- * @param[out] hc On success, will contain the hash of the normalized policy_details object
- * @param[out] handler_out On success, the handler might provide an output
- * @param[out] error_hint On failure, might contain a hint of the error from the extension
- * @return GNUNET_OK on success.
- */
-enum GNUNET_GenericReturnValue
-check_policy_details (
- json_t *policy_details,
- struct TALER_ExtensionPolicyHashP *hc,
- json_t **handler_out,
- char **error_hint)
-{
- const char *type = NULL;
- const struct TALER_Extension *extension;
- enum GNUNET_GenericReturnValue ret;
-
- *error_hint = NULL;
-
- if ((NULL == policy_details) ||
- (! json_is_object (policy_details)))
- {
- *error_hint = "invalid policy object";
- return GNUNET_SYSERR;
- }
-
- // parse and evaluate the object
- {
- json_t *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->deposit_handler))
- {
- GNUNET_break (0);
- *error_hint = "no such policy";
- return GNUNET_SYSERR;
- }
-
- ret = extension->deposit_handler (policy_details,
- handler_out);
- if (GNUNET_OK != ret)
- {
- GNUNET_break (0);
- if (NULL != *handler_out)
- {
- *error_hint = json_dumps (*handler_out, JSON_INDENT (2));
- }
- else
- {
- GNUNET_break (1);
- *error_hint = "unknown error with the policy";
- }
- return ret;
- }
- }
-
- TALER_deposit_policy_hash (policy_details,
- hc);
- return GNUNET_OK;
-}
-
-
MHD_RESULT
TEH_handler_deposit (struct MHD_Connection *connection,
const struct TALER_CoinSpendPublicKeyP *coin_pub,
@@ -296,9 +241,7 @@ TEH_handler_deposit (struct MHD_Connection *connection,
struct DepositContext dc;
struct TALER_EXCHANGEDB_Deposit deposit;
const char *payto_uri;
- struct TALER_ExtensionPolicyHashP h_policy;
struct TALER_ExtensionPolicyHashP *ph_policy = NULL;
- bool no_policy;
struct GNUNET_JSON_Specification spec[] = {
GNUNET_JSON_spec_string ("merchant_payto_uri",
&payto_uri),
@@ -311,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 (
@@ -324,17 +265,20 @@ TEH_handler_deposit (struct MHD_Connection *connection,
GNUNET_JSON_spec_timestamp ("timestamp",
&deposit.timestamp),
- /* TODO: this will move to an extension for refunds */
+ /* 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),
- &no_policy),
- GNUNET_JSON_spec_timestamp ("wire_transfer_deadline",
- &deposit.wire_deadline),
+ &deposit.no_policy_details),
GNUNET_JSON_spec_end ()
};
struct TALER_MerchantWireHashP h_wire;
@@ -472,29 +416,11 @@ TEH_handler_deposit (struct MHD_Connection *connection,
NULL);
}
- /* TODO: check policy_details */
- if (! no_policy)
+ if (! deposit.no_policy_details)
{
- char *hint;
- json_t *out;
- MHD_RESULT res;
-
- if (GNUNET_OK !=
- check_policy_details (dc.deposit->policy_details,
- &h_policy,
- &out,
- &hint))
- {
- res = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_BAD_REQUEST,
- /* TODO: new error type needed */
- TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
- hint);
- GNUNET_free (hint);
- return res;
- }
-
- ph_policy = &h_policy;
+ TALER_deposit_policy_hash (deposit.policy_details,
+ &deposit.h_policy);
+ ph_policy = &deposit.h_policy;
}
deposit.deposit_fee = dk->meta.fees.deposit;