libidav/methods.c

changeset 208
1fb26aca5093
parent 207
de23f8881e9f
child 223
cbbdf207e67e
--- a/libidav/methods.c	Mon Mar 14 11:54:55 2016 +0100
+++ b/libidav/methods.c	Mon Mar 14 17:18:33 2016 +0100
@@ -707,13 +707,22 @@
 
 CURLcode do_proppatch_request(
         CURL *handle,
+        char *lock,
         UcxBuffer *request,
         UcxBuffer *response)
-{
+{  
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPPATCH");
     
     struct curl_slist *headers = NULL;
-    headers = curl_slist_append(headers, "Content-Type: text/xml");
+    headers = curl_slist_append(headers, "Content-Type: text/xml"); 
+    if(lock) {
+        char *url = NULL;
+        curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
+        char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr;
+        headers = curl_slist_append(headers, ltheader);
+        free(ltheader);
+        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
+    }
     curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
     
     curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 
@@ -891,13 +900,20 @@
     return s*n;
 }
 
-CURLcode do_put_request(CURL *handle, void *data, dav_read_func read_func, size_t length) {
+CURLcode do_put_request(CURL *handle, char *lock, void *data, dav_read_func read_func, size_t length) {
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
-    curl_easy_setopt(handle, CURLOPT_PUT, 1L);  
     curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
     
     // clear headers
     struct curl_slist *headers = NULL;
+    if(lock) {
+        char *url = NULL;
+        curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
+        char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr;
+        headers = curl_slist_append(headers, ltheader);
+        free(ltheader);
+        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
+    }
     curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
     
     UcxBuffer *buf = NULL;
@@ -929,24 +945,42 @@
     return ret;
 }
 
-CURLcode do_delete_request(CURL *handle, UcxBuffer *response) {
+CURLcode do_delete_request(CURL *handle, char *lock, UcxBuffer *response) { 
     struct curl_slist *headers = NULL;
-    curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
+    if(lock) {
+        char *url = NULL;
+        curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
+        char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr;
+        headers = curl_slist_append(headers, ltheader);
+        free(ltheader);
+        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
+    } else {
+        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
+    }
     
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "DELETE");
-    curl_easy_setopt(handle, CURLOPT_PUT, 0L);  
     curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
     
     curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
     curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
     
     CURLcode ret = curl_easy_perform(handle);
+    curl_slist_free_all(headers);
     return ret;
 }
 
-CURLcode do_mkcol_request(CURL *handle) { 
+CURLcode do_mkcol_request(CURL *handle, char *lock) {
     struct curl_slist *headers = NULL;
-    curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
+    if(lock) {
+        char *url = NULL;
+        curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
+        char *ltheader = ucx_sprintf("If: <%s> (<%s>)", url, lock).ptr;
+        headers = curl_slist_append(headers, ltheader);
+        free(ltheader);
+        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
+    } else {
+        curl_easy_setopt(handle, CURLOPT_HTTPHEADER, NULL);
+    }
     
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MKCOL");
     curl_easy_setopt(handle, CURLOPT_PUT, 0L);  
@@ -956,6 +990,7 @@
     curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
     
     CURLcode ret = curl_easy_perform(handle);
+    curl_slist_free_all(headers);
     return ret;
 }
 
@@ -978,7 +1013,7 @@
 }
 
 
-CURLcode do_copy_move_request(CURL *handle, char *dest, _Bool copy, _Bool override) {
+CURLcode do_copy_move_request(CURL *handle, char *dest, _Bool copy, _Bool override) { 
     if(copy) {
         curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY");
     } else {
@@ -1055,6 +1090,11 @@
                     continue;
                 }
                 
+                if(xstreq(node->name, "activelock")) {
+                    node = node->children;
+                    continue;
+                }
+                
                 if(lockdiscovery) {
                     if(xstreq(node->name, "timeout")) {
                         timeout = util_xml_get_text(node);
@@ -1084,7 +1124,7 @@
     return ret;
 }
 
-CURLcode do_lock_request(CURL *handle, UcxBuffer *request, UcxBuffer *response) {
+CURLcode do_lock_request(CURL *handle, UcxBuffer *request, UcxBuffer *response) { 
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "LOCK");  
     curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
     request->pos = 0;
@@ -1106,10 +1146,13 @@
     return ret;
 }
 
-CURLcode do_unlock_request(CURL *handle, char *locktoken) {
+CURLcode do_unlock_request(CURL *handle, char *locktoken) {   
     curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "UNLOCK");
     curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L);
     
+    curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
+    curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
+    
     // set lock-token header
     sstr_t ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken);
     struct curl_slist *headers = curl_slist_append(NULL, ltheader.ptr);

mercurial