aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2022-10-07 09:59:39 +0200
committerÖzgür Kesim <oec-taler@kesim.org>2022-10-07 09:59:39 +0200
commitd3c509fcd91e5b7e430eda767108d961db196522 (patch)
tree1c647b3e9f5992415682e8c501006a4ecf55a514
parent52106eea42698164fef897f4b177f783275d5c75 (diff)
WIP: Added policy extension handling during deposit
-rw-r--r--src/exchange/taler-exchange-httpd_batch-deposit.c1
-rw-r--r--src/exchange/taler-exchange-httpd_deposit.c50
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c15
-rw-r--r--src/extensions/extensions.c2
-rw-r--r--src/extensions/policy_brandt_vickrey_auction/policy_brandt_vickrey_auction.c12
-rw-r--r--src/include/taler_exchangedb_plugin.h15
-rw-r--r--src/include/taler_extensions.h19
7 files changed, 59 insertions, 55 deletions
diff --git a/src/exchange/taler-exchange-httpd_batch-deposit.c b/src/exchange/taler-exchange-httpd_batch-deposit.c
index 637c8a45..17bbb2c1 100644
--- a/src/exchange/taler-exchange-httpd_batch-deposit.c
+++ b/src/exchange/taler-exchange-httpd_batch-deposit.c
@@ -262,7 +262,6 @@ batch_deposit_transaction (void *cls,
deposit,
known_coin_id,
&dc->h_payto,
- false, /* FIXME-OEC: #7270 extension blocked */
&dc->exchange_timestamp,
&balance_ok,
&in_conflict);
diff --git a/src/exchange/taler-exchange-httpd_deposit.c b/src/exchange/taler-exchange-httpd_deposit.c
index 7c5ab92d..6e75dac5 100644
--- a/src/exchange/taler-exchange-httpd_deposit.c
+++ b/src/exchange/taler-exchange-httpd_deposit.c
@@ -115,11 +115,6 @@ 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).
@@ -161,7 +156,6 @@ 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,
@@ -175,7 +169,6 @@ deposit_transaction (void *cls,
dc->deposit,
dc->known_coin_id,
&dc->h_payto,
- blocked_by_policy,
&dc->exchange_timestamp,
&balance_ok,
&in_conflict);
@@ -334,38 +327,37 @@ TEH_handler_deposit (struct MHD_Connection *connection,
&h_wire);
dc.deposit = &deposit;
- /* TODO: extract policy information */
-#if 0
+ /* Check policy */
if (! deposit.no_policy_details)
{
- const struct TALER_Extension *ext;
- struct TALER_ExtensionsPolicySerialID serialID;
- struct GNUNET_TIME_Timestamp deadline;
enum GNUNET_GenericReturnValue ret;
+ const struct TALER_Extension *ext;
+ const char *error_hint = NULL;
GNUNET_assert (ext->parse_policy_details);
+ do {
+ ret = TALER_extensions_from_policy_details (deposit.policy_details,
+ &ext,
+ &error_hint);
+
+ if (GNUNET_OK != ret)
+ break;
- GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- "DEBUG calling parse_policy_details on extension '%s' with details '%s'\n",
- ext->name,
- json_dumps (dc->deposit->policy_details, JSON_INDENT (2)));
+ deposit.policy_deadline = GNUNET_TIME_UNIT_FOREVER_TS;
- ret = ext->parse_policy_details (dc->deposit->policy_details,
- &serialID,
- &deadline);
+ ret = ext->parse_policy_details (deposit.policy_details,
+ &deposit.policy_serial_id,
+ &deposit.policy_deadline,
+ &error_hint);
+
+ } while(0);
if (GNUNET_OK != ret)
- {
- TALER_LOG_WARNING ("Failed to parse policy details\n");
- *mhd_ret = TALER_MHD_reply_with_error (connection,
- MHD_HTTP_INTERNAL_SERVER_ERROR,
- TALER_EC_GENERIC_DB_STORE_FAILED,
- "deposit");
- return GNUNET_DB_STATUS_HARD_ERROR;
- }
- blocked_by_policy = true;
+ return TALER_MHD_reply_with_error (connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_DEPOSITS_POLICY_NOT_ACCEPTED,
+ error_hint);
}
-#endif
/* new deposit */
dc.exchange_timestamp = GNUNET_TIME_timestamp_get ();
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 34ff0bd5..e03713c3 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -822,8 +822,8 @@ prepare_statements (struct PostgresClosure *pg)
",out_balance_ok AS balance_ok"
",out_conflict AS conflicted"
" FROM exchange_do_deposit"
- " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17);",
- 17),
+ " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19);",
+ 19),
/* used in postgres_do_purse_deposit() */
GNUNET_PQ_make_prepare (
"call_purse_deposit",
@@ -6252,7 +6252,6 @@ postgres_do_deposit (
const struct TALER_EXCHANGEDB_Deposit *deposit,
uint64_t known_coin_id,
const struct TALER_PaytoHashP *h_payto,
- bool policy_blocked,
struct GNUNET_TIME_Timestamp *exchange_timestamp,
bool *balance_ok,
bool *in_conflict)
@@ -6274,10 +6273,16 @@ postgres_do_deposit (
GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
GNUNET_PQ_query_param_auto_from_type (&deposit->csig),
GNUNET_PQ_query_param_uint64 (&deposit_shard),
- GNUNET_PQ_query_param_bool (policy_blocked),
- (NULL == deposit->policy_details)
+ GNUNET_PQ_query_param_bool (! deposit->no_policy_details),
+ (deposit->no_policy_details)
? GNUNET_PQ_query_param_null ()
: TALER_PQ_query_param_json (deposit->policy_details),
+ (deposit->no_policy_details)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_auto_from_type (&deposit->policy_serial_id),
+ (deposit->no_policy_details)
+ ? GNUNET_PQ_query_param_null ()
+ : GNUNET_PQ_query_param_timestamp (&deposit->policy_deadline),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
diff --git a/src/extensions/extensions.c b/src/extensions/extensions.c
index 64574fc2..bf93e9ca 100644
--- a/src/extensions/extensions.c
+++ b/src/extensions/extensions.c
@@ -357,7 +357,7 @@ enum GNUNET_GenericReturnValue
TALER_extensions_from_policy_details (
const json_t *policy_details,
const struct TALER_Extension **extension,
- char **error_hint)
+ const char **error_hint)
{
const json_t *jtype;
const char *type;
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 e00f810f..8521711b 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
@@ -594,14 +594,16 @@ auction_http_post_handler (
* @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"
+ * @param[out] error_hint On error, will contain a hint
* exchange should store the policy_details in the policy_details table.
* @return GNUNET_OK if the request was OK
*/
enum GNUNET_GenericReturnValue
auction_parse_policy_details (
const json_t *input,
- struct TALER_ExtensionsPolicySerialID *serial,
- struct GNUNET_TIME_Timestamp *deadline)
+ struct GNUNET_HashCode *serial,
+ struct GNUNET_TIME_Timestamp *deadline,
+ const char **error_hint)
{
enum GNUNET_GenericReturnValue ret = GNUNET_NO;
struct GNUNET_CRYPTO_EddsaPublicKey pub;
@@ -618,10 +620,12 @@ auction_parse_policy_details (
GNUNET_assert (serial);
GNUNET_assert (deadline);
+ error_hint = NULL;
+
do {
ret = GNUNET_JSON_parse (input,
spec,
- NULL,
+ error_hint,
NULL);
if (GNUNET_OK != ret)
@@ -642,7 +646,7 @@ auction_parse_policy_details (
&hc,
sizeof(hc));
GNUNET_CRYPTO_hash_context_finish (hc,
- &serial->hash);
+ serial);
}
ret = GNUNET_OK;
diff --git a/src/include/taler_exchangedb_plugin.h b/src/include/taler_exchangedb_plugin.h
index b03c004f..0766c091 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1445,6 +1445,19 @@ struct TALER_EXCHANGEDB_Deposit
bool no_policy_details;
/**
+ * If policy_details are present, the corresponding policy extension calculates
+ * a serial id under which the policy_details shall be stored in the policy_details table.
+ */
+ struct GNUNET_HashCode policy_serial_id;
+
+ /**
+ * If policy_details are present, the corresponding policy extension can
+ * set a deadline for this policy. Can be "forever".
+ */
+ struct GNUNET_TIME_Timestamp policy_deadline;
+
+
+ /**
* Hash over the @e policy_details. Only filled if no_policy_details is false.
*/
struct TALER_ExtensionPolicyHashP h_policy;
@@ -3323,7 +3336,6 @@ struct TALER_EXCHANGEDB_Plugin
* @param deposit deposit operation details
* @param known_coin_id row of the coin in the known_coins table
* @param h_payto hash of the merchant's payto URI
- * @param policy_blocked true if an policy extension is blocking the wire transfer
* @param[in,out] exchange_timestamp time to use for the deposit (possibly updated)
* @param[out] balance_ok set to true if the balance was sufficient
* @param[out] in_conflict set to true if the deposit conflicted
@@ -3335,7 +3347,6 @@ struct TALER_EXCHANGEDB_Plugin
const struct TALER_EXCHANGEDB_Deposit *deposit,
uint64_t known_coin_id,
const struct TALER_PaytoHashP *h_payto,
- bool policy_blocked,
struct GNUNET_TIME_Timestamp *exchange_timestamp,
bool *balance_ok,
bool *in_conflict);
diff --git a/src/include/taler_extensions.h b/src/include/taler_extensions.h
index d76de25e..4685464a 100644
--- a/src/include/taler_extensions.h
+++ b/src/include/taler_extensions.h
@@ -54,15 +54,6 @@ struct TALER_Extensions
};
/*
- * @brief Serial ID under which the policy details to an deposit are stored in
- * the policy_details table.
- */
-struct TALER_ExtensionsPolicySerialID
-{
- struct GNUNET_HashCode hash;
-};
-
-/*
* @brief Represents the implementation of an extension.
*
* An "Extension" is an optional feature for the Exchange.
@@ -179,15 +170,17 @@ struct TALER_Extension
* during a deposit request.
* @param[out] serial On success, will contain the serial-ID under which the
* exchange should save the policy_details in the deposit table.
- * @param[out] deadline On sucess, set to the deadline until the policy must
+ * @param[out] deadline On success, set to the deadline until the policy must
* be fulfilled. Might be "forever". This value is used by an external
+ * @param[out] error_hint On error, will contain a hint
* mechanism to detect timeouts.
* @return GNUNET_OK if the data was accepted by the extension.
*/
enum GNUNET_GenericReturnValue (*parse_policy_details)(
const json_t *policy_details,
- struct TALER_ExtensionsPolicySerialID *serial,
- struct GNUNET_TIME_Timestamp *deadline);
+ struct GNUNET_HashCode *serial,
+ struct GNUNET_TIME_Timestamp *deadline,
+ const char **error_hint);
/**
* @brief Handler for POST-requests to the /policy/$name endpoint. Can be NULL.
@@ -407,7 +400,7 @@ enum GNUNET_GenericReturnValue
TALER_extensions_from_policy_details (
const json_t *policy_details,
const struct TALER_Extension **extension,
- char **error_hint);
+ const char **error_hint);
/*
* ================================