diff options
Diffstat (limited to 'src/exchange/taler-exchange-httpd_extensions.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_extensions.c | 123 |
1 files changed, 81 insertions, 42 deletions
diff --git a/src/exchange/taler-exchange-httpd_extensions.c b/src/exchange/taler-exchange-httpd_extensions.c index 48c3f4a94..d62a618ae 100644 --- a/src/exchange/taler-exchange-httpd_extensions.c +++ b/src/exchange/taler-exchange-httpd_extensions.c @@ -1,6 +1,6 @@ /* This file is part of TALER - Copyright (C) 2021 Taler Systems SA + Copyright (C) 2021, 2023 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software @@ -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" @@ -148,7 +149,7 @@ extension_update_event_cb (void *cls, TEH_age_restriction_enabled = false; if (NULL != conf) { - TEH_age_restriction_enabled = true; + TEH_age_restriction_enabled = extension->enabled; TEH_age_restriction_config = *conf; GNUNET_log (GNUNET_ERROR_TYPE_INFO, "[age restriction] DB event has changed the config to %s with mask: %s\n", @@ -208,16 +209,20 @@ TEH_extensions_init () { const struct TALER_Extension *ext = it->extension; uint32_t typ = htonl (ext->type); - char *manifest = json_dumps (ext->manifest (ext), JSON_COMPACT); + json_t *jmani; + char *manifest; + jmani = ext->manifest (ext); + manifest = json_dumps (jmani, + JSON_COMPACT); + json_decref (jmani); TEH_plugin->set_extension_manifest (TEH_plugin->cls, ext->name, manifest); - + free (manifest); extension_update_event_cb (NULL, &typ, sizeof(typ)); - free (manifest); } return GNUNET_OK; @@ -252,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, @@ -334,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); @@ -353,44 +397,39 @@ TEH_extensions_post_handler ( } + if (GNUNET_OK != + ext->policy_post_handler (root, + &args[1], + policy_details, + policy_details_count, + &output)) { - enum GNUNET_GenericReturnValue ret; - - ret = ext->policy_post_handler (root, - &args[1], - policy_details, - policy_details_count, - &output); - - if (GNUNET_OK != ret) - { - TALER_MHD_reply_json_steal ( - rc->connection, - output, - MHD_HTTP_BAD_REQUEST); - } + return TALER_MHD_reply_json_steal ( + rc->connection, + output, + MHD_HTTP_BAD_REQUEST); + } - /* execute fulfillment transaction */ + /* execute fulfillment transaction */ + { + MHD_RESULT mhd_ret; + struct TALER_PolicyFulfillmentTransactionData fulfillment = { + .proof = root, + .timestamp = GNUNET_TIME_timestamp_get (), + .details = policy_details, + .details_count = policy_details_count + }; + + if (GNUNET_OK != + TEH_DB_run_transaction (rc->connection, + "execute policy fulfillment", + TEH_MT_REQUEST_POLICY_FULFILLMENT, + &mhd_ret, + &policy_fulfillment_transaction, + &fulfillment)) { - MHD_RESULT mhd_ret; - struct TALER_PolicyFulfillmentTransactionData fulfillment = { - .proof = root, - .timestamp = GNUNET_TIME_timestamp_get (), - .details = policy_details, - .details_count = policy_details_count - }; - - if (GNUNET_OK != - TEH_DB_run_transaction (rc->connection, - "execute policy fulfillment", - TEH_MT_REQUEST_POLICY_FULFILLMENT, - &mhd_ret, - &policy_fulfillment_transaction, - &fulfillment)) - { - json_decref (output); - return mhd_ret; - } + json_decref (output); + return mhd_ret; } } |