Sun, 28 Feb 2016 18:14:28 +0100
auth input for dav get, put, mkdir and remove commands
dav/main.c | file | annotate | diff | comparison | revisions | |
dav/version.h | file | annotate | diff | comparison | revisions |
--- a/dav/main.c Sun Feb 28 13:39:59 2016 +0100 +++ b/dav/main.c Sun Feb 28 18:14:28 2016 +0100 @@ -574,13 +574,21 @@ DavResource *res; int depth = recursive ? -1 : 1; - res = dav_query( - sn, - "select - from %s with depth = %d where lastmodified > %t", - path, - depth, - t); - + for(int i=0;i<2;i++) { + res = dav_query( + sn, + "select - from %s with depth = %d where lastmodified > %t", + path, + depth, + t); + if(!res && sn->error == DAV_UNAUTHORIZED) { + if(request_auth(repo, sn)) { + continue; + } + } + break; + } + if(!res) { print_resource_error(sn, path); return -1; @@ -768,7 +776,17 @@ } int put_file(Repository *repo, CmdArgs *a, DavSession *sn, char *path, char *name, FILE *in, off_t len) { - DavResource *res = dav_query(sn, "select - from %s", path); + DavResource *res = NULL; + for(int i=0;i<2;i++) { + res = dav_query(sn, "select - from %s", path); + if(!res && sn->error == DAV_UNAUTHORIZED) { + if(request_auth(repo, sn)) { + continue; + } + } + break; + } + if(!res) { if(sn->error == DAV_NOT_FOUND) { res = dav_resource_new(sn, path); @@ -817,7 +835,8 @@ char *url = a->argv[0]; char *path = NULL; - DavSession *sn = connect_to_repo(url2repo(url, &path), a); + Repository *repo = url2repo(url, &path); + DavSession *sn = connect_to_repo(repo, a); if(set_session_config(sn, a)) { return -1; @@ -829,7 +848,17 @@ return -1; } - if(dav_delete(res)) { + int err = 0; + for(int i=0;i<2;i++) { + err = dav_delete(res); + if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) { + continue; + } else { + break; + } + } + + if(err) { print_resource_error(sn, res->path); fprintf(stderr, "Cannot delete resource.\n"); return -1; @@ -848,7 +877,8 @@ char *url = a->argv[0]; char *path = NULL; - DavSession *sn = connect_to_repo(url2repo(url, &path), a); + Repository *repo = url2repo(url, &path); + DavSession *sn = connect_to_repo(repo, a); if(set_session_config(sn, a)) { return -1; @@ -874,7 +904,17 @@ } res->iscollection = 1; - if(dav_create(res)) { + int err = 0; + for(int i=0;i<2;i++) { + err = dav_create(res); + if(err && sn->error == DAV_UNAUTHORIZED && request_auth(repo, sn)) { + continue; + } else { + break; + } + } + + if(err) { print_resource_error(sn, res->path); fprintf(stderr, "Cannot create collection.\n"); return -1;