libidav/resource.c

branch
dav-2
changeset 881
64989511f6c3
parent 872
d24de29ad1fe
child 882
86e61b4ef708
--- a/libidav/resource.c	Mon Sep 08 10:31:08 2025 +0200
+++ b/libidav/resource.c	Mon Sep 08 11:39:54 2025 +0200
@@ -281,6 +281,35 @@
     return resource->href;
 }
 
+CxTreeIterator dav_resource_iterator(DavResource *res) {
+    return cx_tree_iterator(res, FALSE, offsetof(DavResource, children), offsetof(DavResource, next));
+}
+
+CxTreeVisitor dav_resource_visitor(DavResource *res) {
+    return cx_tree_visitor(res, offsetof(DavResource, children), offsetof(DavResource, next));
+}
+
+CxMap* dav_resource_map(DavResource *res) {
+    CxMap *map = cxHashMapCreate(res->session->mp->allocator, CX_STORE_POINTERS, 16);
+    if(!map) {
+        return NULL;
+    }
+    CxTreeIterator i = dav_resource_iterator(res);
+    int error = 0;
+    cx_foreach(DavResource *, res, i) {
+        if(cxMapPut(map, res->path, res)) {
+            error = 1;
+        }
+    }
+    if(!error) {
+        cxMapRehash(map);
+        return map;
+    } else {
+        cxMapFree(map);
+        return NULL;
+    }
+}
+
 void resource_add_prop(DavResource *res, const char *ns, const char *name, DavXmlNode *val) {
     DavSession *sn = res->session;
     

mercurial