dav/finfo.c

changeset 618
4b34d12cf211
parent 614
e72d2b99b0f6
child 646
37a8bfae995e
--- a/dav/finfo.c	Sat Aug 10 19:54:37 2019 +0200
+++ b/dav/finfo.c	Sat Aug 10 21:32:07 2019 +0200
@@ -138,13 +138,13 @@
     char *hash = NULL;
     
     DavXmlNode *node = xml;
-    while(node) {
+    for(;node;node=node->next) {
         if(node->type == DAV_XML_ELEMENT) {
             if(!strcmp(node->name, "hash")) {
                 hash = dav_xml_getstring(node->children);
             } else if(!strcmp(node->name, "xattr")) {
                 char *xattr_name = dav_xml_get_attr(node, "name");
-                if(xattr_name) {
+                if(xattr_name) {                 
                     names = ucx_list_append(names, strdup(xattr_name));
                     
                     char *text = dav_xml_getstring(node->children);
@@ -165,8 +165,6 @@
                 }
             }
         }
-        
-        node = node->next;
     }
     
     XAttributes *attributes = NULL;
@@ -190,7 +188,11 @@
     return attributes;
 }
 
-XAttributes* file_get_attributes(const char *path) {
+XAttributes* file_get_attributes(
+        const char *path,
+        xattr_filter_func filter,
+        void *filterdata)
+{
     ssize_t nelm = 0;
     char **attributes = xattr_list(path, &nelm);
     if(nelm <= 0) {
@@ -206,6 +208,14 @@
     
     size_t nattr = 0;
     for(int i=0;i<nelm;i++) {
+        if(filter) {
+            // apply filter
+            if(!filter(attributes[i], filterdata)) {
+                // exclude attribute
+                continue;
+            }
+        }
+        
         ssize_t valuelen = 0;
         char *value = xattr_get(path, attributes[i], &valuelen);
         if(valuelen >= 0) {

mercurial