Fix to proxy settings

Added back SOCKS5 proxy support for HTTP communications
This commit is contained in:
Christophe Dumez 2010-01-07 20:35:12 +00:00
parent 6ae49acb69
commit 296acf820c
4 changed files with 58 additions and 24 deletions

View file

@ -538,6 +538,18 @@ void Bittorrent::configureSession() {
http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString(); http_proxySettings.hostname = Preferences::getHTTPProxyIp().toStdString();
http_proxySettings.port = Preferences::getHTTPProxyPort(); http_proxySettings.port = Preferences::getHTTPProxyPort();
break; 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: default:
http_proxySettings.type = proxy_settings::none; http_proxySettings.type = proxy_settings::none;
} }

View file

@ -35,6 +35,8 @@
#include <QNetworkRequest> #include <QNetworkRequest>
#include <QNetworkProxy> #include <QNetworkProxy>
enum ProxyType {HTTP=1, SOCKS5=2, HTTP_PW=3, SOCKS5_PW=4, SOCKS4=5};
/** Download Thread **/ /** Download Thread **/
downloadThread::downloadThread(QObject* parent) : QObject(parent) { downloadThread::downloadThread(QObject* parent) : QObject(parent) {
@ -105,7 +107,7 @@ void downloadThread::applyProxySettings() {
qDebug("Using proxy: %s", (IP+QString(":")+port).toLocal8Bit().data()); qDebug("Using proxy: %s", (IP+QString(":")+port).toLocal8Bit().data());
proxy.setPort(port.toUShort()); proxy.setPort(port.toUShort());
// Default proxy type is HTTP, we must change if it is SOCKS5 // 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"); qDebug("Proxy is SOCKS5, not HTTP");
proxy.setType(QNetworkProxy::Socks5Proxy); proxy.setType(QNetworkProxy::Socks5Proxy);
} else { } else {

View file

@ -520,13 +520,22 @@ int options_imp::getPeerProxyType() const{
} }
int options_imp::getHTTPProxyType() const { int options_imp::getHTTPProxyType() const {
if(comboProxyType_http->currentIndex() > 0){ switch(comboProxyType_http->currentIndex()) {
case 1: {
if(isHTTPProxyAuthEnabled()){ if(isHTTPProxyAuthEnabled()){
return HTTP_PW; return HTTP_PW;
} }
return HTTP; return HTTP;
} }
return -1; // disabled case 2: {
if(isHTTPProxyAuthEnabled()) {
return SOCKS5_PW;
}
return SOCKS5;
}
default:
return -1; // Disabled
}
} }
int options_imp::getStyle() const{ int options_imp::getStyle() const{
@ -637,17 +646,18 @@ void options_imp::loadOptions(){
checkResolveHosts->setChecked(Preferences::resolvePeerHostNames()); checkResolveHosts->setChecked(Preferences::resolvePeerHostNames());
intValue = Preferences::getPeerProxyType(); intValue = Preferences::getPeerProxyType();
if(intValue <= 0) { switch(intValue) {
intValue = 0; case SOCKS4:
} else { comboProxyType->setCurrentIndex(1);
if(intValue%2 == 0) { break;
intValue = 2; case SOCKS5:
}else { case SOCKS5_PW:
intValue = 1; comboProxyType->setCurrentIndex(2);
break;
default:
comboProxyType->setCurrentIndex(0);
} }
} enablePeerProxy(comboProxyType->currentIndex());
comboProxyType->setCurrentIndex(intValue);
enablePeerProxy(intValue);
//if(isProxyEnabled()) { //if(isProxyEnabled()) {
// Proxy is enabled, save settings // Proxy is enabled, save settings
textProxyIP->setText(Preferences::getPeerProxyIp()); textProxyIP->setText(Preferences::getPeerProxyIp());
@ -658,13 +668,18 @@ void options_imp::loadOptions(){
enablePeerProxyAuth(checkProxyAuth->isChecked()); enablePeerProxyAuth(checkProxyAuth->isChecked());
//} //}
intValue = Preferences::getHTTPProxyType(); intValue = Preferences::getHTTPProxyType();
if(intValue <= 0) { switch(intValue) {
intValue = 0; case HTTP:
} else { comboProxyType_http->setCurrentIndex(1);
intValue = 1; break;
case SOCKS5:
case SOCKS5_PW:
comboProxyType_http->setCurrentIndex(2);
break;
default:
comboProxyType_http->setCurrentIndex(0);
} }
comboProxyType_http->setCurrentIndex(intValue); enableHTTPProxy(comboProxyType_http->currentIndex());
enableHTTPProxy(intValue);
textProxyUsername_http->setText(Preferences::getHTTPProxyUsername()); textProxyUsername_http->setText(Preferences::getHTTPProxyUsername());
textProxyPassword_http->setText(Preferences::getHTTPProxyPassword()); textProxyPassword_http->setText(Preferences::getHTTPProxyPassword());
textProxyIP_http->setText(Preferences::getHTTPProxyIp()); textProxyIP_http->setText(Preferences::getHTTPProxyIp());

View file

@ -1951,8 +1951,8 @@ QGroupBox {
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>484</width> <width>620</width>
<height>312</height> <height>495</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_16"> <layout class="QVBoxLayout" name="verticalLayout_16">
@ -1983,6 +1983,11 @@ QGroupBox {
<string>HTTP</string> <string>HTTP</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>SOCKS5</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>