From d1abb7ebc594ce2d85ef8ef2ca12dd460b51db95 Mon Sep 17 00:00:00 2001 From: nex Date: Thu, 11 Jun 2020 12:22:35 +0200 Subject: [PATCH] main: Read config file only if no jid parameter provided Signed-off-by: nex --- src/main.c | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/main.c b/src/main.c index eba6587..fa2798d 100644 --- a/src/main.c +++ b/src/main.c @@ -413,30 +413,32 @@ int main(int argc, char *argv[]) { } } - // Loading config file - GKeyFile *config_file = g_key_file_new(); - GError *error = NULL; - GString* configfile = g_string_new( g_get_home_dir()); - g_string_append(configfile,"/.config/xmppc.conf"); - gboolean configfilefound = g_key_file_load_from_file( - config_file, - configfile->str, - G_KEY_FILE_NONE, - &error); + // Loading config file if jid not provided by command line + if (jid == NULL) { + GKeyFile *config_file = g_key_file_new(); + GError *error = NULL; + GString* configfile = g_string_new( g_get_home_dir()); + g_string_append(configfile,"/.config/xmppc.conf"); + gboolean configfilefound = g_key_file_load_from_file( + config_file, + configfile->str, + G_KEY_FILE_NONE, + &error); - if (!configfilefound) { - if(!g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { - logError(&xmppc, "Error loading key file: %s", error->message); - return -1; - } - } else { - if(jid == NULL && pwd == NULL) { - logInfo(&xmppc,"Loading default account\n"); - if( account == NULL ) { - account = "default"; + if (!configfilefound) { + if(!g_error_matches(error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_KEY_NOT_FOUND)) { + logError(&xmppc, "Error loading key file: %s", error->message); + return -1; + } + } else { + if(jid == NULL && pwd == NULL) { + logInfo(&xmppc,"Loading default account\n"); + if( account == NULL ) { + account = "default"; + } + jid = g_key_file_get_value (config_file, account, "jid" ,&error); + pwd = g_key_file_get_value (config_file, account, "pwd" ,&error); } - jid = g_key_file_get_value (config_file, account, "jid" ,&error); - pwd = g_key_file_get_value (config_file, account, "pwd" ,&error); } }