1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-20 15:59:42 +01: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" );
}
static QMutex s_noProxyHostsMutex;
static QStringList s_noProxyHosts;
NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
{
m_noProxyHosts = QStringList( other.m_noProxyHosts );
m_proxy = QNetworkProxy( other.m_proxy );
}
@ -312,13 +313,17 @@ NetworkProxyFactory::NetworkProxyFactory( const NetworkProxyFactory& other )
QList< QNetworkProxy >
NetworkProxyFactory::queryProxy( const QNetworkProxyQuery& query )
{
tDebug() << Q_FUNC_INFO << "query hostname is " << query.peerHostName();
QList< QNetworkProxy > proxies;
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 );
else
proxies << m_proxy << systemProxyForQuery( query );
s_noProxyHostsMutex.unlock();
return proxies;
}
@ -335,7 +340,9 @@ NetworkProxyFactory::setNoProxyHosts( const QStringList& hosts )
//TODO: wildcard support
}
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 )
{
m_proxy = QNetworkProxy( rhs.m_proxy );
m_noProxyHosts = QStringList( rhs.m_noProxyHosts );
}
return *this;
@ -367,7 +373,7 @@ NetworkProxyFactory::operator=( const NetworkProxyFactory& rhs )
bool NetworkProxyFactory::operator==( const NetworkProxyFactory& other ) const
{
tDebug() << Q_FUNC_INFO;
if ( m_noProxyHosts != other.m_noProxyHosts || m_proxy != other.m_proxy )
if ( m_proxy != other.m_proxy )
return false;
return true;
@ -378,25 +384,29 @@ static QMap< QThread*, NetworkProxyFactory* > s_threadProxyFactoryHash;
static QMutex s_namAccessMutex;
NetworkProxyFactory*
proxyFactory( bool noMutexLocker )
proxyFactory( bool makeClone, bool noMutexLocker )
{
// Don't lock if being called from nam()
tDebug() << Q_FUNC_INFO;
QMutex otherMutex;
QMutexLocker locker( noMutexLocker ? &otherMutex : &s_namAccessMutex );
if ( s_threadProxyFactoryHash.contains( QThread::currentThread() ) )
return s_threadProxyFactoryHash[ QThread::currentThread() ];
if ( !makeClone )
{
if ( s_threadProxyFactoryHash.contains( QThread::currentThread() ) )
return s_threadProxyFactoryHash[ QThread::currentThread() ];
if ( !s_threadProxyFactoryHash.contains( TOMAHAWK_APPLICATION::instance()->thread() ) )
return 0;
if ( !s_threadProxyFactoryHash.contains( TOMAHAWK_APPLICATION::instance()->thread() ) )
return 0;
}
// create a new proxy factory for this thread
TomahawkUtils::NetworkProxyFactory *mainProxyFactory = s_threadProxyFactoryHash[ TOMAHAWK_APPLICATION::instance()->thread() ];
TomahawkUtils::NetworkProxyFactory *newProxyFactory = new TomahawkUtils::NetworkProxyFactory();
*newProxyFactory = *mainProxyFactory;
s_threadProxyFactoryHash[ QThread::currentThread() ] = newProxyFactory;
if ( !makeClone )
s_threadProxyFactoryHash[ QThread::currentThread() ] = newProxyFactory;
return newProxyFactory;
}
@ -455,7 +465,7 @@ nam()
newNam->setConfiguration( QNetworkConfiguration( mainNam->configuration() ) );
newNam->setNetworkAccessible( mainNam->networkAccessible() );
newNam->setProxyFactory( proxyFactory( true ) );
newNam->setProxyFactory( proxyFactory( false, true ) );
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() );
proxyFactory->setProxy( proxy );
//FIXME: Jreen is broke without this
QNetworkProxy::setApplicationProxy( proxy );
if ( !s->proxyNoProxyHosts().isEmpty() )
//QNetworkProxy::setApplicationProxy( proxy );
s_noProxyHostsMutex.lock();
if ( !s->proxyNoProxyHosts().isEmpty() && s_noProxyHosts.isEmpty() )
{
s_noProxyHostsMutex.unlock();
proxyFactory->setNoProxyHosts( s->proxyNoProxyHosts().split( ',', QString::SkipEmptyParts ) );
}
else
s_noProxyHostsMutex.unlock();
}
nam->setProxyFactory( proxyFactory );

View File

@ -92,7 +92,7 @@ namespace TomahawkUtils
DLLEXPORT QString extensionToMimetype( const QString& extension );
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 QNetworkAccessManager* nam();
DLLEXPORT void setNam( QNetworkAccessManager* nam, bool noMutexLocker = false );

View File

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

View File

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

View File

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

View File

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

View File

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