dav/finfo.c

changeset 618
4b34d12cf211
parent 614
e72d2b99b0f6
child 646
37a8bfae995e
equal deleted inserted replaced
617:1c995e93bf40 618:4b34d12cf211
136 size_t count = 0; 136 size_t count = 0;
137 137
138 char *hash = NULL; 138 char *hash = NULL;
139 139
140 DavXmlNode *node = xml; 140 DavXmlNode *node = xml;
141 while(node) { 141 for(;node;node=node->next) {
142 if(node->type == DAV_XML_ELEMENT) { 142 if(node->type == DAV_XML_ELEMENT) {
143 if(!strcmp(node->name, "hash")) { 143 if(!strcmp(node->name, "hash")) {
144 hash = dav_xml_getstring(node->children); 144 hash = dav_xml_getstring(node->children);
145 } else if(!strcmp(node->name, "xattr")) { 145 } else if(!strcmp(node->name, "xattr")) {
146 char *xattr_name = dav_xml_get_attr(node, "name"); 146 char *xattr_name = dav_xml_get_attr(node, "name");
147 if(xattr_name) { 147 if(xattr_name) {
148 names = ucx_list_append(names, strdup(xattr_name)); 148 names = ucx_list_append(names, strdup(xattr_name));
149 149
150 char *text = dav_xml_getstring(node->children); 150 char *text = dav_xml_getstring(node->children);
151 if(!text) { 151 if(!text) {
152 text = ""; 152 text = "";
163 163
164 count++; 164 count++;
165 } 165 }
166 } 166 }
167 } 167 }
168
169 node = node->next;
170 } 168 }
171 169
172 XAttributes *attributes = NULL; 170 XAttributes *attributes = NULL;
173 if(count > 0) { 171 if(count > 0) {
174 attributes = calloc(1, sizeof(XAttributes)); 172 attributes = calloc(1, sizeof(XAttributes));
188 } 186 }
189 } 187 }
190 return attributes; 188 return attributes;
191 } 189 }
192 190
193 XAttributes* file_get_attributes(const char *path) { 191 XAttributes* file_get_attributes(
192 const char *path,
193 xattr_filter_func filter,
194 void *filterdata)
195 {
194 ssize_t nelm = 0; 196 ssize_t nelm = 0;
195 char **attributes = xattr_list(path, &nelm); 197 char **attributes = xattr_list(path, &nelm);
196 if(nelm <= 0) { 198 if(nelm <= 0) {
197 return NULL; 199 return NULL;
198 } 200 }
204 206
205 DAV_SHA_CTX *sha256 = dav_hash_init(); 207 DAV_SHA_CTX *sha256 = dav_hash_init();
206 208
207 size_t nattr = 0; 209 size_t nattr = 0;
208 for(int i=0;i<nelm;i++) { 210 for(int i=0;i<nelm;i++) {
211 if(filter) {
212 // apply filter
213 if(!filter(attributes[i], filterdata)) {
214 // exclude attribute
215 continue;
216 }
217 }
218
209 ssize_t valuelen = 0; 219 ssize_t valuelen = 0;
210 char *value = xattr_get(path, attributes[i], &valuelen); 220 char *value = xattr_get(path, attributes[i], &valuelen);
211 if(valuelen >= 0) { 221 if(valuelen >= 0) {
212 dav_hash_update(sha256, attributes[i], strlen(attributes[i])); 222 dav_hash_update(sha256, attributes[i], strlen(attributes[i]));
213 dav_hash_update(sha256, value, valuelen); 223 dav_hash_update(sha256, value, valuelen);

mercurial