Skip to content

Commit

Permalink
Allow setting wmsMaxWidth and wmsMaxHeight in the server env
Browse files Browse the repository at this point in the history
created env variables code

use server settings as well

add since 3.8
  • Loading branch information
mbernasocchi committed Apr 5, 2019
1 parent 3c4b2a7 commit a938507
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 14 deletions.
32 changes: 21 additions & 11 deletions src/server/qgsserversettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,27 @@ void QgsServerSettings::initSettings()
};
mSettings[ sShowGroupSeparator.envVar ] = sShowGroupSeparator;

// max height
const Setting sMaxHeight = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT,
QgsServerSettingsEnv::DEFAULT_VALUE,
"Maximum height for a WMS request. The most conservative between this and the project one is used",
"/qgis/max_wms_height",
QVariant::LongLong,
QVariant( -1 ),
QVariant()
};
mSettings[ sMaxHeight.envVar ] = sMaxHeight;

// max width
const Setting sMaxWidth = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH,
QgsServerSettingsEnv::DEFAULT_VALUE,
"Maximum width for a WMS request. The most conservative between this and the project one is used",
"/qgis/max_wms_width",
QVariant::LongLong,
QVariant( -1 ),
QVariant()
};
mSettings[ sMaxWidth.envVar ] = sMaxWidth;
}

void QgsServerSettings::load()
Expand Down Expand Up @@ -342,14 +363,3 @@ QString QgsServerSettings::cacheDirectory() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
}

QString QgsServerSettings::overrideSystemLocale() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE ).toString();
}

bool QgsServerSettings::showGroupSeparator() const
{
return value( QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR ).toBool();
}

16 changes: 16 additions & 0 deletions src/server/qgsserversettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
QGIS_SERVER_CACHE_SIZE,
QGIS_SERVER_SHOW_GROUP_SEPARATOR, //! Show group (thousands) separator when formatting numeric values, defaults to FALSE (since QGIS 3.8)
QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE, //! Override system locale (since QGIS 3.8)
QGIS_SERVER_WMS_MAX_HEIGHT, //! Maximum height for a WMS request. The most conservative between this and the project one is used (since QGIS 3.8)
QGIS_SERVER_WMS_MAX_WIDTH //! Maximum width for a WMS request. The most conservative between this and the project one is used (since QGIS 3.8)
};
Q_ENUM( EnvVar )
};
Expand Down Expand Up @@ -183,6 +185,20 @@ class SERVER_EXPORT QgsServerSettings
* \since QGIS 3.8
*/
bool showGroupSeparator() const;

/**
* Returns the max height of a WMS GetMap request.
* \returns Returns the max height of a WMS GetMap request.
* \since QGIS 3.8
*/
int wmsMaxHeight() const;

/**
* Returns the max width of a WMS GetMap request.
* \returns the max width of a WMS GetMap request.
* \since QGIS 3.8
*/
int wmsMaxWidth() const;

private:
void initSettings();
Expand Down
37 changes: 34 additions & 3 deletions src/server/services/wms/qgswmsrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ namespace QgsWms

mWmsParameters = mContext.parameters();
mWmsParameters.dump();
mServerSettings = mContext.settings();
}

QgsRenderer::~QgsRenderer()
Expand Down Expand Up @@ -1870,21 +1871,51 @@ namespace QgsWms

bool QgsRenderer::checkMaximumWidthHeight() const
{
//test if maxWidth / maxHeight set and WIDTH / HEIGHT parameter is in the range
int wmsMaxWidth = QgsServerProjectUtils::wmsMaxWidth( *mProject );
//test if maxWidth / maxHeight are set in the project or as an env variable
//and WIDTH / HEIGHT parameter is in the range allowed range
//WIDTH
int wmsMaxWidthProj = QgsServerProjectUtils::wmsMaxWidth( *mProject );
int wmsMaxWidthEnv = mServerSettings.wmsMaxWidth();
int wmsMaxWidth;
if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
{
// both are set, so we take the more conservative one
wmsMaxWidth = qMin( wmsMaxWidthProj, wmsMaxWidthEnv );
}
else
{
// none or one are set, so we take the bigger one which is the one set or -1
wmsMaxWidth = qMax( wmsMaxWidthProj, wmsMaxWidthEnv );
}

int width = this->width();
if ( wmsMaxWidth != -1 && width > wmsMaxWidth )
{
return false;
}

int wmsMaxHeight = QgsServerProjectUtils::wmsMaxHeight( *mProject );
//HEIGHT
int wmsMaxHeightProj = QgsServerProjectUtils::wmsMaxHeight( *mProject );
int wmsMaxHeightEnv = mServerSettings.wmsMaxHeight();
int wmsMaxHeight;
if ( wmsMaxWidthEnv != -1 && wmsMaxWidthProj != -1 )
{
// both are set, so we take the more conservative one
wmsMaxHeight = qMin( wmsMaxHeightProj, wmsMaxHeightEnv );
}
else
{
// none or one are set, so we take the bigger one which is the one set or -1
wmsMaxHeight = qMax( wmsMaxHeightProj, wmsMaxHeightEnv );
}

int height = this->height();
if ( wmsMaxHeight != -1 && height > wmsMaxHeight )
{
return false;
}


// Sanity check from internal QImage checks (see qimage.cpp)
// this is to report a meaningful error message in case of
// image creation failure and to differentiate it from out
Expand Down
2 changes: 2 additions & 0 deletions src/server/services/wms/qgswmsrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ namespace QgsWms

QgsWmsParameters mWmsParameters;

QgsServerSettings mServerSettings;

QgsFeatureFilter mFeatureFilter;

const QgsProject *mProject = nullptr;
Expand Down

0 comments on commit a938507

Please sign in to comment.