libidav/methods.c

branch
v1.2
changeset 481
ff477f1f7765
parent 373
dcc03142eb5f
equal deleted inserted replaced
480:7bb47ddc1b5e 481:ff477f1f7765
38 38
39 #include <ucx/utils.h> 39 #include <ucx/utils.h>
40 40
41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b) 41 #define xstreq(a,b) xmlStrEqual(BAD_CAST a, BAD_CAST b)
42 42
43
44 int dav_buffer_seek(UcxBuffer *b, curl_off_t offset, int origin) {
45 return ucx_buffer_seek(b, offset, origin) == 0 ? 0:CURL_SEEKFUNC_CANTSEEK;
46 }
47
43 /* ----------------------------- PROPFIND ----------------------------- */ 48 /* ----------------------------- PROPFIND ----------------------------- */
44 49
45 CURLcode do_propfind_request( 50 CURLcode do_propfind_request(
46 DavSession *sn, 51 DavSession *sn,
47 UcxBuffer *request, 52 UcxBuffer *request,
58 struct curl_slist *headers = NULL; 63 struct curl_slist *headers = NULL;
59 CURLcode ret = 0; 64 CURLcode ret = 0;
60 65
61 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 66 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
62 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 67 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read);
68 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek);
63 curl_easy_setopt(handle, CURLOPT_READDATA, request); 69 curl_easy_setopt(handle, CURLOPT_READDATA, request);
64 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 70 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
65 71
66 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 72 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
67 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 73 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
730 } 736 }
731 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 737 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
732 738
733 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 739 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
734 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 740 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read);
741 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek);
735 curl_easy_setopt(handle, CURLOPT_READDATA, request); 742 curl_easy_setopt(handle, CURLOPT_READDATA, request);
736 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 743 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
737 744
738 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 745 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
739 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 746 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
918 static size_t dummy_write(void *buf, size_t s, size_t n, void *data) { 925 static size_t dummy_write(void *buf, size_t s, size_t n, void *data) {
919 //fwrite(buf, s, n, stdout); 926 //fwrite(buf, s, n, stdout);
920 return s*n; 927 return s*n;
921 } 928 }
922 929
923 CURLcode do_put_request(DavSession *sn, char *lock, DavBool create, void *data, dav_read_func read_func, size_t length) { 930 CURLcode do_put_request(DavSession *sn, char *lock, DavBool create, void *data, dav_read_func read_func, dav_seek_func seek_func, size_t length) {
924 CURL *handle = sn->handle; 931 CURL *handle = sn->handle;
925 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL); 932 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, NULL);
926 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L); 933 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1L);
927 934
928 // clear headers 935 // clear headers
958 } else { 965 } else {
959 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length); 966 curl_easy_setopt(handle, CURLOPT_INFILESIZE_LARGE, (curl_off_t)length);
960 } 967 }
961 968
962 curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func); 969 curl_easy_setopt(handle, CURLOPT_READFUNCTION, read_func);
970 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, seek_func);
963 curl_easy_setopt(handle, CURLOPT_READDATA, data); 971 curl_easy_setopt(handle, CURLOPT_READDATA, data);
964 972
965 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write); 973 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, dummy_write);
966 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL); 974 curl_easy_setopt(handle, CURLOPT_WRITEDATA, NULL);
967 975
1187 } 1195 }
1188 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 1196 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
1189 1197
1190 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 1198 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
1191 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 1199 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read);
1200 curl_easy_setopt(handle, CURLOPT_SEEKFUNCTION, dav_buffer_seek);
1192 curl_easy_setopt(handle, CURLOPT_READDATA, request); 1201 curl_easy_setopt(handle, CURLOPT_READDATA, request);
1193 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 1202 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
1194 1203
1195 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 1204 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
1196 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 1205 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);

mercurial