libidav/methods.c

changeset 231
f3119e749549
parent 227
bf485439222a
child 236
6b4ce32d0c4e
--- a/libidav/methods.c	Mon Mar 21 16:37:10 2016 +0100
+++ b/libidav/methods.c	Tue Mar 22 11:24:14 2016 +0100
@@ -377,10 +377,8 @@
                         if(n->type == XML_ELEMENT_NODE) {
                             properties = ucx_list_append(properties, n);
                             if(xstreq(n->name, "resourcetype")) {
-                                xmlNode *rsnode = n->children;
-                                if(rsnode && rsnode->type == XML_ELEMENT_NODE) {
-                                    // TODO: check content
-                                    iscollection = 1;
+                                if(parse_resource_type(n)) {
+                                    iscollection = TRUE;
                                 }
                             } else if(xstreq(n->ns->href, DAV_NS)) {
                                 if(xstreq(n->name, "crypto-name")) {
@@ -612,11 +610,8 @@
                         if(n->type == XML_ELEMENT_NODE) {
                             properties = ucx_list_append(properties, n);
                             if(xstreq(n->name, "resourcetype")) {
-                                xmlNode *rsnode = n->children;
-                                if(rsnode && rsnode->type == XML_ELEMENT_NODE) {
-                                    // TODO: this is a ugly lazy hack
-                                    //resource_add_property(res, "DAV:", (char*)n->name, "collection");
-                                    iscollection = 1;
+                                if(parse_resource_type(n)) {
+                                    iscollection = TRUE;
                                 }
                             } else if(xstreq(n->ns->href, DAV_NS)) {
                                 if(xstreq(n->name, "crypto-name")) {
@@ -704,6 +699,21 @@
     res->lastmodified = util_parse_lastmodified(lm);
 }
 
+int parse_resource_type(xmlNode *node) {
+    int collection = FALSE;
+    xmlNode *c = node->children;
+    while(c) {
+        if(c->type == XML_ELEMENT_NODE) {
+            if(xstreq(c->ns->href, "DAV:") && xstreq(c->name, "collection")) {
+                collection = TRUE;
+                break;
+            }
+        }
+        c = c->next;
+    }
+    return collection;
+}
+
 
 /* ----------------------------- PROPPATCH ----------------------------- */
 

mercurial