summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorÖzgür Kesim <oec-taler@kesim.org>2023-12-06 12:37:51 +0100
committerÖzgür Kesim <oec-taler@kesim.org>2023-12-06 12:37:51 +0100
commit381c5efb612e5393bb5a4e85420de8096b95a6e5 (patch)
tree2b4842273f15b6f6afb03581010257920a2a2726 /src
parent3e106030f1d9462dcf93f539acdfa5860833b152 (diff)
downloadexchange-381c5efb612e5393bb5a4e85420de8096b95a6e5.tar.gz
exchange-381c5efb612e5393bb5a4e85420de8096b95a6e5.tar.bz2
exchange-381c5efb612e5393bb5a4e85420de8096b95a6e5.zip
[policy extensions] mark out work for #7999+#8001
Diffstat (limited to 'src')
-rw-r--r--src/exchange/taler-exchange-httpd_extensions.c44
-rw-r--r--src/exchangedb/pg_add_policy_fulfillment_proof.c10
2 files changed, 49 insertions, 5 deletions
diff --git a/src/exchange/taler-exchange-httpd_extensions.c b/src/exchange/taler-exchange-httpd_extensions.c
index dd0fada76..d62a618ae 100644
--- a/src/exchange/taler-exchange-httpd_extensions.c
+++ b/src/exchange/taler-exchange-httpd_extensions.c
@@ -23,6 +23,7 @@
#include "taler-exchange-httpd_keys.h"
#include "taler-exchange-httpd_responses.h"
#include "taler-exchange-httpd_extensions.h"
+#include "taler_extensions_policy.h"
#include "taler_json_lib.h"
#include "taler_mhd_lib.h"
#include "taler_extensions.h"
@@ -256,11 +257,16 @@ policy_fulfillment_transaction (
{
struct TALER_PolicyFulfillmentTransactionData *fulfillment = cls;
+ /* FIXME[oec]: use connection and mhd_ret? */
+ (void) connection;
+ (void) mhd_ret;
+
return TEH_plugin->add_policy_fulfillment_proof (TEH_plugin->cls,
fulfillment);
}
+/* FIXME[oec]-#7999: In this handler: do we transition correctly between states? */
MHD_RESULT
TEH_extensions_post_handler (
struct TEH_RequestContext *rc,
@@ -338,14 +344,48 @@ TEH_extensions_post_handler (
qs = TEH_plugin->get_policy_details (TEH_plugin->cls,
&hcs[idx],
&policy_details[idx]);
- if (qs < 0)
+ if (0 > qs)
+ {
+ GNUNET_free (hcs);
+ GNUNET_free (policy_details);
+ return TALER_MHD_reply_with_error (rc->connection,
+ MHD_HTTP_BAD_REQUEST,
+ TALER_EC_EXCHANGE_GENERIC_OPERATION_UNKNOWN,
+ "a policy_hash_code couldn't be found");
+ }
+
+ /* We proceed according to the state of fulfillment */
+ switch (policy_details[idx].fulfillment_state)
{
- error_msg = "a policy_hash_code couldn't be found";
+ case TALER_PolicyFulfillmentReady:
+ break;
+ case TALER_PolicyFulfillmentInsufficient:
+ error_msg = "a policy is not yet fully funded";
+ ret = GNUNET_SYSERR;
+ break;
+ case TALER_PolicyFulfillmentTimeout:
+ error_msg = "a policy is has already timed out";
+ ret = GNUNET_SYSERR;
break;
+ case TALER_PolicyFulfillmentSuccess:
+ /* FIXME[oec]-#8001: Idempotency handling. */
+ GNUNET_break (0);
+ break;
+ case TALER_PolicyFulfillmentFailure:
+ /* FIXME[oec]-#7999: What to do in the failure case? */
+ GNUNET_break (0);
+ break;
+ default:
+ /* Unknown state */
+ GNUNET_assert (0);
}
+
+ if (GNUNET_OK != ret)
+ break;
}
GNUNET_free (hcs);
+
if (GNUNET_OK != ret)
{
GNUNET_free (policy_details);
diff --git a/src/exchangedb/pg_add_policy_fulfillment_proof.c b/src/exchangedb/pg_add_policy_fulfillment_proof.c
index 0fd6b1c92..93d070712 100644
--- a/src/exchangedb/pg_add_policy_fulfillment_proof.c
+++ b/src/exchangedb/pg_add_policy_fulfillment_proof.c
@@ -55,6 +55,7 @@ TEH_PG_add_policy_fulfillment_proof (
enum GNUNET_DB_QueryStatus qs;
struct PostgresClosure *pg = cls;
size_t count = fulfillment->details_count;
+ /* FIXME: this seems to be prone to VLA attacks */
struct GNUNET_HashCode hcs[count];
/* Create the sorted policy_hash_codes */
@@ -84,8 +85,7 @@ TEH_PG_add_policy_fulfillment_proof (
GNUNET_PQ_query_param_timestamp (&fulfillment->timestamp),
TALER_PQ_query_param_json (fulfillment->proof),
GNUNET_PQ_query_param_auto_from_type (&fulfillment->h_proof),
- GNUNET_PQ_query_param_fixed_size (hcs,
- count * sizeof(struct GNUNET_HashCode)),
+ TALER_PQ_query_param_array_hash_code (count, hcs, pg->conn),
GNUNET_PQ_query_param_end
};
struct GNUNET_PQ_ResultSpec rs[] = {
@@ -132,7 +132,6 @@ TEH_PG_add_policy_fulfillment_proof (
GNUNET_PQ_query_param_end
};
- // FIXME-Oec: review if this is the intended logic here!
PREPARE (pg,
"update_policy_details",
"UPDATE policy_details SET"
@@ -151,5 +150,10 @@ TEH_PG_add_policy_fulfillment_proof (
}
}
+ /*
+ * FIXME[oec]-#7999: When all policies of a deposit are fulfilled,
+ * unblock it and trigger a wire-transfer.
+ */
+
return qs;
}