libidav/resource.c

changeset 587
3c917df041b8
parent 558
1a9e6a5c1e79
child 589
2514559a6367
--- 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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+    ucx_buffer_puts(content, "<D:prop xmlns:D=\"DAV:\">\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, "</D:prop>");
+    
+    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) {
+    
+}

mercurial