add func for creating the content of crypto-prop properties

Mon, 22 Apr 2019 12:54:31 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 22 Apr 2019 12:54:31 +0200
changeset 587
3c917df041b8
parent 586
b45719a52ea6
child 588
0cfe006fcad2

add func for creating the content of crypto-prop properties

crypto-prop is a proposed property for storing encrypted properties
create_crypto_prop() is used to create a base64 encoded, encrypted xml document, containing properties

dav/main.c file | annotate | diff | comparison | revisions
libidav/resource.c file | annotate | diff | comparison | revisions
libidav/resource.h file | annotate | diff | comparison | revisions
libidav/webdav.c file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
test/bin-test/test-dav-sync-push1.sh file | annotate | diff | comparison | revisions
--- a/dav/main.c	Sun Apr 21 12:17:53 2019 +0200
+++ b/dav/main.c	Mon Apr 22 12:54:31 2019 +0200
@@ -67,6 +67,7 @@
 //include <libidav/davqlparser.h>
 //include <libidav/davqlexec.h>
 //include "tags.h"
+//include <libidav/resource.h>
 
 void test() {
     
--- 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) {
+    
+}
--- a/libidav/resource.h	Sun Apr 21 12:17:53 2019 +0200
+++ b/libidav/resource.h	Mon Apr 22 12:54:31 2019 +0200
@@ -44,6 +44,11 @@
     UcxList *remove;
     
     /*
+     * properties encapsulated in a crypto-prop property or NULL
+     */
+    UcxMap *crypto_properties;
+    
+    /*
      * char* or stream
      */
     void      *content;
@@ -83,6 +88,9 @@
 
 sstr_t dav_property_key_a(UcxAllocator *a, const char *ns, const char *name);
 
+DavXmlNode* create_crypto_prop(DavSession *sn, UcxMap *properties);
+UcxMap* parse_crypto_prop(DavSession *sn, DavXmlNode *node);
+
 #ifdef	__cplusplus
 }
 #endif
--- a/libidav/webdav.c	Sun Apr 21 12:17:53 2019 +0200
+++ b/libidav/webdav.c	Mon Apr 22 12:54:31 2019 +0200
@@ -41,7 +41,7 @@
 #include "davqlexec.h"
 
 
-DavContext* dav_context_new() {
+DavContext* dav_context_new(void) {
     // initialize
     DavContext *context = calloc(1, sizeof(DavContext));
     if(!context) {
--- a/libidav/webdav.h	Sun Apr 21 12:17:53 2019 +0200
+++ b/libidav/webdav.h	Mon Apr 22 12:54:31 2019 +0200
@@ -221,7 +221,7 @@
     DavXmlAttr *next;
 };
 
-DavContext* dav_context_new();
+DavContext* dav_context_new(void);
 void dav_context_destroy(DavContext *ctx);
 
 void dav_context_add_key(DavContext *context, DavKey *key);
--- a/test/bin-test/test-dav-sync-push1.sh	Sun Apr 21 12:17:53 2019 +0200
+++ b/test/bin-test/test-dav-sync-push1.sh	Mon Apr 22 12:54:31 2019 +0200
@@ -229,7 +229,7 @@
 
 # don't test if there was a single delete for each collection
 # and don't check if the delete counter has a specific value
-# because maybe there will be some optimizations 
+# because there will be some optimizations maybe
 check_tmpout "0 files pushed" "push8: wrong push counter"
 check_tmpout "0 conflicts" "push8: wrong conflict counter"
 check_tmpout "0 errors" "push8: wrong error counter"

mercurial