implemented dav_create for non-collection resources

Mon, 19 Aug 2013 17:10:22 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Mon, 19 Aug 2013 17:10:22 +0200
changeset 24
a317202ae787
parent 23
2b0a7361f15c
child 25
29f77f1fdbf3

implemented dav_create for non-collection resources

dav/main.c file | annotate | diff | comparison | revisions
dav/methods.c file | annotate | diff | comparison | revisions
dav/webdav.c file | annotate | diff | comparison | revisions
--- a/dav/main.c	Mon Aug 19 14:45:53 2013 +0200
+++ b/dav/main.c	Mon Aug 19 17:10:22 2013 +0200
@@ -591,9 +591,14 @@
     }
     
     DavResource *res = dav_query(sn, "get - from %s", path);
+    sn->error = DAV_NOT_FOUND;
     if(!res) {
-        if(sn->error = DAV_NOT_FOUND) {
+        if(sn->error == DAV_NOT_FOUND) {
             res = dav_resource_new(sn, path);
+            if(dav_create(res)) {
+                fprintf(stderr, "Cannot create resource.\n");
+                return -1;
+            }
         } else {
             if(sn->errorstr) {
                 fprintf(stderr, "Error: %s\n", sn->errorstr);
--- a/dav/methods.c	Mon Aug 19 14:45:53 2013 +0200
+++ b/dav/methods.c	Mon Aug 19 17:10:22 2013 +0200
@@ -446,6 +446,7 @@
     } else if(length == 0) {
         struct curl_slist *headers = NULL;
         headers = curl_slist_append(headers, "Transfer-Encoding: chunked");
+        curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)1);
         curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
     } else {
         curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length);
--- 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