application/config.c

changeset 50
9c25e2616bfa
parent 49
2f71f4ee247a
--- a/application/config.c	Sun Oct 06 18:18:04 2024 +0200
+++ b/application/config.c	Sun Oct 06 18:43:06 2024 +0200
@@ -118,42 +118,47 @@
     return cx_mutstrn(buf.space, buf.size);
 }
 
-int load_config(DavContext* ctx) {
+int load_config(DavContext *ctx) {
     context = ctx;
     // TODO: free the config somewhere
     repos = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
     keys = cxHashMapCreate(cxDefaultAllocator, CX_STORE_POINTERS, 16);
-
-    char* pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
+    
+    char *pwfile = util_concat_path(ENV_HOME, ".dav/secrets.crypt");
     pstore = pwdstore_open(pwfile);
     free(pwfile);
-
-    char* file = util_concat_path(ENV_HOME, ".dav/config.xml");
-
+    
+    char *file = util_concat_path(ENV_HOME, ".dav/config.xml");
+    
     struct stat s;
-    if (stat(file, &s)) {
-        switch (errno) {
-        case ENOENT: {
-            return 0;
-        }
-        default: {
-            perror("Cannot load config.xml");
-        }
+    if(stat(file, &s)) {
+        switch(errno) {
+            case ENOENT: {
+                davconfig = dav_config_new(NULL);
+                return 0;
+            }
+            default: {
+                perror("Cannot load config.xml");
+            }
         }
         return 1;
     }
-
+    
     cxmutstr config_content = config_load_file(file);
     int config_error;
     davconfig = dav_config_load(config_content, &config_error);
     free(config_content.ptr);
     free(file);
-
-    if (!davconfig) {
+    
+    if(!davconfig) {
         fprintf(stderr, "Cannot load config.xml\n");
         return 1;
     }
-
+    
+    if(dav_config_register_namespaces(davconfig, ctx)) {
+        return 1;
+    }
+    
     return dav_config_register_keys(davconfig, ctx, load_key_file);
 }
 

mercurial