libidav/session.c

changeset 806
673a803d2203
parent 805
bff983370565
--- a/libidav/session.c	Thu Feb 01 10:41:39 2024 +0100
+++ b/libidav/session.c	Tue Feb 06 13:29:31 2024 +0100
@@ -114,6 +114,35 @@
     return sn;
 }
 
+DavSession* dav_session_clone(DavSession *sn) {
+    CURL *newhandle = curl_easy_duphandle(sn->handle);
+
+    DavSession *newsn = malloc(sizeof(DavSession));
+    memset(newsn, 0, sizeof(DavSession));
+    newsn->mp = cxBasicMempoolCreate(DAV_SESSION_MEMPOOL_SIZE);
+    newsn->pathcache = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
+    newsn->key = sn->key;
+    newsn->errorstr = NULL;
+    newsn->error = DAV_OK;
+    newsn->flags = 0;
+
+    newsn->handle = newhandle;
+
+    newsn->base_url = cx_strdup_a(newsn->mp->allocator, cx_str(sn->base_url)).ptr;
+    newsn->auth_prompt = sn->auth_prompt;
+    newsn->authprompt_userdata = sn->authprompt_userdata;
+    newsn->logfunc = sn->logfunc;
+    newsn->get_progress = sn->get_progress;
+    newsn->put_progress = sn->put_progress;
+    newsn->progress_userdata = sn->progress_userdata;
+
+    // add to context
+    dav_context_add_session(sn->context, newsn);
+    newsn->context = sn->context;
+
+    return newsn;
+}
+
 void dav_session_set_auth(DavSession *sn, const char *user, const char *password) {
     if(user && password) {
         dav_session_set_auth_s(sn, cx_str(user), cx_str(password));

mercurial