From a4b8bf2f4c8b0e16f0e27a2821bed6b31f28aaac Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 1 Feb 2025 21:03:49 +0100 Subject: [PATCH] implemented WHY2_CHAT_CODE_PASSWORD --- src/chat/main/client.c | 2 +- src/chat/misc.c | 45 ++++++++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/chat/main/client.c b/src/chat/main/client.c index 90da628..23b7472 100644 --- a/src/chat/main/client.c +++ b/src/chat/main/client.c @@ -288,7 +288,7 @@ int main(void) char *hash = why2_sha256(line, strlen(line)); //HASHISH - why2_send_socket(hash, NULL, listen_socket); //SEND BUT HASHED + why2_send_socket_code(hash, NULL, listen_socket, WHY2_CHAT_CODE_PASSWORD); //SEND BUT HASHED //DEALLOCATION why2_deallocate(hash); diff --git a/src/chat/misc.c b/src/chat/misc.c index 36b1294..3283243 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -572,6 +572,7 @@ void *why2_communicate_thread(void *arg) code = get_string_from_json_string(raw, "code"); exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_USERNAME) == 0; } while (!exiting_read); + why2_deallocate(code); decoded_buffer = get_string_from_json_string(raw, "message"); //DECODE @@ -617,11 +618,25 @@ void *why2_communicate_thread(void *arg) { send_socket_code_deallocate(NULL, why2_chat_server_config("server_username"), connection, WHY2_CHAT_CODE_ENTER_PASSWORD); - if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ + //KEEP READING UNTIL CODE ARRIVES + char *code = NULL; + why2_bool exiting_read = 0; + do { - force_exiting = 1; //FAILURE - goto deallocation; - } + //DEALLOCATE + why2_deallocate(code); + + if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ + { + force_exiting = 1; //FAILURE + goto deallocation; + } + + //COMPARE CODE + code = get_string_from_json_string(raw, "code"); + exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_PASSWORD) == 0; + } while (!exiting_read); + why2_deallocate(code); password = get_string_from_json_string(raw, "message"); //DECODE @@ -634,11 +649,25 @@ void *why2_communicate_thread(void *arg) for (unsigned char i = 0; i < max_tries; i++) { - if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ + //KEEP READING UNTIL CODE ARRIVES + char *code = NULL; + why2_bool exiting_read = 0; + do { - force_exiting = 1; //FAILURE - goto deallocation; - } + //DEALLOCATE + why2_deallocate(code); + + if ((raw = read_user(connection, &raw_ptr)) == NULL) //READ + { + force_exiting = 1; //FAILURE + goto deallocation; + } + + //COMPARE CODE + code = get_string_from_json_string(raw, "code"); + exiting_read = code != NULL && strcmp(code, WHY2_CHAT_CODE_PASSWORD) == 0; + } while (!exiting_read); + why2_deallocate(code); password = get_string_from_json_string(raw, "message"); //DECODE