diff -r b45719a52ea6 -r 3c917df041b8 libidav/resource.c --- a/libidav/resource.c Sun Apr 21 12:17:53 2019 +0200 +++ b/libidav/resource.c Mon Apr 22 12:54:31 2019 +0200 @@ -1287,3 +1287,59 @@ return 1; } } + +/* ----------------------------- crypto-prop ----------------------------- */ + +DavXmlNode* create_crypto_prop(DavSession *sn, UcxMap *properties) { + if(!sn->key) { + return NULL; + } + + UcxBuffer *content = ucx_buffer_new(NULL, 2048, UCX_BUFFER_AUTOEXTEND); + + // create an xml document containing all properties + UcxMap *nsmap = ucx_map_new(8); + ucx_map_cstr_put(nsmap, "DAV:", strdup("D")); + + ucx_buffer_puts(content, "\n"); + ucx_buffer_puts(content, "\n"); + + UcxMapIterator i = ucx_map_iterator(properties); + DavProperty *prop; + UCX_MAP_FOREACH(key, prop, i) { + DavXmlNode pnode; + pnode.type = DAV_XML_ELEMENT; + pnode.namespace = prop->ns->name; + pnode.name = prop->name; + pnode.prev = NULL; + pnode.next = NULL; + pnode.children = prop->value; + pnode.parent = NULL; + pnode.attributes = NULL; + pnode.content = NULL; + pnode.contentlength = 0; + + dav_print_node(content, (write_func)ucx_buffer_write, nsmap, &pnode); + ucx_buffer_putc(content, '\n'); + } + + ucx_buffer_puts(content, ""); + + ucx_map_free_content(nsmap, (ucx_destructor)free); + ucx_map_free(nsmap); + + // encrypt xml document + char *crypto_prop_content = aes_encrypt(content->space, content->size, sn->key); + ucx_buffer_free(content); + + DavXmlNode *ret = NULL; + if(crypto_prop_content) { + ret = dav_text_node(sn, crypto_prop_content); + free(crypto_prop_content); + } + return ret; +} + +UcxMap* parse_crypto_prop(DavSession *sn, DavXmlNode *node) { + +}