From 296acf820c86d972681d17b46502fae772ed4f04 Mon Sep 17 00:00:00 2001 From: Christophe Dumez Date: Thu, 7 Jan 2010 20:35:12 +0000 Subject: [PATCH] Fix to proxy settings Added back SOCKS5 proxy support for HTTP communications --- src/bittorrent.cpp | 12 +++++++++ src/downloadthread.cpp | 4 ++- src/options_imp.cpp | 57 ++++++++++++++++++++++++++---------------- src/ui/options.ui | 9 +++++-- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/bittorrent.cpp b/src/bittorrent.cpp index 5b7cef414..1556eaebc 100644 --- a/src/bittorrent.cpp +++ b/src/bittorrent.cpp @@ -538,6 +538,18 @@ void Bittorrent::configureSession() { http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); http_proxySettings.port = Preferences::getHTTPProxyPort(); break; + case SOCKS5: + http_proxySettings.type = proxy_settings::socks5; + http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); + http_proxySettings.port = Preferences::getHTTPProxyPort(); + break; + case SOCKS5_PW: + http_proxySettings.type = proxy_settings::socks5_pw; + http_proxySettings.username = Preferences::getHTTPProxyUsername().toStdString(); + http_proxySettings.password = Preferences::getHTTPProxyPassword().toStdString(); + http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); + http_proxySettings.port = Preferences::getHTTPProxyPort(); + break; default: http_proxySettings.type = proxy_settings::none; } diff --git a/src/downloadthread.cpp b/src/downloadthread.cpp index 7b64a1bf2..e9f3f1a93 100644 --- a/src/downloadthread.cpp +++ b/src/downloadthread.cpp @@ -35,6 +35,8 @@ #include #include +enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5}; + /** Download Thread **/ downloadThread::downloadThread(QObject* parent) : QObject(parent) { @@ -105,7 +107,7 @@ void downloadThread::applyProxySettings() { qDebug("Using proxy: %s", (IP+QString(":")+port).toLocal8Bit().data()); proxy.setPort(port.toUShort()); // Default proxy type is HTTP, we must change if it is SOCKS5 - if(intValue%2==0) { + if(intValue == SOCKS5 || intValue == SOCKS5_PW) { qDebug("Proxy is SOCKS5, not HTTP"); proxy.setType(QNetworkProxy::Socks5Proxy); } else { diff --git a/src/options_imp.cpp b/src/options_imp.cpp index a3b7320bc..fbbd19b9b 100644 --- a/src/options_imp.cpp +++ b/src/options_imp.cpp @@ -520,13 +520,22 @@ int options_imp::getPeerProxyType() const{ } int options_imp::getHTTPProxyType() const { - if(comboProxyType_http->currentIndex() > 0){ - if(isHTTPProxyAuthEnabled()){ - return HTTP_PW; + switch(comboProxyType_http->currentIndex()) { + case 1: { + if(isHTTPProxyAuthEnabled()){ + return HTTP_PW; + } + return HTTP; + } + case 2: { + if(isHTTPProxyAuthEnabled()) { + return SOCKS5_PW; + } + return SOCKS5; } - return HTTP; + default: + return -1; // Disabled } - return -1; // disabled } int options_imp::getStyle() const{ @@ -637,17 +646,18 @@ void options_imp::loadOptions(){ checkResolveHosts->setChecked(Preferences::resolvePeerHostNames()); intValue = Preferences::getPeerProxyType(); - if(intValue <= 0) { - intValue = 0; - } else { - if(intValue%2 == 0) { - intValue = 2; - }else { - intValue = 1; - } + switch(intValue) { + case SOCKS4: + comboProxyType->setCurrentIndex(1); + break; + case SOCKS5: + case SOCKS5_PW: + comboProxyType->setCurrentIndex(2); + break; + default: + comboProxyType->setCurrentIndex(0); } - comboProxyType->setCurrentIndex(intValue); - enablePeerProxy(intValue); + enablePeerProxy(comboProxyType->currentIndex()); //if(isProxyEnabled()) { // Proxy is enabled, save settings textProxyIP->setText(Preferences::getPeerProxyIp()); @@ -658,13 +668,18 @@ void options_imp::loadOptions(){ enablePeerProxyAuth(checkProxyAuth->isChecked()); //} intValue = Preferences::getHTTPProxyType(); - if(intValue <= 0) { - intValue = 0; - } else { - intValue = 1; + switch(intValue) { + case HTTP: + comboProxyType_http->setCurrentIndex(1); + break; + case SOCKS5: + case SOCKS5_PW: + comboProxyType_http->setCurrentIndex(2); + break; + default: + comboProxyType_http->setCurrentIndex(0); } - comboProxyType_http->setCurrentIndex(intValue); - enableHTTPProxy(intValue); + enableHTTPProxy(comboProxyType_http->currentIndex()); textProxyUsername_http->setText(Preferences::getHTTPProxyUsername()); textProxyPassword_http->setText(Preferences::getHTTPProxyPassword()); textProxyIP_http->setText(Preferences::getHTTPProxyIp()); diff --git a/src/ui/options.ui b/src/ui/options.ui index 31ae82566..108faecaf 100644 --- a/src/ui/options.ui +++ b/src/ui/options.ui @@ -1951,8 +1951,8 @@ QGroupBox { 0 0 - 484 - 312 + 620 + 495 @@ -1983,6 +1983,11 @@ QGroupBox { HTTP + + + SOCKS5 + +