libidav/config.c

changeset 826
b6e9fd3f1951
parent 823
04c60a353331
child 827
d9928f11970f
--- a/libidav/config.c	Tue Jul 23 14:40:20 2024 +0200
+++ b/libidav/config.c	Wed Jul 24 23:45:31 2024 +0200
@@ -98,6 +98,20 @@
 }
 
 
+DavConfig* dav_config_new(void) {
+    CxMempool *cfg_mp = cxMempoolCreate(128, NULL);
+    DavConfig *config = cxMalloc(cfg_mp->allocator, sizeof(DavConfig));
+    memset(config, 0, sizeof(DavConfig));
+    config->mp = cfg_mp;
+    
+    xmlDoc *doc = xmlNewDoc(BAD_CAST "1.0");
+    xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration");
+    xmlDocSetRootElement(doc, root);
+    config->doc = doc;
+    
+    return config;
+}
+
 DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error) {
     xmlDoc *doc = xmlReadMemory(xmlfilecontent.ptr, xmlfilecontent.length, NULL, NULL, 0);
     if(!doc) {
@@ -107,12 +121,9 @@
         return NULL;
     }
     
-    CxMempool *cfg_mp = cxMempoolCreate(128, NULL);
+    DavConfig *config = dav_config_new();
+    CxMempool *cfg_mp = config->mp;
     cxMempoolRegister(cfg_mp, doc, (cx_destructor_func)xmlFreeDoc);
-    DavConfig *config = cxMalloc(cfg_mp->allocator, sizeof(DavConfig));
-    memset(config, 0, sizeof(DavConfig));
-    config->mp = cfg_mp;
-    config->doc = doc;
     
     DavCfgRepository *repos_begin = NULL;
     DavCfgRepository *repos_end = NULL;
@@ -723,6 +734,9 @@
 
 
 DavCfgRepository* dav_config_get_repository(DavConfig *config, cxstring name) {
+    if(!config) {
+        return NULL;
+    }
     DavCfgRepository *repo = config->repositories;
     while(repo) {
         if(!cx_strcmp(cx_strcast(repo->name.value), name)) {

mercurial