QGIS API Documentation 4.1.0-Master (5bf3c20f3c9)
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 {
43 const Setting sOptPath
44 = { QgsServerSettingsEnv::QGIS_OPTIONS_PATH, QgsServerSettingsEnv::DEFAULT_VALUE, u"Override the default path for user configuration"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
45 mSettings[sOptPath.envVar] = sOptPath;
46 }
47
48 // parallel rendering
49 {
50 const Setting sParRend = {
53 u"Activate/Deactivate parallel rendering for WMS getMap request"_s,
54 u"/qgis/parallel_rendering"_s,
55 QMetaType::Type::Bool,
56 QVariant( false ),
57 QVariant()
58 };
59 mSettings[sParRend.envVar] = sParRend;
60 }
61
62 // max threads
63 {
64 const Setting sMaxThreads
65 = { 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() };
66 mSettings[sMaxThreads.envVar] = sMaxThreads;
67 }
68
69 // log level
70 {
71 const Setting sLogLevel
72 = { QgsServerSettingsEnv::QGIS_SERVER_LOG_LEVEL, QgsServerSettingsEnv::DEFAULT_VALUE, u"Log level"_s, QString(), QMetaType::Type::Int, QVariant::fromValue( Qgis::MessageLevel::NoLevel ), QVariant() };
73 mSettings[sLogLevel.envVar] = sLogLevel;
74 }
75
76 // log file
77 {
78 const Setting sLogFile = { QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Log file"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
79 mSettings[sLogFile.envVar] = sLogFile;
80 }
81
82 // log to stderr
83 {
84 const Setting sLogStderr
85 = { QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR, QgsServerSettingsEnv::DEFAULT_VALUE, u"Activate/Deactivate logging to stderr"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
86 mSettings[sLogStderr.envVar] = sLogStderr;
87 }
88
89 // project file
90 {
91 const Setting sProject = { QgsServerSettingsEnv::QGIS_PROJECT_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"QGIS project file"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
92 mSettings[sProject.envVar] = sProject;
93 }
94
95 // cache directory
96 {
97 const Setting sCacheDir
98 = { 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() };
99 mSettings[sCacheDir.envVar] = sCacheDir;
100 }
101
102 // cache size
103 {
104 const Setting sCacheSize
105 = { 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() };
106 mSettings[sCacheSize.envVar] = sCacheSize;
107 }
108
109 // system locale override
110 {
111 const Setting sOverrideSystemLocale
112 = { QgsServerSettingsEnv::QGIS_SERVER_OVERRIDE_SYSTEM_LOCALE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Override system locale"_s, u"/locale/userLocale"_s, QMetaType::Type::QString, QVariant( "" ), QVariant() };
113 mSettings[sOverrideSystemLocale.envVar] = sOverrideSystemLocale;
114 }
115
116 // bad layers handling
117 {
118 const Setting sIgnoreBadLayers
119 = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Ignore bad layers"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
120 mSettings[sIgnoreBadLayers.envVar] = sIgnoreBadLayers;
121 }
122
123 {
124 const Setting sIgnoreRenderingErrors
125 = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_RENDERING_ERRORS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Ignore rendering errors"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
126 mSettings[sIgnoreRenderingErrors.envVar] = sIgnoreRenderingErrors;
127 }
128
129 // retry bad layers
130 {
131 const Setting sRetryBadLayers
132 = { QgsServerSettingsEnv::QGIS_SERVER_RETRY_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Retry bad layers"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
133 mSettings[sRetryBadLayers.envVar] = sRetryBadLayers;
134 }
135
136 // trust layer metadata
137 {
138 const Setting sTrustLayerMetadata
139 = { QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA, QgsServerSettingsEnv::DEFAULT_VALUE, u"Trust layer metadata"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
140 mSettings[sTrustLayerMetadata.envVar] = sTrustLayerMetadata;
141 }
142
143 // force to open layers in read-only mode
144 {
145 const Setting sForceReadOnlyLayers
146 = { 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() };
147 mSettings[sForceReadOnlyLayers.envVar] = sForceReadOnlyLayers;
148 }
149
150 // don't load layouts
151 {
152 const Setting sDontLoadLayouts
153 = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT, QgsServerSettingsEnv::DEFAULT_VALUE, u"Don't load layouts"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
154 mSettings[sDontLoadLayouts.envVar] = sDontLoadLayouts;
155 }
156
157 // show group separator
158 {
159 const Setting sShowGroupSeparator
160 = { 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() };
161 mSettings[sShowGroupSeparator.envVar] = sShowGroupSeparator;
162 }
163
164 // max height
165 {
166 const Setting sMaxHeight = {
169 u"Maximum height for a WMS request. The lower one of this and the project configuration is used."_s,
170 u"/qgis/max_wms_height"_s,
171 QMetaType::Type::LongLong,
172 QVariant( -1 ),
173 QVariant()
174 };
175 mSettings[sMaxHeight.envVar] = sMaxHeight;
176 }
177
178 // max width
179 {
180 const Setting sMaxWidth = {
183 u"Maximum width for a WMS request. The most conservative between this and the project one is used"_s,
184 u"/qgis/max_wms_width"_s,
185 QMetaType::Type::LongLong,
186 QVariant( -1 ),
187 QVariant()
188 };
189 mSettings[sMaxWidth.envVar] = sMaxWidth;
190 }
191
192 // API templates and static override directory
193 {
194 const Setting sApiResourcesDirectory = {
197 u"Base directory where HTML templates and static assets (e.g. images, js and css files) are searched for"_s,
198 u"/qgis/server_api_resources_directory"_s,
199 QMetaType::Type::QString,
200 QDir( QgsApplication::pkgDataPath() ).absoluteFilePath( u"resources/server/api"_s ),
201 QString()
202 };
203 mSettings[sApiResourcesDirectory.envVar] = sApiResourcesDirectory;
204 }
205
206 // API WFS3 max limit
207 {
208 const Setting sApiWfs3MaxLimit = {
211 u"Maximum value for \"limit\" in a features request, defaults to 10000"_s,
212 u"/qgis/server_api_wfs3_max_limit"_s,
213 QMetaType::Type::LongLong,
214 QVariant( 10000 ),
215 QVariant()
216 };
217 mSettings[sApiWfs3MaxLimit.envVar] = sApiWfs3MaxLimit;
218 }
219
220 {
221 // API WFS3 root path
222 // TODO: remove when QGIS 4 is released
223#if _QGIS_VERSION_INT > 40000
224 const Setting sApiWfs3RootPath
225 = { 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() };
226#else
227 const Setting sApiWfs3RootPath
228 = { 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() };
229#endif
230 mSettings[sApiWfs3RootPath.envVar] = sApiWfs3RootPath;
231 }
232
233 // projects directory for landing page service
234 {
235 const Setting sProjectsDirectories = {
238 u"Directories used by the landing page service to find .qgs and .qgz projects"_s,
239 u"/qgis/server_projects_directories"_s,
240 QMetaType::Type::QString,
241 QVariant( "" ),
242 QVariant()
243 };
244 mSettings[sProjectsDirectories.envVar] = sProjectsDirectories;
245 }
246
247 // postgresql connection string for landing page service
248 {
249 const Setting sProjectsPgConnections = {
252 u"PostgreSQL connection strings used by the landing page service to find projects"_s,
253 u"/qgis/server_projects_pg_connections"_s,
254 QMetaType::Type::QString,
255 QVariant( "" ),
256 QVariant()
257 };
258 mSettings[sProjectsPgConnections.envVar] = sProjectsPgConnections;
259 }
260
261 // landing page base URL prefix
262 {
263 const Setting sLandingPageBaseUrlPrefix
264 = { 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() };
265 mSettings[sLandingPageBaseUrlPrefix.envVar] = sLandingPageBaseUrlPrefix;
266 }
267
268 // log profile
269 {
270 const Setting sLogProfile = {
273 u"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0"_s,
274 u"/qgis/server_log_profile"_s,
275 QMetaType::Type::Bool,
276 QVariant( false ),
277 QVariant()
278 };
279 mSettings[sLogProfile.envVar] = sLogProfile;
280 }
281
282 // the default service URL.
283 {
284 const Setting sServiceUrl
285 = { 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() };
286 mSettings[sServiceUrl.envVar] = sServiceUrl;
287 }
288
289 // the default WMS service URL.
290 {
291 const Setting sWmsServiceUrl
292 = { 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() };
293 mSettings[sWmsServiceUrl.envVar] = sWmsServiceUrl;
294 }
295
296 // the default WFS service URL.
297 {
298 const Setting sWfsServiceUrl
299 = { 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() };
300 mSettings[sWfsServiceUrl.envVar] = sWfsServiceUrl;
301 }
302
303 // the default WCS service URL.
304 {
305 const Setting sWcsServiceUrl
306 = { 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() };
307 mSettings[sWcsServiceUrl.envVar] = sWcsServiceUrl;
308 }
309
310 // the default WMTS service URL.
311 {
312 const Setting sWmtsServiceUrl
313 = { 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() };
314 mSettings[sWmtsServiceUrl.envVar] = sWmtsServiceUrl;
315 }
316
317 // the default config cache check interval
318 {
319 const Setting sConfigCacheCheckInterval = {
322 u"The default project cache check interval (in ms)"_s,
323 u"/qgis/server_project_cache_check_interval"_s,
324 QMetaType::Type::Int,
325 QVariant( 0 ),
326 QVariant()
327 };
328 mSettings[sConfigCacheCheckInterval.envVar] = sConfigCacheCheckInterval;
329 }
330
331 // the default config cache strategy
332 {
333 const Setting sProjectCacheStrategy = {
336 u"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'"_s,
337 u"/qgis/server_project_cache_strategy"_s,
338 QMetaType::Type::QString,
339 QVariant( "" ),
340 QVariant()
341 };
342 mSettings[sProjectCacheStrategy.envVar] = sProjectCacheStrategy;
343 }
344
345 // the default config cache size
346 {
347 const Setting sProjectCacheSize
348 = { 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() };
349 mSettings[sProjectCacheSize.envVar] = sProjectCacheSize;
350 }
351
352 {
353 const Setting sAllowedExtraSqlTokens = {
356 u"List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features"_s,
357 u"/qgis/server_allowed_extra_sql_tokens"_s,
358 QMetaType::Type::QString,
359 QVariant( "" ),
360 QVariant()
361 };
362 mSettings[sAllowedExtraSqlTokens.envVar] = sAllowedExtraSqlTokens;
363 }
364
365 {
366 const Setting sApplicationName = {
369 u"The QGIS Server application name"_s,
370 u"/qgis/application_full_name"_s,
371 QMetaType::Type::QString,
373 QVariant()
374 };
375 mSettings[sApplicationName.envVar] = sApplicationName;
376 }
377
378 {
379 const Setting sCapabilitiesCacheSize
380 = { 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() };
381 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
382 }
383}
384
386{
387 // init settings each time to take into account QgsApplication and
388 // QCoreApplication configuration for some default values
389 initSettings();
390
391 // store environment variables
392 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
393
394 // load QSettings if QGIS_OPTIONS_PATH is defined
395 loadQSettings( env[QgsServerSettingsEnv::QGIS_OPTIONS_PATH] );
396
397 // prioritize values: 'env var' -> 'ini file' -> 'default value'
398 prioritize( env );
399}
400
401bool QgsServerSettings::load( const QString &envVarName )
402{
403 bool rc( false );
404 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
405 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
406
407 if ( value >= 0 )
408 {
409 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
410 prioritize( QMap<QgsServerSettingsEnv::EnvVar, QString> { { ( QgsServerSettingsEnv::EnvVar ) value, envValue } } );
411 rc = true;
412 }
413
414 return rc;
415}
416
417QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
418{
419 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
420
421 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
422 for ( int i = 0; i < metaEnum.keyCount(); i++ )
423 {
424 env[( QgsServerSettingsEnv::EnvVar ) metaEnum.value( i )] = getenv( metaEnum.key( i ) );
425 }
426
427 return env;
428}
429
430QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
431{
432 if ( actual )
433 {
434 const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );
435
436 if ( !envValue.isEmpty() )
437 return envValue;
438 }
439
440 if ( mSettings[envVar].src == QgsServerSettingsEnv::DEFAULT_VALUE )
441 {
442 return mSettings[envVar].defaultVal;
443 }
444 else
445 {
446 return mSettings[envVar].val;
447 }
448}
449
450void QgsServerSettings::loadQSettings( const QString &envOptPath ) const
451{
452 if ( !envOptPath.isEmpty() )
453 {
454 QSettings::setDefaultFormat( QSettings::IniFormat );
455 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
456 }
457}
458
459void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
460{
461 for ( auto envIt = env.constBegin(); envIt != env.constEnd(); ++envIt )
462 {
463 const QgsServerSettingsEnv::EnvVar e = envIt.key();
464
465 auto settingIt = mSettings.find( e );
466 if ( settingIt == mSettings.end() )
467 continue;
468
469 QVariant varValue;
470 if ( !envIt.value().isEmpty() )
471 {
472 varValue.setValue( envIt.value() );
473 }
474
475 if ( !QgsVariantUtils::isNull( varValue ) && varValue.canConvert( settingIt->type ) )
476 {
477 settingIt->val = varValue;
479 }
480 else if ( !settingIt->iniKey.isEmpty() && QSettings().contains( settingIt->iniKey ) && QSettings().value( settingIt->iniKey ).canConvert( settingIt->type ) )
481 {
482 settingIt->val = QSettings().value( settingIt->iniKey );
483 settingIt->src = QgsServerSettingsEnv::INI_FILE;
484 }
485 else
486 {
487 settingIt->val = QVariant();
489 }
490
491 // an empty string can be returned from QSettings. In this case, we want
492 // to use the default value
493 if ( settingIt->type == QMetaType::Type::QString && settingIt->val.toString().isEmpty() )
494 {
495 settingIt->val = QVariant();
497 }
498 }
499}
500
502{
503 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
504 return metaEnumEnv.valueToKey( env );
505}
506
508{
509 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
510
511 QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::MessageLevel::Info );
512 for ( const Setting &s : std::as_const( mSettings ) )
513 {
514 const QString src = metaEnumSrc.valueToKey( s.src );
515 const QString var = name( s.envVar );
516
517 const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
519 }
520
521 if ( !iniFile().isEmpty() )
522 {
523 const QString msg = "Ini file used to initialize settings: " + iniFile();
525 }
526}
527
528// getter
530{
531 return QSettings().fileName();
532}
533
538
540{
541 return value( QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS ).toInt();
542}
543
545{
546 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE ).toString();
547}
548
550{
551 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR ).toBool();
552}
553
558
560{
561 return value( QgsServerSettingsEnv::QGIS_PROJECT_FILE ).toString();
562}
563
565{
566 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE ).toLongLong();
567}
568
570{
571 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
572}
573
578
583
588
593
598
603
608
613
615{
616 return value( QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT ).toLongLong();
617}
618
620{
622}
623
628
633
638
643
648
653
655{
656 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, false ).toBool();
657}
658
659QString QgsServerSettings::serviceUrl( const QString &service ) const
660{
661 QString result;
662 if ( service.compare( "WMS"_L1, Qt::CaseInsensitive ) == 0 )
663 {
664 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL ).toString();
665 }
666 else if ( service.compare( "WFS"_L1, Qt::CaseInsensitive ) == 0 )
667 {
668 result = value( QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL ).toString();
669 }
670 else if ( service.compare( "WCS"_L1, Qt::CaseInsensitive ) == 0 )
671 {
672 result = value( QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL ).toString();
673 }
674 else if ( service.compare( "WMTS"_L1, Qt::CaseInsensitive ) == 0 )
675 {
676 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL ).toString();
677 }
678
679 if ( result.isEmpty() )
680 {
681 result = value( QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL ).toString();
682 }
683
684 return result;
685}
686
691
693{
694 QString result = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY ).toString();
695 if ( result.compare( "filesystem"_L1 ) && result.compare( "periodic"_L1 ) && result.compare( "off"_L1 ) )
696 {
697 if ( !result.isEmpty() )
698 {
699 QgsMessageLog::logMessage( u"Invalid cache strategy '%1', expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default."_s.arg( result ), "Server", Qgis::MessageLevel::Warning );
700 }
701 else
702 {
703 QgsMessageLog::logMessage( u"No cache strategy was specified. Using 'filesystem' as default."_s, "Server", Qgis::MessageLevel::Info );
704 }
705 result = u"filesystem"_s;
706 }
707 return result;
708}
709
711{
712 bool ok;
713 int size = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_SIZE ).toInt( &ok );
714 if ( ok && size >= 1 )
715 return size;
716
717 QgsMessageLog::logMessage( u"Invalid project cache size, expecting integer - defaulting to 100"_s, "Server", Qgis::MessageLevel::Warning );
718 return 100;
719}
720
722{
723 const QString strVal { value( QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS ).toString().trimmed() };
724 if ( strVal.isEmpty() )
725 {
726 return QStringList();
727 }
728 return strVal.split( ',' );
729}
730
732{
733 return value( QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME ).toString().trimmed();
734}
735
737{
738 bool ok;
739 int size = value( QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE ).toInt( &ok );
740 if ( ok && size >= 1 )
741 return size;
742
743 QgsMessageLog::logMessage( u"Invalid capabilities cache size, expecting integer - defaulting to 40"_s, "Server", Qgis::MessageLevel::Warning );
744 return 40;
745}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:160
@ NoLevel
No level.
Definition qgis.h:165
@ Warning
Warning message.
Definition qgis.h:162
@ Info
Information message.
Definition qgis.h:161
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(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
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.