Skip to content
Permalink
Browse files

Allow setting wmsMaxWidth and wmsMaxHeight in the server env

created env variables code

use server settings as well

add since 3.8
  • Loading branch information
mbernasocchi committed Apr 1, 2019
1 parent 3c4b2a7 commit a9385070708aee989ad41ed3fd10271e303f8d9b
@@ -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()
@@ -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();
}

@@ -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 )
};
@@ -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();
@@ -120,6 +120,7 @@ namespace QgsWms

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

QgsRenderer::~QgsRenderer()
@@ -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
@@ -283,6 +283,8 @@ namespace QgsWms

QgsWmsParameters mWmsParameters;

QgsServerSettings mServerSettings;

QgsFeatureFilter mFeatureFilter;

const QgsProject *mProject = nullptr;

0 comments on commit a938507

Please sign in to comment.
You can’t perform that action at this time.