# HG changeset patch # User Olaf Wintermann # Date 1555934677 -7200 # Node ID 2514559a63670cc9611b84491cb1da1f5a319b8c # Parent 0cfe006fcad228bd69361e05f3270c6c9cdd477c add function for decrypting and parsing crypto-prop elements diff -r 0cfe006fcad2 -r 2514559a6367 libidav/resource.c --- a/libidav/resource.c Mon Apr 22 14:02:34 2019 +0200 +++ b/libidav/resource.c Mon Apr 22 14:04:37 2019 +0200 @@ -1341,5 +1341,62 @@ } UcxMap* parse_crypto_prop(DavSession *sn, DavXmlNode *node) { + if(!node || node->type != DAV_XML_TEXT || node->contentlength == 0) { + return NULL; + } + size_t len = 0; + char *dec_str = aes_decrypt(node->content, &len, sn->key); + + xmlDoc *doc = xmlReadMemory(dec_str, len, NULL, NULL, 0); + free(dec_str); + if(!doc) { + return NULL; + } + + int err = 0; + xmlNode *xml_root = xmlDocGetRootElement(doc); + if(xml_root) { + if( + !xml_root->ns || + !xstreq(xml_root->name, "prop") || + !xstreq(xml_root->ns->href, "DAV:")) + { + err = 1; + } + } else { + err = 1; + } + + if(err) { + xmlFreeDoc(doc); + return NULL; + } + + // ready to get the properties + UcxMap *map = ucx_map_new(32); + xmlNode *n = xml_root->children; + while(n) { + if(n->type == XML_ELEMENT_NODE && n->ns && n->ns->href) { + DavProperty *property = dav_session_malloc(sn, sizeof(DavProperty)); + property->name = dav_session_strdup(sn, (const char*)n->name); + property->ns = dav_session_malloc(sn, sizeof(DavNamespace)); + property->ns->name = dav_session_strdup(sn, (const char*)n->ns->href); + property->ns->prefix = n->ns->prefix ? + dav_session_strdup(sn, (const char*)n->ns->prefix) : NULL; + property->value = n->children ? dav_convert_xml(sn, n->children) : NULL; + + sstr_t key = dav_property_key(property->ns->name, property->name); + ucx_map_sstr_put(map, key, property); + free(key.ptr); + } + n = n->next; + } + + xmlFreeDoc(doc); + if(map->count == 0) { + ucx_map_free(map); + return NULL; + } + return map; }