diff -r 017a4f09e6fa -r 52e4171d42ce libidav/methods.c --- a/libidav/methods.c Sun Sep 23 08:13:50 2018 +0200 +++ b/libidav/methods.c Sun Sep 23 12:51:41 2018 +0200 @@ -129,7 +129,7 @@ return buf; } -UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties) { +UcxBuffer* create_propfind_request(DavSession *sn, UcxList *properties, char *rootelm, DavBool nocrypt) { UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOEXTEND); sstr_t s; @@ -161,7 +161,7 @@ } DavNamespace idav_ns; - if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn)) { + if(add_crypto_name && add_crypto_key && DAV_CRYPTO(sn) && !nocrypt) { idav_ns.prefix = "idav"; idav_ns.name = DAV_NS; ucx_map_cstr_put(namespaces, "idav", &idav_ns); @@ -171,8 +171,8 @@ ucx_buffer_write(s.ptr, 1, s.length, buf); // write root element and namespaces - s = S("\n\n"); - ucx_buffer_write(s.ptr, 1, s.length, buf); + ucx_bprintf(buf, "\n\n", rootelm); ucx_map_free(namespaces); return buf; @@ -1223,3 +1222,55 @@ return ret; } + +CURLcode do_simple_request(DavSession *sn, char *method, char *locktoken) { + CURL *handle = sn->handle; + curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, method); + 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; + struct curl_slist *headers = NULL; + if(locktoken) { + ltheader = ucx_sprintf("Lock-Token: <%s>", locktoken); + headers = curl_slist_append(NULL, ltheader.ptr); + } + curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); + + CURLcode ret = dav_session_curl_perform(sn, NULL); + if(locktoken) { + curl_slist_free_all(headers); + free(ltheader.ptr); + } + + return ret; +} + + +CURLcode do_report_request(DavSession *sn, UcxBuffer *request, UcxBuffer *response) { + CURL *handle = sn->handle; + curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "REPORT"); + + curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); + curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); + curl_easy_setopt(handle, CURLOPT_READDATA, request); + curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); + + curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); + curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); + + struct curl_slist *headers = NULL; + headers = curl_slist_append(headers, "Content-Type: text/xml"); + curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); + + request->pos = 0; + response->size = response->pos = 0; + CURLcode ret = dav_session_curl_perform_buf(sn, request, response, NULL); + + curl_slist_free_all(headers); + + return ret; +}