Skip to content

Commit

Permalink
Clean WMS service
Browse files Browse the repository at this point in the history
    - Remove "transitional" code
    - Remove duplicated code (or functionaly equivalent code)
    - Remove dead code
    - Sanitize error checking
    - Ensure correct build with HAVE_SERVER_PYTHON_PLUGINS not defined
  • Loading branch information
dmarteau committed Jan 18, 2017
1 parent d0a4697 commit a80497e
Show file tree
Hide file tree
Showing 41 changed files with 1,118 additions and 1,199 deletions.
4 changes: 2 additions & 2 deletions src/server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ SET ( qgis_mapserv_SRCS
qgsfcgiserverresponse.cpp
qgsbufferserverresponse.cpp
qgsfilterresponsedecorator.cpp
qgsserverinterface.cpp
qgsserverinterfaceimpl.cpp
qgsfilterrestorer.cpp
#----------------------------
)
Expand Down Expand Up @@ -98,11 +100,9 @@ SET(qgis_mapserv_MOC_HDRS ${qgis_mapserv_MOC_HDRS})
IF (WITH_SERVER_PLUGINS)
SET(qgis_mapserv_SRCS ${qgis_mapserv_SRCS}
qgsserverplugins.cpp
qgsserverinterface.cpp
qgsserverfilter.cpp
qgsaccesscontrolfilter.cpp
qgsaccesscontrol.cpp
qgsserverinterfaceimpl.cpp
)
ENDIF (WITH_SERVER_PLUGINS)

Expand Down
12 changes: 0 additions & 12 deletions src/server/qgsconfigcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ QgsServerProjectParser* QgsConfigCache::serverConfiguration( const QString& file

QgsWCSProjectParser *QgsConfigCache::wcsConfiguration(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
)
{
QgsWCSProjectParser *p = mWCSConfigCache.object( filePath );
Expand All @@ -94,9 +92,7 @@ QgsWCSProjectParser *QgsConfigCache::wcsConfiguration(
}
p = new QgsWCSProjectParser(
filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, accessControl
#endif
);
mWCSConfigCache.insert( filePath, p );
p = mWCSConfigCache.object( filePath );
Expand All @@ -109,9 +105,7 @@ QgsWCSProjectParser *QgsConfigCache::wcsConfiguration(

QgsWfsProjectParser *QgsConfigCache::wfsConfiguration(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
)
{
QgsWfsProjectParser *p = mWFSConfigCache.object( filePath );
Expand All @@ -124,9 +118,7 @@ QgsWfsProjectParser *QgsConfigCache::wfsConfiguration(
}
p = new QgsWfsProjectParser(
filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, accessControl
#endif
);
mWFSConfigCache.insert( filePath, p );
p = mWFSConfigCache.object( filePath );
Expand All @@ -139,9 +131,7 @@ QgsWfsProjectParser *QgsConfigCache::wfsConfiguration(

QgsWmsConfigParser *QgsConfigCache::wmsConfiguration(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
, const QMap<QString, QString>& parameterMap
)
{
Expand All @@ -165,9 +155,7 @@ QgsWmsConfigParser *QgsConfigCache::wmsConfiguration(
{
p = new QgsWmsProjectParser(
filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, accessControl
#endif
);
}
mWMSConfigCache.insert( filePath, p );
Expand Down
6 changes: 0 additions & 6 deletions src/server/qgsconfigcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,15 @@ class SERVER_EXPORT QgsConfigCache : public QObject
QgsServerProjectParser* serverConfiguration( const QString& filePath );
QgsWCSProjectParser* wcsConfiguration(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
);
QgsWfsProjectParser* wfsConfiguration(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
);
QgsWmsConfigParser* wmsConfiguration(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
, const QMap<QString, QString>& parameterMap = ( QMap< QString, QString >() )
);

Expand Down
8 changes: 7 additions & 1 deletion src/server/qgsfilterrestorer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"

//! Apply filter from AccessControl
#ifdef HAVE_SERVER_PYTHON_PLUGINS
#include "qgsaccesscontrol.h"
#endif

//! Apply filter from AccessControal
#ifdef HAVE_SERVER_PYTHON_PLUGINS
void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccessControl* accessControl, QgsMapLayer* mapLayer,
QHash<QgsMapLayer*, QString>& originalLayerFilters )
{
Expand All @@ -45,6 +50,7 @@ void QgsOWSServerFilterRestorer::applyAccessControlLayerFilters( const QgsAccess
}
}
}
#endif

//! Restore layer filter as original
void QgsOWSServerFilterRestorer::restoreLayerFilters( const QHash<QgsMapLayer*, QString>& filterMap )
Expand Down
2 changes: 1 addition & 1 deletion src/server/qgsfilterrestorer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
#ifndef QGSFILTERRESTORER_H
#define QGSFILTERRESTORER_H

#include "qgsaccesscontrol.h"
#include "qgis_server.h"

#include <QHash>

class QgsMapLayer;
class QgsAccessControl;

/** RAII class to restore layer filters on destruction
*/
Expand Down
14 changes: 9 additions & 5 deletions src/server/qgsserverinterfaceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ QgsServerInterfaceImpl::QgsServerInterfaceImpl( QgsCapabilitiesCache* capCache,
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mAccessControls = new QgsAccessControl();
#else
mAccessControls = nullptr
mAccessControls = nullptr;
#endif
}

Expand All @@ -43,7 +43,9 @@ QString QgsServerInterfaceImpl::getEnv( const QString& name ) const

QgsServerInterfaceImpl::~QgsServerInterfaceImpl()
{
#ifdef HAVE_SERVER_PYTHON_PLUGINS
delete mAccessControls;
#endif
}


Expand Down Expand Up @@ -75,10 +77,12 @@ void QgsServerInterfaceImpl::setFilters( QgsServerFiltersMap* filters )
//! Register a new access control filter
void QgsServerInterfaceImpl::registerAccessControl( QgsAccessControlFilter* accessControl, int priority )
{
if ( mAccessControls )
{
mAccessControls->registerAccessControl( accessControl, priority );
}
#ifdef HAVE_SERVER_PYTHON_PLUGINS
mAccessControls->registerAccessControl( accessControl, priority );
#else
Q_UNUSED( accessControl );
Q_UNUSED( priority );
#endif
}


Expand Down
10 changes: 4 additions & 6 deletions src/server/qgswcsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@

QgsWCSProjectParser::QgsWCSProjectParser(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* as
#endif
)
#ifdef HAVE_SERVER_PYTHON_PLUGINS
:
mAccessControl( as )
#endif
: mAccessControl( as )
{
#ifndef HAVE_SERVER_PYTHON_PLUGINS
Q_UNUSED( mAccessControl );
#endif
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

Expand Down
6 changes: 0 additions & 6 deletions src/server/qgswcsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@
#include "qgsserverprojectparser.h"
#include "qgis_server.h"

#ifdef HAVE_SERVER_PYTHON_PLUGINS
class QgsAccessControl;
#endif

class SERVER_EXPORT QgsWCSProjectParser
{
public:
QgsWCSProjectParser(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* ac
#endif
);
~QgsWCSProjectParser();

Expand All @@ -49,9 +45,7 @@ class SERVER_EXPORT QgsWCSProjectParser

private:
QgsServerProjectParser* mProjectParser;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
const QgsAccessControl* mAccessControl;
#endif

};

Expand Down
10 changes: 4 additions & 6 deletions src/server/qgswfsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

QgsWfsProjectParser::QgsWfsProjectParser(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* ac
#endif
)
#ifdef HAVE_SERVER_PYTHON_PLUGINS
:
mAccessControl( ac )
#endif
: mAccessControl( ac )
{
#ifndef HAVE_SERVER_PYTHON_PLUGINS
Q_UNUSED( mAccessControl );
#endif
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
}

Expand Down
6 changes: 0 additions & 6 deletions src/server/qgswfsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,15 @@
#include "qgis_server.h"


#ifdef HAVE_SERVER_PYTHON_PLUGINS
class QgsAccessControl;
#endif


class SERVER_EXPORT QgsWfsProjectParser
{
public:
QgsWfsProjectParser(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* ac
#endif
);
~QgsWfsProjectParser();

Expand All @@ -60,9 +56,7 @@ class SERVER_EXPORT QgsWfsProjectParser

private:
QgsServerProjectParser* mProjectParser;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
const QgsAccessControl* mAccessControl;
#endif

};

Expand Down
12 changes: 0 additions & 12 deletions src/server/qgswmsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,10 @@

QgsWmsProjectParser::QgsWmsProjectParser(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
)
: QgsWmsConfigParser()
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, mAccessControl( accessControl )
#endif
{
mProjectParser = QgsConfigCache::instance()->serverConfiguration( filePath );
mLegendLayerFont.fromString( mProjectParser->firstComposerLegendElement().attribute( QStringLiteral( "layerFont" ) ) );
Expand Down Expand Up @@ -230,9 +226,7 @@ QList<QgsMapLayer*> QgsWmsProjectParser::mapLayerFromStyle( const QString& lName
QString project = mProjectParser->convertToAbsolutePath( legendIt->attribute( QStringLiteral( "project" ) ) );
QgsWmsProjectParser* p = dynamic_cast<QgsWmsProjectParser*>( QgsConfigCache::instance()->wmsConfiguration(
project
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, mAccessControl
#endif
) );
if ( p )
{
Expand Down Expand Up @@ -279,9 +273,7 @@ void QgsWmsProjectParser::addLayersFromGroup( const QDomElement& legendGroupElem
QString project = mProjectParser->convertToAbsolutePath( legendGroupElem.attribute( QStringLiteral( "project" ) ) );
QgsWmsProjectParser* p = dynamic_cast<QgsWmsProjectParser*>( QgsConfigCache::instance()->wmsConfiguration(
project
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, mAccessControl
#endif
) );
if ( p )
{
Expand Down Expand Up @@ -1198,9 +1190,7 @@ void QgsWmsProjectParser::addLayers( QDomDocument &doc,
QString embeddedGroupName = currentChildElem.attribute( QStringLiteral( "name" ) );
QgsWmsProjectParser* p = dynamic_cast<QgsWmsProjectParser*>( QgsConfigCache::instance()->wmsConfiguration(
project
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, mAccessControl
#endif
) );
if ( p )
{
Expand Down Expand Up @@ -1542,9 +1532,7 @@ void QgsWmsProjectParser::addOWSLayers( QDomDocument &doc,
QString embeddedGroupName = currentChildElem.attribute( QStringLiteral( "name" ) );
QgsWmsProjectParser* p = dynamic_cast<QgsWmsProjectParser*>( QgsConfigCache::instance()->wmsConfiguration(
project
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, mAccessControl
#endif
) );
if ( p )
{
Expand Down
6 changes: 0 additions & 6 deletions src/server/qgswmsprojectparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include "qgslayertreegroup.h"
#include "qgis_server.h"

#ifdef HAVE_SERVER_PYTHON_PLUGINS
class QgsAccessControl;
#endif

class QTextDocument;
class QSvgRenderer;
Expand All @@ -36,9 +34,7 @@ class SERVER_EXPORT QgsWmsProjectParser : public QgsWmsConfigParser
public:
QgsWmsProjectParser(
const QString& filePath
#ifdef HAVE_SERVER_PYTHON_PLUGINS
, const QgsAccessControl* accessControl
#endif
);
virtual ~QgsWmsProjectParser();

Expand Down Expand Up @@ -133,9 +129,7 @@ class SERVER_EXPORT QgsWmsProjectParser : public QgsWmsConfigParser

private:
QgsServerProjectParser* mProjectParser;
#ifdef HAVE_SERVER_PYTHON_PLUGINS
const QgsAccessControl* mAccessControl;
#endif

mutable QFont mLegendLayerFont;
mutable QFont mLegendItemFont;
Expand Down
4 changes: 2 additions & 2 deletions src/server/services/wcs/qgswcsgetcoverage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ namespace QgsWcs
QByteArray getCoverageData( QgsServerInterface* serverIface, const QgsServerRequest& request )
{
QgsWCSProjectParser* configParser = getConfigParser( serverIface );

#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsAccessControl* accessControl = serverIface->accessControls();

#endif
QStringList wcsLayersId = configParser->wcsLayers();

QList<QgsMapLayer*> layerList;
Expand Down
3 changes: 2 additions & 1 deletion src/server/services/wfs/qgswfstransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ namespace QgsWfs
QDomDocument doc;

QgsWfsProjectParser* configParser = getConfigParser( serverIface );
#ifdef HAVE_SERVER_PYTHON_PLUGINS
QgsAccessControl* accessControl = serverIface->accessControls();

#endif
const QString requestBody = request.getParameter( QStringLiteral( "REQUEST_BODY" ) );

QString errorMsg;
Expand Down
3 changes: 2 additions & 1 deletion src/server/services/wms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ SET (wms_SRCS
qgswmsgetschemaextension.cpp
qgswmsgetstyle.cpp
qgswmsgetstyles.cpp
qgswmsservertransitional.cpp
qgsmaprendererjobproxy.cpp
qgsmediancut.cpp
qgswmsrenderer.cpp
)

########################################################
Expand Down
Loading

0 comments on commit a80497e

Please sign in to comment.