# HG changeset patch # User Olaf Wintermann # Date 1561214212 -7200 # Node ID 5dc7fe41e8f85ad63afbc358f7453485a832b61b # Parent aa49966e4e851a56cfe28e6d0ced60ad82af245b move some properties to new namespace for properties encryption we need to decide which props must be encrypted and the plan is, to decide by namespace diff -r aa49966e4e85 -r 5dc7fe41e8f8 dav/finfo.c --- a/dav/finfo.c Sun Jun 16 13:14:24 2019 +0200 +++ b/dav/finfo.c Sat Jun 22 16:36:52 2019 +0200 @@ -101,7 +101,7 @@ char str[32]; struct tm *date = gmtime(&s->st_mtime); strftime(str, 32, "%a, %d %b %Y %H:%M:%S GMT", date); - DavXmlNode *mtime = dav_xml_createnode_with_text(DAV_NS, "mtime", str); + DavXmlNode *mtime = dav_xml_createnode_with_text(DAV_PROPS_NS, "mtime", str); content = mtime; last = mtime; } @@ -113,7 +113,7 @@ mode_t mode = s->st_mode & 07777; char str[32]; snprintf(str, 32, "%o", (int)mode); - DavXmlNode *xmode = dav_xml_createnode_with_text(DAV_NS, "mode", str); + DavXmlNode *xmode = dav_xml_createnode_with_text(DAV_PROPS_NS, "mode", str); if(last) { last->next = xmode; } else { @@ -124,7 +124,7 @@ #endif - dav_set_property(res, "idav:finfo", content);; + dav_set_property_ns(res, DAV_PROPS_NS, "finfo", content);; return 0; } @@ -245,11 +245,11 @@ return 0; } - DavXmlNode *content = dav_xml_createnode_with_text(DAV_NS, "hash", xattr->hash); + DavXmlNode *content = dav_xml_createnode_with_text(DAV_PROPS_NS, "hash", xattr->hash); DavXmlNode *last = content; for(int i=0;inattr;i++) { - DavXmlNode *attr = dav_xml_createnode(DAV_NS, "xattr"); + DavXmlNode *attr = dav_xml_createnode(DAV_PROPS_NS, "xattr"); dav_xml_add_attr(attr, "name", xattr->names[i]); last->next = attr; last = attr; @@ -262,7 +262,7 @@ } } - dav_set_property(res, "idav:xattributes", content); + dav_set_property_ns(res, DAV_PROPS_NS, "xattributes", content); return 0; } diff -r aa49966e4e85 -r 5dc7fe41e8f8 dav/sync.c --- a/dav/sync.c Sun Jun 16 13:14:24 2019 +0200 +++ b/dav/sync.c Sat Jun 22 16:36:52 2019 +0200 @@ -77,12 +77,12 @@ static DavPropName defprops[] = { { "DAV:", "getetag" }, { DAV_NS, "status" }, - { DAV_NS, "finfo" }, - { DAV_NS, "tags" }, - { DAV_NS, "xattributes" }, { DAV_NS, "content-hash" }, { DAV_NS, "split" }, - { DAV_NS, "link" } + { DAV_PROPS_NS, "finfo" }, + { DAV_PROPS_NS, "tags" }, + { DAV_PROPS_NS, "xattributes" }, + { DAV_PROPS_NS, "link" } }; static size_t numdefprops = 8 ; @@ -345,7 +345,7 @@ return 1; } - DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags"); + DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); UcxList *res_tags = parse_dav_xml_taglist(tagsprop); int ret = matches_tagfilter(res_tags, tagfilter); @@ -552,7 +552,7 @@ } int ret = 0; - DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:tags,idav:finfo,idav:xattributes,idav:split,idav:link,`idav:content-hash` from / with depth = infinity"); + DavResource *ls = dav_query(sn, "select D:getetag,idav:status,idav:split,`idav:content-hash`,idavprops:tags,idavprops:finfo,idavprops:xattributes,idavprops:link from / with depth = infinity"); if(!ls) { print_resource_error(sn, "/"); if(locked) { @@ -743,7 +743,7 @@ prev = elm->prev; next = elm->next; - if(dav_get_property_ns(res, DAV_NS, "link")) { + if(dav_get_property_ns(res, DAV_PROPS_NS, "link")) { continue; } @@ -958,7 +958,7 @@ char *local_path = create_local_path(dir, res->path); char *link = SYNC_SYMLINK(dir) ? - dav_get_string_property_ns(res, DAV_NS, "link") : NULL; + dav_get_string_property_ns(res, DAV_PROPS_NS, "link") : NULL; SYS_STAT s; DavBool exists = 1; @@ -1019,7 +1019,7 @@ while(ret == REMOTE_NO_CHANGE && local) { // check if tags have changed if(dir->tagconfig) { - DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags"); + DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); UcxList *remote_tags = NULL; if(tagsprop) { remote_tags = parse_dav_xml_taglist(tagsprop); @@ -1040,7 +1040,7 @@ // check if extended attributes have changed if((dir->metadata & FINFO_XATTR) == FINFO_XATTR) { - DavXmlNode *xattr = dav_get_property_ns(res, DAV_NS, "xattributes"); + DavXmlNode *xattr = dav_get_property_ns(res, DAV_PROPS_NS, "xattributes"); char *xattr_hash = get_xattr_hash(xattr); if(nullstrcmp(xattr_hash, local->xattr_hash)) { ret = REMOTE_CHANGE_METADATA; @@ -1049,7 +1049,7 @@ } // check if finfo has changed - DavXmlNode *finfo = dav_get_property_ns(res, DAV_NS, "finfo"); + DavXmlNode *finfo = dav_get_property_ns(res, DAV_PROPS_NS, "finfo"); if((dir->metadata & FINFO_MODE) == FINFO_MODE) { FileInfo f; finfo_get_values(finfo, &f); @@ -1291,7 +1291,7 @@ char *local_path = create_local_path(dir, path); char *link = SYNC_SYMLINK(dir) ? - dav_get_string_property_ns(res, DAV_NS, "link") : NULL; + dav_get_string_property_ns(res, DAV_PROPS_NS, "link") : NULL; char *etag = dav_get_string_property(res, "D:getetag"); SYS_STAT s; @@ -2311,7 +2311,7 @@ UCX_FOREACH(elm, resources) { LocalResource *resource = elm->data; - DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:version-collection,idav:finfo,idav:xattributes"); + DavResource *res = dav_get(sn, resource->path, "D:getetag,idav:status,idav:version-collection,idav:split,`idav:content-hash`,idavprops:tags,idavprops:finfo,idavprops:xattributes,idavprops:link"); if(!res) { printf("skip: %s\n", resource->path); continue; @@ -2673,11 +2673,11 @@ { DavPropName properties[] = { {"DAV:", "getetag"}, - {DAV_NS, "tags"}, {DAV_NS, "version-collection"}, {DAV_NS, "content-hash"}, {DAV_NS, "split" }, - {DAV_NS, "link" } + {DAV_PROPS_NS, "tags"}, + {DAV_PROPS_NS, "link" } }; int err = dav_load_prop(remote, properties, 6); @@ -2808,7 +2808,7 @@ // TODO: remove code dup (main.c: find_version) DavResource* versioning_deltav_find(DavResource *res, const char *version) { - DavResource *list = dav_versiontree(res, "D:getetag,idav:status,idav:finfo,idav:xattributes,idav:tags"); + DavResource *list = dav_versiontree(res, "D:getetag,idav:status,idav:split,idavprops:link,idavprops:finfo,idavprops:xattributes,idavprops:tags"); DavResource *ret = NULL; while(list) { DavResource *next = list->next; @@ -2877,7 +2877,7 @@ int sync_store_metadata(SyncDirectory *dir, const char *path, LocalResource *local, DavResource *res) { int ret = 0; - DavXmlNode *fileinfo = dav_get_property_ns(res, DAV_NS, "finfo"); + DavXmlNode *fileinfo = dav_get_property_ns(res, DAV_PROPS_NS, "finfo"); if(fileinfo) { FileInfo f; finfo_get_values(fileinfo, &f); @@ -2900,7 +2900,7 @@ } } - DavXmlNode *xattr_prop = dav_get_property_ns(res, DAV_NS, "xattributes"); + DavXmlNode *xattr_prop = dav_get_property_ns(res, DAV_PROPS_NS, "xattributes"); if(xattr_prop) { XAttributes *xattr = xml_get_attributes(xattr_prop); if(xattr) { @@ -2941,7 +2941,7 @@ UcxList *tags = NULL; if(dir->tagconfig) { - DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags"); + DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); if(tagsprop) { tags = parse_dav_xml_taglist(tagsprop); @@ -3572,7 +3572,7 @@ DavBool islink = local->link_target ? 1 : 0; if(!local->link_target && local->link_updated) { - dav_remove_property_ns(res, DAV_NS, "link"); + dav_remove_property_ns(res, DAV_PROPS_NS, "link"); } size_t split_blocksize = resource_get_blocksize(dir, local, res, s.st_size); @@ -3590,7 +3590,7 @@ uint64_t blockcount = 0; if(islink) { - dav_set_string_property_ns(res, DAV_NS, "link", local->link_target); + dav_set_string_property_ns(res, DAV_PROPS_NS, "link", local->link_target); } else if(issplit) { // set split property char blocksize_str[32]; @@ -3894,7 +3894,7 @@ DavBool store_tags = TRUE; // get remote tags UcxList *remote_tags = NULL; - DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_NS, "tags"); + DavXmlNode *tagsprop = dav_get_property_ns(res, DAV_PROPS_NS, "tags"); if(tagsprop) { remote_tags = parse_dav_xml_taglist(tagsprop); } @@ -3927,9 +3927,9 @@ if(store_tags) { if(tags) { DavXmlNode *tagprop = create_xml_taglist(tags); - dav_set_property_ns(res, DAV_NS, "tags", tagprop); + dav_set_property_ns(res, DAV_PROPS_NS, "tags", tagprop); } else { - dav_remove_property_ns(res, DAV_NS, "tags"); + dav_remove_property_ns(res, DAV_PROPS_NS, "tags"); } } @@ -3956,7 +3956,7 @@ resource_set_xattr(res, local->xattr); hashes.xattr = strdup(local->xattr->hash); } else { - dav_remove_property(res, "idav:xattributes"); + dav_remove_property(res, "idavprops:xattributes"); } } return hashes; diff -r aa49966e4e85 -r 5dc7fe41e8f8 libidav/webdav.c --- a/libidav/webdav.c Sun Jun 16 13:14:24 2019 +0200 +++ b/libidav/webdav.c Sat Jun 22 16:36:52 2019 +0200 @@ -70,61 +70,24 @@ } // add DAV: namespace - DavNamespace *davns = malloc(sizeof(DavNamespace)); - if(!davns) { - free(davns); - dav_context_destroy(context); - return NULL; - } - davns->prefix = strdup("D"); - if(!davns->prefix) { - free(davns); - dav_context_destroy(context); - return NULL; - } - davns->name = strdup("DAV:"); - if(!davns->name) { - free(davns->prefix); - free(davns); - dav_context_destroy(context); - return NULL; - } - if(ucx_map_cstr_put(context->namespaces, "D", davns)) { - free(davns->prefix); - free(davns->name); - free(davns); + if(dav_add_namespace(context, "D", "DAV:")) { dav_context_destroy(context); return NULL; } + // add idav namespace - DavNamespace *idavns = malloc(sizeof(DavNamespace)); - if(!idavns) { - free(idavns); - dav_context_destroy(context); - return NULL; - } - idavns->prefix = strdup("idav"); - if(!idavns->prefix) { - free(idavns); - dav_context_destroy(context); - return NULL; - } - idavns->name = strdup(DAV_NS); - if(!idavns->name) { - free(idavns->prefix); - free(idavns); - dav_context_destroy(context); - return NULL; - } - if(ucx_map_cstr_put(context->namespaces, "idav", idavns)) { - free(idavns->prefix); - free(idavns->name); - free(idavns); + if(dav_add_namespace(context, "idav", DAV_NS)) { dav_context_destroy(context); return NULL; } + // add idavprops namespace + if(dav_add_namespace(context, "idavprops", DAV_PROPS_NS)) { + dav_context_destroy(context); + return NULL; + } + return context; } @@ -195,9 +158,24 @@ if(!namespace) { return 1; } - namespace->prefix = strdup(prefix); - namespace->name = strdup(name); - return ucx_map_cstr_put(context->namespaces, prefix, namespace); + + char *p = strdup(prefix); + char *n = strdup(name); + + int err = 0; + if(p && n) { + namespace->prefix = p; + namespace->name = n; + err = ucx_map_cstr_put(context->namespaces, prefix, namespace); + } + + if(err) { + free(namespace); + if(p) free(p); + if(n) free(n); + } + + return err; } DavNamespace* dav_get_namespace(DavContext *context, const char *prefix) { diff -r aa49966e4e85 -r 5dc7fe41e8f8 libidav/webdav.h --- a/libidav/webdav.h Sun Jun 16 13:14:24 2019 +0200 +++ b/libidav/webdav.h Sat Jun 22 16:36:52 2019 +0200 @@ -114,7 +114,8 @@ #define DAV_SESSION_FULL_ENCRYPTION 0x003f -#define DAV_NS "http://davutils.org/" +#define DAV_NS "http://davutils.org/" +#define DAV_PROPS_NS "http://davutils.org/props/" struct DavNamespace { char *prefix;