From f77f3a8c934df588b5bcdcce1f89b6d889a28558 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Wed, 21 Feb 2024 10:48:48 +0100 Subject: [PATCH] implemented config functions way better now --- src/chat/config.c | 4 ++-- src/chat/main/client.c | 6 ++---- src/chat/misc.c | 5 +---- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/chat/config.c b/src/chat/config.c index cc721c0..243b435 100644 --- a/src/chat/config.c +++ b/src/chat/config.c @@ -84,9 +84,9 @@ void init_config(char *filename) char *config(char *key, enum CONFIG_TYPES type) { - char *path; + char *path = NULL; - switch (type) //GET PATH + switch (type) //GET path { case CLIENT: path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER")); diff --git a/src/chat/main/client.c b/src/chat/main/client.c index c47b1f4..d4d27e9 100644 --- a/src/chat/main/client.c +++ b/src/chat/main/client.c @@ -52,12 +52,11 @@ int main(void) //GET IP printf("Welcome.\n\n"); - char *path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER")); - char *auto_connect = why2_toml_read(path, "auto_connect"); + char *auto_connect = why2_chat_client_config("auto_connect"); if (strcmp(auto_connect, "true") == 0) //USER ENABLED AUTOMATIC CONNECTION { - char *auto_connect_ip = why2_toml_read(path, "auto_connect_ip"); //GET IP + char *auto_connect_ip = why2_chat_client_config("auto_connect_ip"); //GET IP line = strdup(auto_connect_ip); printf("%s\n", line); @@ -71,7 +70,6 @@ int main(void) line_length = 3; //THIS IS FOR THE UNDERLINE THINGY } - why2_deallocate(path); why2_toml_read_free(auto_connect); server_addr.sin_addr.s_addr = inet_addr(line); diff --git a/src/chat/misc.c b/src/chat/misc.c index d62c460..35ca4aa 100644 --- a/src/chat/misc.c +++ b/src/chat/misc.c @@ -368,8 +368,7 @@ void *why2_communicate_thread(void *arg) printf("User connected.\t\t%d\n", connection); //GET USERNAME - char *string_buffer = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER")); - char *config_username = why2_toml_read(string_buffer, "user_pick_username"); + char *config_username = why2_chat_server_config("user_pick_username"); char *raw = NULL; void *raw_ptr = NULL; @@ -382,8 +381,6 @@ void *why2_communicate_thread(void *arg) int usernames_n = 0; struct json_object *json = json_tokener_parse("{}"); - why2_deallocate(string_buffer); - if (config_username == NULL || strcmp(config_username, "true") == 0) { if (config_username == NULL) fprintf(stderr, "Your config doesn't contain 'user_pick_username'. Please update your configuration.\n");