libidav/session.c

changeset 18
af411868ab9b
parent 2
fbdfaacc4182
equal deleted inserted replaced
17:7cfd36aa005b 18:af411868ab9b
48 if(url.length == 0) { 48 if(url.length == 0) {
49 return NULL; 49 return NULL;
50 } 50 }
51 DavSession *sn = malloc(sizeof(DavSession)); 51 DavSession *sn = malloc(sizeof(DavSession));
52 memset(sn, 0, sizeof(DavSession)); 52 memset(sn, 0, sizeof(DavSession));
53 sn->mp = cxMempoolCreate(DAV_SESSION_MEMPOOL_SIZE, NULL); 53 sn->mp = cxBasicMempoolCreate(DAV_SESSION_MEMPOOL_SIZE);
54 sn->pathcache = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE); 54 sn->pathcache = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
55 sn->key = NULL; 55 sn->key = NULL;
56 sn->errorstr = NULL; 56 sn->errorstr = NULL;
57 sn->error = DAV_OK; 57 sn->error = DAV_OK;
58 sn->flags = 0; 58 sn->flags = 0;
92 curl_easy_setopt(sn->handle, CURLOPT_DEFAULT_PROTOCOL, "http"); 92 curl_easy_setopt(sn->handle, CURLOPT_DEFAULT_PROTOCOL, "http");
93 #endif 93 #endif
94 curl_easy_setopt(sn->handle, CURLOPT_URL, base_url); 94 curl_easy_setopt(sn->handle, CURLOPT_URL, base_url);
95 95
96 // add to context 96 // add to context
97 cxListAdd(context->sessions, sn); 97 dav_context_add_session(context, sn);
98 sn->context = context; 98 sn->context = context;
99 99
100 return sn; 100 return sn;
101 } 101 }
102 102
110 if(!sn) { 110 if(!sn) {
111 return NULL; 111 return NULL;
112 } 112 }
113 dav_session_set_auth(sn, user, password); 113 dav_session_set_auth(sn, user, password);
114 return sn; 114 return sn;
115 }
116
117 DavSession* dav_session_clone(DavSession *sn) {
118 CURL *newhandle = curl_easy_duphandle(sn->handle);
119
120 DavSession *newsn = malloc(sizeof(DavSession));
121 memset(newsn, 0, sizeof(DavSession));
122 newsn->mp = cxMempoolCreate(DAV_SESSION_MEMPOOL_SIZE, NULL);
123 newsn->pathcache = cxHashMapCreate(sn->mp->allocator, CX_STORE_POINTERS, DAV_PATH_CACHE_SIZE);
124 newsn->key = sn->key;
125 newsn->errorstr = NULL;
126 newsn->error = DAV_OK;
127 newsn->flags = 0;
128
129 newsn->handle = newhandle;
130
131 newsn->base_url = cx_strdup_a(newsn->mp->allocator, cx_str(sn->base_url)).ptr;
132 newsn->auth_prompt = sn->auth_prompt;
133 newsn->authprompt_userdata = sn->authprompt_userdata;
134 newsn->logfunc = sn->logfunc;
135 newsn->get_progress = sn->get_progress;
136 newsn->put_progress = sn->put_progress;
137 newsn->progress_userdata = sn->progress_userdata;
138
139 // add to context
140 dav_context_add_session(sn->context, newsn);
141 newsn->context = sn->context;
142
143 return newsn;
115 } 144 }
116 145
117 void dav_session_set_auth(DavSession *sn, const char *user, const char *password) { 146 void dav_session_set_auth(DavSession *sn, const char *user, const char *password) {
118 if(user && password) { 147 if(user && password) {
119 dav_session_set_auth_s(sn, cx_str(user), cx_str(password)); 148 dav_session_set_auth_s(sn, cx_str(user), cx_str(password));
300 sn->errorstr = errstr; 329 sn->errorstr = errstr;
301 } 330 }
302 331
303 void dav_session_destroy(DavSession *sn) { 332 void dav_session_destroy(DavSession *sn) {
304 // remove session from context 333 // remove session from context
305 CxList *sessions = sn->context->sessions; 334 if (dav_context_remove_session(sn->context, sn)) {
306 ssize_t i = cxListFind(sessions, sn); 335 fprintf(stderr, "Error: session not found in ctx->sessions\n");
307 if(i >= 0) {
308 cxListRemove(sessions, i);
309 } else {
310 printf("Error: session not found in ctx->sessions\n");
311 dav_session_destructor(sn); 336 dav_session_destructor(sn);
312 } 337 }
313 } 338 }
314 339
315 void dav_session_destructor(DavSession *sn) { 340 void dav_session_destructor(DavSession *sn) {

mercurial