From 99ae6a71064668b03f13a725967b194a680aad12 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Sat, 1 Feb 2025 15:23:04 +0100 Subject: [PATCH] simplified config using config_path fn --- src/chat/config.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/chat/config.c b/src/chat/config.c index 443051f..bbbff2a 100644 --- a/src/chat/config.c +++ b/src/chat/config.c @@ -34,7 +34,8 @@ along with this program. If not, see . enum CONFIG_TYPES { CLIENT, - SERVER + SERVER, + SERVER_USERS }; void init_config(char *filename) @@ -78,7 +79,7 @@ void init_config(char *filename) why2_deallocate(buffer); } -char *config(char *key, enum CONFIG_TYPES type) +char *config_path(enum CONFIG_TYPES type) { char *path = NULL; @@ -92,11 +93,23 @@ char *config(char *key, enum CONFIG_TYPES type) path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{HOME}", getenv("HOME")); break; + case SERVER_USERS: + path = why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{HOME}", getenv("HOME")); + break; + default: why2_die("CONFIG_TYPE not implemented!"); break; } + return path; +} + +char *config(char *key, enum CONFIG_TYPES type) +{ + //GET CONFIGURATION PATH + char *path = config_path(type); + //VALUE char *value = why2_toml_read(path, key); @@ -167,5 +180,5 @@ char *why2_chat_client_config(char *key) char *why2_get_server_users_path(void) { - return why2_replace(WHY2_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER_USERS, "{HOME}", getenv("HOME")); + return config_path(SERVER_USERS); } \ No newline at end of file