QGIS API Documentation 4.1.0-Master (376402f9aeb)
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
361 = { QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME, QgsServerSettingsEnv::DEFAULT_VALUE, u"The QGIS Server application name"_s, u"app/full-name"_s, QMetaType::Type::QString, QVariant( QgsApplication::applicationFullName() ), QVariant() };
362 mSettings[sApplicationName.envVar] = sApplicationName;
363 }
364
365 {
366 const Setting sCapabilitiesCacheSize
367 = { 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() };
368 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
369 }
370}
371
373{
374 // init settings each time to take into account QgsApplication and
375 // QCoreApplication configuration for some default values
376 initSettings();
377
378 // store environment variables
379 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
380
381 // load QSettings if QGIS_OPTIONS_PATH is defined
382 loadQSettings( env[QgsServerSettingsEnv::QGIS_OPTIONS_PATH] );
383
384 // prioritize values: 'env var' -> 'ini file' -> 'default value'
385 prioritize( env );
386}
387
388bool QgsServerSettings::load( const QString &envVarName )
389{
390 bool rc( false );
391 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
392 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
393
394 if ( value >= 0 )
395 {
396 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
397 prioritize( QMap<QgsServerSettingsEnv::EnvVar, QString> { { ( QgsServerSettingsEnv::EnvVar ) value, envValue } } );
398 rc = true;
399 }
400
401 return rc;
402}
403
404QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
405{
406 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
407
408 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
409 for ( int i = 0; i < metaEnum.keyCount(); i++ )
410 {
411 env[( QgsServerSettingsEnv::EnvVar ) metaEnum.value( i )] = getenv( metaEnum.key( i ) );
412 }
413
414 return env;
415}
416
417QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
418{
419 if ( actual )
420 {
421 const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );
422
423 if ( !envValue.isEmpty() )
424 return envValue;
425 }
426
427 if ( mSettings[envVar].src == QgsServerSettingsEnv::DEFAULT_VALUE )
428 {
429 return mSettings[envVar].defaultVal;
430 }
431 else
432 {
433 return mSettings[envVar].val;
434 }
435}
436
437void QgsServerSettings::loadQSettings( const QString &envOptPath ) const
438{
439 if ( !envOptPath.isEmpty() )
440 {
441 QSettings::setDefaultFormat( QSettings::IniFormat );
442 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
443 }
444}
445
446void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
447{
448 for ( auto envIt = env.constBegin(); envIt != env.constEnd(); ++envIt )
449 {
450 const QgsServerSettingsEnv::EnvVar e = envIt.key();
451
452 auto settingIt = mSettings.find( e );
453 if ( settingIt == mSettings.end() )
454 continue;
455
456 QVariant varValue;
457 if ( !envIt.value().isEmpty() )
458 {
459 varValue.setValue( envIt.value() );
460 }
461
462 if ( !QgsVariantUtils::isNull( varValue ) && varValue.canConvert( settingIt->type ) )
463 {
464 settingIt->val = varValue;
466 }
467 else if ( !settingIt->iniKey.isEmpty() && QSettings().contains( settingIt->iniKey ) && QSettings().value( settingIt->iniKey ).canConvert( settingIt->type ) )
468 {
469 settingIt->val = QSettings().value( settingIt->iniKey );
470 settingIt->src = QgsServerSettingsEnv::INI_FILE;
471 }
472 else
473 {
474 settingIt->val = QVariant();
476 }
477
478 // an empty string can be returned from QSettings. In this case, we want
479 // to use the default value
480 if ( settingIt->type == QMetaType::Type::QString && settingIt->val.toString().isEmpty() )
481 {
482 settingIt->val = QVariant();
484 }
485 }
486}
487
489{
490 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
491 return metaEnumEnv.valueToKey( env );
492}
493
495{
496 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
497
498 QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::MessageLevel::Info );
499 for ( const Setting &s : std::as_const( mSettings ) )
500 {
501 const QString src = metaEnumSrc.valueToKey( s.src );
502 const QString var = name( s.envVar );
503
504 const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
506 }
507
508 if ( !iniFile().isEmpty() )
509 {
510 const QString msg = "Ini file used to initialize settings: " + iniFile();
512 }
513}
514
515// getter
517{
518 return QSettings().fileName();
519}
520
525
527{
528 return value( QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS ).toInt();
529}
530
532{
533 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE ).toString();
534}
535
537{
538 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR ).toBool();
539}
540
545
547{
548 return value( QgsServerSettingsEnv::QGIS_PROJECT_FILE ).toString();
549}
550
552{
553 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE ).toLongLong();
554}
555
557{
558 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
559}
560
565
570
575
580
585
590
595
600
602{
603 return value( QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT ).toLongLong();
604}
605
607{
609}
610
615
620
625
630
635
640
642{
643 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, false ).toBool();
644}
645
646QString QgsServerSettings::serviceUrl( const QString &service ) const
647{
648 QString result;
649 if ( service.compare( "WMS"_L1, Qt::CaseInsensitive ) == 0 )
650 {
651 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL ).toString();
652 }
653 else if ( service.compare( "WFS"_L1, Qt::CaseInsensitive ) == 0 )
654 {
655 result = value( QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL ).toString();
656 }
657 else if ( service.compare( "WCS"_L1, Qt::CaseInsensitive ) == 0 )
658 {
659 result = value( QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL ).toString();
660 }
661 else if ( service.compare( "WMTS"_L1, Qt::CaseInsensitive ) == 0 )
662 {
663 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL ).toString();
664 }
665
666 if ( result.isEmpty() )
667 {
668 result = value( QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL ).toString();
669 }
670
671 return result;
672}
673
678
680{
681 QString result = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY ).toString();
682 if ( result.compare( "filesystem"_L1 ) && result.compare( "periodic"_L1 ) && result.compare( "off"_L1 ) )
683 {
684 if ( !result.isEmpty() )
685 {
686 QgsMessageLog::logMessage( u"Invalid cache strategy '%1', expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default."_s.arg( result ), "Server", Qgis::MessageLevel::Warning );
687 }
688 else
689 {
690 QgsMessageLog::logMessage( u"No cache strategy was specified. Using 'filesystem' as default."_s, "Server", Qgis::MessageLevel::Info );
691 }
692 result = u"filesystem"_s;
693 }
694 return result;
695}
696
698{
699 bool ok;
700 int size = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_SIZE ).toInt( &ok );
701 if ( ok && size >= 1 )
702 return size;
703
704 QgsMessageLog::logMessage( u"Invalid project cache size, expecting integer - defaulting to 100"_s, "Server", Qgis::MessageLevel::Warning );
705 return 100;
706}
707
709{
710 const QString strVal { value( QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS ).toString().trimmed() };
711 if ( strVal.isEmpty() )
712 {
713 return QStringList();
714 }
715 return strVal.split( ',' );
716}
717
719{
720 return value( QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME ).toString().trimmed();
721}
722
724{
725 bool ok;
726 int size = value( QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE ).toInt( &ok );
727 if ( ok && size >= 1 )
728 return size;
729
730 QgsMessageLog::logMessage( u"Invalid capabilities cache size, expecting integer - defaulting to 40"_s, "Server", Qgis::MessageLevel::Warning );
731 return 40;
732}
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.