add new api for encrypted properties

Sat, 15 Jun 2019 11:01:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 15 Jun 2019 11:01:37 +0200
changeset 605
bbc66c72661a
parent 604
c7bedb422d63
child 606
aa49966e4e85

add new api for encrypted properties

libidav/resource.c file | annotate | diff | comparison | revisions
libidav/resource.h file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
--- a/libidav/resource.c	Sat Jun 01 10:55:32 2019 +0200
+++ b/libidav/resource.c	Sat Jun 15 11:01:37 2019 +0200
@@ -474,6 +474,20 @@
     return property;
 }
 
+static DavProperty* createprop(DavSession *sn, const char *ns, const char *name) {
+    DavProperty *property = dav_session_malloc(sn, sizeof(DavProperty));
+    property->name = dav_session_strdup(sn, name);
+    property->value = NULL;
+    
+    DavNamespace *namespace = dav_session_malloc(sn, sizeof(DavNamespace));
+    namespace->prefix = NULL;
+    namespace->name = dav_session_strdup(sn, ns);
+    
+    property->ns = namespace;
+    
+    return property;
+}
+
 void dav_set_string_property(DavResource *res, char *name, char *value) {
     char *pns;
     char *pname;
@@ -485,19 +499,9 @@
     UcxAllocator *a = res->session->mp->allocator;
     DavResourceData *data = res->data;
     
-    DavProperty *property = dav_session_malloc(
-            res->session,
-            sizeof(DavProperty));
-    property->name = dav_session_strdup(res->session, name);
+    DavProperty *property = createprop(res->session, ns, name);
     property->value = dav_text_node(res->session, value);
     
-    DavNamespace *namespace = dav_session_malloc(
-            res->session,
-            sizeof(DavNamespace));
-    namespace->prefix = NULL;
-    namespace->name = dav_session_strdup(res->session, ns);
-    property->ns = namespace;
-    
     data->set = ucx_list_append_a(a, data->set, property);
 }
 
@@ -512,19 +516,9 @@
     UcxAllocator *a = res->session->mp->allocator;
     DavResourceData *data = res->data;
     
-    DavProperty *property = dav_session_malloc(
-            res->session,
-            sizeof(DavProperty));
-    property->name = dav_session_strdup(res->session, name);
+    DavProperty *property = createprop(res->session, ns, name);
     property->value = value; // TODO: copy node?
     
-    DavNamespace *namespace = dav_session_malloc(
-            res->session,
-            sizeof(DavNamespace));
-    namespace->prefix = NULL;
-    namespace->name = dav_session_strdup(res->session, ns);
-    property->ns = namespace;
-    
     data->set = ucx_list_append_a(a, data->set, property);
 }
 
@@ -539,22 +533,40 @@
     DavResourceData *data = res->data;
     UcxAllocator *a = res->session->mp->allocator;
     
-    DavProperty *property = dav_session_malloc(
-            res->session,
-            sizeof(DavProperty));
-    property->name = sstrdup_a(a, sstr(name)).ptr;
-    property->value = NULL;
-    
-    DavNamespace *namespace = dav_session_malloc(
-            res->session,
-            sizeof(DavNamespace));
-    namespace->prefix = NULL;
-    namespace->name = sstrdup_a(a, sstr(ns)).ptr;
-    property->ns = namespace;
+    DavProperty *property = createprop(res->session, ns, name);
     
     data->remove = ucx_list_append_a(a, data->remove, property);
 }
 
+void dav_set_encrypted_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value) {
+    UcxAllocator *a = res->session->mp->allocator;
+    DavResourceData *data = res->data;
+    
+    DavProperty *property = createprop(res->session, ns, name);
+    property->value = value; // TODO: copy node?
+    
+    data->crypto_set = ucx_list_append_a(a, data->crypto_set, property);
+}
+
+void dav_set_encrypted_string_property_ns(DavResource *res, char *ns, char *name, char *value) {
+    UcxAllocator *a = res->session->mp->allocator;
+    DavResourceData *data = res->data;
+    
+    DavProperty *property = createprop(res->session, ns, name);
+    property->value = dav_text_node(res->session, value);
+    
+    data->crypto_set = ucx_list_append_a(a, data->crypto_set, property);
+}
+
+void dav_remove_encrypted_property_ns(DavResource *res, char *ns, char *name) {
+    DavResourceData *data = res->data;
+    UcxAllocator *a = res->session->mp->allocator;
+    
+    DavProperty *property = createprop(res->session, ns, name);
+    
+    data->crypto_remove = ucx_list_append_a(a, data->crypto_remove, property);
+}
+
 static int compare_propname(const void *a, const void *b) {
     const DavPropName *p1 = a;
     const DavPropName *p2 = b;
--- a/libidav/resource.h	Sat Jun 01 10:55:32 2019 +0200
+++ b/libidav/resource.h	Sat Jun 15 11:01:37 2019 +0200
@@ -42,6 +42,8 @@
     UcxMap  *properties;
     UcxList *set;
     UcxList *remove;
+    UcxList *crypto_set;
+    UcxList *crypto_remove;
     
     /*
      * properties encapsulated in a crypto-prop property or NULL
--- a/libidav/webdav.h	Sat Jun 01 10:55:32 2019 +0200
+++ b/libidav/webdav.h	Sat Jun 15 11:01:37 2019 +0200
@@ -306,6 +306,9 @@
 void dav_set_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value);
 void dav_remove_property(DavResource *res, char *name);
 void dav_remove_property_ns(DavResource *res, char *ns, char *name);
+void dav_set_encrypted_property_ns(DavResource *res, char *ns, char *name, DavXmlNode *value);
+void dav_set_encrypted_string_property_ns(DavResource *res, char *ns, char *name, char *value);
+void dav_remove_encrypted_property_ns(DavResource *res, char *ns, char *name);
 
 DavPropName* dav_get_property_names(DavResource *res, size_t *count);
 

mercurial