diff --git a/cloud-storage/driver_utils.c b/cloud-storage/driver_utils.c index 19f2f6e6cb4c..82f6091fa869 100644 --- a/cloud-storage/driver_utils.c +++ b/cloud-storage/driver_utils.c @@ -43,9 +43,27 @@ struct oauth_receive_args_t { struct authorize_state_t *authorize_state; + const char *browser_response; bool (*process_request)(char *code_verifier, int port, uint8_t *request, size_t request_len); }; +static const char *_DEFAULT_OAUTH_BROWSER_RESPONSE = + "\n" + " \n" + " Authorized\n" + " \n" + " \n" + "
\n" + " \n" + " \n" + " \n" + "
\n" + "
\n" + " You have now authorized RetroArch. This window will close soon.\n" + "
\n" + " \n" + ""; + char *cloud_storage_join_strings(size_t *length, ...) { va_list valist; @@ -696,8 +714,27 @@ static void _oauth_receive_browser_request_thread(void *data) rc = socket_select(clientfd + 1, (fd_set *)NULL, &write_set, (fd_set *)NULL, &timeout); if (rc > 0) { - const char *response = "HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nContent-Length: 0\r\n\r\n"; - send(clientfd, response, strlen(response), 0); + const char *response_headers = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: "; + char length_str[16]; + char *response; + size_t response_length; + + send(clientfd, response_headers, strlen(response_headers), 0); + + if (thread_args->browser_response) + { + response = thread_args->browser_response; + } else + { + response = _DEFAULT_OAUTH_BROWSER_RESPONSE; + } + + response_length = strlen(thread_args->browser_response); + sprintf(length_str, "%ld", response_length); + send(clientfd, length_str, strlen(length_str), 0); + + send(clientfd, "\r\n\r\n", 4, 0); + send(clientfd, thread_args->browser_response, response_length, 0); } #if defined(_WIN32) || defined(_WIN64) @@ -769,6 +806,7 @@ static void _oauth_receive_browser_request_thread(void *data) bool cloud_storage_oauth_receive_browser_request( struct authorize_state_t *authorize_state, + const char *browser_response, bool (*process_request)(char *code_verifier, int port, uint8_t *request, size_t request_len)) { u_long on = 1; @@ -847,6 +885,7 @@ bool cloud_storage_oauth_receive_browser_request( thread_args = (struct oauth_receive_args_t *)malloc(sizeof(struct oauth_receive_args_t)); thread_args->authorize_state = authorize_state; + thread_args->browser_response = browser_response; thread_args->process_request = process_request; sthread_create(_oauth_receive_browser_request_thread, thread_args); diff --git a/cloud-storage/driver_utils.h b/cloud-storage/driver_utils.h index 343235639211..4ba5d0404515 100644 --- a/cloud-storage/driver_utils.h +++ b/cloud-storage/driver_utils.h @@ -81,6 +81,7 @@ void cloud_storage_add_request_body_data( bool cloud_storage_oauth_receive_browser_request( struct authorize_state_t *authorize_state, + const char *browser_response, bool (*process_request)(char *code_verifier, int port, uint8_t *request, size_t request_len) ); diff --git a/cloud-storage/google/authorize.c b/cloud-storage/google/authorize.c index 90c73192ac00..7862bd22f3eb 100644 --- a/cloud-storage/google/authorize.c +++ b/cloud-storage/google/authorize.c @@ -375,7 +375,10 @@ authorization_status_t cloud_storage_google_authorize(void (*callback)(bool succ authorize_state->callback = callback; slock_lock(authorize_state->mutex); - if (!cloud_storage_oauth_receive_browser_request(authorize_state, _process_request)) + if (!cloud_storage_oauth_receive_browser_request( + authorize_state, + NULL, + _process_request)) { goto failed; } diff --git a/cloud-storage/onedrive/authorize.c b/cloud-storage/onedrive/authorize.c index a8fe5c3800f0..4dfc7090d572 100644 --- a/cloud-storage/onedrive/authorize.c +++ b/cloud-storage/onedrive/authorize.c @@ -353,7 +353,10 @@ authorization_status_t cloud_storage_onedrive_authorize(void (*callback)(bool su authorize_state->callback = callback; slock_lock(authorize_state->mutex); - if (!cloud_storage_oauth_receive_browser_request(authorize_state, _process_request)) + if (!cloud_storage_oauth_receive_browser_request( + authorize_state, + NULL, + _process_request)) { goto failed; }