From f49bd5ca449e332aa547f9dac31b391e438d2b31 Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Mon, 8 Aug 2016 20:34:46 +0200 Subject: [PATCH] [WFS] Fixes #15360 and other issues - fixes authcfg params not passed to requests - fixes backward URI compatibility - fixes version parameter ignored in old style URI - check for "user" in addition to "username" in WFS URI --- src/providers/wfs/qgswfscapabilities.cpp | 2 +- src/providers/wfs/qgswfsconstants.cpp | 2 + src/providers/wfs/qgswfsconstants.h | 4 ++ src/providers/wfs/qgswfsdatasourceuri.cpp | 58 +++++++++++++++++++---- src/providers/wfs/qgswfsdatasourceuri.h | 5 +- src/providers/wfs/qgswfsprovider.cpp | 6 +-- 6 files changed, 63 insertions(+), 14 deletions(-) diff --git a/src/providers/wfs/qgswfscapabilities.cpp b/src/providers/wfs/qgswfscapabilities.cpp index e3349d494fda..ec83cd22237b 100644 --- a/src/providers/wfs/qgswfscapabilities.cpp +++ b/src/providers/wfs/qgswfscapabilities.cpp @@ -26,7 +26,7 @@ #include #include -QgsWFSCapabilities::QgsWFSCapabilities( const QString& theUri ) +QgsWFSCapabilities::QgsWFSCapabilities( const QString &theUri ) : QgsWFSRequest( theUri ) { connect( this, SIGNAL( downloadFinished() ), this, SLOT( capabilitiesReplyFinished() ) ); diff --git a/src/providers/wfs/qgswfsconstants.cpp b/src/providers/wfs/qgswfsconstants.cpp index 380e5f08c612..2aecf3e408db 100644 --- a/src/providers/wfs/qgswfsconstants.cpp +++ b/src/providers/wfs/qgswfsconstants.cpp @@ -23,11 +23,13 @@ const QString QgsWFSConstants::XMLSCHEMA_NAMESPACE( "http://www.w3.org/2001/XMLS const QString QgsWFSConstants::URI_PARAM_URL( "url" ); const QString QgsWFSConstants::URI_PARAM_USERNAME( "username" ); +const QString QgsWFSConstants::URI_PARAM_USER( "user" ); const QString QgsWFSConstants::URI_PARAM_PASSWORD( "password" ); const QString QgsWFSConstants::URI_PARAM_AUTHCFG( "authcfg" ); const QString QgsWFSConstants::URI_PARAM_VERSION( "version" ); const QString QgsWFSConstants::URI_PARAM_TYPENAME( "typename" ); const QString QgsWFSConstants::URI_PARAM_SRSNAME( "srsname" ); +const QString QgsWFSConstants::URI_PARAM_BBOX( "bbox" ); const QString QgsWFSConstants::URI_PARAM_FILTER( "filter" ); const QString QgsWFSConstants::URI_PARAM_RESTRICT_TO_REQUEST_BBOX( "retrictToRequestBBOX" ); const QString QgsWFSConstants::URI_PARAM_MAXNUMFEATURES( "maxNumFeatures" ); diff --git a/src/providers/wfs/qgswfsconstants.h b/src/providers/wfs/qgswfsconstants.h index 3011a341f50d..23345aca866b 100644 --- a/src/providers/wfs/qgswfsconstants.h +++ b/src/providers/wfs/qgswfsconstants.h @@ -29,12 +29,16 @@ struct QgsWFSConstants // URI parameters static const QString URI_PARAM_URL; static const QString URI_PARAM_USERNAME; + // QgsDataSourceURI recognizes "user" instead of "username" + // we are going to check both + static const QString URI_PARAM_USER; static const QString URI_PARAM_PASSWORD; static const QString URI_PARAM_AUTHCFG; static const QString URI_PARAM_VERSION; static const QString URI_PARAM_TYPENAME; static const QString URI_PARAM_SRSNAME; static const QString URI_PARAM_FILTER; + static const QString URI_PARAM_BBOX; static const QString URI_PARAM_RESTRICT_TO_REQUEST_BBOX; static const QString URI_PARAM_MAXNUMFEATURES; static const QString URI_PARAM_IGNOREAXISORIENTATION; diff --git a/src/providers/wfs/qgswfsdatasourceuri.cpp b/src/providers/wfs/qgswfsdatasourceuri.cpp index 735051cc6c8e..337563be40d5 100644 --- a/src/providers/wfs/qgswfsdatasourceuri.cpp +++ b/src/providers/wfs/qgswfsdatasourceuri.cpp @@ -13,6 +13,8 @@ * * ***************************************************************************/ +#include "QtGlobal" + #include "qgswfsconstants.h" #include "qgswfsdatasourceuri.h" #include "qgsmessagelog.h" @@ -25,11 +27,26 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri ) if ( !mURI.hasParam( QgsWFSConstants::URI_PARAM_URL ) ) { QUrl url( uri ); - QString srsname = url.queryItemValue( "SRSNAME" ); - QString bbox = url.queryItemValue( "BBOX" ); - QString typeName = url.queryItemValue( "TYPENAME" ); - QString filter = url.queryItemValue( "FILTER" ); + // Transform all param keys to lowercase + typedef QPair queryItem; + QList items( url.queryItems() ); + foreach ( queryItem item, items ) + { + url.removeQueryItem( item.first ); + url.addQueryItem( item.first.toLower(), item.second ); + } + + QString srsname = url.queryItemValue( QgsWFSConstants::URI_PARAM_SRSNAME ); + QString bbox = url.queryItemValue( QgsWFSConstants::URI_PARAM_BBOX ); + QString typeName = url.queryItemValue( QgsWFSConstants::URI_PARAM_TYPENAME ); + QString version = url.queryItemValue( QgsWFSConstants::URI_PARAM_VERSION ); + QString filter = url.queryItemValue( QgsWFSConstants::URI_PARAM_FILTER ); mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME ); + // In QgsDataSourceURI, the "username" param is named "user", check it + if ( mAuth.mUserName.isEmpty() ) + { + mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER ); + } mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD ); mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG ); @@ -49,6 +66,7 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri ) mURI.setParam( QgsWFSConstants::URI_PARAM_URL, url.toEncoded() ); setTypeName( typeName ); setSRSName( srsname ); + setVersion( version ); //if the xml comes from the dialog, it needs to be a string to pass the validity test if ( filter.startsWith( '\'' ) && filter.endsWith( '\'' ) && filter.size() > 1 ) @@ -63,17 +81,32 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri ) } else { - mAuth.mUserName = mURI.param( QgsWFSConstants::URI_PARAM_USERNAME ); - mAuth.mPassword = mURI.param( QgsWFSConstants::URI_PARAM_PASSWORD ); - mAuth.mAuthCfg = mURI.param( QgsWFSConstants::URI_PARAM_AUTHCFG ); + mAuth.mUserName = mURI.username(); + mAuth.mPassword = mURI.password(); + mAuth.mAuthCfg = mURI.authConfigId(); } } -QString QgsWFSDataSourceURI::uri() +const QString QgsWFSDataSourceURI::uri( bool expandAuthConfig ) const { - return mURI.uri(); + QgsDataSourceURI theURI( mURI ); + // Add auth params back into the uri + if ( ! mAuth.mAuthCfg.isEmpty() ) + { + theURI.setAuthConfigId( mAuth.mAuthCfg ); + } + if ( ! mAuth.mUserName.isEmpty() ) + { + theURI.setUsername( mAuth.mUserName ); + } + if ( ! mAuth.mPassword.isEmpty() ) + { + theURI.setPassword( mAuth.mPassword ); + } + return theURI.uri( expandAuthConfig ); } + QUrl QgsWFSDataSourceURI::baseURL( bool bIncludeServiceWFS ) const { QUrl url( mURI.param( QgsWFSConstants::URI_PARAM_URL ) ); @@ -122,6 +155,13 @@ void QgsWFSDataSourceURI::setSRSName( const QString& crsString ) mURI.setParam( QgsWFSConstants::URI_PARAM_SRSNAME, crsString ); } +void QgsWFSDataSourceURI::setVersion( const QString& versionString ) +{ + mURI.removeParam( QgsWFSConstants::URI_PARAM_VERSION ); + if ( !versionString.isEmpty() ) + mURI.setParam( QgsWFSConstants::URI_PARAM_VERSION, versionString ); +} + QString QgsWFSDataSourceURI::SRSName() const { return mURI.param( QgsWFSConstants::URI_PARAM_SRSNAME ); diff --git a/src/providers/wfs/qgswfsdatasourceuri.h b/src/providers/wfs/qgswfsdatasourceuri.h index d995b1ca80fa..7375068d476c 100644 --- a/src/providers/wfs/qgswfsdatasourceuri.h +++ b/src/providers/wfs/qgswfsdatasourceuri.h @@ -66,7 +66,7 @@ class QgsWFSDataSourceURI explicit QgsWFSDataSourceURI( const QString& uri ); /** Return the URI */ - QString uri(); + const QString uri( bool expandAuthConfig = true ) const; /** Return base URL (with SERVICE=WFS parameter if bIncludeServiceWFS=true) */ QUrl baseURL( bool bIncludeServiceWFS = true ) const; @@ -92,6 +92,9 @@ class QgsWFSDataSourceURI /** Set SRS name (in the normalized form EPSG:xxxx) */ void setSRSName( const QString& crsString ); + /** Set version */ + void setVersion( const QString& versionString ); + /** Get OGC filter xml or a QGIS expression */ QString filter() const; diff --git a/src/providers/wfs/qgswfsprovider.cpp b/src/providers/wfs/qgswfsprovider.cpp index 41759c9388b3..0a2fcc1315fc 100644 --- a/src/providers/wfs/qgswfsprovider.cpp +++ b/src/providers/wfs/qgswfsprovider.cpp @@ -1101,7 +1101,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields& { fields.clear(); - QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri() ); + QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri( false ) ); if ( !describeFeatureType.requestFeatureType( mShared->mWFSVersion, mShared->mURI.typeName() ) ) { @@ -1321,7 +1321,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum return false; } - QgsWFSTransactionRequest request( mShared->mURI.uri() ); + QgsWFSTransactionRequest request( mShared->mURI.uri( false ) ); return request.send( doc, serverResponse ); } @@ -1424,7 +1424,7 @@ bool QgsWFSProvider::getCapabilities() if ( mShared->mCaps.version.isEmpty() ) { - QgsWFSCapabilities getCapabilities( mShared->mURI.uri() ); + QgsWFSCapabilities getCapabilities( mShared->mURI.uri( false ) ); if ( !getCapabilities.requestCapabilities( true ) ) { QgsMessageLog::logMessage( tr( "GetCapabilities failed for url %1: %2" ).