libidav/methods.c

changeset 163
c6d05f646b59
parent 162
25374afa5616
child 164
4c204e40ef52
equal deleted inserted replaced
162:25374afa5616 163:c6d05f646b59
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 long follow = 0;
52 curl_easy_getinfo(handle, CURLOPT_FOLLOWLOCATION, &follow);
53 int maxredirect = 16;
54
51 struct curl_slist *headers = NULL; 55 struct curl_slist *headers = NULL;
52 56 CURLcode ret = 0;
53 char *url = NULL;
54 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
55 if(url) {
56 size_t ulen = strlen(url);
57 if(ulen > 0) {
58 if(url[ulen-1] == '/') {
59 headers = curl_slist_append(headers, "Depth: 1");
60 } else {
61 headers = curl_slist_append(headers, "Depth: 0");
62 }
63 } else {
64 return CURLE_URL_MALFORMAT;
65 }
66 } else {
67 return CURLE_URL_MALFORMAT;
68 }
69
70 headers = curl_slist_append(headers, "Content-Type: text/xml");
71
72 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
73 57
74 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1); 58 curl_easy_setopt(handle, CURLOPT_UPLOAD, 1);
75 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read); 59 curl_easy_setopt(handle, CURLOPT_READFUNCTION, ucx_buffer_read);
76 curl_easy_setopt(handle, CURLOPT_READDATA, request); 60 curl_easy_setopt(handle, CURLOPT_READDATA, request);
77 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size); 61 curl_easy_setopt(handle, CURLOPT_INFILESIZE, request->size);
78 62
79 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write); 63 curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ucx_buffer_write);
80 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response); 64 curl_easy_setopt(handle, CURLOPT_WRITEDATA, response);
81 65
82 ucx_buffer_seek(request, 0, SEEK_SET); 66 curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 0L);
83 CURLcode ret = curl_easy_perform(handle); 67 for(int i=0;i<=maxredirect;i++) {
84 curl_slist_free_all(headers); 68 char *url = NULL;
69 curl_easy_getinfo(handle, CURLINFO_EFFECTIVE_URL, &url);
70 if(url) {
71 size_t ulen = strlen(url);
72 if(ulen > 0) {
73 if(url[ulen-1] == '/') {
74 headers = curl_slist_append(headers, "Depth: 1");
75 } else {
76 headers = curl_slist_append(headers, "Depth: 0");
77 }
78 } else {
79 return CURLE_URL_MALFORMAT;
80 }
81 } else {
82 return CURLE_URL_MALFORMAT;
83 }
84 headers = curl_slist_append(headers, "Content-Type: text/xml");
85 curl_easy_setopt(handle, CURLOPT_HTTPHEADER, headers);
86
87 ucx_buffer_seek(request, 0, SEEK_SET);
88 ucx_buffer_seek(response, 0 , SEEK_SET);
89 ret = curl_easy_perform(handle);
90 curl_slist_free_all(headers);
91 headers = NULL;
92
93 char *location = NULL;
94 curl_easy_getinfo(handle, CURLINFO_REDIRECT_URL, &location);
95 if(location) {
96 // redirect
97 curl_easy_setopt(handle, CURLOPT_URL, location);
98 } else {
99 break;
100 }
101 }
102
103 // reset followlocation option
104 curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, follow);
105
85 return ret; 106 return ret;
86 } 107 }
87 108
88 UcxBuffer* create_allprop_propfind_request() { 109 UcxBuffer* create_allprop_propfind_request() {
89 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOFREE); 110 UcxBuffer *buf = ucx_buffer_new(NULL, 512, UCX_BUFFER_AUTOFREE);

mercurial