diff options
author | Christian Grothoff <christian@grothoff.org> | 2020-07-05 20:43:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2020-07-05 20:43:28 +0200 |
commit | 6de49ea2c02e311e5f5366005bd3497a9bb25187 (patch) | |
tree | a221b9c784b4e004eb5972e18516653d1aea6a5c /src/exchange/taler-exchange-httpd.c | |
parent | e428783e2e0295186dc4eae273df8a3f8b75df60 (diff) | |
parent | ed5b98a2c2308fbd44b906a30286d2689fd304dd (diff) | |
download | exchange-6de49ea2c02e311e5f5366005bd3497a9bb25187.tar.gz exchange-6de49ea2c02e311e5f5366005bd3497a9bb25187.tar.bz2 exchange-6de49ea2c02e311e5f5366005bd3497a9bb25187.zip |
Merge branch 'protocolv8'
Diffstat (limited to 'src/exchange/taler-exchange-httpd.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd.c | 65 |
1 files changed, 58 insertions, 7 deletions
diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index 339303d53..c614b711e 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -421,6 +421,45 @@ proceed_with_handler (const struct TEH_RequestHandler *rh, /** + * Handle a "/seed" request. + * + * @param rh context of the handler + * @param connection the MHD connection to handle + * @param args array of additional options (must be empty for this function) + * @return MHD result code + */ +static MHD_RESULT +handler_seed (const struct TEH_RequestHandler *rh, + struct MHD_Connection *connection, + const char *const args[]) +{ +#define SEED_SIZE 32 + char *body; + MHD_RESULT ret; + struct MHD_Response *resp; + + (void) rh; + body = malloc (SEED_SIZE); /* must use malloc(), because MHD will use free() */ + if (NULL == body) + return MHD_NO; + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, + body, + SEED_SIZE); + resp = MHD_create_response_from_buffer (SEED_SIZE, + body, + MHD_RESPMEM_MUST_FREE); + TALER_MHD_add_global_headers (resp); + ret = MHD_queue_response (connection, + MHD_HTTP_OK, + resp); + GNUNET_break (MHD_YES == ret); + MHD_destroy_response (resp); + return ret; +#undef SEED_SIZE +} + + +/** * Handle incoming HTTP request. * * @param cls closure for MHD daemon (unused) @@ -472,6 +511,11 @@ handle_mhd_request (void *cls, .method = MHD_HTTP_METHOD_GET, .handler.get = &TEH_handler_agpl_redirect }, + { + .url = "seed", + .method = MHD_HTTP_METHOD_GET, + .handler.get = &handler_seed + }, /* Terms of service */ { .url = "terms", @@ -654,9 +698,10 @@ handle_mhd_request (void *cls, { struct TEH_RequestHandler *rh = &handlers[i]; - if (0 != strncmp (tok, - rh->url, - tok_size)) + if ( (0 != strncmp (tok, + rh->url, + tok_size)) || + (tok_size != strlen (rh->url) ) ) continue; found = GNUNET_YES; /* The URL is a match! What we now do depends on the method. */ @@ -782,8 +827,8 @@ exchange_serve_process_config (void) &TEH_master_public_key. eddsa_pub)) { - fprintf (stderr, - "Invalid master public key given in exchange configuration."); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Invalid master public key given in exchange configuration."); GNUNET_free (master_public_key_str); return GNUNET_SYSERR; } @@ -795,14 +840,18 @@ exchange_serve_process_config (void) if (GNUNET_OK != TEH_WIRE_init (TEH_cfg)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to setup wire subsystem\n"); return GNUNET_SYSERR; + } if (NULL == (TEH_plugin = TALER_EXCHANGEDB_plugin_load (TEH_cfg))) { - fprintf (stderr, - "Failed to initialize DB subsystem\n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to initialize DB subsystem\n"); TEH_WIRE_done (); return GNUNET_SYSERR; } @@ -814,6 +863,8 @@ exchange_serve_process_config (void) &serve_unixpath, &unixpath_mode)) { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to setup HTTPd subsystem\n"); TEH_WIRE_done (); return GNUNET_SYSERR; } |