added some dav api functions

Tue, 20 Aug 2013 11:34:44 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 20 Aug 2013 11:34:44 +0200
changeset 26
146171b57e69
parent 25
29f77f1fdbf3
child 27
e584c351b402

added some dav api functions

dav/main.c file | annotate | diff | comparison | revisions
dav/webdav.c file | annotate | diff | comparison | revisions
dav/webdav.h file | annotate | diff | comparison | revisions
--- a/dav/main.c	Mon Aug 19 17:42:40 2013 +0200
+++ b/dav/main.c	Tue Aug 20 11:34:44 2013 +0200
@@ -591,7 +591,6 @@
     }
     
     DavResource *res = dav_query(sn, "get - from %s", path);
-    sn->error = DAV_NOT_FOUND;
     if(!res) {
         if(sn->error == DAV_NOT_FOUND) {
             res = dav_resource_new(sn, path);
--- a/dav/webdav.c	Mon Aug 19 17:42:40 2013 +0200
+++ b/dav/webdav.c	Tue Aug 20 11:34:44 2013 +0200
@@ -437,6 +437,7 @@
         child->prev = NULL;
         parent->children = child;
     }
+    child->parent = parent;
 }
 
 void resource_set_info(DavResource *res, char *href_str) {
@@ -572,16 +573,66 @@
     return 0;
 }
 
+void get_property_namespace(
+        DavContext *ctx,
+        char *prefixed_name,
+        char **ns,
+        char **name)
+{
+    char *pname = strchr(prefixed_name, ':');
+    char *pns = "DAV:";
+    if(pname) {
+        DavNamespace *ns = dav_get_namespace_s(
+                ctx,
+                sstrn(prefixed_name, pname-prefixed_name));
+        pns = ns->name;
+        pname++;
+    } else {
+        pname = prefixed_name;
+    }
+    *ns = pns;
+    *name = pname;
+}
+
+char* dav_get_property(DavResource *res, char *name) {
+    char *pns;
+    char *pname;
+    get_property_namespace(res->session->context, name, &pns, &pname);
+    return dav_get_property_ns(res, pns, pname);
+}
+
 char* dav_get_property_ns(DavResource *res, char *ns, char *name) {
     char *property = resource_get_property(res, ns, name);
-    if(property && res->data->remove) {
-        // TODO
-    } else if(!property && res->data->set) {
-        // TODO
+    // resource_get_property only returns persistent properties
+    // check the remove and set list
+    if(property) {
+        // if the property is in the remove list, we return NULL
+        UCX_FOREACH(elm, res->data->remove) {
+            DavProperty *p = elm->data;
+            if(!strcmp(p->name, name) && !strcmp(p->ns->name, ns)) {
+                return NULL;
+            }
+        }
     }
+    // the set list contains property updates
+    // we return an updated property if possible
+    UCX_FOREACH(elm, res->data->set) {
+        DavProperty *p = elm->data;
+        if(!strcmp(p->name, name) && !strcmp(p->ns->name, ns)) {
+            return p->value;
+        }
+    }
+    // no property update
     return property;
 }
 
+void dav_set_property(DavResource *res, char *name, char *value) {
+    char *pns;
+    char *pname;
+    get_property_namespace(res->session->context, name, &pns, &pname);
+    dav_set_property_ns(res, pns, pname, value);
+}
+
 void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value) {
     UcxAllocator *a = res->session->allocator;
     
@@ -596,7 +647,14 @@
     res->data->set = ucx_list_append_a(a, res->data->set, property);
 }
 
-void dav_remove_property_ns(DavResource *res, char *ns, char *name, char *value) {
+void dav_remove_property(DavResource *res, char *name) {
+    char *pns;
+    char *pname;
+    get_property_namespace(res->session->context, name, &pns, &pname);
+    dav_remove_property_ns(res, pns, pname);
+}
+
+void dav_remove_property_ns(DavResource *res, char *ns, char *name) {
     UcxAllocator *a = res->session->allocator;
     
     DavProperty *property = a->malloc(a->pool, sizeof(DavProperty));
--- a/dav/webdav.h	Mon Aug 19 17:42:40 2013 +0200
+++ b/dav/webdav.h	Tue Aug 20 11:34:44 2013 +0200
@@ -172,9 +172,18 @@
 int dav_load(DavResource *res);
 int dav_store(DavResource *res);
 
+void get_property_namespace(
+        DavContext *ctx,
+        char *prefixed_name,
+        char **ns,
+        char **name);
+
+char* dav_get_property(DavResource *res, char *name);
 char* dav_get_property_ns(DavResource *res, char *ns, char *name);
+void dav_set_property(DavResource *res, char *name, char *value);
 void dav_set_property_ns(DavResource *res, char *ns, char *name, char *value);
-void dav_remove_property_ns(DavResource *res, char *ns, char *name, char *value);
+void dav_remove_property(DavResource *res, char *name);
+void dav_remove_property_ns(DavResource *res, char *ns, char *name);
 
 
 

mercurial