fix session dup

Tue, 06 Feb 2024 13:29:31 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 06 Feb 2024 13:29:31 +0100
changeset 806
673a803d2203
parent 805
bff983370565
child 807
b41630ecc481

fix session dup

dav/config.c file | annotate | diff | comparison | revisions
dav/main.c file | annotate | diff | comparison | revisions
libidav/session.c file | annotate | diff | comparison | revisions
libidav/webdav.h file | annotate | diff | comparison | revisions
--- a/dav/config.c	Thu Feb 01 10:41:39 2024 +0100
+++ b/dav/config.c	Tue Feb 06 13:29:31 2024 +0100
@@ -569,7 +569,8 @@
     
     sn->flags = dav_repository_get_flags(repo);
     sn->key = dav_context_get_key(ctx, repo->default_key.value.ptr);
-    curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods);
+    // TODO: reactivate
+    //curl_easy_setopt(sn->handle, CURLOPT_HTTPAUTH, repo->authmethods);
     curl_easy_setopt(sn->handle, CURLOPT_SSLVERSION, repo->ssl_version);
     if(repo->cert.value.ptr) {
         curl_easy_setopt(sn->handle, CURLOPT_CAINFO, repo->cert.value.ptr);
--- a/dav/main.c	Thu Feb 01 10:41:39 2024 +0100
+++ b/dav/main.c	Tue Feb 06 13:29:31 2024 +0100
@@ -440,6 +440,7 @@
     
     int depth = cmd_getoption(a, "recursive") ? -1 : 1;
     int ret = 0;
+
     DavResource *ls = dav_query(
             sn,
             date ? LIST_QUERY_ORDER_BY_DATE : LIST_QUERY_ORDER_BY_NAME,
--- 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));
--- a/libidav/webdav.h	Thu Feb 01 10:41:39 2024 +0100
+++ b/libidav/webdav.h	Tue Feb 06 13:29:31 2024 +0100
@@ -289,6 +289,7 @@
         char *base_url,
         char *user,
         char *password);
+DavSession* dav_session_clone(DavSession *sn);
 void dav_session_set_auth(DavSession *sn, const char *user, const char *password);
 void dav_session_set_auth_s(DavSession *sn, cxstring user, cxstring password);
 void dav_session_set_baseurl(DavSession *sn, char *base_url);

mercurial