Skip to content

Commit 5e71dfa

Browse files
committed
[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 (cherry-picked from f49bd5c)
1 parent 50e4b06 commit 5e71dfa

6 files changed

+63
-14
lines changed

src/providers/wfs/qgswfscapabilities.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#include <QSettings>
2727
#include <QStringList>
2828

29-
QgsWFSCapabilities::QgsWFSCapabilities( const QString& theUri )
29+
QgsWFSCapabilities::QgsWFSCapabilities( const QString &theUri )
3030
: QgsWFSRequest( theUri )
3131
{
3232
connect( this, SIGNAL( downloadFinished() ), this, SLOT( capabilitiesReplyFinished() ) );

src/providers/wfs/qgswfsconstants.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ const QString QgsWFSConstants::XMLSCHEMA_NAMESPACE( "http://www.w3.org/2001/XMLS
2323

2424
const QString QgsWFSConstants::URI_PARAM_URL( "url" );
2525
const QString QgsWFSConstants::URI_PARAM_USERNAME( "username" );
26+
const QString QgsWFSConstants::URI_PARAM_USER( "user" );
2627
const QString QgsWFSConstants::URI_PARAM_PASSWORD( "password" );
2728
const QString QgsWFSConstants::URI_PARAM_AUTHCFG( "authcfg" );
2829
const QString QgsWFSConstants::URI_PARAM_VERSION( "version" );
2930
const QString QgsWFSConstants::URI_PARAM_TYPENAME( "typename" );
3031
const QString QgsWFSConstants::URI_PARAM_SRSNAME( "srsname" );
32+
const QString QgsWFSConstants::URI_PARAM_BBOX( "bbox" );
3133
const QString QgsWFSConstants::URI_PARAM_FILTER( "filter" );
3234
const QString QgsWFSConstants::URI_PARAM_RESTRICT_TO_REQUEST_BBOX( "retrictToRequestBBOX" );
3335
const QString QgsWFSConstants::URI_PARAM_MAXNUMFEATURES( "maxNumFeatures" );

src/providers/wfs/qgswfsconstants.h

+4
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,16 @@ struct QgsWFSConstants
2929
// URI parameters
3030
static const QString URI_PARAM_URL;
3131
static const QString URI_PARAM_USERNAME;
32+
// QgsDataSourceURI recognizes "user" instead of "username"
33+
// we are going to check both
34+
static const QString URI_PARAM_USER;
3235
static const QString URI_PARAM_PASSWORD;
3336
static const QString URI_PARAM_AUTHCFG;
3437
static const QString URI_PARAM_VERSION;
3538
static const QString URI_PARAM_TYPENAME;
3639
static const QString URI_PARAM_SRSNAME;
3740
static const QString URI_PARAM_FILTER;
41+
static const QString URI_PARAM_BBOX;
3842
static const QString URI_PARAM_RESTRICT_TO_REQUEST_BBOX;
3943
static const QString URI_PARAM_MAXNUMFEATURES;
4044
static const QString URI_PARAM_IGNOREAXISORIENTATION;

src/providers/wfs/qgswfsdatasourceuri.cpp

+49-9
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* *
1414
***************************************************************************/
1515

16+
#include "QtGlobal"
17+
1618
#include "qgswfsconstants.h"
1719
#include "qgswfsdatasourceuri.h"
1820
#include "qgsmessagelog.h"
@@ -25,11 +27,26 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
2527
if ( !mURI.hasParam( QgsWFSConstants::URI_PARAM_URL ) )
2628
{
2729
QUrl url( uri );
28-
QString srsname = url.queryItemValue( "SRSNAME" );
29-
QString bbox = url.queryItemValue( "BBOX" );
30-
QString typeName = url.queryItemValue( "TYPENAME" );
31-
QString filter = url.queryItemValue( "FILTER" );
30+
// Transform all param keys to lowercase
31+
typedef QPair<QString, QString> queryItem;
32+
QList<queryItem> items( url.queryItems() );
33+
foreach ( queryItem item, items )
34+
{
35+
url.removeQueryItem( item.first );
36+
url.addQueryItem( item.first.toLower(), item.second );
37+
}
38+
39+
QString srsname = url.queryItemValue( QgsWFSConstants::URI_PARAM_SRSNAME );
40+
QString bbox = url.queryItemValue( QgsWFSConstants::URI_PARAM_BBOX );
41+
QString typeName = url.queryItemValue( QgsWFSConstants::URI_PARAM_TYPENAME );
42+
QString version = url.queryItemValue( QgsWFSConstants::URI_PARAM_VERSION );
43+
QString filter = url.queryItemValue( QgsWFSConstants::URI_PARAM_FILTER );
3244
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USERNAME );
45+
// In QgsDataSourceURI, the "username" param is named "user", check it
46+
if ( mAuth.mUserName.isEmpty() )
47+
{
48+
mAuth.mUserName = url.queryItemValue( QgsWFSConstants::URI_PARAM_USER );
49+
}
3350
mAuth.mPassword = url.queryItemValue( QgsWFSConstants::URI_PARAM_PASSWORD );
3451
mAuth.mAuthCfg = url.queryItemValue( QgsWFSConstants::URI_PARAM_AUTHCFG );
3552

@@ -49,6 +66,7 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
4966
mURI.setParam( QgsWFSConstants::URI_PARAM_URL, url.toEncoded() );
5067
setTypeName( typeName );
5168
setSRSName( srsname );
69+
setVersion( version );
5270

5371
//if the xml comes from the dialog, it needs to be a string to pass the validity test
5472
if ( filter.startsWith( '\'' ) && filter.endsWith( '\'' ) && filter.size() > 1 )
@@ -63,17 +81,32 @@ QgsWFSDataSourceURI::QgsWFSDataSourceURI( const QString& uri )
6381
}
6482
else
6583
{
66-
mAuth.mUserName = mURI.param( QgsWFSConstants::URI_PARAM_USERNAME );
67-
mAuth.mPassword = mURI.param( QgsWFSConstants::URI_PARAM_PASSWORD );
68-
mAuth.mAuthCfg = mURI.param( QgsWFSConstants::URI_PARAM_AUTHCFG );
84+
mAuth.mUserName = mURI.username();
85+
mAuth.mPassword = mURI.password();
86+
mAuth.mAuthCfg = mURI.authConfigId();
6987
}
7088
}
7189

72-
QString QgsWFSDataSourceURI::uri()
90+
const QString QgsWFSDataSourceURI::uri( bool expandAuthConfig ) const
7391
{
74-
return mURI.uri();
92+
QgsDataSourceURI theURI( mURI );
93+
// Add auth params back into the uri
94+
if ( ! mAuth.mAuthCfg.isEmpty() )
95+
{
96+
theURI.setAuthConfigId( mAuth.mAuthCfg );
97+
}
98+
if ( ! mAuth.mUserName.isEmpty() )
99+
{
100+
theURI.setUsername( mAuth.mUserName );
101+
}
102+
if ( ! mAuth.mPassword.isEmpty() )
103+
{
104+
theURI.setPassword( mAuth.mPassword );
105+
}
106+
return theURI.uri( expandAuthConfig );
75107
}
76108

109+
77110
QUrl QgsWFSDataSourceURI::baseURL( bool bIncludeServiceWFS ) const
78111
{
79112
QUrl url( mURI.param( QgsWFSConstants::URI_PARAM_URL ) );
@@ -122,6 +155,13 @@ void QgsWFSDataSourceURI::setSRSName( const QString& crsString )
122155
mURI.setParam( QgsWFSConstants::URI_PARAM_SRSNAME, crsString );
123156
}
124157

158+
void QgsWFSDataSourceURI::setVersion( const QString& versionString )
159+
{
160+
mURI.removeParam( QgsWFSConstants::URI_PARAM_VERSION );
161+
if ( !versionString.isEmpty() )
162+
mURI.setParam( QgsWFSConstants::URI_PARAM_VERSION, versionString );
163+
}
164+
125165
QString QgsWFSDataSourceURI::SRSName() const
126166
{
127167
return mURI.param( QgsWFSConstants::URI_PARAM_SRSNAME );

src/providers/wfs/qgswfsdatasourceuri.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class QgsWFSDataSourceURI
6666
explicit QgsWFSDataSourceURI( const QString& uri );
6767

6868
/** Return the URI */
69-
QString uri();
69+
const QString uri( bool expandAuthConfig = true ) const;
7070

7171
/** Return base URL (with SERVICE=WFS parameter if bIncludeServiceWFS=true) */
7272
QUrl baseURL( bool bIncludeServiceWFS = true ) const;
@@ -92,6 +92,9 @@ class QgsWFSDataSourceURI
9292
/** Set SRS name (in the normalized form EPSG:xxxx) */
9393
void setSRSName( const QString& crsString );
9494

95+
/** Set version */
96+
void setVersion( const QString& versionString );
97+
9598
/** Get OGC filter xml or a QGIS expression */
9699
QString filter() const;
97100

src/providers/wfs/qgswfsprovider.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ bool QgsWFSProvider::describeFeatureType( QString& geometryAttribute, QgsFields&
11011101
{
11021102
fields.clear();
11031103

1104-
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri() );
1104+
QgsWFSDescribeFeatureType describeFeatureType( mShared->mURI.uri( false ) );
11051105
if ( !describeFeatureType.requestFeatureType( mShared->mWFSVersion,
11061106
mShared->mURI.typeName() ) )
11071107
{
@@ -1330,7 +1330,7 @@ bool QgsWFSProvider::sendTransactionDocument( const QDomDocument& doc, QDomDocum
13301330
return false;
13311331
}
13321332

1333-
QgsWFSTransactionRequest request( mShared->mURI.uri() );
1333+
QgsWFSTransactionRequest request( mShared->mURI.uri( false ) );
13341334
return request.send( doc, serverResponse );
13351335
}
13361336

@@ -1433,7 +1433,7 @@ bool QgsWFSProvider::getCapabilities()
14331433

14341434
if ( mShared->mCaps.version.isEmpty() )
14351435
{
1436-
QgsWFSCapabilities getCapabilities( mShared->mURI.uri() );
1436+
QgsWFSCapabilities getCapabilities( mShared->mURI.uri( false ) );
14371437
if ( !getCapabilities.requestCapabilities( true ) )
14381438
{
14391439
QgsMessageLog::logMessage( tr( "GetCapabilities failed for url %1: %2" ).

0 commit comments

Comments
 (0)