diff -r 5b58389ab9dd -r a8f8cdbf85df libidav/methods.c --- a/libidav/methods.c Fri Oct 23 22:15:12 2015 +0200 +++ b/libidav/methods.c Tue Jan 12 19:17:46 2016 +0100 @@ -741,14 +741,14 @@ DavProperty *p = elm->data; if(strcmp(p->ns->name, "DAV:")) { snprintf(prefix, 8, "x%d", pfxnum++); - ucx_map_cstr_put(namespaces, p->ns->name, prefix); + ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); } } UCX_FOREACH(elm, data->remove) { DavProperty *p = elm->data; if(strcmp(p->ns->name, "DAV:")) { snprintf(prefix, 8, "x%d", pfxnum++); - ucx_map_cstr_put(namespaces, p->ns->name, prefix); + ucx_map_cstr_put(namespaces, p->ns->name, strdup(prefix)); } } @@ -782,6 +782,9 @@ UCX_FOREACH(elm, data->set) { DavProperty *property = elm->data; char *prefix = ucx_map_cstr_get(namespaces, property->ns->name); + if(!prefix) { + prefix = "D"; + } s = S("<"); ucx_buffer_write(s.ptr, 1, s.length, buf); @@ -834,6 +837,8 @@ s = S("\n"); ucx_buffer_write(s.ptr, 1, s.length, buf); + // TODO: cleanup namespace map + return buf; } @@ -968,3 +973,36 @@ curl_easy_setopt(handle, CURLOPT_NOBODY, 0L); return ret; } + + +CURLcode do_copy_move_request(CURL *handle, char *dest, _Bool copy, _Bool override) { + if(copy) { + curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "COPY"); + } else { + curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "MOVE"); + } + curl_easy_setopt(handle, CURLOPT_PUT, 0L); + curl_easy_setopt(handle, CURLOPT_UPLOAD, 0L); + + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); + + struct curl_slist *headers = NULL; + //sstr_t deststr = ucx_sprintf("Destination: %s", dest); + sstr_t deststr = sstrcat(2, S("Destination: "), sstr(dest)); + headers = curl_slist_append(headers, deststr.ptr); + if(override) { + headers = curl_slist_append(headers, "Overwrite: T"); + } else { + headers = curl_slist_append(headers, "Overwrite: F"); + } + curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); + + CURLcode ret = curl_easy_perform(handle); + free(deststr.ptr); + curl_slist_free_all(headers); + headers = NULL; + curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); + return ret; +} +