implemented config functions

way better now
This commit is contained in:
Václav Šmejkal 2024-02-21 10:48:48 +01:00
parent 41a0911a28
commit f77f3a8c93
Signed by: ENGO150
GPG Key ID: 4A57E86482968843
3 changed files with 5 additions and 10 deletions

View File

@ -84,9 +84,9 @@ void init_config(char *filename)
char *config(char *key, enum CONFIG_TYPES type) char *config(char *key, enum CONFIG_TYPES type)
{ {
char *path; char *path = NULL;
switch (type) //GET PATH switch (type) //GET path
{ {
case CLIENT: case CLIENT:
path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER")); path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER"));

View File

@ -52,12 +52,11 @@ int main(void)
//GET IP //GET IP
printf("Welcome.\n\n"); printf("Welcome.\n\n");
char *path = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_CLIENT, "{USER}", getenv("USER")); char *auto_connect = why2_chat_client_config("auto_connect");
char *auto_connect = why2_toml_read(path, "auto_connect");
if (strcmp(auto_connect, "true") == 0) //USER ENABLED AUTOMATIC CONNECTION 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); line = strdup(auto_connect_ip);
printf("%s\n", line); printf("%s\n", line);
@ -71,7 +70,6 @@ int main(void)
line_length = 3; //THIS IS FOR THE UNDERLINE THINGY line_length = 3; //THIS IS FOR THE UNDERLINE THINGY
} }
why2_deallocate(path);
why2_toml_read_free(auto_connect); why2_toml_read_free(auto_connect);
server_addr.sin_addr.s_addr = inet_addr(line); server_addr.sin_addr.s_addr = inet_addr(line);

View File

@ -368,8 +368,7 @@ void *why2_communicate_thread(void *arg)
printf("User connected.\t\t%d\n", connection); printf("User connected.\t\t%d\n", connection);
//GET USERNAME //GET USERNAME
char *string_buffer = why2_replace(WHY2_CHAT_CONFIG_DIR "/" WHY2_CHAT_CONFIG_SERVER, "{USER}", getenv("USER")); char *config_username = why2_chat_server_config("user_pick_username");
char *config_username = why2_toml_read(string_buffer, "user_pick_username");
char *raw = NULL; char *raw = NULL;
void *raw_ptr = NULL; void *raw_ptr = NULL;
@ -382,8 +381,6 @@ void *why2_communicate_thread(void *arg)
int usernames_n = 0; int usernames_n = 0;
struct json_object *json = json_tokener_parse("{}"); struct json_object *json = json_tokener_parse("{}");
why2_deallocate(string_buffer);
if (config_username == NULL || strcmp(config_username, "true") == 0) 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"); if (config_username == NULL) fprintf(stderr, "Your config doesn't contain 'user_pick_username'. Please update your configuration.\n");