# HG changeset patch # User Olaf Wintermann # Date 1721857531 -7200 # Node ID b6e9fd3f1951dfb6d40554e147cfd19808c68339 # Parent ca568c209dfd3b0a455dfbd595b5a79bd963dd0e fix dav add-repo crash in case .dav/config.xml doesn't exist diff -r ca568c209dfd -r b6e9fd3f1951 dav/config.c --- a/dav/config.c Tue Jul 23 14:40:20 2024 +0200 +++ b/dav/config.c Wed Jul 24 23:45:31 2024 +0200 @@ -136,6 +136,7 @@ if(stat(file, &s)) { switch(errno) { case ENOENT: { + davconfig = dav_config_new(); return 0; } default: { diff -r ca568c209dfd -r b6e9fd3f1951 libidav/config.c --- 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)) { diff -r ca568c209dfd -r b6e9fd3f1951 libidav/config.h --- a/libidav/config.h Tue Jul 23 14:40:20 2024 +0200 +++ b/libidav/config.h Wed Jul 24 23:45:31 2024 +0200 @@ -160,6 +160,8 @@ DAV_CONFIG_ERROR_XML = 0 }; +DavConfig* dav_config_new(void); + DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error); void dav_config_free(DavConfig *config);