# HG changeset patch # User Olaf Wintermann # Date 1555930471 -7200 # Node ID 3c917df041b8c7078431e372e7266410962a5a1c # Parent b45719a52ea6bb781f963494e8a490c784ac3203 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 diff -r b45719a52ea6 -r 3c917df041b8 dav/main.c --- 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 //include //include "tags.h" +//include void test() { 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) { + +} diff -r b45719a52ea6 -r 3c917df041b8 libidav/resource.h --- 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 diff -r b45719a52ea6 -r 3c917df041b8 libidav/webdav.c --- 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) { diff -r b45719a52ea6 -r 3c917df041b8 libidav/webdav.h --- 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); diff -r b45719a52ea6 -r 3c917df041b8 test/bin-test/test-dav-sync-push1.sh --- 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"