Skip to content
Permalink
Browse files
fix #3401
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 5aa9ee8ee5e5e893709be89423a6a43a628bd8d8
Showing with 24 additions and 3 deletions.
  1. +5 −0 src/core/qgsdatasourceuri.cpp
  2. +15 −3 src/providers/wms/qgswmsprovider.cpp
  3. +4 −0 src/providers/wms/qgswmsprovider.h
@@ -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=.* " );
@@ -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
@@ -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;
@@ -176,7 +176,6 @@ void QgsWmsProvider::parseUri( QString uri )
}
}
}

}
}

@@ -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() ) );
@@ -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 );
@@ -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 );
@@ -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 );

@@ -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 );

@@ -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
@@ -33,6 +33,7 @@
class QgsCoordinateTransform;
class QNetworkAccessManager;
class QNetworkReply;
class QNetworkRequest;

/*
* The following structs reflect the WMS XML schema,
@@ -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;

0 comments on commit 5aa9ee8

Please sign in to comment.