libidav/methods.c

changeset 166
8911170d5e78
parent 164
4c204e40ef52
child 170
cf054cded046
equal deleted inserted replaced
165:b66bed169fc3 166:8911170d5e78
46 UcxBuffer *request, 46 UcxBuffer *request,
47 UcxBuffer *response) 47 UcxBuffer *response)
48 { 48 {
49 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND"); 49 curl_easy_setopt(handle, CURLOPT_CUSTOMREQUEST, "PROPFIND");
50 50
51 // implement own redirection follower
51 long follow = 0; 52 long follow = 0;
52 curl_easy_getinfo(handle, CURLOPT_FOLLOWLOCATION, &follow); 53 curl_easy_getinfo(handle, CURLOPT_FOLLOWLOCATION, &follow);
53 int maxredirect = 16; 54 curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 0L);
55 const int maxredirect = 16;
54 56
55 struct curl_slist *headers = NULL; 57 struct curl_slist *headers = NULL;
56 CURLcode ret = 0; 58 CURLcode ret = 0;
57 59
58 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 60 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
61 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 63 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
62 64
63 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 65 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
64 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 66 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
65 67
66 curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 0L);
67 for(int i=0;i<=maxredirect;i++) { 68 for(int i=0;i<=maxredirect;i++) {
68 char *url = NULL; 69 char *url = NULL;
69 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url); 70 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
70 if(url) { 71 if(url) {
71 size_t ulen = strlen(url); 72 size_t ulen = strlen(url);
81 } else { 82 } else {
82 return CURLE_URL_MALFORMAT; 83 return CURLE_URL_MALFORMAT;
83 } 84 }
84 headers = curl_slist_append(headers, "Content-Type: text/xml"); 85 headers = curl_slist_append(headers, "Content-Type: text/xml");
85 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers); 86 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
86 87
87 ucx_buffer_seek(request, 0, SEEK_SET); 88 // reset buffers and perform request
88 ucx_buffer_seek(response, 0 , SEEK_SET); 89 request->pos = 0;
90 response->size = response->pos = 0;
89 ret = curl_easy_perform(handle); 91 ret = curl_easy_perform(handle);
90 curl_slist_free_all(headers); 92 curl_slist_free_all(headers);
91 headers = NULL; 93 headers = NULL;
92 94
95 // continue work with URL we get from the server!
93 char *location = NULL; 96 char *location = NULL;
94 curl_easy_getinfo(handle, CURLINFO_REDIRECT_URL, &location); 97 curl_easy_getinfo(handle, CURLINFO_REDIRECT_URL, &location);
95 if(location) { 98 if(location) {
96 // redirect 99 // redirect
97 curl_easy_setopt(handle, CURLOPT_URL, location); 100 curl_easy_setopt(handle, CURLOPT_URL, location);

mercurial