Compare commits

...

2 Commits

Author SHA1 Message Date
07eb596180
checking for WHY2_CHAT_CODE_ACCEPT_MESSAGES from client
All checks were successful
Codacy Scan / Codacy Security Scan (push) Successful in 1m9s
Test WHY2-core / test-why2 (why2, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-core-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m43s
Build WHY2-chat / test-why2 (./out/why2-chat-client, ./configure.sh, ubuntu-latest, ./out/why2-chat-server) (push) Successful in 2m51s
Test WHY2-logger / test-why2 (why2-logger, ./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./out/why2-logger-test, valgrind --leak-check=full --show-leak-kinds=reachable --track-origins=yes -s) (push) Successful in 2m53s
Test Project / test-project (./configure.sh, gdb -ex "run" -ex "quit" --batch, ubuntu-latest, ./test) (push) Successful in 2m53s
it was using the first received message
2025-01-31 14:49:37 +01:00
15e36f5919
added key to connection_node_t 2025-01-31 14:42:30 +01:00

View File

@ -46,6 +46,7 @@ typedef struct _connection_node
pthread_t thread; pthread_t thread;
char *username; char *username;
unsigned long id; unsigned long id;
char *key; //EACH USER WILL USE DIFFERENT KEY FOR COMMUNICATION
} connection_node_t; //SINGLE LINKED LIST } connection_node_t; //SINGLE LINKED LIST
why2_list_t connection_list = WHY2_LIST_EMPTY; why2_list_t connection_list = WHY2_LIST_EMPTY;
@ -658,7 +659,8 @@ void *why2_communicate_thread(void *arg)
connection, connection,
pthread_self(), pthread_self(),
why2_strdup(username), why2_strdup(username),
get_latest_id() get_latest_id(),
why2_generate_key(why2_get_key_length())
}; };
why2_list_push(&connection_list, &node, sizeof(node)); //ADD TO LIST why2_list_push(&connection_list, &node, sizeof(node)); //ADD TO LIST
@ -856,6 +858,7 @@ void *why2_communicate_thread(void *arg)
//DEALLOCATION //DEALLOCATION
close(connection); close(connection);
why2_deallocate(node.username); why2_deallocate(node.username);
why2_deallocate(node.key);
why2_list_remove(&connection_list, find_connection(connection)); why2_list_remove(&connection_list, find_connection(connection));
@ -959,6 +962,8 @@ void *why2_listen_server(void *socket)
if (server_uname == NULL) //GET SERVER USERNAME if (server_uname == NULL) //GET SERVER USERNAME
{ {
if (code == NULL || strcmp(code, WHY2_CHAT_CODE_ACCEPT_MESSAGES) != 0) goto deallocation;
server_uname = why2_strdup(username); //GET USERNAME server_uname = why2_strdup(username); //GET USERNAME
//GET INFO //GET INFO
@ -1094,13 +1099,14 @@ void *why2_listen_server(void *socket)
printf("\n\n%s%s: %s\n\n", WHY2_CLEAR_AND_GO_UP, username, message); printf("\n\n%s%s: %s\n\n", WHY2_CLEAR_AND_GO_UP, username, message);
} }
if (!exiting && !continuing) if (!exiting && !continuing)
{ {
printf(">>> "); printf(">>> ");
fflush(stdout); fflush(stdout);
} }
deallocation:
//DEALLOCATION //DEALLOCATION
why2_deallocate(read); why2_deallocate(read);
why2_deallocate(username); why2_deallocate(username);