diff -r 26a1d5b9d9d2 -r e3c0440bd599 dav/finfo.c --- a/dav/finfo.c Sun Mar 17 15:00:48 2019 +0100 +++ b/dav/finfo.c Sun Mar 17 18:11:31 2019 +0100 @@ -32,15 +32,17 @@ #include #include #include +#include #include #include +#include #include #include #include "libxattr.h" -uint32_t parse_finfo(const char *str, char **error) { +uint32_t parse_finfo_settings(const char *str, char **error) { scstr_t s = scstr(str); if(!sstrcmp(s, SC("*")) || !sstrcmp(s, SC("a")) || !sstrcmp(s, SC("all"))) { @@ -127,6 +129,65 @@ return 0; } +XAttributes* xml_get_attributes(DavXmlNode *xml) { + UcxList *names = NULL; + UcxList *values = NULL; + + size_t count = 0; + + char *hash = NULL; + + DavXmlNode *node = xml; + while(node) { + 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) { + names = ucx_list_append(names, strdup(xattr_name)); + + char *text = dav_xml_getstring(node->children); + if(!text) { + text = ""; + } + + int len = 0; + char *val = util_base64decode_len(text, &len); + + sstr_t *value = malloc(sizeof(sstr_t)); + value->ptr = val; + value->length = len; + + values = ucx_list_append(values, value); + + count++; + } + } + } + + node = node->next; + } + + XAttributes *attributes = NULL; + if(count > 0) { + attributes = calloc(1, sizeof(XAttributes)); + attributes->hash = hash ? strdup(hash) : NULL; + attributes->nattr = count; + int i=0; + UCX_FOREACH(elm, names) { + attributes->names[i] = elm->data; + i++; + } + i=0; + UCX_FOREACH(elm, values) { + attributes->values[i] = *(sstr_t*)elm->data; + i++; + } + } + return attributes; +} + XAttributes* file_get_attributes(const char *path) { ssize_t nelm = 0; char **attributes = xattr_list(path, &nelm); @@ -212,3 +273,44 @@ } free(xattr); } + +char* get_xattr_hash(DavXmlNode *finfo) { + DavXmlNode *node = finfo; + while(node) { + if(node->type == DAV_XML_ELEMENT && !strcmp(node->name, "hash")) { + return dav_xml_getstring(node->children); + } + node = node->next; + } + return NULL; +} + +void finfo_get_values(DavXmlNode *xml, FileInfo *outval) { + memset(outval, 0, sizeof(FileInfo)); + DavXmlNode *node = xml; + while(node) { + if(node->type == DAV_XML_ELEMENT) { + if(!strcmp(node->name, "mtime")) { + char *mtime = dav_xml_getstring(node->children); + if(mtime) { + outval->last_modified = util_parse_lastmodified(mtime); + outval->date_set = TRUE; + } + } else if(!strcmp(node->name, "mode")) { + char *mode_str = dav_xml_getstring(node->children); + if(mode_str) { + char *end; + errno = 0; + long int mode = strtol(mode_str, &end, 8); + if(errno == 0) { + mode &= 07777; + outval->mode = mode; + outval->mode_set = TRUE; + } + } + } + } + node = node->next; + } + +}