# HG changeset patch # User Olaf Wintermann # Date 1456679668 -3600 # Node ID 8e58561826688c8fb797b90774d9907d4664e808 # Parent cc474cf2c2f51025f6d2f6bc3eae2e38fd9e1509 auth input for dav get, put, mkdir and remove commands diff -r cc474cf2c2f5 -r 8e5856182668 dav/main.c --- 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; diff -r cc474cf2c2f5 -r 8e5856182668 dav/version.h --- a/dav/version.h Sun Feb 28 13:39:59 2016 +0100 +++ b/dav/version.h Sun Feb 28 18:14:28 2016 +0100 @@ -29,7 +29,7 @@ #ifndef VERSION_H #define VERSION_H -#define DAV_VERSION "0.9.3" +#define DAV_VERSION "0.9.4" #endif /* VERSION_H */