[QGIS Commit] r15036 - in trunk/qgis/src: core providers/wms
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Thu Jan 13 16:02:06 EST 2011
Author: jef
Date: 2011-01-13 13:02:06 -0800 (Thu, 13 Jan 2011)
New Revision: 15036
Modified:
trunk/qgis/src/core/qgsdatasourceuri.cpp
trunk/qgis/src/providers/wms/qgswmsprovider.cpp
trunk/qgis/src/providers/wms/qgswmsprovider.h
Log:
fix #3401
Modified: trunk/qgis/src/core/qgsdatasourceuri.cpp
===================================================================
--- trunk/qgis/src/core/qgsdatasourceuri.cpp 2011-01-13 19:47:56 UTC (rev 15035)
+++ trunk/qgis/src/core/qgsdatasourceuri.cpp 2011-01-13 21:02:06 UTC (rev 15036)
@@ -200,6 +200,11 @@
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=.* " );
Modified: trunk/qgis/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2011-01-13 19:47:56 UTC (rev 15035)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2011-01-13 21:02:06 UTC (rev 15036)
@@ -82,6 +82,8 @@
, 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 @@
// 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 @@
}
}
}
-
}
}
@@ -520,6 +519,7 @@
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 @@
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 @@
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 @@
mError = "";
QNetworkRequest request( url );
+ setAuthorization( request );
request.setAttribute( QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
@@ -925,6 +928,7 @@
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 @@
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
Modified: trunk/qgis/src/providers/wms/qgswmsprovider.h
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.h 2011-01-13 19:47:56 UTC (rev 15035)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.h 2011-01-13 21:02:06 UTC (rev 15036)
@@ -33,6 +33,7 @@
class QgsCoordinateTransform;
class QNetworkAccessManager;
class QNetworkReply;
+class QNetworkRequest;
/*
* The following structs reflect the WMS XML schema,
@@ -751,6 +752,9 @@
QString layerMetadata( QgsWmsLayerProperty &layer );
+ //! set authorization header
+ void setAuthorization( QNetworkRequest &request ) const;
+
//! Data source URI of the WMS for this layer
QString httpuri;
More information about the QGIS-commit
mailing list