summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-01 18:48:02 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-01 18:48:02 +0300
commit8b1922e8e7a227090cf01b05e65209076dec9df5 (patch)
treeba3c487dff6da52c6cca10e925b2b5a77f073742
parenteb119ecb58cce24813b37108fce4c0f343bdc2ab (diff)
downloadplus-8b1922e8e7a227090cf01b05e65209076dec9df5.tar.gz
plus-8b1922e8e7a227090cf01b05e65209076dec9df5.tar.bz2
plus-8b1922e8e7a227090cf01b05e65209076dec9df5.tar.xz
plus-8b1922e8e7a227090cf01b05e65209076dec9df5.zip
Add support form different proxy types in download process.
-rw-r--r--src/defaults.cpp2
-rw-r--r--src/gui/setup_other.cpp25
-rw-r--r--src/gui/setup_other.h6
-rw-r--r--src/gui/whoisonline.cpp2
-rw-r--r--src/net/download.cpp39
-rw-r--r--src/net/download.h2
6 files changed, 76 insertions, 0 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 9451ff2ff..0b9e68092 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -241,6 +241,8 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "soundguild", "newmessage");
AddDEF(configData, "autohideButtons", true);
AddDEF(configData, "autohideChat", false);
+ AddDEF(configData, "downloadProxy", "");
+ AddDEF(configData, "downloadProxyType", 0);
return configData;
}
diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp
index 02ad9ae5e..602f94fcb 100644
--- a/src/gui/setup_other.cpp
+++ b/src/gui/setup_other.cpp
@@ -167,6 +167,25 @@ Setup_Other::Setup_Other()
new SetupItemCheckBox(_("Auto hide shortcuts buttons."), "",
"autohideButtons", this, "autohideButtonsEvent");
+
+ new SetupItemLabel(_("Proxy server"), "", this);
+
+ mProxyTypeList = new SetupItemNames();
+ mProxyTypeList->push_back(_("System proxy"));
+ mProxyTypeList->push_back(_("Direct connection"));
+ mProxyTypeList->push_back("HTTP");
+ mProxyTypeList->push_back("HTTP 1.0");
+ mProxyTypeList->push_back("SOCKS4");
+ mProxyTypeList->push_back("SOCKS4A");
+ mProxyTypeList->push_back("SOCKS5");
+ mProxyTypeList->push_back(_("SOCKS5 hostname"));
+ new SetupItemSlider2(_("Proxy type"), "", "downloadProxyType", this,
+ "downloadProxyTypeEvent", 0, 7, mProxyTypeList);
+
+ new SetupItemTextField(_("Proxy address:port"), "",
+ "downloadProxy", this, "downloadProxyEvent");
+
+
new SetupItemLabel(_("Other"), "", this);
new SetupItemCheckBox(_("Enable server side attack"), "",
@@ -199,6 +218,12 @@ Setup_Other::Setup_Other()
setDimension(gcn::Rectangle(0, 0, 550, 350));
}
+Setup_Other::~Setup_Other()
+{
+ delete mProxyTypeList;
+ mProxyTypeList = nullptr;
+}
+
void Setup_Other::apply()
{
SetupTabScroll::apply();
diff --git a/src/gui/setup_other.h b/src/gui/setup_other.h
index 182a3f4c6..ae7daed50 100644
--- a/src/gui/setup_other.h
+++ b/src/gui/setup_other.h
@@ -25,6 +25,7 @@
#include "guichanfwd.h"
+#include "gui/widgets/setupitem.h"
#include "gui/widgets/setuptabscroll.h"
#include <guichan/actionlistener.hpp>
@@ -37,7 +38,12 @@ class Setup_Other : public SetupTabScroll
public:
Setup_Other();
+ ~Setup_Other();
+
void apply();
+
+ protected:
+ SetupItemNames *mProxyTypeList;
};
#endif
diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp
index aece25115..b9b692c0f 100644
--- a/src/gui/whoisonline.cpp
+++ b/src/gui/whoisonline.cpp
@@ -42,6 +42,7 @@
#include "playerrelations.h"
#include "main.h"
+#include "net/download.h"
#include "net/net.h"
#include "net/playerhandler.h"
@@ -526,6 +527,7 @@ int WhoIsOnline::downloadThread(void *ptr)
curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 7);
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
+ Net::Download::addProxy(curl);
struct curl_slist *pHeaders = nullptr;
// Make sure the resources2.txt and news.txt aren't cached,
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,