Mon, 11 Sep 2017 14:17:26 +0200
adds dav remove-property command
dav/main.c | file | annotate | diff | comparison | revisions | |
dav/main.h | file | annotate | diff | comparison | revisions |
--- a/dav/main.c Sun Sep 10 10:23:25 2017 +0200 +++ b/dav/main.c Mon Sep 11 14:17:26 2017 +0200 @@ -124,6 +124,8 @@ ret = cmd_set_property(args); } else if(!strcasecmp(cmd, "get-property")) { ret = cmd_get_property(args); + } else if(!strcasecmp(cmd, "remove-property")) { + ret = cmd_remove_property(args); } else if(!strcasecmp(cmd, "lock")) { ret = cmd_lock(args); } else if(!strcasecmp(cmd, "unlock")) { @@ -1248,6 +1250,51 @@ return ret; } +int cmd_remove_property(CmdArgs *a) { + if(a->argc < 2) { + fprintf(stderr, "Too few arguments\n"); + return -1; + } + + char *url = a->argv[0]; + char *path = NULL; + Repository *repo = url2repo(url, &path); + DavSession *sn = connect_to_repo(repo, a); + + if(set_session_config(sn, a)) { + return -1; + } + + char *namespace = cmd_getoption(a, "namespace"); + char *property = a->argv[1]; + + DavPropName propname; + if(namespace) { + propname.ns = namespace; + propname.name = property; + } else { + dav_get_property_namespace_str(ctx, property, &propname.ns, &propname.name); + } + + int ret = 0; + DavResource *res = dav_resource_new(sn, path); + dav_remove_property_ns(res, propname.ns, propname.name); + for(int i=0;i<2;i++) { + if(dav_store(res)) { + if(i == 0 && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn, a)) { + continue; + } + print_resource_error(sn, res->path); + fprintf(stderr, "Cannot set property.\n"); + ret = -1; + } + break; + } + + free(path); + return ret; +} + int cmd_lock(CmdArgs *a) { if(a->argc != 1) { fprintf(stderr, "Too %s arguments\n", a->argc > 1 ? "many" : "few");