# HG changeset patch # User Olaf Wintermann # Date 1726244464 -7200 # Node ID d9928f11970f7ce586994fb7f7c2e6b32642a0e8 # Parent b6e9fd3f1951dfb6d40554e147cfd19808c68339 fix load_config stores wrong xml doc pointer in the config object diff -r b6e9fd3f1951 -r d9928f11970f dav/config.c --- a/dav/config.c Wed Jul 24 23:45:31 2024 +0200 +++ b/dav/config.c Fri Sep 13 18:21:04 2024 +0200 @@ -136,7 +136,7 @@ if(stat(file, &s)) { switch(errno) { case ENOENT: { - davconfig = dav_config_new(); + davconfig = dav_config_new(NULL); return 0; } default: { diff -r b6e9fd3f1951 -r d9928f11970f dav/main.c --- a/dav/main.c Wed Jul 24 23:45:31 2024 +0200 +++ b/dav/main.c Fri Sep 13 18:21:04 2024 +0200 @@ -2449,7 +2449,10 @@ repo->name.value = cx_strdup_a(a, cx_str(name)); repo->url.value = cx_strdup_a(a, cx_str(url)); - dav_repository_set_auth(config, repo, cx_str(user), cx_str(password)); + + cxstring user_s = user ? cx_str(user) : cx_strn(NULL, 0); + cxstring password_s = password ? cx_str(password) : cx_strn(NULL, 0); + dav_repository_set_auth(config, repo, user_s, password_s); dav_config_add_repository(config, repo); diff -r b6e9fd3f1951 -r d9928f11970f libidav/config.c --- a/libidav/config.c Wed Jul 24 23:45:31 2024 +0200 +++ b/libidav/config.c Fri Sep 13 18:21:04 2024 +0200 @@ -98,15 +98,17 @@ } -DavConfig* dav_config_new(void) { +DavConfig* dav_config_new(xmlDoc *doc) { 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); + if(!doc) { + doc = xmlNewDoc(BAD_CAST "1.0"); + xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration"); + xmlDocSetRootElement(doc, root); + } config->doc = doc; return config; @@ -121,7 +123,7 @@ return NULL; } - DavConfig *config = dav_config_new(); + DavConfig *config = dav_config_new(doc); CxMempool *cfg_mp = config->mp; cxMempoolRegister(cfg_mp, doc, (cx_destructor_func)xmlFreeDoc); @@ -484,10 +486,14 @@ void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password) { const CxAllocator *a = config->mp->allocator; - repo->user.value = cx_strdup_a(a, user); - char *pwenc = util_base64encode(password.ptr, password.length); - repo->password.value = cx_strdup_a(a, cx_str(pwenc)); - free(pwenc); + if(user.length > 0) { + repo->user.value = cx_strdup_a(a, user); + } + if(password.length > 0) { + char *pwenc = util_base64encode(password.ptr, password.length); + repo->password.value = cx_strdup_a(a, cx_str(pwenc)); + free(pwenc); + } } cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo) { diff -r b6e9fd3f1951 -r d9928f11970f libidav/config.h --- a/libidav/config.h Wed Jul 24 23:45:31 2024 +0200 +++ b/libidav/config.h Fri Sep 13 18:21:04 2024 +0200 @@ -160,7 +160,7 @@ DAV_CONFIG_ERROR_XML = 0 }; -DavConfig* dav_config_new(void); +DavConfig* dav_config_new(xmlDoc *doc); DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error);