44 DavContext *context = malloc(sizeof(DavContext)); |
44 DavContext *context = malloc(sizeof(DavContext)); |
45 if(!context) { |
45 if(!context) { |
46 return NULL; |
46 return NULL; |
47 } |
47 } |
48 context->sessions = NULL; |
48 context->sessions = NULL; |
|
49 context->http_proxy = calloc(1, sizeof(DavProxy)); |
|
50 context->https_proxy = calloc(1, sizeof(DavProxy)); |
49 context->namespaces = ucx_map_new(16); |
51 context->namespaces = ucx_map_new(16); |
50 context->http_proxy = NULL; |
|
51 context->https_proxy = NULL; |
|
52 context->no_proxy = NULL; |
|
53 if(!context->namespaces) { |
52 if(!context->namespaces) { |
54 free(context); |
53 free(context); |
55 return NULL; |
54 return NULL; |
56 } |
55 } |
57 DavNamespace *davns = malloc(sizeof(DavNamespace)); |
56 DavNamespace *davns = malloc(sizeof(DavNamespace)); |
75 void dav_context_destroy(DavContext *ctx) { |
74 void dav_context_destroy(DavContext *ctx) { |
76 // destroy all sessions assoziated with this context |
75 // destroy all sessions assoziated with this context |
77 UCX_FOREACH(elm, ctx->sessions) { |
76 UCX_FOREACH(elm, ctx->sessions) { |
78 dav_session_destroy(elm->data); |
77 dav_session_destroy(elm->data); |
79 } |
78 } |
|
79 free(ctx->http_proxy); |
|
80 free(ctx->https_proxy); |
80 |
81 |
81 UcxMapIterator i = ucx_map_iterator(ctx->namespaces); |
82 UcxMapIterator i = ucx_map_iterator(ctx->namespaces); |
82 UcxKey k; |
83 UcxKey k; |
83 DavNamespace *ns; |
84 DavNamespace *ns; |
84 // TODO: free map elements |
85 // TODO: free map elements |
147 } |
148 } |
148 sn->context = context; |
149 sn->context = context; |
149 sn->handle = curl_easy_init(); |
150 sn->handle = curl_easy_init(); |
150 //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
151 //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); |
151 //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
152 //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); |
152 |
153 |
153 // set proxy |
154 // set proxy |
154 if(sstrprefix(url, S("https"))) { |
155 DavProxy *proxy = sstrprefix(url, S("https")) ? context->https_proxy |
155 if(context->https_proxy) { |
156 : context->http_proxy; |
156 //printf("use https_proxy: %s\n", context->https_proxy); |
157 |
157 curl_easy_setopt(sn->handle, CURLOPT_PROXY, context->https_proxy); |
158 if (proxy->url) { |
158 } |
159 curl_easy_setopt(sn->handle, CURLOPT_PROXY, proxy->url); |
159 } else { |
160 if (proxy->username) { |
160 if(context->http_proxy) { |
161 curl_easy_setopt(sn->handle, CURLOPT_PROXYUSERNAME, |
161 //printf("use http_proxy: %s\n", context->http_proxy); |
162 proxy->username); |
162 curl_easy_setopt(sn->handle, CURLOPT_PROXY, context->http_proxy); |
163 if (proxy->password) { |
163 } |
164 curl_easy_setopt(sn->handle, CURLOPT_PROXYPASSWORD, |
164 } |
165 proxy->password); |
165 if(context->no_proxy) { |
166 } else { |
166 //printf("use no_proxy: %s\n", context->no_proxy); |
167 // TODO: prompt |
167 curl_easy_setopt(sn->handle, CURLOPT_NOPROXY, context->no_proxy); |
168 } |
168 } |
169 } |
|
170 if(proxy->no_proxy) { |
|
171 curl_easy_setopt(sn->handle, CURLOPT_NOPROXY, |
|
172 proxy->no_proxy); |
|
173 } |
|
174 } |
|
175 |
169 // set url |
176 // set url |
170 curl_easy_setopt(sn->handle, CURLOPT_URL, base_url); |
177 curl_easy_setopt(sn->handle, CURLOPT_URL, base_url); |
171 |
178 |
172 sn->mp = ucx_mempool_new(1024); |
179 sn->mp = ucx_mempool_new(1024); |
173 sn->allocator = ucx_mempool_allocator(sn->mp); |
180 sn->allocator = ucx_mempool_allocator(sn->mp); |