Skip to content

Commit ec1bfad

Browse files
committedJun 22, 2014
wms: fix redirected requests
1 parent e8d80a3 commit ec1bfad

File tree

2 files changed

+67
-55
lines changed

2 files changed

+67
-55
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9775,41 +9775,43 @@ void QgisApp::namAuthenticationRequired( QNetworkReply *reply, QAuthenticator *a
97759775
QString username = auth->user();
97769776
QString password = auth->password();
97779777

9778-
QMutexLocker lock( QgsCredentials::instance()->mutex() );
9779-
9780-
do
97819778
{
9782-
bool ok = QgsCredentials::instance()->get(
9783-
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
9784-
username, password,
9785-
tr( "Authentication required" ) );
9786-
if ( !ok )
9787-
return;
9788-
9789-
if ( reply->isFinished() )
9790-
return;
9779+
QMutexLocker lock( QgsCredentials::instance()->mutex() );
97919780

9792-
if ( auth->user() == username && password == auth->password() )
9781+
do
97939782
{
9794-
if ( !password.isNull() )
9783+
bool ok = QgsCredentials::instance()->get(
9784+
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
9785+
username, password,
9786+
tr( "Authentication required" ) );
9787+
if ( !ok )
9788+
return;
9789+
9790+
if ( reply->isFinished() )
9791+
return;
9792+
9793+
if ( auth->user() == username && password == auth->password() )
97959794
{
9796-
// credentials didn't change - stored ones probably wrong? clear password and retry
9795+
if ( !password.isNull() )
9796+
{
9797+
// credentials didn't change - stored ones probably wrong? clear password and retry
9798+
QgsCredentials::instance()->put(
9799+
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
9800+
username, QString::null );
9801+
continue;
9802+
}
9803+
}
9804+
else
9805+
{
9806+
// save credentials
97979807
QgsCredentials::instance()->put(
97989808
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
9799-
username, QString::null );
9800-
continue;
9809+
username, password
9810+
);
98019811
}
98029812
}
9803-
else
9804-
{
9805-
// save credentials
9806-
QgsCredentials::instance()->put(
9807-
QString( "%1 at %2" ).arg( auth->realm() ).arg( reply->url().host() ),
9808-
username, password
9809-
);
9810-
}
9813+
while ( 0 );
98119814
}
9812-
while ( 0 );
98139815

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

9831-
QMutexLocker lock( QgsCredentials::instance()->mutex() );
9832-
9833-
do
98349833
{
9835-
bool ok = QgsCredentials::instance()->get(
9836-
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
9837-
username, password,
9838-
tr( "Proxy authentication required" ) );
9839-
if ( !ok )
9840-
return;
9834+
QMutexLocker lock( QgsCredentials::instance()->mutex() );
98419835

9842-
if ( auth->user() == username && password == auth->password() )
9836+
do
98439837
{
9844-
if ( !password.isNull() )
9838+
bool ok = QgsCredentials::instance()->get(
9839+
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
9840+
username, password,
9841+
tr( "Proxy authentication required" ) );
9842+
if ( !ok )
9843+
return;
9844+
9845+
if ( auth->user() == username && password == auth->password() )
9846+
{
9847+
if ( !password.isNull() )
9848+
{
9849+
// credentials didn't change - stored ones probably wrong? clear password and retry
9850+
QgsCredentials::instance()->put(
9851+
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
9852+
username, QString::null );
9853+
continue;
9854+
}
9855+
}
9856+
else
98459857
{
9846-
// credentials didn't change - stored ones probably wrong? clear password and retry
98479858
QgsCredentials::instance()->put(
98489859
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
9849-
username, QString::null );
9850-
continue;
9860+
username, password
9861+
);
98519862
}
98529863
}
9853-
else
9854-
{
9855-
QgsCredentials::instance()->put(
9856-
QString( "proxy %1:%2 [%3]" ).arg( proxy.hostName() ).arg( proxy.port() ).arg( auth->realm() ),
9857-
username, password
9858-
);
9859-
}
9864+
while ( 0 );
98609865
}
9861-
while ( 0 );
98629866

98639867
auth->setUser( username );
98649868
auth->setPassword( password );

‎src/providers/wms/qgswmsprovider.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2367,7 +2367,7 @@ QgsRasterIdentifyResult QgsWmsProvider::identify( const QgsPoint & thePoint, Qgs
23672367
connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) );
23682368

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

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

27682768
void QgsWmsProvider::identifyReplyFinished()
27692769
{
2770+
QgsDebugMsg( "Entered." );
27702771
mIdentifyResultHeaders.clear();
27712772
mIdentifyResultBodies.clear();
27722773

2774+
QEventLoop *loop = qobject_cast< QEventLoop *>( sender()->property( "eventLoop" ).value< QObject *>() );
2775+
27732776
if ( mIdentifyReply->error() == QNetworkReply::NoError )
27742777
{
27752778
QVariant redirect = mIdentifyReply->attribute( QNetworkRequest::RedirectionTargetAttribute );
@@ -2782,8 +2785,8 @@ void QgsWmsProvider::identifyReplyFinished()
27822785

27832786
QgsDebugMsg( QString( "redirected getfeatureinfo: %1" ).arg( redirect.toString() ) );
27842787
mIdentifyReply = QgsNetworkAccessManager::instance()->get( QNetworkRequest( redirect.toUrl() ) );
2788+
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( loop ) ) );
27852789
connect( mIdentifyReply, SIGNAL( finished() ), this, SLOT( identifyReplyFinished() ) );
2786-
27872790
return;
27882791
}
27892792

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

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

2827+
if ( loop )
2828+
QMetaObject::invokeMethod( loop, "quit", Qt::QueuedConnection );
2829+
28272830
mIdentifyReply->deleteLater();
28282831
mIdentifyReply = 0;
28292832
}
@@ -3016,12 +3019,11 @@ QImage QgsWmsProvider::getLegendGraphic( double scale, bool forceRefresh )
30163019

30173020
QgsDebugMsg( QString( "getlegendgraphics: %1" ).arg( url.toString() ) );
30183021
mGetLegendGraphicReply = QgsNetworkAccessManager::instance()->get( request );
3019-
30203022
connect( mGetLegendGraphicReply, SIGNAL( finished() ), this, SLOT( getLegendGraphicReplyFinished() ) );
30213023
connect( mGetLegendGraphicReply, SIGNAL( downloadProgress( qint64, qint64 ) ), this, SLOT( getLegendGraphicReplyProgress( qint64, qint64 ) ) );
30223024

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

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

3038+
QEventLoop *loop = qobject_cast< QEventLoop *>( sender()->property( "eventLoop" ).value< QObject *>() );
3039+
30363040
if ( mGetLegendGraphicReply->error() == QNetworkReply::NoError )
30373041
{
30383042
QgsDebugMsg( "reply ok" );
@@ -3060,6 +3064,7 @@ void QgsWmsProvider::getLegendGraphicReplyFinished()
30603064
mGetLegendGraphicReply->deleteLater();
30613065
QgsDebugMsg( QString( "redirected GetLegendGraphic: %1" ).arg( redirect.toString() ) );
30623066
mGetLegendGraphicReply = QgsNetworkAccessManager::instance()->get( request );
3067+
mIdentifyReply->setProperty( "eventLoop", QVariant::fromValue( qobject_cast<QObject *>( loop ) ) );
30633068

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

3107+
if ( loop )
3108+
QMetaObject::invokeMethod( loop, "quit", Qt::QueuedConnection );
3109+
31023110
mGetLegendGraphicReply->deleteLater();
31033111
mGetLegendGraphicReply = 0;
31043112
}

0 commit comments

Comments
 (0)
Please sign in to comment.