96 char *value = util_xml_get_text(node); |
96 char *value = util_xml_get_text(node); |
97 cbool->value = util_getboolean(value); |
97 cbool->value = util_getboolean(value); |
98 } |
98 } |
99 |
99 |
100 |
100 |
|
101 DavConfig* dav_config_new(xmlDoc *doc) { |
|
102 CxMempool *cfg_mp = cxMempoolCreate(128, NULL); |
|
103 DavConfig *config = cxMalloc(cfg_mp->allocator, sizeof(DavConfig)); |
|
104 memset(config, 0, sizeof(DavConfig)); |
|
105 config->mp = cfg_mp; |
|
106 |
|
107 if(!doc) { |
|
108 doc = xmlNewDoc(BAD_CAST "1.0"); |
|
109 xmlNode *root = xmlNewNode(NULL, BAD_CAST "configuration"); |
|
110 xmlDocSetRootElement(doc, root); |
|
111 } |
|
112 config->doc = doc; |
|
113 |
|
114 return config; |
|
115 } |
|
116 |
101 DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error) { |
117 DavConfig* dav_config_load(cxmutstr xmlfilecontent, int *error) { |
102 xmlDoc *doc = xmlReadMemory(xmlfilecontent.ptr, xmlfilecontent.length, NULL, NULL, 0); |
118 xmlDoc *doc = xmlReadMemory(xmlfilecontent.ptr, xmlfilecontent.length, NULL, NULL, 0); |
103 if(!doc) { |
119 if(!doc) { |
104 if(error) { |
120 if(error) { |
105 *error = DAV_CONFIG_ERROR_XML; |
121 *error = DAV_CONFIG_ERROR_XML; |
106 } |
122 } |
107 return NULL; |
123 return NULL; |
108 } |
124 } |
109 |
125 |
110 CxMempool *cfg_mp = cxMempoolCreate(128, NULL); |
126 DavConfig *config = dav_config_new(doc); |
|
127 CxMempool *cfg_mp = config->mp; |
111 cxMempoolRegister(cfg_mp, doc, (cx_destructor_func)xmlFreeDoc); |
128 cxMempoolRegister(cfg_mp, doc, (cx_destructor_func)xmlFreeDoc); |
112 DavConfig *config = cxMalloc(cfg_mp->allocator, sizeof(DavConfig)); |
|
113 memset(config, 0, sizeof(DavConfig)); |
|
114 config->mp = cfg_mp; |
|
115 config->doc = doc; |
|
116 |
129 |
117 DavCfgRepository *repos_begin = NULL; |
130 DavCfgRepository *repos_begin = NULL; |
118 DavCfgRepository *repos_end = NULL; |
131 DavCfgRepository *repos_end = NULL; |
119 DavCfgKey *keys_begin = NULL; |
132 DavCfgKey *keys_begin = NULL; |
120 DavCfgKey *keys_end = NULL; |
133 DavCfgKey *keys_end = NULL; |
471 repo->url.value = cx_strdup_a(config->mp->allocator, newurl); |
484 repo->url.value = cx_strdup_a(config->mp->allocator, newurl); |
472 } |
485 } |
473 |
486 |
474 void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password) { |
487 void dav_repository_set_auth(DavConfig *config, DavCfgRepository *repo, cxstring user, cxstring password) { |
475 const CxAllocator *a = config->mp->allocator; |
488 const CxAllocator *a = config->mp->allocator; |
476 repo->user.value = cx_strdup_a(a, user); |
489 if(user.length > 0) { |
477 char *pwenc = util_base64encode(password.ptr, password.length); |
490 repo->user.value = cx_strdup_a(a, user); |
478 repo->password.value = cx_strdup_a(a, cx_str(pwenc)); |
491 } |
479 free(pwenc); |
492 if(password.length > 0) { |
|
493 char *pwenc = util_base64encode(password.ptr, password.length); |
|
494 repo->password.value = cx_strdup_a(a, cx_str(pwenc)); |
|
495 free(pwenc); |
|
496 } |
480 } |
497 } |
481 |
498 |
482 cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo) { |
499 cxmutstr dav_repository_get_decodedpassword(DavCfgRepository *repo) { |
483 cxmutstr pw = { NULL, 0 }; |
500 cxmutstr pw = { NULL, 0 }; |
484 if(repo->password.value.ptr) { |
501 if(repo->password.value.ptr) { |