136 if(flags != 0) { |
136 if(flags != 0) { |
137 sn->flags |= flags; |
137 sn->flags |= flags; |
138 } else { |
138 } else { |
139 sn->flags |= DAV_SESSION_ENCRYPT_CONTENT; |
139 sn->flags |= DAV_SESSION_ENCRYPT_CONTENT; |
140 } |
140 } |
|
141 } |
|
142 |
|
143 void dav_session_set_authcallback(DavSession *sn, dav_auth_func func, void *userdata) { |
|
144 sn->auth_prompt = func; |
|
145 sn->authprompt_userdata = userdata; |
|
146 } |
|
147 |
|
148 CURLcode dav_session_curl_perform(DavSession *sn, long *status) { |
|
149 return dav_session_curl_perform_buf(sn, NULL, NULL, status); |
|
150 } |
|
151 |
|
152 CURLcode dav_session_curl_perform_buf(DavSession *sn, UcxBuffer *request, UcxBuffer *response, long *status) { |
|
153 CURLcode ret = curl_easy_perform(sn->handle); |
|
154 long http_status; |
|
155 curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status); |
|
156 if(ret == CURLE_OK && http_status == 401 && sn->auth_prompt) { |
|
157 if(!sn->auth_prompt(sn, sn->authprompt_userdata)) { |
|
158 if(request) { |
|
159 ucx_buffer_seek(request, 0, SEEK_SET); |
|
160 } |
|
161 if(response) { |
|
162 ucx_buffer_seek(response, 0, SEEK_SET); |
|
163 } |
|
164 ret = curl_easy_perform(sn->handle); |
|
165 curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status); |
|
166 } |
|
167 } |
|
168 if(status) { |
|
169 *status = http_status; |
|
170 } |
|
171 return ret; |
141 } |
172 } |
142 |
173 |
143 void dav_session_set_error(DavSession *sn, CURLcode c, int status) { |
174 void dav_session_set_error(DavSession *sn, CURLcode c, int status) { |
144 if(status > 0) { |
175 if(status > 0) { |
145 switch(status) { |
176 switch(status) { |