diff options
author | Özgür Kesim <oec-taler@kesim.org> | 2022-10-02 22:51:54 +0200 |
---|---|---|
committer | Özgür Kesim <oec-taler@kesim.org> | 2022-10-02 22:51:54 +0200 |
commit | 72cbf663952bc95888aa2187894da78725e7590c (patch) | |
tree | 0d0f9758e082a36487a85fd4335f0342f5c1e6f6 /src/exchange | |
parent | 04c7e0bb337dd88dde60293d94d2e192a8fc2ff5 (diff) |
WiP: added auction_brandt as extension
- added an extension to handle auctions via libbrandt
- /extensions/auction_brandt GET and POST handler defined
- initial parsing of transcript.json implemented, yet WiP
- multiple cleanups and changes to extension handling
Diffstat (limited to 'src/exchange')
-rw-r--r-- | src/exchange/taler-exchange-httpd.c | 43 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_extensions.c | 17 | ||||
-rw-r--r-- | src/exchange/taler-exchange-httpd_keys.c | 13 |
3 files changed, 63 insertions, 10 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index d7651d79..68fc9fb7 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -1040,6 +1040,42 @@ handle_post_auditors (struct TEH_RequestContext *rc, root); } +/** + * Handle GET "/extensions/..." requests. + * + * @param rc request context + * @param args array of additional options + * @return MHD result code + */ +static MHD_RESULT +handle_get_extensions (struct TEH_RequestContext *rc, + const char *const args[]) +{ + const struct TALER_Extension *ext = NULL; + + if (NULL == args[0]) + { + GNUNET_break_op (0); + return r404 (rc->connection, + "/extensions/$EXTENSION"); + } + + ext = TALER_extensions_get_by_name (args[0]); + if (NULL == ext) + { + GNUNET_break_op (0); + return r404 (rc->connection, + "/extensions/$EXTENSION unknown"); + } + + if (NULL == ext->http_get_handler) + return MHD_HTTP_NOT_IMPLEMENTED; + + return ext->http_get_handler ( + rc->connection, + &args[1]); +} + /** * Handle POST "/extensions/..." requests. @@ -1301,6 +1337,13 @@ handle_mhd_request (void *cls, /* extensions endpoints */ { .url = "extensions", + .method = MHD_HTTP_METHOD_GET, + .handler.get = &handle_get_extensions, + .nargs = 4, /* Arbitrary upper bound */ + .nargs_is_upper_bound = true, + }, + { + .url = "extensions", .method = MHD_HTTP_METHOD_POST, .handler.post = &handle_post_extensions, .nargs = 4, /* Arbitrary upper bound */ diff --git a/src/exchange/taler-exchange-httpd_extensions.c b/src/exchange/taler-exchange-httpd_extensions.c index 2a99d7a2..2aee1b5c 100644 --- a/src/exchange/taler-exchange-httpd_extensions.c +++ b/src/exchange/taler-exchange-httpd_extensions.c @@ -78,6 +78,7 @@ extension_update_event_cb (void *cls, } // Get the config from the database as string + if (extension->has_config) { char *config_str = NULL; enum GNUNET_DB_QueryStatus qs; @@ -117,26 +118,26 @@ extension_update_event_cb (void *cls, err.text, err.source); GNUNET_break (0); - free(config_str); + free (config_str); return; } // Call the parser for the extension ret = extension->load_json_config ( (struct TALER_Extension *) extension, - json_object_get(config, "config")); + json_object_get (config, "config")); if (GNUNET_OK != ret) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Couldn't parse configuration for extension %s from the database: %s\n", extension->name, - config_str); + config_str); GNUNET_break (0); } - free(config_str); - json_decref(config); + free (config_str); + json_decref (config); } /* Special case age restriction: Update global flag and mask */ @@ -190,12 +191,16 @@ TEH_extensions_init () it = it->next) { const struct TALER_Extension *ext = it->extension; + uint32_t typ = htonl (ext->type); char *conf = json_dumps (ext->config_to_json (ext), JSON_COMPACT); TEH_plugin->set_extension_config (TEH_plugin->cls, ext->name, conf); - extension_update_event_cb (NULL, &ext->type, sizeof(ext->type)); + + extension_update_event_cb (NULL, + &typ, + sizeof(typ)); free (conf); } diff --git a/src/exchange/taler-exchange-httpd_keys.c b/src/exchange/taler-exchange-httpd_keys.c index 4fb8a717..4761f314 100644 --- a/src/exchange/taler-exchange-httpd_keys.c +++ b/src/exchange/taler-exchange-httpd_keys.c @@ -1916,18 +1916,23 @@ create_krd (struct TEH_KeyStateHandle *ksh, /* flag our findings so far */ has_extensions = true; - GNUNET_assert (NULL != extension->config_json); ext = GNUNET_JSON_PACK ( GNUNET_JSON_pack_bool ("critical", extension->critical), GNUNET_JSON_pack_string ("version", - extension->version), - GNUNET_JSON_pack_object_incref ("config", - extension->config_json) + extension->version) ); GNUNET_assert (NULL != ext); + if (extension->has_config) + { + GNUNET_assert (extension->config_json); + json_object_set_new (ext, + "config", + extension->config_json); + } + r = json_object_set_new ( extensions, extension->name, |