diff -r ad0c9dacd7e3 -r c8755c87ce7f libidav/webdav.c --- a/libidav/webdav.c Fri Aug 30 12:48:15 2013 +0200 +++ b/libidav/webdav.c Mon Sep 02 10:31:29 2013 +0200 @@ -46,10 +46,9 @@ return NULL; } context->sessions = NULL; + context->http_proxy = calloc(1, sizeof(DavProxy)); + context->https_proxy = calloc(1, sizeof(DavProxy)); context->namespaces = ucx_map_new(16); - context->http_proxy = NULL; - context->https_proxy = NULL; - context->no_proxy = NULL; if(!context->namespaces) { free(context); return NULL; @@ -77,6 +76,8 @@ UCX_FOREACH(elm, ctx->sessions) { dav_session_destroy(elm->data); } + free(ctx->http_proxy); + free(ctx->https_proxy); UcxMapIterator i = ucx_map_iterator(ctx->namespaces); UcxKey k; @@ -149,23 +150,29 @@ sn->handle = curl_easy_init(); //curl_easy_setopt(sn->handle, CURLOPT_VERBOSE, 1L); //curl_easy_setopt(sn->handle, CURLOPT_STDERR, stderr); - + // set proxy - if(sstrprefix(url, S("https"))) { - if(context->https_proxy) { - //printf("use https_proxy: %s\n", context->https_proxy); - curl_easy_setopt(sn->handle, CURLOPT_PROXY, context->https_proxy); + DavProxy *proxy = sstrprefix(url, S("https")) ? context->https_proxy + : context->http_proxy; + + if (proxy->url) { + curl_easy_setopt(sn->handle, CURLOPT_PROXY, proxy->url); + if (proxy->username) { + curl_easy_setopt(sn->handle, CURLOPT_PROXYUSERNAME, + proxy->username); + if (proxy->password) { + curl_easy_setopt(sn->handle, CURLOPT_PROXYPASSWORD, + proxy->password); + } else { + // TODO: prompt + } } - } else { - if(context->http_proxy) { - //printf("use http_proxy: %s\n", context->http_proxy); - curl_easy_setopt(sn->handle, CURLOPT_PROXY, context->http_proxy); + if(proxy->no_proxy) { + curl_easy_setopt(sn->handle, CURLOPT_NOPROXY, + proxy->no_proxy); } } - if(context->no_proxy) { - //printf("use no_proxy: %s\n", context->no_proxy); - curl_easy_setopt(sn->handle, CURLOPT_NOPROXY, context->no_proxy); - } + // set url curl_easy_setopt(sn->handle, CURLOPT_URL, base_url);