added lock support to some dav commands

Tue, 15 Mar 2016 11:07:31 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 15 Mar 2016 11:07:31 +0100
changeset 210
1d19e0ff18d9
parent 209
d24761f1e07c
child 211
3d12817414e9

added lock support to some dav commands

put, mkdir, remove and set-property can use lock tokens now
lock tokens can be specified with -L <token>

dav/main.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Tue Mar 15 10:35:57 2016 +0100
+++ b/dav/main.c	Tue Mar 15 11:07:31 2016 +0100
@@ -233,7 +233,7 @@
     return 1;
 }
 
-Repository* url2repo(char *url, char **path) {
+static Repository* url2repo(char *url, char **path) {
     size_t ulen = strlen(url);
     *path = NULL;
     
@@ -285,7 +285,7 @@
     return repo;
 }
 
-int set_session_config(DavSession *sn, CmdArgs *a) {
+static int set_session_config(DavSession *sn, CmdArgs *a) {
     char *plain = cmd_getoption(a, "plain");
     char *crypt = cmd_getoption(a, "crypt");
     
@@ -304,10 +304,18 @@
         curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
         curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
     }
-    
+       
     return 0;
 }
 
+static void set_session_lock(DavSession *sn, CmdArgs *a) {
+    char *locktoken = cmd_getoption(a, "lock");
+    if(locktoken) {
+        DavLock *lock = dav_create_lock(sn, locktoken, NULL);
+        dav_add_collection_lock(sn, "/", lock);
+    }
+}
+
 static DavSession* connect_to_repo(Repository *repo, CmdArgs *a) {
     DavSession *sn = dav_session_new_auth(ctx, repo->url, repo->user, repo->password);
     sn->flags = get_repository_flags(repo);
@@ -704,6 +712,7 @@
     if(set_session_config(sn, a)) {
         return -1;
     }
+    set_session_lock(sn, a);
     
     // override the session key if the -k option is specified
     char *keyname = cmd_getoption(a, "key");
@@ -852,6 +861,7 @@
     if(set_session_config(sn, a)) {
         return -1;
     }
+    set_session_lock(sn, a);
     
     DavResource *res = dav_resource_new(sn, path);
     if(!res) {
@@ -894,6 +904,7 @@
     if(set_session_config(sn, a)) {
         return -1;
     }
+    set_session_lock(sn, a);
     
     // override the session key if the -k option is specified
     char *keyname = cmd_getoption(a, "key");
@@ -955,6 +966,9 @@
         return -1;
     }
     
+    // TODO: add lock support (do_copy_move_request doesn't support locks yet)
+    // set_session_lock(sn, a);
+    
     DavBool override = cmd_getoption(a, "override") ? true : false;
     
     if(repo1 == repo2) {
@@ -1103,6 +1117,7 @@
     if(set_session_config(sn, a)) {
         return -1;
     }
+    set_session_lock(sn, a);
     
     DavResource *res = dav_resource_new(sn, path);
     if(!dav_exists(res)) {

mercurial