implemented WHY2_CHAT_CODE_PASSWORD

This commit is contained in:
Václav Šmejkal 2025-02-01 21:03:49 +01:00
parent ee309b2cbb
commit a4b8bf2f4c
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
2 changed files with 38 additions and 9 deletions

View File

@ -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);

View File

@ -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