application/config.c

changeset 60
ee4e4742391e
parent 55
1ce14068ef31
--- a/application/config.c	Wed Oct 23 21:46:43 2024 +0200
+++ b/application/config.c	Sun Oct 27 18:24:37 2024 +0100
@@ -162,6 +162,36 @@
     return dav_config_register_keys(davconfig, ctx, load_key_file);
 }
 
+DavConfig* load_config_file(void) {
+    char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
+    
+    struct stat s;
+    if(stat(file, &s)) {
+        switch(errno) {
+            case ENOENT: {
+                davconfig = dav_config_new(NULL);
+                return NULL;
+            }
+            default: {
+                perror("Cannot load config.xml");
+            }
+        }
+        return NULL;
+    }
+    
+    cxmutstr config_content = config_load_file(file);
+    int config_error;
+    DavConfig *cfg = dav_config_load(config_content, &config_error);
+    free(config_content.ptr);
+    free(file);
+    return cfg;
+}
+
+
+void set_config(DavConfig *cfg) {
+    davconfig = cfg;
+}
+
 DavConfig* get_config(void) {
     return davconfig;
 }

mercurial