QGIS API Documentation 3.99.0-Master (d270888f95f)
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
21#include "qgsapplication.h"
22#include "qgsvariantutils.h"
23
24#include <QDir>
25#include <QSettings>
26#include <QString>
27
28#include "moc_qgsserversettings.cpp"
29
30using namespace Qt::StringLiterals;
31
36
37void QgsServerSettings::initSettings()
38{
39 mSettings.clear();
40
41 // options path
42 const Setting sOptPath = { QgsServerSettingsEnv::QGIS_OPTIONS_PATH, QgsServerSettingsEnv::DEFAULT_VALUE, u"Override the default path for user configuration"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
43 mSettings[sOptPath.envVar] = sOptPath;
44
45 // parallel rendering
46 const Setting sParRend = { QgsServerSettingsEnv::QGIS_SERVER_PARALLEL_RENDERING, QgsServerSettingsEnv::DEFAULT_VALUE, u"Activate/Deactivate parallel rendering for WMS getMap request"_s, u"/qgis/parallel_rendering"_s, QMetaType::Type::Bool, QVariant( false ), QVariant() };
47 mSettings[sParRend.envVar] = sParRend;
48
49 // max threads
50 const Setting sMaxThreads = { QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Number of threads to use when parallel rendering is activated"_s, u"/qgis/max_threads"_s, QMetaType::Type::Int, QVariant( -1 ), QVariant() };
51 mSettings[sMaxThreads.envVar] = sMaxThreads;
52
53 // log level
54 const Setting sLogLevel = { QgsServerSettingsEnv::QGIS_SERVER_LOG_LEVEL, QgsServerSettingsEnv::DEFAULT_VALUE, u"Log level"_s, QString(), QMetaType::Type::Int, QVariant::fromValue( Qgis::MessageLevel::NoLevel ), QVariant() };
55 mSettings[sLogLevel.envVar] = sLogLevel;
56
57 // log file
58 const Setting sLogFile = { QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Log file"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
59 mSettings[sLogFile.envVar] = sLogFile;
60
61 // log to stderr
62 const Setting sLogStderr = { QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR, QgsServerSettingsEnv::DEFAULT_VALUE, u"Activate/Deactivate logging to stderr"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
63 mSettings[sLogStderr.envVar] = sLogStderr;
64
65 // project file
66 const Setting sProject = { QgsServerSettingsEnv::QGIS_PROJECT_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"QGIS project file"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
67 mSettings[sProject.envVar] = sProject;
68
69 // cache directory
70 const Setting sCacheDir = { QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY, QgsServerSettingsEnv::DEFAULT_VALUE, u"Specify the cache directory"_s, u"/cache/directory"_s, QMetaType::Type::QString, QVariant( QgsApplication::qgisSettingsDirPath() + "cache" ), QVariant() };
71 mSettings[sCacheDir.envVar] = sCacheDir;
72
73 // cache size
74 const Setting sCacheSize = { QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Specify the cache size (0 = automatic size)"_s, u"/cache/size-bytes"_s, QMetaType::Type::LongLong, 0, QVariant() };
75 mSettings[sCacheSize.envVar] = sCacheSize;
76
77 // system locale override
78 const Setting sOverrideSystemLocale = { QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Override system locale"_s, u"/locale/userLocale"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
79 mSettings[sOverrideSystemLocale.envVar] = sOverrideSystemLocale;
80
81 // bad layers handling
82 const Setting sIgnoreBadLayers = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Ignore bad layers"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
83 mSettings[sIgnoreBadLayers.envVar] = sIgnoreBadLayers;
84
85 const Setting sIgnoreRenderingErrors = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_RENDERING_ERRORS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Ignore rendering errors"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
86 mSettings[sIgnoreRenderingErrors.envVar] = sIgnoreRenderingErrors;
87
88 // retry bad layers
89 const Setting sRetryBadLayers = { QgsServerSettingsEnv::QGIS_SERVER_RETRY_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Retry bad layers"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
90 mSettings[sRetryBadLayers.envVar] = sRetryBadLayers;
91
92 // trust layer metadata
93 const Setting sTrustLayerMetadata = { QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA, QgsServerSettingsEnv::DEFAULT_VALUE, u"Trust layer metadata"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
94 mSettings[sTrustLayerMetadata.envVar] = sTrustLayerMetadata;
95
96
97 // force to open layers in read-only mode
98 const Setting sForceReadOnlyLayers = { QgsServerSettingsEnv::QGIS_SERVER_FORCE_READONLY_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Force to open layers in read-only mode"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
99 mSettings[sForceReadOnlyLayers.envVar] = sForceReadOnlyLayers;
100
101 // don't load layouts
102 const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT, QgsServerSettingsEnv::DEFAULT_VALUE, u"Don't load layouts"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
103 mSettings[sDontLoadLayouts.envVar] = sDontLoadLayouts;
104
105 // show group separator
106 const Setting sShowGroupSeparator = { QgsServerSettingsEnv::QGIS_SERVER_SHOW_GROUP_SEPARATOR, QgsServerSettingsEnv::DEFAULT_VALUE, u"Show group (thousands) separator"_s, u"/locale/showGroupSeparator"_s, QMetaType::Type::QString, QVariant( false ), QVariant() };
107 mSettings[sShowGroupSeparator.envVar] = sShowGroupSeparator;
108
109 // max height
110 const Setting sMaxHeight = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_HEIGHT, QgsServerSettingsEnv::DEFAULT_VALUE, u"Maximum height for a WMS request. The lower one of this and the project configuration is used."_s, u"/qgis/max_wms_height"_s, QMetaType::Type::LongLong, QVariant( -1 ), QVariant() };
111 mSettings[sMaxHeight.envVar] = sMaxHeight;
112
113 // max width
114 const Setting sMaxWidth = { QgsServerSettingsEnv::QGIS_SERVER_WMS_MAX_WIDTH, QgsServerSettingsEnv::DEFAULT_VALUE, u"Maximum width for a WMS request. The most conservative between this and the project one is used"_s, u"/qgis/max_wms_width"_s, QMetaType::Type::LongLong, QVariant( -1 ), QVariant() };
115 mSettings[sMaxWidth.envVar] = sMaxWidth;
116
117 // API templates and static override directory
118 const Setting sApiResourcesDirectory = { QgsServerSettingsEnv::QGIS_SERVER_API_RESOURCES_DIRECTORY, QgsServerSettingsEnv::DEFAULT_VALUE, u"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for"_s, u"/qgis/server_api_resources_directory"_s, QMetaType::Type::QString, QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( u"resources/server/api"_s ), QString() };
119
120 mSettings[sApiResourcesDirectory.envVar] = sApiResourcesDirectory;
121
122 // API WFS3 max limit
123 const Setting sApiWfs3MaxLimit = { QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT, QgsServerSettingsEnv::DEFAULT_VALUE, u"Maximum value for \"limit\" in a features request, defaults to 10000"_s, u"/qgis/server_api_wfs3_max_limit"_s, QMetaType::Type::LongLong, QVariant( 10000 ), QVariant() };
124
125 mSettings[sApiWfs3MaxLimit.envVar] = sApiWfs3MaxLimit;
126
127 // API WFS3 root path
128 // TODO: remove when QGIS 4 is released
129#if _QGIS_VERSION_INT > 40000
130 const Setting sApiWfs3RootPath = { QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_ROOT_PATH, QgsServerSettingsEnv::DEFAULT_VALUE, u"Root path for the OAPIF (WFS3) API"_s, u"/qgis/server_api_wfs3_root_path"_s, QMetaType::Type::QString, QVariant( "/ogcapi" ), QVariant() };
131#else
132 const Setting sApiWfs3RootPath = { QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_ROOT_PATH, QgsServerSettingsEnv::DEFAULT_VALUE, u"Root path for the OAPIF (WFS3) API"_s, u"/qgis/server_api_wfs3_root_path"_s, QMetaType::Type::QString, QVariant( "/wfs3" ), QVariant() };
133#endif
134
135 mSettings[sApiWfs3RootPath.envVar] = sApiWfs3RootPath;
136
137 // projects directory for landing page service
138 const Setting sProjectsDirectories = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_DIRECTORIES, QgsServerSettingsEnv::DEFAULT_VALUE, u"Directories used by the landing page service to find .qgs and .qgz projects"_s, u"/qgis/server_projects_directories"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
139
140 mSettings[sProjectsDirectories.envVar] = sProjectsDirectories;
141
142 // postgresql connection string for landing page service
143 const Setting sProjectsPgConnections = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PROJECTS_PG_CONNECTIONS, QgsServerSettingsEnv::DEFAULT_VALUE, u"PostgreSQL connection strings used by the landing page service to find projects"_s, u"/qgis/server_projects_pg_connections"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
144
145 mSettings[sProjectsPgConnections.envVar] = sProjectsPgConnections;
146
147 // landing page base URL prefix
148 const Setting sLandingPageBaseUrlPrefix = { QgsServerSettingsEnv::QGIS_SERVER_LANDING_PAGE_PREFIX, QgsServerSettingsEnv::DEFAULT_VALUE, u"Landing page base URL path prefix"_s, u"/qgis/server_landing_page_base_url_prefix"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
149
150 mSettings[sLandingPageBaseUrlPrefix.envVar] = sLandingPageBaseUrlPrefix;
151
152 // log profile
153 const Setting sLogProfile = { QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0"_s, u"/qgis/server_log_profile"_s, QMetaType::Type::Bool, QVariant( false ), QVariant() };
154
155 mSettings[sLogProfile.envVar] = sLogProfile;
156
157 // the default service URL.
158 const Setting sServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, u"The default service URL"_s, u"/qgis/server_service_url"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
159 mSettings[sServiceUrl.envVar] = sServiceUrl;
160
161 // the default WMS service URL.
162 const Setting sWmsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, u"The default WMS service URL"_s, u"/qgis/server_wms_service_url"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
163 mSettings[sServiceUrl.envVar] = sWmsServiceUrl;
164
165 // the default WFS service URL.
166 const Setting sWfsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, u"The default WFS service URL"_s, u"/qgis/server_wfs_service_url"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
167 mSettings[sServiceUrl.envVar] = sWfsServiceUrl;
168
169 // the default WCS service URL.
170 const Setting sWcsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, u"The default WcS service URL"_s, u"/qgis/server_wcs_service_url"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
171 mSettings[sServiceUrl.envVar] = sWfsServiceUrl;
172
173 // the default WMTS service URL.
174 const Setting sWmtsServiceUrl = { QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL, QgsServerSettingsEnv::DEFAULT_VALUE, u"The default WMTS service URL"_s, u"/qgis/server_wmts_service_url"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
175 mSettings[sServiceUrl.envVar] = sWmtsServiceUrl;
176
177 // the default config cache check interval
178 const Setting sConfigCacheCheckInterval = { QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_CHECK_INTERVAL, QgsServerSettingsEnv::DEFAULT_VALUE, u"The default project cache check interval (in ms)"_s, u"/qgis/server_project_cache_check_interval"_s, QMetaType::Type::Int, QVariant( 0 ), QVariant() };
179 mSettings[sConfigCacheCheckInterval.envVar] = sConfigCacheCheckInterval;
180
181 // the default config cache strategy
182 const Setting sProjectCacheStrategy = { QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY, QgsServerSettingsEnv::DEFAULT_VALUE, u"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'"_s, u"/qgis/server_project_cache_strategy"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
183 mSettings[sProjectCacheStrategy.envVar] = sProjectCacheStrategy;
184
185 // the default config cache size
186 const Setting sProjectCacheSize = { QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_SIZE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Project's cache size, in number of projects."_s, u"/qgis/server_project_cache_size"_s, QMetaType::Type::QString, QVariant( 100 ), QVariant() };
187 mSettings[sProjectCacheSize.envVar] = sProjectCacheSize;
188
189 const Setting sAllowedExtraSqlTokens = { QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS, QgsServerSettingsEnv::DEFAULT_VALUE, u"List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features"_s, u"/qgis/server_allowed_extra_sql_tokens"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
190 mSettings[sAllowedExtraSqlTokens.envVar] = sAllowedExtraSqlTokens;
191
192 const Setting sApplicationName = { QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME, QgsServerSettingsEnv::DEFAULT_VALUE, u"The QGIS Server application name"_s, u"/qgis/application_full_name"_s, QMetaType::Type::QString, QVariant( QgsApplication::applicationFullName() ), QVariant() };
193 mSettings[sApplicationName.envVar] = sApplicationName;
194
195 const Setting sCapabilitiesCacheSize = { QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE, QgsServerSettingsEnv::DEFAULT_VALUE, u"The QGIS Server capabilities cache size"_s, u"/qgis/capabilities_cache_size"_s, QMetaType::Type::Int, QVariant( 40 ), QVariant() };
196 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
197}
198
200{
201 // init settings each time to take into account QgsApplication and
202 // QCoreApplication configuration for some default values
203 initSettings();
204
205 // store environment variables
206 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
207
208 // load QSettings if QGIS_OPTIONS_PATH is defined
209 loadQSettings( env[QgsServerSettingsEnv::QGIS_OPTIONS_PATH] );
210
211 // prioritize values: 'env var' -> 'ini file' -> 'default value'
212 prioritize( env );
213}
214
215bool QgsServerSettings::load( const QString &envVarName )
216{
217 bool rc( false );
218 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
219 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
220
221 if ( value >= 0 )
222 {
223 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
224 prioritize( QMap<QgsServerSettingsEnv::EnvVar, QString> { { ( QgsServerSettingsEnv::EnvVar ) value, envValue } } );
225 rc = true;
226 }
227
228 return rc;
229}
230
231QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
232{
233 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
234
235 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
236 for ( int i = 0; i < metaEnum.keyCount(); i++ )
237 {
238 env[( QgsServerSettingsEnv::EnvVar ) metaEnum.value( i )] = getenv( metaEnum.key( i ) );
239 }
240
241 return env;
242}
243
244QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
245{
246 if ( actual )
247 {
248 const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );
249
250 if ( !envValue.isEmpty() )
251 return envValue;
252 }
253
254 if ( mSettings[envVar].src == QgsServerSettingsEnv::DEFAULT_VALUE )
255 {
256 return mSettings[envVar].defaultVal;
257 }
258 else
259 {
260 return mSettings[envVar].val;
261 }
262}
263
264void QgsServerSettings::loadQSettings( const QString &envOptPath ) const
265{
266 if ( !envOptPath.isEmpty() )
267 {
268 QSettings::setDefaultFormat( QSettings::IniFormat );
269 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
270 }
271}
272
273void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
274{
275 const auto constKeys( env.keys() );
276 for ( const QgsServerSettingsEnv::EnvVar &e : constKeys )
277 {
278 Setting s = mSettings[e];
279
280 QVariant varValue;
281 if ( !env.value( e ).isEmpty() )
282 {
283 varValue.setValue( env.value( e ) );
284 }
285
286 if ( !QgsVariantUtils::isNull( varValue ) && varValue.canConvert( s.type ) )
287 {
288 s.val = varValue;
290 }
291 else if ( !s.iniKey.isEmpty() && QSettings().contains( s.iniKey ) && QSettings().value( s.iniKey ).canConvert( s.type ) )
292 {
293 s.val = QSettings().value( s.iniKey );
295 }
296 else
297 {
298 s.val = QVariant();
300 }
301
302 // an empty string can be returned from QSettings. In this case, we want
303 // to use the default value
304 if ( s.type == QMetaType::Type::QString && s.val.toString().isEmpty() )
305 {
306 s.val = QVariant();
308 }
309
310 mSettings[e] = s;
311 }
312}
313
315{
316 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
317 return metaEnumEnv.valueToKey( env );
318}
319
321{
322 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
323
324 QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::MessageLevel::Info );
325 for ( const Setting &s : std::as_const( mSettings ) )
326 {
327 const QString src = metaEnumSrc.valueToKey( s.src );
328 const QString var = name( s.envVar );
329
330 const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
332 }
333
334 if ( !iniFile().isEmpty() )
335 {
336 const QString msg = "Ini file used to initialize settings: " + iniFile();
338 }
339}
340
341// getter
343{
344 return QSettings().fileName();
345}
346
351
353{
354 return value( QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS ).toInt();
355}
356
358{
359 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE ).toString();
360}
361
363{
364 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR ).toBool();
365}
366
371
373{
374 return value( QgsServerSettingsEnv::QGIS_PROJECT_FILE ).toString();
375}
376
378{
379 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE ).toLongLong();
380}
381
383{
384 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
385}
386
391
396
401
406
411
416
421
426
428{
429 return value( QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT ).toLongLong();
430}
431
433{
435}
436
441
446
451
456
461
466
468{
469 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, false ).toBool();
470}
471
472QString QgsServerSettings::serviceUrl( const QString &service ) const
473{
474 QString result;
475 if ( service.compare( "WMS"_L1 ) )
476 {
477 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL ).toString();
478 }
479 else if ( service.compare( "WFS"_L1 ) )
480 {
481 result = value( QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL ).toString();
482 }
483 else if ( service.compare( "WCS"_L1 ) )
484 {
485 result = value( QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL ).toString();
486 }
487 else if ( service.compare( "WMTS"_L1 ) )
488 {
489 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL ).toString();
490 }
491
492 if ( result.isEmpty() )
493 {
494 result = value( QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL ).toString();
495 }
496
497 return result;
498}
499
504
506{
507 QString result = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY ).toString();
508 if ( result.compare( "filesystem"_L1 ) && result.compare( "periodic"_L1 ) && result.compare( "off"_L1 ) )
509 {
510 if ( !result.isEmpty() )
511 {
512 QgsMessageLog::logMessage( u"Invalid cache strategy '%1', expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default."_s.arg( result ), "Server", Qgis::MessageLevel::Warning );
513 }
514 else
515 {
516 QgsMessageLog::logMessage( u"No cache strategy was specified. Using 'filesystem' as default."_s, "Server", Qgis::MessageLevel::Info );
517 }
518 result = u"filesystem"_s;
519 }
520 return result;
521}
522
524{
525 bool ok;
526 int size = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_SIZE ).toInt( &ok );
527 if ( ok && size >= 1 )
528 return size;
529
530 QgsMessageLog::logMessage( u"Invalid project cache size, expecting integer - defaulting to 100"_s, "Server", Qgis::MessageLevel::Warning );
531 return 100;
532}
533
535{
536 const QString strVal { value( QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS ).toString().trimmed() };
537 if ( strVal.isEmpty() )
538 {
539 return QStringList();
540 }
541 return strVal.split( ',' );
542}
543
545{
546 return value( QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME ).toString().trimmed();
547}
548
550{
551 bool ok;
552 int size = value( QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE ).toInt( &ok );
553 if ( ok && size >= 1 )
554 return size;
555
556 QgsMessageLog::logMessage( u"Invalid capabilities cache size, expecting integer - defaulting to 40"_s, "Server", Qgis::MessageLevel::Warning );
557 return 40;
558}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:159
@ NoLevel
No level.
Definition qgis.h:164
@ Warning
Warning message.
Definition qgis.h:161
@ Info
Information message.
Definition qgis.h:160
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, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE())
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_PROJECT_CACHE_SIZE
Set the project cache size, in number of projects.
@ 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_API_WFS3_ROOT_PATH
Root path for OAPIF (WFS3) service API, default value is "/wfs3".
@ 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_RETRY_BAD_LAYERS
Retry bad layers in following request in case they might only be temporary unavailable.
@ 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_IGNORE_RENDERING_ERRORS
Ignore rendering errors if true. If false, the server returns an error if a rendering error occurs.
@ 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:...
int projectCacheSize() const
Returns the projects cache size The default value is 100, the value can be changed by setting the env...
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 retryBadLayers() const
Returns true if bad layers should be re-checked after the project has been cached.
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 apiWfs3RootPath() const
Returns the server-wide root path for OAPIF (WFS3) service API.
QString logFile() const
Returns the log file.
qlonglong apiWfs3MaxLimit() const
Returns the server-wide maximum allowed value for "limit" in a features request.
bool ignoreRenderingErrors() const
Returns true if rendering errors are ignored by the server.
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.