dav/webdav.c

changeset 24
a317202ae787
parent 22
e593f7e41be0
child 25
29f77f1fdbf3
--- a/dav/webdav.c	Mon Aug 19 14:45:53 2013 +0200
+++ b/dav/webdav.c	Mon Aug 19 17:10:22 2013 +0200
@@ -114,7 +114,7 @@
     }
     DavSession *sn = malloc(sizeof(DavSession));
     sn->errorstr = NULL;
-    sn->error = CURLE_OK;
+    sn->error = DAV_OK;
     if(url.ptr[url.length - 1] == '/') {
         sn->base_url = strdup(base_url);
     } else {
@@ -126,6 +126,8 @@
     }
     sn->context = context;
     sn->handle = curl_easy_init();
+    //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L);
+    //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr);
     
     // set proxy
     if(sstrprefix(url, S("https"))) {
@@ -687,7 +689,7 @@
             free(parent);
             return r;
         }
-    } else if(parent_res && !res->iscollection) {
+    } else if(parent_res && !parent_res->iscollection) {
         sn->error = DAV_FORBIDDEN;
         return 1;
     } else if(sn->error != DAV_OK) {
@@ -699,9 +701,13 @@
     free(url);
     free(parent);
     
-    // TODO: check iscollection and create empty resource or collection
-    
-    CURLcode ret = do_mkcol_request(handle);
+    // create new collection or do an empty put request
+    CURLcode ret;
+    if(res->iscollection) {
+        ret = do_mkcol_request(handle);
+    } else {
+        ret = do_put_request(handle, "", NULL, 0); 
+    }
     int status = 0;
     curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
     if(ret == CURLE_OK && (status >= 200 && status < 300)) {

mercurial