diff -r 74a6e2d4fb1f -r 40be8db6fe45 libidav/xml.c --- a/libidav/xml.c Sun Aug 08 16:50:36 2021 +0200 +++ b/libidav/xml.c Mon Aug 09 17:22:21 2021 +0200 @@ -240,16 +240,52 @@ return NULL; } -DavXmlNode* dav_text_node(DavSession *sn, char *text) { +DavXmlNode* dav_text_node(DavSession *sn, const char *text) { UcxMempool *mp = sn->mp; DavXmlNode *newxn = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode)); newxn->type = DAV_XML_TEXT; - sstr_t content = sstrdup_a(mp->allocator, sstr(text)); + sstr_t content = scstrdup_a(mp->allocator, scstr(text)); newxn->content = content.ptr; newxn->contentlength = content.length; return newxn; } +DavXmlNode* dav_text_element(DavSession *sn, const char *ns, const char *name, const char *text) { + UcxMempool *mp = sn->mp; + DavXmlNode *newelm = ucx_mempool_calloc(mp, 1, sizeof(DavXmlNode)); + newelm->type = DAV_XML_ELEMENT; + newelm->namespace = scstrdup_a(mp->allocator, scstr(ns)).ptr; + newelm->name = scstrdup_a(mp->allocator, scstr(name)).ptr; + newelm->children = dav_text_node(sn, text); + return newelm; +} + +static void dav_free_xml_node_a(UcxAllocator *a, DavXmlNode *node) { + if(node->name) alfree(a, node->name); + if(node->namespace) alfree(a, node->namespace); + if(node->content) alfree(a, node->content); + DavXmlAttr *attr = node->attributes; + while(attr) { + if(attr->name) alfree(a, attr->name); + if(attr->value) alfree(a, attr->value); + attr = attr->next; + } + DavXmlNode *children = node->children; + while(children) { + DavXmlNode *next_ch = children->next; + dav_free_xml_node_a(a, children); + children = next_ch; + } + alfree(a, node); +} + +void dav_free_xml_node_sn(DavSession *sn, DavXmlNode *node) { + dav_free_xml_node_a(sn->mp->allocator, node); +} + +void dav_free_xml_node(DavXmlNode *node) { + dav_free_xml_node_a(ucx_default_allocator(), node); +} DavXmlAttr* dav_copy_xml_attr(DavXmlAttr *attr) { if(!attr) {