Navigation Menu

Skip to content

Commit

Permalink
fix #3401
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15036 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 13, 2011
1 parent 47cf93e commit 5aa9ee8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/core/qgsdatasourceuri.cpp
Expand Up @@ -200,6 +200,11 @@ QString QgsDataSourceURI::removePassword( const QString& aUri )
regexp.setPattern( " password=.* " );
safeName.replace( regexp, " " );
}
else if ( aUri.contains( ",password=" ) )
{
regexp.setPattern( ",password=.*," );
safeName.replace( regexp, "," );
}
else if ( aUri.contains( "IDB:" ) )
{
regexp.setPattern( " pass=.* " );
Expand Down
18 changes: 15 additions & 3 deletions src/providers/wms/qgswmsprovider.cpp
Expand Up @@ -82,6 +82,8 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri )
, mCacheHits( 0 )
, mCacheMisses( 0 )
, mErrors( 0 )
, mUserName( QString::null )
, mPassword( QString::null )
{
// URL may contain username/password information for a WMS
// requiring authentication. In this case the URL is prefixed
Expand Down Expand Up @@ -113,8 +115,6 @@ void QgsWmsProvider::parseUri( QString uri )
// Strip off and store the user name and password (if they exist)
if ( !uri.startsWith( " http:" ) )
{
mUserName = "";
mPassword = "";
mTiled = false;
mTileWidth = 0;
mTileHeight = 0;
Expand Down Expand Up @@ -176,7 +176,6 @@ void QgsWmsProvider::parseUri( QString uri )
}
}
}

}
}

Expand Down Expand Up @@ -520,6 +519,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i

QgsDebugMsg( QString( "getmap: %1" ).arg( url ) );
QNetworkRequest request( url );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
cacheReply = QgsNetworkAccessManager::instance()->get( request );
connect( cacheReply, SIGNAL( finished() ), this, SLOT( cacheReplyFinished() ) );
Expand Down Expand Up @@ -638,6 +638,7 @@ QImage *QgsWmsProvider::draw( QgsRectangle const &viewExtent, int pixelWidth, i
turl += urlargs;

QNetworkRequest request( turl );
setAuthorization( request );
QgsDebugMsg( QString( "tileRequest %1 %2/%3: %4" ).arg( mTileReqNo ).arg( i++ ).arg( n ).arg( turl ) );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
Expand Down Expand Up @@ -711,6 +712,7 @@ void QgsWmsProvider::tileReplyFinished()
if ( !redirect.isNull() )
{
QNetworkRequest request( redirect.toUrl() );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferCache );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
request.setAttribute( static_cast<QNetworkRequest::Attribute>( QNetworkRequest::User + 0 ), tileReqNo );
Expand Down Expand Up @@ -859,6 +861,7 @@ bool QgsWmsProvider::retrieveServerCapabilities( bool forceRefresh )
mError = "";

QNetworkRequest request( url );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

Expand Down Expand Up @@ -925,6 +928,7 @@ void QgsWmsProvider::capabilitiesReplyFinished()
emit statusChanged( tr( "Capabilities request redirected." ) );

QNetworkRequest request( redirect.toUrl() );
setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );

Expand Down Expand Up @@ -2831,6 +2835,14 @@ void QgsWmsProvider::reloadData()
cachedImage = 0;
}

void QgsWmsProvider::setAuthorization( QNetworkRequest &request ) const
{
if ( !mUserName.isNull() || !mPassword.isNull() )
{
request.setRawHeader( "Authorization", "Basic " + QString( "%1:%2" ).arg( mUserName ).arg( mPassword ).toAscii().toBase64() );
}
}

/**
* Class factory to return a pointer to a newly created
* QgsWmsProvider object
Expand Down
4 changes: 4 additions & 0 deletions src/providers/wms/qgswmsprovider.h
Expand Up @@ -33,6 +33,7 @@
class QgsCoordinateTransform;
class QNetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;

/*
* The following structs reflect the WMS XML schema,
Expand Down Expand Up @@ -751,6 +752,9 @@ class QgsWmsProvider : public QgsRasterDataProvider

QString layerMetadata( QgsWmsLayerProperty &layer );

//! set authorization header
void setAuthorization( QNetworkRequest &request ) const;

//! Data source URI of the WMS for this layer
QString httpuri;

Expand Down

0 comments on commit 5aa9ee8

Please sign in to comment.