1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-07-31 11:20:22 +02:00

Fix XMPP proxy. Make no proxy hosts static so changing it works across

all threads; make a duplication method so jreen doesn't scopepointer us
to death on shutdown; pass in proxyfactory to jreen.

Conflicts:

	src/settingsdialog.cpp
	src/sip/jabber/jabber.cpp
This commit is contained in:
Jeff Mitchell
2012-03-09 17:41:38 -05:00
parent 240517b0cd
commit 18e3669911
7 changed files with 46 additions and 32 deletions

View File

@@ -301,10 +301,11 @@ extensionToMimetype( const QString& extension )
return s_ext2mime.value( extension, "unknown" ); return s_ext2mime.value( extension, "unknown" );
} }
static QMutex s_noProxyHostsMutex;
static QStringList s_noProxyHosts;
NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other ) NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
{ {
m_noProxyHosts = QStringList( other.m_noProxyHosts );
m_proxy = QNetworkProxy( other.m_proxy ); m_proxy = QNetworkProxy( other.m_proxy );
} }
@@ -312,13 +313,17 @@ NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
QList< QNetworkProxy > QList< QNetworkProxy >
NetworkProxyFactory::queryProxy( const QNetworkProxyQuery& query ) NetworkProxyFactory::queryProxy( const QNetworkProxyQuery& query )
{ {
tDebug() << Q_FUNC_INFO << "query hostname is " << query.peerHostName();
QList< QNetworkProxy > proxies; QList< QNetworkProxy > proxies;
QString hostname = query.peerHostName(); QString hostname = query.peerHostName();
if ( m_proxy.hostName().isEmpty() || hostname.isEmpty() || m_noProxyHosts.contains( hostname ) || TomahawkSettings::instance()->proxyType() == QNetworkProxy::NoProxy ) s_noProxyHostsMutex.lock();
if ( s_noProxyHosts.contains( hostname ) )
proxies << QNetworkProxy::NoProxy << systemProxyForQuery( query );
else if ( m_proxy.hostName().isEmpty() || hostname.isEmpty() || TomahawkSettings::instance()->proxyType() == QNetworkProxy::NoProxy )
proxies << systemProxyForQuery( query ); proxies << systemProxyForQuery( query );
else else
proxies << m_proxy << systemProxyForQuery( query ); proxies << m_proxy << systemProxyForQuery( query );
s_noProxyHostsMutex.unlock();
return proxies; return proxies;
} }
@@ -335,7 +340,9 @@ NetworkProxyFactory::setNoProxyHosts( const QStringList& hosts )
//TODO: wildcard support //TODO: wildcard support
} }
tDebug() << Q_FUNC_INFO << "New no-proxy hosts:" << newList; tDebug() << Q_FUNC_INFO << "New no-proxy hosts:" << newList;
m_noProxyHosts = newList; s_noProxyHostsMutex.lock();
s_noProxyHosts = newList;
s_noProxyHostsMutex.unlock();
} }
@@ -357,7 +364,6 @@ NetworkProxyFactory::operator=( const NetworkProxyFactory& rhs )
if ( this != &rhs ) if ( this != &rhs )
{ {
m_proxy = QNetworkProxy( rhs.m_proxy ); m_proxy = QNetworkProxy( rhs.m_proxy );
m_noProxyHosts = QStringList( rhs.m_noProxyHosts );
} }
return *this; return *this;
@@ -367,7 +373,7 @@ NetworkProxyFactory::operator=( const NetworkProxyFactory& rhs )
bool NetworkProxyFactory::operator==( const NetworkProxyFactory& other ) const bool NetworkProxyFactory::operator==( const NetworkProxyFactory& other ) const
{ {
tDebug() << Q_FUNC_INFO; tDebug() << Q_FUNC_INFO;
if ( m_noProxyHosts != other.m_noProxyHosts || m_proxy != other.m_proxy ) if ( m_proxy != other.m_proxy )
return false; return false;
return true; return true;
@@ -378,25 +384,29 @@ static QMap< QThread*, NetworkProxyFactory* > s_threadProxyFactoryHash;
static QMutex s_namAccessMutex; static QMutex s_namAccessMutex;
NetworkProxyFactory* NetworkProxyFactory*
proxyFactory( bool noMutexLocker ) proxyFactory( bool makeClone, bool noMutexLocker )
{ {
// Don't lock if being called from nam() // Don't lock if being called from nam()
tDebug() << Q_FUNC_INFO; tDebug() << Q_FUNC_INFO;
QMutex otherMutex; QMutex otherMutex;
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex ); QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
if ( s_threadProxyFactoryHash.contains( QThread::currentThread() ) ) if ( !makeClone )
return s_threadProxyFactoryHash[ QThread::currentThread() ]; {
if ( s_threadProxyFactoryHash.contains( QThread::currentThread() ) )
return s_threadProxyFactoryHash[ QThread::currentThread() ];
if ( !s_threadProxyFactoryHash.contains( TOMAHAWK_APPLICATION::instance()->thread() ) ) if ( !s_threadProxyFactoryHash.contains( TOMAHAWK_APPLICATION::instance()->thread() ) )
return 0; return 0;
}
// create a new proxy factory for this thread // create a new proxy factory for this thread
TomahawkUtils::NetworkProxyFactory *mainProxyFactory = s_threadProxyFactoryHash[ TOMAHAWK_APPLICATION::instance()->thread() ]; TomahawkUtils::NetworkProxyFactory *mainProxyFactory = s_threadProxyFactoryHash[ TOMAHAWK_APPLICATION::instance()->thread() ];
TomahawkUtils::NetworkProxyFactory *newProxyFactory = new TomahawkUtils::NetworkProxyFactory(); TomahawkUtils::NetworkProxyFactory *newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
*newProxyFactory = *mainProxyFactory; *newProxyFactory = *mainProxyFactory;
s_threadProxyFactoryHash[ QThread::currentThread() ] = newProxyFactory; if ( !makeClone )
s_threadProxyFactoryHash[ QThread::currentThread() ] = newProxyFactory;
return newProxyFactory; return newProxyFactory;
} }
@@ -455,7 +465,7 @@ nam()
newNam->setConfiguration( QNetworkConfiguration( mainNam->configuration() ) ); newNam->setConfiguration( QNetworkConfiguration( mainNam->configuration() ) );
newNam->setNetworkAccessible( mainNam->networkAccessible() ); newNam->setNetworkAccessible( mainNam->networkAccessible() );
newNam->setProxyFactory( proxyFactory( true ) ); newNam->setProxyFactory( proxyFactory( false, true ) );
s_threadNamHash[ QThread::currentThread() ] = newNam; s_threadNamHash[ QThread::currentThread() ] = newNam;
@@ -485,9 +495,15 @@ setNam( QNetworkAccessManager* nam, bool noMutexLocker )
QNetworkProxy proxy( s->proxyType(), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() ); QNetworkProxy proxy( s->proxyType(), s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() );
proxyFactory->setProxy( proxy ); proxyFactory->setProxy( proxy );
//FIXME: Jreen is broke without this //FIXME: Jreen is broke without this
QNetworkProxy::setApplicationProxy( proxy ); //QNetworkProxy::setApplicationProxy( proxy );
if ( !s->proxyNoProxyHosts().isEmpty() ) s_noProxyHostsMutex.lock();
if ( !s->proxyNoProxyHosts().isEmpty() && s_noProxyHosts.isEmpty() )
{
s_noProxyHostsMutex.unlock();
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) ); proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
}
else
s_noProxyHostsMutex.unlock();
} }
nam->setProxyFactory( proxyFactory ); nam->setProxyFactory( proxyFactory );

View File

@@ -92,7 +92,7 @@ namespace TomahawkUtils
DLLEXPORT QString extensionToMimetype( const QString& extension ); DLLEXPORT QString extensionToMimetype( const QString& extension );
DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion ); DLLEXPORT bool newerVersion( const QString& oldVersion, const QString& newVersion );
DLLEXPORT NetworkProxyFactory* proxyFactory( bool noMutexLocker = false ); DLLEXPORT NetworkProxyFactory* proxyFactory( bool makeClone = false, bool noMutexLocker = false );
DLLEXPORT void setProxyFactory( TomahawkUtils::NetworkProxyFactory* factory, bool noMutexLocker = false ); DLLEXPORT void setProxyFactory( TomahawkUtils::NetworkProxyFactory* factory, bool noMutexLocker = false );
DLLEXPORT QNetworkAccessManager* nam(); DLLEXPORT QNetworkAccessManager* nam();
DLLEXPORT void setNam( QNetworkAccessManager* nam, bool noMutexLocker = false ); DLLEXPORT void setNam( QNetworkAccessManager* nam, bool noMutexLocker = false );

View File

@@ -139,7 +139,8 @@
<item row="5" column="0"> <item row="5" column="0">
<widget class="QLabel" name="label"> <widget class="QLabel" name="label">
<property name="text"> <property name="text">
<string>No Proxy Hosts:</string> <string>No Proxy Hosts:
(Overrides system proxy)</string>
</property> </property>
</widget> </widget>
</item> </item>

View File

@@ -22,13 +22,13 @@
#include "utils/tomahawkutilsgui.h" #include "utils/tomahawkutilsgui.h"
#include <QDesktopServices> #include <QtGui/QDesktopServices>
#include <QFileDialog> #include <QtGui/QFileDialog>
#include <QMessageBox> #include <QtGui/QMessageBox>
#include <QNetworkConfiguration> #include <QtNetwork/QNetworkConfiguration>
#include <QNetworkProxy> #include <QtNetwork/QNetworkProxy>
#include <QVBoxLayout> #include <QtGui/QVBoxLayout>
#include <QSizeGrip> #include <QtGui/QSizeGrip>
#ifdef LIBLASTFM_FOUND #ifdef LIBLASTFM_FOUND
#include <lastfm/ws.h> #include <lastfm/ws.h>
@@ -859,7 +859,6 @@ ProxyDialog::ProxyDialog( QWidget *parent )
ui->userLineEdit->setEnabled( false ); ui->userLineEdit->setEnabled( false );
ui->passwordLineEdit->setEnabled( false ); ui->passwordLineEdit->setEnabled( false );
ui->checkBoxUseProxyForDns->setEnabled( false ); ui->checkBoxUseProxyForDns->setEnabled( false );
ui->noHostLineEdit->setEnabled( false );
} }
connect( ui->typeBox, SIGNAL( currentIndexChanged( int ) ), SLOT( proxyTypeChangedSlot( int ) ) ); connect( ui->typeBox, SIGNAL( currentIndexChanged( int ) ), SLOT( proxyTypeChangedSlot( int ) ) );
@@ -876,7 +875,6 @@ ProxyDialog::proxyTypeChangedSlot( int index )
ui->userLineEdit->setEnabled( false ); ui->userLineEdit->setEnabled( false );
ui->passwordLineEdit->setEnabled( false ); ui->passwordLineEdit->setEnabled( false );
ui->checkBoxUseProxyForDns->setEnabled( false ); ui->checkBoxUseProxyForDns->setEnabled( false );
ui->noHostLineEdit->setEnabled( false );
} }
else else
{ {
@@ -885,7 +883,6 @@ ProxyDialog::proxyTypeChangedSlot( int index )
ui->userLineEdit->setEnabled( true ); ui->userLineEdit->setEnabled( true );
ui->passwordLineEdit->setEnabled( true ); ui->passwordLineEdit->setEnabled( true );
ui->checkBoxUseProxyForDns->setEnabled( true ); ui->checkBoxUseProxyForDns->setEnabled( true );
ui->noHostLineEdit->setEnabled( true );
} }
} }
@@ -923,8 +920,8 @@ ProxyDialog::saveSettings()
proxyFactory->setProxy( QNetworkProxy( type, s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() ) ); proxyFactory->setProxy( QNetworkProxy( type, s->proxyHost(), s->proxyPort(), s->proxyUsername(), s->proxyPassword() ) );
if ( !ui->noHostLineEdit->text().isEmpty() ) if ( !ui->noHostLineEdit->text().isEmpty() )
{ {
tDebug() << Q_FUNC_INFO << "hosts line edit is " << ui->noHostLineEdit->text(); tDebug() << Q_FUNC_INFO << "noproxy line edit is " << ui->noHostLineEdit->text();
tDebug() << Q_FUNC_INFO << "split hosts line edit is " << ui->noHostLineEdit->text().split( ' ', QString::SkipEmptyParts ); tDebug() << Q_FUNC_INFO << "split noproxy line edit is " << ui->noHostLineEdit->text().split( ' ', QString::SkipEmptyParts );
proxyFactory->setNoProxyHosts( ui->noHostLineEdit->text().split( ' ', QString::SkipEmptyParts ) ); proxyFactory->setNoProxyHosts( ui->noHostLineEdit->text().split( ' ', QString::SkipEmptyParts ) );
} }
} }

View File

@@ -19,8 +19,8 @@
#ifndef SETTINGSDIALOG_H #ifndef SETTINGSDIALOG_H
#define SETTINGSDIALOG_H #define SETTINGSDIALOG_H
#include <QDialog> #include <QtGui/QDialog>
#include <QModelIndex> #include <QtCore/QModelIndex>
#include "config.h" #include "config.h"

View File

@@ -102,6 +102,7 @@ JabberPlugin::JabberPlugin( const QString& pluginId )
// general client setup // general client setup
m_client = new Jreen::Client( jid, m_currentPassword ); m_client = new Jreen::Client( jid, m_currentPassword );
m_client->setProxyFactory( TomahawkUtils::proxyFactory( true ) );
setupClientHelper(); setupClientHelper();
m_client->registerPayload(new TomahawkSipMessageFactory); m_client->registerPayload(new TomahawkSipMessageFactory);

View File

@@ -28,7 +28,6 @@
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QtCore/QFile> #include <QtCore/QFile>
#include <QtCore/QFileInfo> #include <QtCore/QFileInfo>
#include <QtNetwork/QNetworkProxy>
#include "artist.h" #include "artist.h"
#include "album.h" #include "album.h"