From 8b1922e8e7a227090cf01b05e65209076dec9df5 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 1 Apr 2012 18:48:02 +0300 Subject: Add support form different proxy types in download process. --- src/net/download.cpp | 39 +++++++++++++++++++++++++++++++++++++++ src/net/download.h | 2 ++ 2 files changed, 41 insertions(+) (limited to 'src/net') diff --git a/src/net/download.cpp b/src/net/download.cpp index 355d30eca..4eec6b0b4 100644 --- a/src/net/download.cpp +++ b/src/net/download.cpp @@ -249,6 +249,7 @@ int Download::downloadThread(void *ptr) curl_easy_setopt(d->mCurl, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(d->mCurl, CURLOPT_CONNECTTIMEOUT, 30); curl_easy_setopt(d->mCurl, CURLOPT_TIMEOUT, 1800); + addProxy(d->mCurl); if ((res = curl_easy_perform(d->mCurl)) != 0 && !d->mOptions.cancel) @@ -360,4 +361,42 @@ int Download::downloadThread(void *ptr) return 0; } +void Download::addProxy(CURL *curl) +{ + const int mode = config.getIntValue("downloadProxyType"); + if (!mode) + return; + + if (mode > 1) + { + curl_easy_setopt(curl, CURLOPT_PROXY, + config.getStringValue("downloadProxy").c_str()); + } + switch (mode) + { + case 1: // direct connection + default: + curl_easy_setopt(curl, CURLOPT_PROXY, ""); + break; + case 2: // HTTP + break; + case 3: // HTTP 1.0 + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP_1_0); + break; + case 4: // SOCKS4 + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4); + break; + case 5: // SOCKS4A + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A); + break; + case 6: // SOCKS5 + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5); + break; + case 7: // SOCKS5 hostname + curl_easy_setopt(curl, CURLOPT_PROXYTYPE, + CURLPROXY_SOCKS5_HOSTNAME); + break; + } +} + } // namespace Net diff --git a/src/net/download.h b/src/net/download.h index b31350eff..90e9777ae 100644 --- a/src/net/download.h +++ b/src/net/download.h @@ -91,6 +91,8 @@ class Download static unsigned long fadler32(FILE *file); + static void addProxy(CURL *curl); + private: static int downloadThread(void *ptr); static int downloadProgress(void *clientp, double dltotal, -- cgit v1.2.3-70-g09d2