Skip to content
Permalink
Browse files
wms: fix redirected requests
  • Loading branch information
jef-n committed Jun 22, 2014
1 parent e8d80a3 commit ec1bfadac3cf527d311da632ee3fc144ce56fff1
Showing with 67 additions and 55 deletions.
  1. +52 −48 src/app/qgisapp.cpp
  2. +15 −7 src/providers/wms/qgswmsprovider.cpp
@@ -9775,41 +9775,43 @@ void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *a
QString username = auth->user();
QString password = auth->password();

QMutexLocker lock( QgsCredentials::instance()->mutex() );

do
{
bool ok = QgsCredentials::instance()->get(
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
username, password,
tr( "Authentication required" ) );
if ( !ok )
return;

if ( reply->isFinished() )
return;
QMutexLocker lock( QgsCredentials::instance()->mutex() );

if ( auth->user() == username && password == auth->password() )
do
{
if ( !password.isNull() )
bool ok = QgsCredentials::instance()->get(
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
username, password,
tr( "Authentication required" ) );
if ( !ok )
return;

if ( reply->isFinished() )
return;

if ( auth->user() == username && password == auth->password() )
{
// credentials didn't change - stored ones probably wrong? clear password and retry
if ( !password.isNull() )
{
// credentials didn't change - stored ones probably wrong? clear password and retry
QgsCredentials::instance()->put(
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
username, QString::null );
continue;
}
}
else
{
// save credentials
QgsCredentials::instance()->put(
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
username, QString::null );
continue;
username, password
);
}
}
else
{
// save credentials
QgsCredentials::instance()->put(
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
username, password
);
}
while ( 0 );
}
while ( 0 );

auth->setUser( username );
auth->setPassword( password );
@@ -9828,37 +9830,39 @@ void QgisApp::namProxyAuthenticationRequired( const QNetworkProxy &proxy, QAuthe
QString username = auth->user();
QString password = auth->password();

QMutexLocker lock( QgsCredentials::instance()->mutex() );

do
{
bool ok = QgsCredentials::instance()->get(
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
username, password,
tr( "Proxy authentication required" ) );
if ( !ok )
return;
QMutexLocker lock( QgsCredentials::instance()->mutex() );

if ( auth->user() == username && password == auth->password() )
do
{
if ( !password.isNull() )
bool ok = QgsCredentials::instance()->get(
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
username, password,
tr( "Proxy authentication required" ) );
if ( !ok )
return;

if ( auth->user() == username && password == auth->password() )
{
if ( !password.isNull() )
{
// credentials didn't change - stored ones probably wrong? clear password and retry
QgsCredentials::instance()->put(
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
username, QString::null );
continue;
}
}
else
{
// credentials didn't change - stored ones probably wrong? clear password and retry
QgsCredentials::instance()->put(
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
username, QString::null );
continue;
username, password
);
}
}
else
{
QgsCredentials::instance()->put(
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
username, password
);
}
while ( 0 );
}
while ( 0 );

auth->setUser( username );
auth->setPassword( password );
@@ -2367,7 +2367,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) );

QEventLoop loop;
connect( mIdentifyReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( &loop ) ) );
loop.exec( QEventLoop::ExcludeUserInputEvents );

if ( mIdentifyResultBodies.size() == 0 ) // no result
@@ -2767,9 +2767,12 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs

void QgsWmsProvider::identifyReplyFinished()
{
QgsDebugMsg( "Entered." );
mIdentifyResultHeaders.clear();
mIdentifyResultBodies.clear();

QEventLoop *loop = qobject_cast< QEventLoop *>( sender()->property( "eventLoop" ).value< QObject *>() );

if ( mIdentifyReply->error() == QNetworkReply::NoError )
{
QVariant redirect = mIdentifyReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
@@ -2782,8 +2785,8 @@ void QgsWmsProvider::identifyReplyFinished()

QgsDebugMsg( QString( "redirected getfeatureinfo: %1" ).arg( redirect.toString() ) );
mIdentifyReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) );
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( loop ) ) );
connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) );

return;
}

@@ -2794,8 +2797,6 @@ void QgsWmsProvider::identifyReplyFinished()
mErrorFormat = "text/plain";
mError = tr( "Map getfeatureinfo error %1: %2" ).arg( status.toInt() ).arg( phrase.toString() );
emit statusChanged( mError );

//mIdentifyResult = "";
}

QgsNetworkReplyParser parser( mIdentifyReply );
@@ -2805,7 +2806,6 @@ void QgsWmsProvider::identifyReplyFinished()
mErrorFormat = "text/plain";
mError = tr( "Cannot parse getfeatureinfo: %1" ).arg( parser.error() );
emit statusChanged( mError );
//mIdentifyResult = "";
}
else
{
@@ -2824,6 +2824,9 @@ void QgsWmsProvider::identifyReplyFinished()
QgsMessageLog::logMessage( mError, tr( "WMS" ) );
}

if ( loop )
QMetaObject::invokeMethod( loop, "quit", Qt::QueuedConnection );

mIdentifyReply->deleteLater();
mIdentifyReply = 0;
}
@@ -3016,12 +3019,11 @@ QImage QgsWmsProvider::getLegendGraphic( double scale, bool forceRefresh )

QgsDebugMsg( QString( "getlegendgraphics: %1" ).arg( url.toString() ) );
mGetLegendGraphicReply = QgsNetworkAccessManager::instance()->get( request );

connect( mGetLegendGraphicReply, SIGNAL( finished() ), this, SLOT( getLegendGraphicReplyFinished() ) );
connect( mGetLegendGraphicReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( getLegendGraphicReplyProgress( qint64, qint64 ) ) );

QEventLoop loop;
connect( mGetLegendGraphicReply, SIGNAL( finished() ), &loop, SLOT( quit() ) );
mGetLegendGraphicReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( &loop ) ) );
loop.exec( QEventLoop::ExcludeUserInputEvents );

QgsDebugMsg( "exiting." );
@@ -3033,6 +3035,8 @@ void QgsWmsProvider::getLegendGraphicReplyFinished()
{
QgsDebugMsg( "entering." );

QEventLoop *loop = qobject_cast< QEventLoop *>( sender()->property( "eventLoop" ).value< QObject *>() );

if ( mGetLegendGraphicReply->error() == QNetworkReply::NoError )
{
QgsDebugMsg( "reply ok" );
@@ -3060,6 +3064,7 @@ void QgsWmsProvider::getLegendGraphicReplyFinished()
mGetLegendGraphicReply->deleteLater();
QgsDebugMsg( QString( "redirected GetLegendGraphic: %1" ).arg( redirect.toString() ) );
mGetLegendGraphicReply = QgsNetworkAccessManager::instance()->get( request );
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( loop ) ) );

connect( mGetLegendGraphicReply, SIGNAL( finished() ), this, SLOT( getLegendGraphicReplyFinished() ) );
connect( mGetLegendGraphicReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( getLegendGraphicReplyProgress( qint64, qint64 ) ) );
@@ -3099,6 +3104,9 @@ void QgsWmsProvider::getLegendGraphicReplyFinished()
mHttpGetLegendGraphicResponse.clear();
}

if ( loop )
QMetaObject::invokeMethod( loop, "quit", Qt::QueuedConnection );

mGetLegendGraphicReply->deleteLater();
mGetLegendGraphicReply = 0;
}

0 comments on commit ec1bfad

Please sign in to comment.