QGIS API Documentation 4.1.0-Master (3b8ef1f72a3)
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 const Setting sApiWfs3RootPath
223 = { 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() };
224 mSettings[sApiWfs3RootPath.envVar] = sApiWfs3RootPath;
225 }
226
227 // projects directory for landing page service
228 {
229 const Setting sProjectsDirectories = {
232 u"Directories used by the landing page service to find .qgs and .qgz projects"_s,
233 u"/qgis/server_projects_directories"_s,
234 QMetaType::Type::QString,
235 QVariant( "" ),
236 QVariant()
237 };
238 mSettings[sProjectsDirectories.envVar] = sProjectsDirectories;
239 }
240
241 // postgresql connection string for landing page service
242 {
243 const Setting sProjectsPgConnections = {
246 u"PostgreSQL connection strings used by the landing page service to find projects"_s,
247 u"/qgis/server_projects_pg_connections"_s,
248 QMetaType::Type::QString,
249 QVariant( "" ),
250 QVariant()
251 };
252 mSettings[sProjectsPgConnections.envVar] = sProjectsPgConnections;
253 }
254
255 // landing page base URL prefix
256 {
257 const Setting sLandingPageBaseUrlPrefix
258 = { 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() };
259 mSettings[sLandingPageBaseUrlPrefix.envVar] = sLandingPageBaseUrlPrefix;
260 }
261
262 // log profile
263 {
264 const Setting sLogProfile = {
267 u"Add detailed profile information to the logs, only effective when QGIS_SERVER_LOG_LEVEL=0"_s,
268 u"/qgis/server_log_profile"_s,
269 QMetaType::Type::Bool,
270 QVariant( false ),
271 QVariant()
272 };
273 mSettings[sLogProfile.envVar] = sLogProfile;
274 }
275
276 // the default service URL.
277 {
278 const Setting sServiceUrl
279 = { 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() };
280 mSettings[sServiceUrl.envVar] = sServiceUrl;
281 }
282
283 // the default WMS service URL.
284 {
285 const Setting sWmsServiceUrl
286 = { 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() };
287 mSettings[sWmsServiceUrl.envVar] = sWmsServiceUrl;
288 }
289
290 // the default WFS service URL.
291 {
292 const Setting sWfsServiceUrl
293 = { 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() };
294 mSettings[sWfsServiceUrl.envVar] = sWfsServiceUrl;
295 }
296
297 // the default WCS service URL.
298 {
299 const Setting sWcsServiceUrl
300 = { 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() };
301 mSettings[sWcsServiceUrl.envVar] = sWcsServiceUrl;
302 }
303
304 // the default WMTS service URL.
305 {
306 const Setting sWmtsServiceUrl
307 = { 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() };
308 mSettings[sWmtsServiceUrl.envVar] = sWmtsServiceUrl;
309 }
310
311 // the default config cache check interval
312 {
313 const Setting sConfigCacheCheckInterval = {
316 u"The default project cache check interval (in ms)"_s,
317 u"/qgis/server_project_cache_check_interval"_s,
318 QMetaType::Type::Int,
319 QVariant( 0 ),
320 QVariant()
321 };
322 mSettings[sConfigCacheCheckInterval.envVar] = sConfigCacheCheckInterval;
323 }
324
325 // the default config cache strategy
326 {
327 const Setting sProjectCacheStrategy = {
330 u"Project's cache strategy. Possible values are 'off','filesystem' or 'periodic'"_s,
331 u"/qgis/server_project_cache_strategy"_s,
332 QMetaType::Type::QString,
333 QVariant( "" ),
334 QVariant()
335 };
336 mSettings[sProjectCacheStrategy.envVar] = sProjectCacheStrategy;
337 }
338
339 // the default config cache size
340 {
341 const Setting sProjectCacheSize
342 = { 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() };
343 mSettings[sProjectCacheSize.envVar] = sProjectCacheSize;
344 }
345
346 {
347 const Setting sAllowedExtraSqlTokens = {
350 u"List of comma separated SQL tokens to be added to the list of allowed tokens that the services accepts when filtering features"_s,
351 u"/qgis/server_allowed_extra_sql_tokens"_s,
352 QMetaType::Type::QString,
353 QVariant( "" ),
354 QVariant()
355 };
356 mSettings[sAllowedExtraSqlTokens.envVar] = sAllowedExtraSqlTokens;
357 }
358
359 {
360 const Setting sApplicationName = {
363 u"The QGIS Server application name"_s,
364 u"/qgis/application_full_name"_s,
365 QMetaType::Type::QString,
367 QVariant()
368 };
369 mSettings[sApplicationName.envVar] = sApplicationName;
370 }
371
372 {
373 const Setting sCapabilitiesCacheSize
374 = { 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() };
375 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
376 }
377}
378
380{
381 // init settings each time to take into account QgsApplication and
382 // QCoreApplication configuration for some default values
383 initSettings();
384
385 // store environment variables
386 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
387
388 // load QSettings if QGIS_OPTIONS_PATH is defined
389 loadQSettings( env[QgsServerSettingsEnv::QGIS_OPTIONS_PATH] );
390
391 // prioritize values: 'env var' -> 'ini file' -> 'default value'
392 prioritize( env );
393}
394
395bool QgsServerSettings::load( const QString &envVarName )
396{
397 bool rc( false );
398 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
399 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
400
401 if ( value >= 0 )
402 {
403 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
404 prioritize( QMap<QgsServerSettingsEnv::EnvVar, QString> { { ( QgsServerSettingsEnv::EnvVar ) value, envValue } } );
405 rc = true;
406 }
407
408 return rc;
409}
410
411QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
412{
413 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
414
415 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
416 for ( int i = 0; i < metaEnum.keyCount(); i++ )
417 {
418 env[( QgsServerSettingsEnv::EnvVar ) metaEnum.value( i )] = getenv( metaEnum.key( i ) );
419 }
420
421 return env;
422}
423
424QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
425{
426 if ( actual )
427 {
428 const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );
429
430 if ( !envValue.isEmpty() )
431 return envValue;
432 }
433
434 if ( mSettings[envVar].src == QgsServerSettingsEnv::DEFAULT_VALUE )
435 {
436 return mSettings[envVar].defaultVal;
437 }
438 else
439 {
440 return mSettings[envVar].val;
441 }
442}
443
444void QgsServerSettings::loadQSettings( const QString &envOptPath ) const
445{
446 if ( !envOptPath.isEmpty() )
447 {
448 QSettings::setDefaultFormat( QSettings::IniFormat );
449 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
450 }
451}
452
453void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
454{
455 for ( auto envIt = env.constBegin(); envIt != env.constEnd(); ++envIt )
456 {
457 const QgsServerSettingsEnv::EnvVar e = envIt.key();
458
459 auto settingIt = mSettings.find( e );
460 if ( settingIt == mSettings.end() )
461 continue;
462
463 QVariant varValue;
464 if ( !envIt.value().isEmpty() )
465 {
466 varValue.setValue( envIt.value() );
467 }
468
469 if ( !QgsVariantUtils::isNull( varValue ) && varValue.canConvert( settingIt->type ) )
470 {
471 settingIt->val = varValue;
473 }
474 else if ( !settingIt->iniKey.isEmpty() && QSettings().contains( settingIt->iniKey ) && QSettings().value( settingIt->iniKey ).canConvert( settingIt->type ) )
475 {
476 settingIt->val = QSettings().value( settingIt->iniKey );
477 settingIt->src = QgsServerSettingsEnv::INI_FILE;
478 }
479 else
480 {
481 settingIt->val = QVariant();
483 }
484
485 // an empty string can be returned from QSettings. In this case, we want
486 // to use the default value
487 if ( settingIt->type == QMetaType::Type::QString && settingIt->val.toString().isEmpty() )
488 {
489 settingIt->val = QVariant();
491 }
492 }
493}
494
496{
497 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
498 return metaEnumEnv.valueToKey( env );
499}
500
502{
503 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
504
505 QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::MessageLevel::Info );
506 for ( const Setting &s : std::as_const( mSettings ) )
507 {
508 const QString src = metaEnumSrc.valueToKey( s.src );
509 const QString var = name( s.envVar );
510
511 const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
513 }
514
515 if ( !iniFile().isEmpty() )
516 {
517 const QString msg = "Ini file used to initialize settings: " + iniFile();
519 }
520}
521
522// getter
524{
525 return QSettings().fileName();
526}
527
532
534{
535 return value( QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS ).toInt();
536}
537
539{
540 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE ).toString();
541}
542
544{
545 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR ).toBool();
546}
547
552
554{
555 return value( QgsServerSettingsEnv::QGIS_PROJECT_FILE ).toString();
556}
557
559{
560 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE ).toLongLong();
561}
562
564{
565 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
566}
567
572
577
582
587
592
597
602
607
609{
610 return value( QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT ).toLongLong();
611}
612
614{
616}
617
622
627
632
637
642
647
649{
650 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, false ).toBool();
651}
652
653QString QgsServerSettings::serviceUrl( const QString &service ) const
654{
655 QString result;
656 if ( service.compare( "WMS"_L1, Qt::CaseInsensitive ) == 0 )
657 {
658 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL ).toString();
659 }
660 else if ( service.compare( "WFS"_L1, Qt::CaseInsensitive ) == 0 )
661 {
662 result = value( QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL ).toString();
663 }
664 else if ( service.compare( "WCS"_L1, Qt::CaseInsensitive ) == 0 )
665 {
666 result = value( QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL ).toString();
667 }
668 else if ( service.compare( "WMTS"_L1, Qt::CaseInsensitive ) == 0 )
669 {
670 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL ).toString();
671 }
672
673 if ( result.isEmpty() )
674 {
675 result = value( QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL ).toString();
676 }
677
678 return result;
679}
680
685
687{
688 QString result = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY ).toString();
689 if ( result.compare( "filesystem"_L1 ) && result.compare( "periodic"_L1 ) && result.compare( "off"_L1 ) )
690 {
691 if ( !result.isEmpty() )
692 {
693 QgsMessageLog::logMessage( u"Invalid cache strategy '%1', expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default."_s.arg( result ), "Server", Qgis::MessageLevel::Warning );
694 }
695 else
696 {
697 QgsMessageLog::logMessage( u"No cache strategy was specified. Using 'filesystem' as default."_s, "Server", Qgis::MessageLevel::Info );
698 }
699 result = u"filesystem"_s;
700 }
701 return result;
702}
703
705{
706 bool ok;
707 int size = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_SIZE ).toInt( &ok );
708 if ( ok && size >= 1 )
709 return size;
710
711 QgsMessageLog::logMessage( u"Invalid project cache size, expecting integer - defaulting to 100"_s, "Server", Qgis::MessageLevel::Warning );
712 return 100;
713}
714
716{
717 const QString strVal { value( QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS ).toString().trimmed() };
718 if ( strVal.isEmpty() )
719 {
720 return QStringList();
721 }
722 return strVal.split( ',' );
723}
724
726{
727 return value( QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME ).toString().trimmed();
728}
729
731{
732 bool ok;
733 int size = value( QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE ).toInt( &ok );
734 if ( ok && size >= 1 )
735 return size;
736
737 QgsMessageLog::logMessage( u"Invalid capabilities cache size, expecting integer - defaulting to 40"_s, "Server", Qgis::MessageLevel::Warning );
738 return 40;
739}
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.