Skip to content
Permalink
Browse files
network manager: fix authentication of private network manager instan…
…ces and support system proxies with exclusions
  • Loading branch information
jef-n committed May 10, 2014
1 parent b1570fb commit afc2e055373812265d16feedb3e3d7c7649d4837
Showing with 54 additions and 9 deletions.
  1. +8 −0 src/app/qgsoptions.cpp
  2. +2 −0 src/app/qgsoptions.h
  3. +41 −9 src/core/qgsnetworkaccessmanager.cpp
  4. +3 −0 src/core/qgsnetworkaccessmanager.h
@@ -860,6 +860,14 @@ void QgsOptions::setCurrentPage( QString pageWidgetName )
}
}

void QgsOptions::on_mProxyTypeComboBox_currentIndexChanged( int idx )
{
leProxyHost->setEnabled( idx != 0 );
leProxyPort->setEnabled( idx != 0 );
leProxyUser->setEnabled( idx != 0 );
leProxyPassword->setEnabled( idx != 0 );
}

void QgsOptions::on_cbxProjectDefaultNew_toggled( bool checked )
{
if ( checked )
@@ -135,6 +135,8 @@ class APP_EXPORT QgsOptions : public QgsOptionsDialogBase, private Ui::QgsOption
*/
void on_mBoldGroupBoxTitleChkBx_clicked( bool chkd );

void on_mProxyTypeComboBox_currentIndexChanged( int idx );

/**Add a new URL to exclude from Proxy*/
void on_mAddUrlPushButton_clicked();

@@ -69,20 +69,32 @@ class QgsNetworkProxyFactory : public QNetworkProxyFactory
}
}

QgsDebugMsg( QString( "using user proxy for %1" ).arg( url ) );
if ( nam->useSystemProxy() )
{
QgsDebugMsg( QString( "requesting system proxy for query %1" ).arg( url ) );
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery( query );
if ( !proxies.isEmpty() )
{
QgsDebugMsg( QString( "using system proxy %1:%2 for query" )
.arg( proxies.first().hostName() ).arg( proxies.first().port() ) );
return proxies;
}
}

QgsDebugMsg( QString( "using fallback proxy for %1" ).arg( url ) );
return QList<QNetworkProxy>() << nam->fallbackProxy();
}
};

QgsNetworkAccessManager *QgsNetworkAccessManager::instance()
{
static QgsNetworkAccessManager sInstance;

return &sInstance;
}

QgsNetworkAccessManager::QgsNetworkAccessManager( QObject *parent )
: QNetworkAccessManager( parent )
, mUseSystemProxy( false )
{
setProxyFactory( new QgsNetworkProxyFactory() );
}
@@ -230,7 +242,30 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()

QSettings settings;

//check if proxy is enabled
mUseSystemProxy = false;

if ( this != instance() )
{
connect( this, SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ),
instance(), SIGNAL( authenticationRequired( QNetworkReply *, QAuthenticator * ) ),
Qt::BlockingQueuedConnection );

connect( this, SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
instance(), SIGNAL( proxyAuthenticationRequired( const QNetworkProxy &, QAuthenticator * ) ),
Qt::BlockingQueuedConnection );

connect( this, SIGNAL( requestTimedOut( QNetworkReply* ) ),
instance(), SIGNAL( requestTimedOut( QNetworkReply* ) ),
Qt::BlockingQueuedConnection );

#ifndef QT_NO_OPENSSL
connect( this, SIGNAL( sslErrors( QNetworkReply *, const QList<QSslError> & ) ),
instance(), SIGNAL( sslErrors( QNetworkReply *, const QList<QSslError> & ) ),
Qt::BlockingQueuedConnection );
#endif
}

// check if proxy is enabled
bool proxyEnabled = settings.value( "proxy/proxyEnabled", false ).toBool();
if ( proxyEnabled )
{
@@ -243,24 +278,21 @@ void QgsNetworkAccessManager::setupDefaultProxyAndCache()
QString proxyPassword = settings.value( "proxy/proxyPassword", "" ).toString();

QString proxyTypeString = settings.value( "proxy/proxyType", "" ).toString();
QNetworkProxy::ProxyType proxyType = QNetworkProxy::NoProxy;

if ( proxyTypeString == "DefaultProxy" )
{
proxyType = QNetworkProxy::DefaultProxy;

#if defined(Q_OS_WIN)
mUseSystemProxy = true;
QNetworkProxyFactory::setUseSystemConfiguration( true );
QList<QNetworkProxy> proxies = QNetworkProxyFactory::systemProxyForQuery();
if ( !proxies.isEmpty() )
{
proxy = proxies.first();
}
#endif

QgsDebugMsg( "setting default proxy" );
}
else
{
QNetworkProxy::ProxyType proxyType = QNetworkProxy::DefaultProxy;
if ( proxyTypeString == "Socks5Proxy" )
{
proxyType = QNetworkProxy::Socks5Proxy;
@@ -82,6 +82,8 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
//! Setup the NAM according to the user's settings
void setupDefaultProxyAndCache();

bool useSystemProxy() { return mUseSystemProxy; }

signals:
void requestAboutToBeCreated( QNetworkAccessManager::Operation, const QNetworkRequest &, QIODevice * );
void requestCreated( QNetworkReply * );
@@ -97,6 +99,7 @@ class CORE_EXPORT QgsNetworkAccessManager : public QNetworkAccessManager
QList<QNetworkProxyFactory*> mProxyFactories;
QNetworkProxy mFallbackProxy;
QStringList mExcludedURLs;
bool mUseSystemProxy;
};

#endif // QGSNETWORKACCESSMANAGER_H

0 comments on commit afc2e05

Please sign in to comment.