libidav/resource.c

changeset 181
a8f8cdbf85df
parent 178
e137883e620f
child 182
ca07f14f7bfe
--- a/libidav/resource.c	Fri Oct 23 22:15:12 2015 +0200
+++ b/libidav/resource.c	Tue Jan 12 19:17:46 2016 +0100
@@ -629,6 +629,7 @@
     if(data->set || data->remove) {
         UcxBuffer *request = create_proppatch_request(data);
         UcxBuffer *response = ucx_buffer_new(NULL, 1024, UCX_BUFFER_AUTOEXTEND);
+        //printf("request:\n%.*s\n\n", request->pos, request->space);
 
         CURLcode ret = do_proppatch_request(sn->handle, request, response);
         int status = 0;
@@ -870,6 +871,35 @@
     }
 }
 
+static int dav_cp_mv(DavResource *res, char *newpath, _Bool copy, _Bool override) {
+    DavSession *sn = res->session;
+    CURL *handle = sn->handle;
+    util_set_url(sn, dav_resource_get_href(res));
+    
+    char *dest = dav_session_get_href(sn, newpath);
+    dav_session_free(sn, dest);
+    char *desturl = util_get_url(sn, dest);
+    
+    CURLcode ret = do_copy_move_request(handle, desturl, copy, override);
+    free(desturl);
+    int status = 0;
+    curl_easy_getinfo (handle, CURLINFO_RESPONSE_CODE, &status);
+    if(ret == CURLE_OK && (status >= 200 && status < 300)) {
+        return 0;
+    } else {
+        dav_session_set_error(sn, ret, status);
+        return 1;
+    }
+}
+
+int dav_copy(DavResource *res, char *newpath) {
+    return dav_cp_mv(res, newpath, 1, 0);
+}
+
+int dav_move(DavResource *res, char *newpath) {
+    return dav_cp_mv(res, newpath, 0, 0);
+}
+
 
 int resource_add_crypto_info(DavSession *sn, char *href, char *name, char *hash) {
     if(!DAV_IS_ENCRYPTED(sn)) {

mercurial