challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit 9e02e59010fd6a0192e8ad547217189f1beba72e
parent e74b90750c0e7f63bc9a880efbde696399abe200
Author: Sebastian <sebasjm@gmail.com>
Date:   Wed,  3 Jul 2024 10:48:48 -0300

keep request params on redirect

Diffstat:
Msrc/challenger/challenger-httpd.c | 31++++++++++++++++++++++++++-----
Msrc/challenger/challenger-httpd.h | 5+++++
Msrc/challenger/challenger-httpd_spa.c | 14+++++++++++++-
3 files changed, 44 insertions(+), 6 deletions(-)

diff --git a/src/challenger/challenger-httpd.c b/src/challenger/challenger-httpd.c @@ -117,6 +117,29 @@ char *CH_auth_command; /** + * Function called first by MHD with the full URL. + * + * @param cls NULL + * @param full_url the full URL + * @param con MHD connection object + * @return our handler context + */ +static void * +full_url_track_callback (void *cls, + const char *full_url, + struct MHD_Connection *con) +{ + struct CH_HandlerContext *hc; + + hc = GNUNET_new (struct CH_HandlerContext); + GNUNET_async_scope_fresh (&hc->async_scope_id); + GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id); + hc->full_url = GNUNET_strdup (full_url); + return hc; +} + + +/** * A client has requested the given url using the given method * (#MHD_HTTP_METHOD_GET, #MHD_HTTP_METHOD_PUT, * #MHD_HTTP_METHOD_DELETE, #MHD_HTTP_METHOD_POST, etc). The callback @@ -235,16 +258,12 @@ url_handler (void *cls, "Handling %s request for `%s'\n", method, url); - if (NULL == hc) + if (NULL == hc->connection) { const char *correlation_id; bool found = false; - hc = GNUNET_new (struct CH_HandlerContext); - *con_cls = hc; hc->connection = connection; - GNUNET_async_scope_fresh (&hc->async_scope_id); - GNUNET_SCHEDULER_begin_async_scope (&hc->async_scope_id); /* We only read the correlation ID on the first callback for every client */ correlation_id = MHD_lookup_connection_value (connection, MHD_HEADER_KIND, @@ -668,6 +687,8 @@ run (void *cls, NULL, NULL, &url_handler, NULL, MHD_OPTION_LISTEN_SOCKET, fh, + MHD_OPTION_URI_LOG_CALLBACK, + &full_url_track_callback, NULL, MHD_OPTION_NOTIFY_COMPLETED, &handle_mhd_completion_callback, NULL, MHD_OPTION_CONNECTION_TIMEOUT, diff --git a/src/challenger/challenger-httpd.h b/src/challenger/challenger-httpd.h @@ -75,6 +75,11 @@ struct CH_HandlerContext const char *path; /** + * Copy of our original full URL with query parameters. + */ + char *full_url; + + /** * Request handler for this request. */ const struct CH_RequestHandler *rh; diff --git a/src/challenger/challenger-httpd_spa.c b/src/challenger/challenger-httpd_spa.c @@ -380,6 +380,7 @@ CH_spa_redirect (struct CH_HandlerContext *hc, { const char *text = "Redirecting to /webui/"; struct MHD_Response *response; + char *dst; response = MHD_create_response_from_buffer (strlen (text), (void *) text, @@ -394,13 +395,23 @@ CH_spa_redirect (struct CH_HandlerContext *hc, MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/plain")); + + const char *rparams = strchr (hc->full_url, '?'); + if (NULL == rparams) + dst = GNUNET_strdup ("/webui/"); + else + GNUNET_asprintf (&dst, + "/webui/%s", + rparams); + if (MHD_NO == MHD_add_response_header (response, MHD_HTTP_HEADER_LOCATION, - "/webui/")) + dst)) { GNUNET_break (0); MHD_destroy_response (response); + GNUNET_free (dst); return MHD_NO; } @@ -411,6 +422,7 @@ CH_spa_redirect (struct CH_HandlerContext *hc, MHD_HTTP_FOUND, response); MHD_destroy_response (response); + GNUNET_free (dst); return ret; } }