libidav/session.c

changeset 354
067ea2315a8a
parent 292
0a47ffc8b73b
child 355
5da2cf15eb44
--- a/libidav/session.c	Tue Dec 12 23:58:54 2017 +0100
+++ b/libidav/session.c	Mon Dec 18 11:56:11 2017 +0100
@@ -140,6 +140,37 @@
     }
 }
 
+void dav_session_set_authcallback(DavSession *sn, dav_auth_func func, void *userdata) {
+    sn->auth_prompt = func;
+    sn->authprompt_userdata = userdata;
+}
+
+CURLcode dav_session_curl_perform(DavSession *sn, long *status) {
+    return dav_session_curl_perform_buf(sn, NULL, NULL, status);
+}
+
+CURLcode dav_session_curl_perform_buf(DavSession *sn, UcxBuffer *request, UcxBuffer *response, long *status) {
+    CURLcode ret = curl_easy_perform(sn->handle);
+    long http_status;
+    curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status);
+    if(ret == CURLE_OK && http_status == 401 && sn->auth_prompt) {
+        if(!sn->auth_prompt(sn, sn->authprompt_userdata)) {
+            if(request) {
+                ucx_buffer_seek(request, 0, SEEK_SET);
+            }
+            if(response) {
+                ucx_buffer_seek(response, 0, SEEK_SET);
+            }
+            ret = curl_easy_perform(sn->handle);
+            curl_easy_getinfo(sn->handle, CURLINFO_RESPONSE_CODE, &http_status);
+        }
+    }
+    if(status) {
+        *status = http_status;
+    }
+    return ret;
+}
+
 void dav_session_set_error(DavSession *sn, CURLcode c, int status) {
     if(status > 0) {
         switch(status) {

mercurial