From 1714eeff5b381bd53e942e6d8a3de960e7a22b5a Mon Sep 17 00:00:00 2001 From: DebXWoody <stefan@debxwoody.de> Date: Sun, 19 Apr 2020 18:57:29 +0200 Subject: [PATCH] Use a xmppc config file for JID and PWD Config file ~/.config/xmppc.conf Issue: #2 --- src/main.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main.c b/src/main.c index a08e1ba..dcae03e 100644 --- a/src/main.c +++ b/src/main.c @@ -133,6 +133,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <glib.h> #include <strophe.h> #include "xmppc.h" @@ -370,6 +371,30 @@ 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); + + 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"); + jid = g_key_file_get_value (config_file, "default", "jid" ,&error); + pwd = g_key_file_get_value (config_file, "default", "pwd" ,&error); + } + } + int paramc = argc- optind; char* paramv[paramc];