Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
referer for wfs: one has to modify a lot... stop here and consider on…
…ly wms
  • Loading branch information
Stefan Ziegler committed Mar 29, 2013
1 parent b06eeca commit ade381f
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/core/qgsowsconnection.cpp
Expand Up @@ -93,6 +93,12 @@ QgsOWSConnection::QgsOWSConnection( const QString & theService, const QString &
mUri.setParam( "password", password );
}

QString referer = settings.value( key + "/referer" ).toString();
if ( !referer.isEmpty() )
{
mUri.setParam( "referer", referer );
}

bool ignoreGetMap = settings.value( key + "/ignoreGetMapURI", false ).toBool();
bool ignoreGetFeatureInfo = settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool();
bool ignoreAxisOrientation = settings.value( key + "/ignoreAxisOrientation", false ).toBool();
Expand Down
6 changes: 6 additions & 0 deletions src/gui/qgsmanageconnectionsdialog.cpp
Expand Up @@ -347,6 +347,8 @@ QDomDocument QgsManageConnectionsDialog::saveOWSConnections( const QStringList &
el.setAttribute( "invertAxisOrientation", settings.value( path + connections[i] + "/invertAxisOrientation", false ).toBool() ? "true" : "false" );
}

el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() );

path = "/Qgis/" + service.toUpper() + "/";
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
Expand All @@ -372,6 +374,8 @@ QDomDocument QgsManageConnectionsDialog::saveWFSConnections( const QStringList &
el.setAttribute( "name", connections[ i ] );
el.setAttribute( "url", settings.value( path + connections[ i ] + "/url", "" ).toString() );

el.setAttribute( "referer", settings.value( path + connections[ i ] + "/referer", "" ).toString() );

path = "/Qgis/WFS/";
el.setAttribute( "username", settings.value( path + connections[ i ] + "/username", "" ).toString() );
el.setAttribute( "password", settings.value( path + connections[ i ] + "/password", "" ).toString() );
Expand Down Expand Up @@ -576,6 +580,7 @@ void QgsManageConnectionsDialog::loadOWSConnections( const QDomDocument &doc, co
settings.setValue( QString( "/" + connectionName + "/ignoreGetFeatureInfoURI" ), child.attribute( "ignoreGetFeatureInfoURI" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/ignoreAxisOrientation" ), child.attribute( "ignoreAxisOrientation" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/invertAxisOrientation" ), child.attribute( "invertAxisOrientation" ) == "true" );
settings.setValue( QString( "/" + connectionName + "/referer" ), child.attribute( "referer" ) );
settings.endGroup();

if ( !child.attribute( "username" ).isEmpty() )
Expand Down Expand Up @@ -656,6 +661,7 @@ void QgsManageConnectionsDialog::loadWFSConnections( const QDomDocument &doc, co
// no dups detected or overwrite is allowed
settings.beginGroup( "/Qgis/connections-wfs" );
settings.setValue( QString( "/" + connectionName + "/url" ) , child.attribute( "url" ) );
settings.setValue( QString( "/" + connectionName + "/referer" ), child.attribute( "referer" ) );
settings.endGroup();

if ( !child.attribute( "username" ).isEmpty() )
Expand Down
6 changes: 4 additions & 2 deletions src/gui/qgsnewhttpconnection.cpp
Expand Up @@ -55,10 +55,11 @@ QgsNewHttpConnection::QgsNewHttpConnection(
cbxIgnoreAxisOrientation->setChecked( settings.value( key + "/ignoreAxisOrientation", false ).toBool() );
cbxInvertAxisOrientation->setChecked( settings.value( key + "/invertAxisOrientation", false ).toBool() );
cbxIgnoreGetFeatureInfoURI->setChecked( settings.value( key + "/ignoreGetFeatureInfoURI", false ).toBool() );

txtReferer->setText( settings.value( key + "/referer" ).toString() );

txtUserName->setText( settings.value( credentialsKey + "/username" ).toString() );
txtPassword->setText( settings.value( credentialsKey + "/password" ).toString() );
txtReferer->setText( settings.value( credentialsKey + "/referer" ).toString() );
}

if ( mBaseKey != "/Qgis/connections-wms/" )
Expand Down Expand Up @@ -159,9 +160,10 @@ void QgsNewHttpConnection::accept()
settings.setValue( key + "/ignoreGetFeatureInfoURI", cbxIgnoreGetFeatureInfoURI->isChecked() );
}

settings.setValue( key + "/referer", txtReferer->text() );

settings.setValue( credentialsKey + "/username", txtUserName->text() );
settings.setValue( credentialsKey + "/password", txtPassword->text() );
settings.setValue( credentialsKey + "/referer", txtReferer->text() );

settings.setValue( mBaseKey + "/selected", txtName->text() );

Expand Down
12 changes: 11 additions & 1 deletion src/providers/wfs/qgswfscapabilities.cpp
Expand Up @@ -36,7 +36,7 @@ QgsWFSCapabilities::QgsWFSCapabilities( QString theUri ) :
mBaseUrl = prepareUri( mUri.param( "url" ) );

QgsDebugMsg( "mBaseUrl = " + mBaseUrl );

//find out the server URL
/*
QSettings settings;
Expand Down Expand Up @@ -142,10 +142,20 @@ void QgsWFSCapabilities::requestCapabilities()

QNetworkRequest request( uriGetCapabilities() );
request.setAttribute( QNetworkRequest::CacheSaveControlAttribute, true );
setReferer( request );
mCapabilitiesReply = QgsNetworkAccessManager::instance()->get( request );
connect( mCapabilitiesReply, SIGNAL( finished() ), this, SLOT( capabilitiesReplyFinished() ) );
}

void QgsWFSCapabilities::setReferer( QNetworkRequest &request ) const
{
QString referer = mUri.param( "referer" );
if ( !referer.isNull() )
{
request.setRawHeader( "Referer", QString( "%1" ).arg( referer ).toAscii() );
}
}

void QgsWFSCapabilities::capabilitiesReplyFinished()
{
// handle network errors
Expand Down
6 changes: 5 additions & 1 deletion src/providers/wfs/qgswfscapabilities.h
Expand Up @@ -21,6 +21,7 @@
#include "qgsdatasourceuri.h"

class QNetworkReply;
class QNetworkRequest;

class QgsWFSCapabilities : public QObject
{
Expand All @@ -47,7 +48,10 @@ class QgsWFSCapabilities : public QObject

//! start network connection to get capabilities
void requestCapabilities();


//! set referer header
void setReferer( QNetworkRequest &request ) const;

//! description of a vector layer
struct FeatureType
{
Expand Down
2 changes: 1 addition & 1 deletion src/providers/wms/qgswmsconnection.cpp
Expand Up @@ -67,7 +67,7 @@ QgsWMSConnection::QgsWMSConnection( QString theConnName ) :
mUri.setParam( "password", password );
}

QString referer = settings.value( credentialsKey + "/referer" ).toString();
QString referer = settings.value( key + "/referer" ).toString();
if ( !referer.isEmpty() )
{
mUri.setParam( "referer", referer );
Expand Down

0 comments on commit ade381f

Please sign in to comment.