QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsserversettings.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsserversettings.cpp
3 ---------------------
4 begin : December 19, 2016
5 copyright : (C) 2016 by Paul Blottiere
6 email : paul dot blottiere at oslandia dot com
7
8***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "qgsserversettings.h"
20#include "moc_qgsserversettings.cpp"
21#include "qgsapplication.h"
22#include "qgsvariantutils.h"
23
24#include <QSettings>
25#include <QDir>
26
31
32void QgsServerSettings::initSettings()
33{
34 mSettings.clear();
35
36 // options path
37 const Setting sOptPath = { QgsServerSettingsEnv::QGIS_OPTIONS_PATH, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Override the default path for user configuration" ), QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
38 mSettings[sOptPath.envVar] = sOptPath;
39
40 // parallel rendering
41 const Setting sParRend = { QgsServerSettingsEnv::QGIS_SERVER_PARALLEL_RENDERING, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Activate/Deactivate parallel rendering for WMS getMap request" ), QStringLiteral( "/qgis/parallel_rendering" ), QMetaType::Type::Bool, QVariant( false ), QVariant() };
42 mSettings[sParRend.envVar] = sParRend;
43
44 // max threads
45 const Setting sMaxThreads = { QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Number of threads to use when parallel rendering is activated" ), QStringLiteral( "/qgis/max_threads" ), QMetaType::Type::Int, QVariant( -1 ), QVariant() };
46 mSettings[sMaxThreads.envVar] = sMaxThreads;
47
48 // log level
49 const Setting sLogLevel = { QgsServerSettingsEnv::QGIS_SERVER_LOG_LEVEL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Log level" ), QString(), QMetaType::Type::Int, QVariant::fromValue( Qgis::MessageLevel::NoLevel ), QVariant() };
50 mSettings[sLogLevel.envVar] = sLogLevel;
51
52 // log file
53 const Setting sLogFile = { QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Log file" ), QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
54 mSettings[sLogFile.envVar] = sLogFile;
55
56 // log to stderr
57 const Setting sLogStderr = { QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Activate/Deactivate logging to stderr" ), QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
58 mSettings[sLogStderr.envVar] = sLogStderr;
59
60 // project file
61 const Setting sProject = { QgsServerSettingsEnv::QGIS_PROJECT_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "QGIS project file" ), QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
62 mSettings[sProject.envVar] = sProject;
63
64 // cache directory
65 const Setting sCacheDir = { QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Specify the cache directory" ), QStringLiteral( "/cache/directory" ), QMetaType::Type::QString, QVariant( QgsApplication::qgisSettingsDirPath() + "cache" ), QVariant() };
66 mSettings[sCacheDir.envVar] = sCacheDir;
67
68 // cache size
69 const Setting sCacheSize = { QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Specify the cache size (0 = automatic size)" ), QStringLiteral( "/cache/size-bytes" ), QMetaType::Type::LongLong, 0, QVariant() };
70 mSettings[sCacheSize.envVar] = sCacheSize;
71
72 // system locale override
73 const Setting sOverrideSystemLocale = { QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Override system locale" ), QStringLiteral( "/locale/userLocale" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
74 mSettings[sOverrideSystemLocale.envVar] = sOverrideSystemLocale;
75
76 // bad layers handling
77 const Setting sIgnoreBadLayers = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Ignore bad layers" ), QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
78 mSettings[sIgnoreBadLayers.envVar] = sIgnoreBadLayers;
79
80 // trust layer metadata
81 const Setting sTrustLayerMetadata = { QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Trust layer metadata" ), QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
82 mSettings[sTrustLayerMetadata.envVar] = sTrustLayerMetadata;
83
84
85 // force to open layers in read-only mode
86 const Setting sForceReadOnlyLayers = { QgsServerSettingsEnv::QGIS_SERVER_FORCE_READONLY_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Force to open layers in read-only mode" ), QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
87 mSettings[sForceReadOnlyLayers.envVar] = sForceReadOnlyLayers;
88
89 // don't load layouts
90 const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Don't load layouts" ), QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
91 mSettings[sDontLoadLayouts.envVar] = sDontLoadLayouts;
92
93 // show group separator
94 const Setting sShowGroupSeparator = { QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Show group (thousands) separator" ), QStringLiteral( "/locale/showGroupSeparator" ), QMetaType::Type::QString, QVariant( false ), QVariant() };
95 mSettings[sShowGroupSeparator.envVar] = sShowGroupSeparator;
96
97 // max height
98 const Setting sMaxHeight = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Maximum height for a WMS request. The lower one of this and the project configuration is used." ), QStringLiteral( "/qgis/max_wms_height" ), QMetaType::Type::LongLong, QVariant( -1 ), QVariant() };
99 mSettings[sMaxHeight.envVar] = sMaxHeight;
100
101 // max width
102 const Setting sMaxWidth = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Maximum width for a WMS request. The most conservative between this and the project one is used" ), QStringLiteral( "/qgis/max_wms_width" ), QMetaType::Type::LongLong, QVariant( -1 ), QVariant() };
103 mSettings[sMaxWidth.envVar] = sMaxWidth;
104
105 // API templates and static override directory
106 const Setting sApiResourcesDirectory = { QgsServerSettingsEnv::QGIS_SERVER_API_RESOURCES_DIRECTORY, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for" ), QStringLiteral( "/qgis/server_api_resources_directory" ), QMetaType::Type::QString, QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( QStringLiteral( "resources/server/api" ) ), QString() };
107
108 mSettings[sApiResourcesDirectory.envVar] = sApiResourcesDirectory;
109
110 // API WFS3 max limit
111 const Setting sApiWfs3MaxLimit = { QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Maximum value for \"limit\" in a features request, defaults to 10000" ), QStringLiteral( "/qgis/server_api_wfs3_max_limit" ), QMetaType::Type::LongLong, QVariant( 10000 ), QVariant() };
112
113 mSettings[sApiWfs3MaxLimit.envVar] = sApiWfs3MaxLimit;
114
115 // projects directory for landing page service
116 const Setting sProjectsDirectories = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Directories used by the landing page service to find .qgs and .qgz projects" ), QStringLiteral( "/qgis/server_projects_directories" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
117
118 mSettings[sProjectsDirectories.envVar] = sProjectsDirectories;
119
120 // postgresql connection string for landing page service
121 const Setting sProjectsPgConnections = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "PostgreSQL connection strings used by the landing page service to find projects" ), QStringLiteral( "/qgis/server_projects_pg_connections" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
122
123 mSettings[sProjectsPgConnections.envVar] = sProjectsPgConnections;
124
125 // landing page base URL prefix
126 const Setting sLandingPageBaseUrlPrefix = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PREFIX, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Landing page base URL path prefix" ), QStringLiteral( "/qgis/server_landing_page_base_url_prefix" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
127
128 mSettings[sLandingPageBaseUrlPrefix.envVar] = sLandingPageBaseUrlPrefix;
129
130 // log profile
131 const Setting sLogProfile = { QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0" ), QStringLiteral( "/qgis/server_log_profile" ), QMetaType::Type::Bool, QVariant( false ), QVariant() };
132
133 mSettings[sLogProfile.envVar] = sLogProfile;
134
135 // the default service URL.
136 const Setting sServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The default service URL" ), QStringLiteral( "/qgis/server_service_url" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
137 mSettings[sServiceUrl.envVar] = sServiceUrl;
138
139 // the default WMS service URL.
140 const Setting sWmsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The default WMS service URL" ), QStringLiteral( "/qgis/server_wms_service_url" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
141 mSettings[sServiceUrl.envVar] = sWmsServiceUrl;
142
143 // the default WFS service URL.
144 const Setting sWfsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The default WFS service URL" ), QStringLiteral( "/qgis/server_wfs_service_url" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
145 mSettings[sServiceUrl.envVar] = sWfsServiceUrl;
146
147 // the default WCS service URL.
148 const Setting sWcsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The default WcS service URL" ), QStringLiteral( "/qgis/server_wcs_service_url" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
149 mSettings[sServiceUrl.envVar] = sWfsServiceUrl;
150
151 // the default WMTS service URL.
152 const Setting sWmtsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The default WMTS service URL" ), QStringLiteral( "/qgis/server_wmts_service_url" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
153 mSettings[sServiceUrl.envVar] = sWmtsServiceUrl;
154
155 // the default config cache check interval
156 const Setting sConfigCacheCheckInterval = { QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_CHECK_INTERVAL, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The default project cache check interval (in ms)" ), QStringLiteral( "/qgis/server_project_cache_check_interval" ), QMetaType::Type::Int, QVariant( 0 ), QVariant() };
157 mSettings[sConfigCacheCheckInterval.envVar] = sConfigCacheCheckInterval;
158
159 // the default config cache strategy
160 const Setting sProjectCacheStrategy = { QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'" ), QStringLiteral( "/qgis/server_project_cache_strategy" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
161 mSettings[sProjectCacheStrategy.envVar] = sProjectCacheStrategy;
162
163 const Setting sAllowedExtraSqlTokens = { QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features" ), QStringLiteral( "/qgis/server_allowed_extra_sql_tokens" ), QMetaType::Type::QString, QVariant( "" ), QVariant() };
164 mSettings[sAllowedExtraSqlTokens.envVar] = sAllowedExtraSqlTokens;
165
166 const Setting sApplicationName = { QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The QGIS Server application name" ), QStringLiteral( "/qgis/application_full_name" ), QMetaType::Type::QString, QVariant( QgsApplication::applicationFullName() ), QVariant() };
167 mSettings[sApplicationName.envVar] = sApplicationName;
168
169 const Setting sCapabilitiesCacheSize = { QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE, QgsServerSettingsEnv::DEFAULT_VALUE, QStringLiteral( "The QGIS Server capabilities cache size" ), QStringLiteral( "/qgis/capabilities_cache_size" ), QMetaType::Type::Int, QVariant( 40 ), QVariant() };
170 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
171}
172
174{
175 // init settings each time to take into account QgsApplication and
176 // QCoreApplication configuration for some default values
177 initSettings();
178
179 // store environment variables
180 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
181
182 // load QSettings if QGIS_OPTIONS_PATH is defined
183 loadQSettings( env[QgsServerSettingsEnv::QGIS_OPTIONS_PATH] );
184
185 // prioritize values: 'env var' -> 'ini file' -> 'default value'
186 prioritize( env );
187}
188
189bool QgsServerSettings::load( const QString &envVarName )
190{
191 bool rc( false );
192 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
193 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
194
195 if ( value >= 0 )
196 {
197 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
198 prioritize( QMap<QgsServerSettingsEnv::EnvVar, QString> { { ( QgsServerSettingsEnv::EnvVar ) value, envValue } } );
199 rc = true;
200 }
201
202 return rc;
203}
204
205QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
206{
207 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
208
209 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
210 for ( int i = 0; i < metaEnum.keyCount(); i++ )
211 {
212 env[( QgsServerSettingsEnv::EnvVar ) metaEnum.value( i )] = getenv( metaEnum.key( i ) );
213 }
214
215 return env;
216}
217
218QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
219{
220 if ( actual )
221 {
222 const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );
223
224 if ( !envValue.isEmpty() )
225 return envValue;
226 }
227
228 if ( mSettings[envVar].src == QgsServerSettingsEnv::DEFAULT_VALUE )
229 {
230 return mSettings[envVar].defaultVal;
231 }
232 else
233 {
234 return mSettings[envVar].val;
235 }
236}
237
238void QgsServerSettings::loadQSettings( const QString &envOptPath ) const
239{
240 if ( !envOptPath.isEmpty() )
241 {
242 QSettings::setDefaultFormat( QSettings::IniFormat );
243 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
244 }
245}
246
247void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
248{
249 const auto constKeys( env.keys() );
250 for ( const QgsServerSettingsEnv::EnvVar &e : constKeys )
251 {
252 Setting s = mSettings[e];
253
254 QVariant varValue;
255 if ( !env.value( e ).isEmpty() )
256 {
257 varValue.setValue( env.value( e ) );
258 }
259
260 if ( !QgsVariantUtils::isNull( varValue ) && varValue.canConvert( s.type ) )
261 {
262 s.val = varValue;
264 }
265 else if ( !s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
266 {
267 s.val = QSettings().value( s.iniKey );
269 }
270 else
271 {
272 s.val = QVariant();
274 }
275
276 // an empty string can be returned from QSettings. In this case, we want
277 // to use the default value
278 if ( s.type == QMetaType::Type::QString && s.val.toString().isEmpty() )
279 {
280 s.val = QVariant();
282 }
283
284 mSettings[e] = s;
285 }
286}
287
289{
290 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
291 return metaEnumEnv.valueToKey( env );
292}
293
295{
296 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
297
298 QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::MessageLevel::Info );
299 for ( const Setting &s : std::as_const( mSettings ) )
300 {
301 const QString src = metaEnumSrc.valueToKey( s.src );
302 const QString var = name( s.envVar );
303
304 const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
306 }
307
308 if ( !iniFile().isEmpty() )
309 {
310 const QString msg = "Ini file used to initialize settings: " + iniFile();
312 }
313}
314
315// getter
317{
318 return QSettings().fileName();
319}
320
325
327{
328 return value( QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS ).toInt();
329}
330
332{
333 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE ).toString();
334}
335
337{
338 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR ).toBool();
339}
340
345
347{
348 return value( QgsServerSettingsEnv::QGIS_PROJECT_FILE ).toString();
349}
350
352{
353 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE ).toLongLong();
354}
355
357{
358 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
359}
360
365
370
375
380
385
390
395
400
402{
403 return value( QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT ).toLongLong();
404}
405
410
415
420
425
427{
428 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, false ).toBool();
429}
430
431QString QgsServerSettings::serviceUrl( const QString &service ) const
432{
433 QString result;
434 if ( service.compare( QLatin1String( "WMS" ) ) )
435 {
436 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL ).toString();
437 }
438 else if ( service.compare( QLatin1String( "WFS" ) ) )
439 {
440 result = value( QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL ).toString();
441 }
442 else if ( service.compare( QLatin1String( "WCS" ) ) )
443 {
444 result = value( QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL ).toString();
445 }
446 else if ( service.compare( QLatin1String( "WMTS" ) ) )
447 {
448 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL ).toString();
449 }
450
451 if ( result.isEmpty() )
452 {
453 result = value( QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL ).toString();
454 }
455
456 return result;
457}
458
463
465{
466 QString result = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY ).toString();
467 if ( result.compare( QLatin1String( "filesystem" ) ) && result.compare( QLatin1String( "periodic" ) ) && result.compare( QLatin1String( "off" ) ) )
468 {
469 QgsMessageLog::logMessage( QStringLiteral( "Invalid cache strategy, expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default." ), "Server", Qgis::MessageLevel::Warning );
470 result = QStringLiteral( "filesystem" );
471 }
472 return result;
473}
474
476{
477 const QString strVal { value( QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS ).toString().trimmed() };
478 if ( strVal.isEmpty() )
479 {
480 return QStringList();
481 }
482 return strVal.split( ',' );
483}
484
486{
487 return value( QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME ).toString().trimmed();
488}
489
491{
492 bool ok;
493 int size = value( QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE ).toInt( &ok );
494 if ( ok && size >= 1 )
495 return size;
496
497 QgsMessageLog::logMessage( QStringLiteral( "Invalid capabilities cache size, expecting integer - defaulting to 40" ), "Server", Qgis::MessageLevel::Warning );
498 return 40;
499}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:154
@ NoLevel
No level.
Definition qgis.h:159
@ Warning
Warning message.
Definition qgis.h:156
@ Info
Information message.
Definition qgis.h:155
static QString pkgDataPath()
Returns the common root path of all application data directories.
static QString applicationFullName()
Returns the QGIS application full name.
static QString qgisSettingsDirPath()
Returns the path to the settings directory in user's home dir.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
EnvVar
Environment variables to configure the server.
@ QGIS_SERVER_WCS_SERVICE_URL
To set the WCS service URL if it's not present in the project.
@ QGIS_SERVER_WMTS_SERVICE_URL
To set the WMTS service URL if it's not present in the project.
@ QGIS_SERVER_IGNORE_BAD_LAYERS
Do not consider the whole project unavailable if it contains bad layers.
@ QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS
Adds these tokens to the list of allowed tokens that the services accept when filtering features.
@ QGIS_SERVER_CAPABILITIES_CACHE_SIZE
Define the QGIS Server capabilities cache size.
@ QGIS_SERVER_LANDING_PAGE_PREFIX
Prefix of the path component of the landing page base URL, default is empty.
@ QGIS_SERVER_TRUST_LAYER_METADATA
Trust layer metadata. Improves project read time.
@ QGIS_SERVER_WFS_SERVICE_URL
To set the WFS service URL if it's not present in the project.
@ QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE
Override system locale.
@ QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS
PostgreSQL connection strings used by the landing page service to find projects.
@ QGIS_SERVER_API_WFS3_MAX_LIMIT
Maximum value for "limit" in a features request, defaults to 10000.
@ QGIS_SERVER_API_RESOURCES_DIRECTORY
Base directory where HTML templates and static assets (e.g. images, js and css files) are searched fo...
@ QGIS_SERVER_WMS_MAX_WIDTH
Maximum width for a WMS request. The most conservative between this and the project one is used.
@ QGIS_SERVER_FORCE_READONLY_LAYERS
Force to open layers in read-only mode.
@ QGIS_SERVER_PROJECT_CACHE_STRATEGY
Set the project cache strategy. Possible values are 'filesystem', 'periodic' or 'off'.
@ QGIS_SERVER_APPLICATION_NAME
Define the QGIS Server application name.
@ QGIS_SERVER_WMS_MAX_HEIGHT
Maximum height for a WMS request. The most conservative between this and the project one is used.
@ QGIS_SERVER_WMS_SERVICE_URL
To set the WMS service URL if it's not present in the project.
@ QGIS_SERVER_DISABLE_GETPRINT
Disabled WMS GetPrint request and don't load layouts. Improves project read time.
@ QGIS_SERVER_PROJECT_CACHE_CHECK_INTERVAL
Set the interval in milliseconds for cache invalidation strategy 'interval', default to 0 which selec...
@ QGIS_SERVER_SHOW_GROUP_SEPARATOR
Show group (thousands) separator when formatting numeric values, defaults to false.
@ QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES
Directories used by the landing page service to find .qgs and .qgz projects.
@ QGIS_SERVER_LOG_PROFILE
When QGIS_SERVER_LOG_LEVEL is 0 this flag adds to the logs detailed information about the time taken ...
@ QGIS_SERVER_SERVICE_URL
To set the service URL if it's not present in the project.
QString serviceUrl(const QString &service) const
Returns the service URL from the setting.
QString cacheDirectory() const
Returns the cache directory.
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
QString landingPageProjectsPgConnections() const
Returns the PostgreSQL connection strings used by the landing page service to find projects.
int maxThreads() const
Returns the maximum number of threads to use.
bool logStderr() const
Returns whether logging to stderr is activated.
QgsServerSettings()
Constructor.
QString projectFile() const
Returns the QGS project file to use.
QString apiResourcesDirectory() const
Returns the server-wide base directory where HTML templates and static assets (e.g.
int projectCacheCheckInterval() const
Returns the config cache check interval (in ms) for the 'periodic' strategy.
Qgis::MessageLevel logLevel() const
Returns the log level.
bool logProfile() const
Returns true if profile information has to be added to the logs, default value is false.
QStringList allowedExtraSqlTokens() const
Returns the list of strings that represent the allowed extra SQL tokens accepted as components of a f...
bool forceReadOnlyLayers() const
Returns true if the reading flag force layer read only is activated.
int wmsMaxWidth() const
Returns the server-wide max width of a WMS GetMap request.
int capabilitiesCacheSize() const
Returns the maximum number of project capabilities to cache.
static QString name(QgsServerSettingsEnv::EnvVar env)
Returns the string representation of a setting.
QString landingPageBaseUrlPrefix() const
Returns the landing page base URL regular expression, defaults to /.
void logSummary() const
Log a summary of settings currently loaded.
QString logFile() const
Returns the log file.
qlonglong apiWfs3MaxLimit() const
Returns the server-wide maximum allowed value for "limit" in a features request.
int wmsMaxHeight() const
Returns the server-wide max height of a WMS GetMap request.
QString landingPageProjectsDirectories() const
Returns the directories used by the landing page service to find .qgs and .qgz projects.
bool parallelRendering() const
Returns parallel rendering setting.
QString applicationName() const
Returns the QGIS Server application name.
bool showGroupSeparator() const
Show group (thousand) separator.
bool ignoreBadLayers() const
Returns true if the bad layers are ignored and false when the presence of a bad layers invalidates th...
QString iniFile() const
Returns the ini file loaded by QSetting.
QString projectCacheStrategy() const
Returns the project's cache strategy The default value is 'filesystem', the value can be changed by s...
QString overrideSystemLocale() const
Overrides system locale.
bool trustLayerMetadata() const
Returns true if the reading flag trust layer metadata is activated.
void load()
Load settings according to current environment variables.
qint64 cacheSize() const
Returns the cache size.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.