QGIS API Documentation 3.99.0-Master (c22de0620c0)
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 = { QgsServerSettingsEnv::QGIS_OPTIONS_PATH, QgsServerSettingsEnv::DEFAULT_VALUE, u"Override the default path for user configuration"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
44 mSettings[sOptPath.envVar] = sOptPath;
45 }
46
47 // parallel rendering
48 {
49 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() };
50 mSettings[sParRend.envVar] = sParRend;
51 }
52
53 // max threads
54 {
55 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() };
56 mSettings[sMaxThreads.envVar] = sMaxThreads;
57 }
58
59 // log level
60 {
61 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() };
62 mSettings[sLogLevel.envVar] = sLogLevel;
63 }
64
65 // log file
66 {
67 const Setting sLogFile = { QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"Log file"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
68 mSettings[sLogFile.envVar] = sLogFile;
69 }
70
71 // log to stderr
72 {
73 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() };
74 mSettings[sLogStderr.envVar] = sLogStderr;
75 }
76
77 // project file
78 {
79 const Setting sProject = { QgsServerSettingsEnv::QGIS_PROJECT_FILE, QgsServerSettingsEnv::DEFAULT_VALUE, u"QGIS project file"_s, QString(), QMetaType::Type::QString, QVariant( "" ), QVariant() };
80 mSettings[sProject.envVar] = sProject;
81 }
82
83 // cache directory
84 {
85 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() };
86 mSettings[sCacheDir.envVar] = sCacheDir;
87 }
88
89 // cache size
90 {
91 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() };
92 mSettings[sCacheSize.envVar] = sCacheSize;
93 }
94
95 // system locale override
96 {
97 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() };
98 mSettings[sOverrideSystemLocale.envVar] = sOverrideSystemLocale;
99 }
100
101 // bad layers handling
102 {
103 const Setting sIgnoreBadLayers = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Ignore bad layers"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
104 mSettings[sIgnoreBadLayers.envVar] = sIgnoreBadLayers;
105 }
106
107 {
108 const Setting sIgnoreRenderingErrors = { QgsServerSettingsEnv::QGIS_SERVER_IGNORE_RENDERING_ERRORS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Ignore rendering errors"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
109 mSettings[sIgnoreRenderingErrors.envVar] = sIgnoreRenderingErrors;
110 }
111
112 // retry bad layers
113 {
114 const Setting sRetryBadLayers = { QgsServerSettingsEnv::QGIS_SERVER_RETRY_BAD_LAYERS, QgsServerSettingsEnv::DEFAULT_VALUE, u"Retry bad layers"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
115 mSettings[sRetryBadLayers.envVar] = sRetryBadLayers;
116 }
117
118 // trust layer metadata
119 {
120 const Setting sTrustLayerMetadata = { QgsServerSettingsEnv::QGIS_SERVER_TRUST_LAYER_METADATA, QgsServerSettingsEnv::DEFAULT_VALUE, u"Trust layer metadata"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
121 mSettings[sTrustLayerMetadata.envVar] = sTrustLayerMetadata;
122 }
123
124 // force to open layers in read-only mode
125 {
126 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() };
127 mSettings[sForceReadOnlyLayers.envVar] = sForceReadOnlyLayers;
128 }
129
130 // don't load layouts
131 {
132 const Setting sDontLoadLayouts = { QgsServerSettingsEnv::QGIS_SERVER_DISABLE_GETPRINT, QgsServerSettingsEnv::DEFAULT_VALUE, u"Don't load layouts"_s, QString(), QMetaType::Type::Bool, QVariant( false ), QVariant() };
133 mSettings[sDontLoadLayouts.envVar] = sDontLoadLayouts;
134 }
135
136 // show group separator
137 {
138 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() };
139 mSettings[sShowGroupSeparator.envVar] = sShowGroupSeparator;
140 }
141
142 // max height
143 {
144 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() };
145 mSettings[sMaxHeight.envVar] = sMaxHeight;
146 }
147
148 // max width
149 {
150 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() };
151 mSettings[sMaxWidth.envVar] = sMaxWidth;
152 }
153
154 // API templates and static override directory
155 {
156 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() };
157 mSettings[sApiResourcesDirectory.envVar] = sApiResourcesDirectory;
158 }
159
160 // API WFS3 max limit
161 {
162 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() };
163 mSettings[sApiWfs3MaxLimit.envVar] = sApiWfs3MaxLimit;
164 }
165
166 {
167 // API WFS3 root path
168 // TODO: remove when QGIS 4 is released
169#if _QGIS_VERSION_INT > 40000
170 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() };
171#else
172 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() };
173#endif
174 mSettings[sApiWfs3RootPath.envVar] = sApiWfs3RootPath;
175 }
176
177 // projects directory for landing page service
178 {
179 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() };
180 mSettings[sProjectsDirectories.envVar] = sProjectsDirectories;
181 }
182
183 // postgresql connection string for landing page service
184 {
185 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() };
186 mSettings[sProjectsPgConnections.envVar] = sProjectsPgConnections;
187 }
188
189 // landing page base URL prefix
190 {
191 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() };
192 mSettings[sLandingPageBaseUrlPrefix.envVar] = sLandingPageBaseUrlPrefix;
193 }
194
195 // log profile
196 {
197 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() };
198 mSettings[sLogProfile.envVar] = sLogProfile;
199 }
200
201 // the default service URL.
202 {
203 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() };
204 mSettings[sServiceUrl.envVar] = sServiceUrl;
205 }
206
207 // the default WMS service URL.
208 {
209 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() };
210 mSettings[sWmsServiceUrl.envVar] = sWmsServiceUrl;
211 }
212
213 // the default WFS service URL.
214 {
215 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() };
216 mSettings[sWfsServiceUrl.envVar] = sWfsServiceUrl;
217 }
218
219 // the default WCS service URL.
220 {
221 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() };
222 mSettings[sWcsServiceUrl.envVar] = sWcsServiceUrl;
223 }
224
225 // the default WMTS service URL.
226 {
227 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() };
228 mSettings[sWmtsServiceUrl.envVar] = sWmtsServiceUrl;
229 }
230
231 // the default config cache check interval
232 {
233 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() };
234 mSettings[sConfigCacheCheckInterval.envVar] = sConfigCacheCheckInterval;
235 }
236
237 // the default config cache strategy
238 {
239 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() };
240 mSettings[sProjectCacheStrategy.envVar] = sProjectCacheStrategy;
241 }
242
243 // the default config cache size
244 {
245 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() };
246 mSettings[sProjectCacheSize.envVar] = sProjectCacheSize;
247 }
248
249 {
250 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() };
251 mSettings[sAllowedExtraSqlTokens.envVar] = sAllowedExtraSqlTokens;
252 }
253
254 {
255 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() };
256 mSettings[sApplicationName.envVar] = sApplicationName;
257 }
258
259 {
260 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() };
261 mSettings[sCapabilitiesCacheSize.envVar] = sCapabilitiesCacheSize;
262 }
263}
264
266{
267 // init settings each time to take into account QgsApplication and
268 // QCoreApplication configuration for some default values
269 initSettings();
270
271 // store environment variables
272 QMap<QgsServerSettingsEnv::EnvVar, QString> env = getEnv();
273
274 // load QSettings if QGIS_OPTIONS_PATH is defined
275 loadQSettings( env[QgsServerSettingsEnv::QGIS_OPTIONS_PATH] );
276
277 // prioritize values: 'env var' -> 'ini file' -> 'default value'
278 prioritize( env );
279}
280
281bool QgsServerSettings::load( const QString &envVarName )
282{
283 bool rc( false );
284 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
285 const int value = metaEnum.keyToValue( envVarName.toStdString().c_str() );
286
287 if ( value >= 0 )
288 {
289 const QString envValue( getenv( envVarName.toStdString().c_str() ) );
290 prioritize( QMap<QgsServerSettingsEnv::EnvVar, QString> { { ( QgsServerSettingsEnv::EnvVar ) value, envValue } } );
291 rc = true;
292 }
293
294 return rc;
295}
296
297QMap<QgsServerSettingsEnv::EnvVar, QString> QgsServerSettings::getEnv() const
298{
299 QMap<QgsServerSettingsEnv::EnvVar, QString> env;
300
301 const QMetaEnum metaEnum( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
302 for ( int i = 0; i < metaEnum.keyCount(); i++ )
303 {
304 env[( QgsServerSettingsEnv::EnvVar ) metaEnum.value( i )] = getenv( metaEnum.key( i ) );
305 }
306
307 return env;
308}
309
310QVariant QgsServerSettings::value( QgsServerSettingsEnv::EnvVar envVar, bool actual ) const
311{
312 if ( actual )
313 {
314 const QString envValue( getenv( name( envVar ).toStdString().c_str() ) );
315
316 if ( !envValue.isEmpty() )
317 return envValue;
318 }
319
320 if ( mSettings[envVar].src == QgsServerSettingsEnv::DEFAULT_VALUE )
321 {
322 return mSettings[envVar].defaultVal;
323 }
324 else
325 {
326 return mSettings[envVar].val;
327 }
328}
329
330void QgsServerSettings::loadQSettings( const QString &envOptPath ) const
331{
332 if ( !envOptPath.isEmpty() )
333 {
334 QSettings::setDefaultFormat( QSettings::IniFormat );
335 QSettings::setPath( QSettings::IniFormat, QSettings::UserScope, envOptPath );
336 }
337}
338
339void QgsServerSettings::prioritize( const QMap<QgsServerSettingsEnv::EnvVar, QString> &env )
340{
341 for ( auto envIt = env.constBegin(); envIt != env.constEnd(); ++envIt )
342 {
343 const QgsServerSettingsEnv::EnvVar e = envIt.key();
344
345 auto settingIt = mSettings.find( e );
346 if ( settingIt == mSettings.end() )
347 continue;
348
349 QVariant varValue;
350 if ( !envIt.value().isEmpty() )
351 {
352 varValue.setValue( envIt.value() );
353 }
354
355 if ( !QgsVariantUtils::isNull( varValue ) && varValue.canConvert( settingIt->type ) )
356 {
357 settingIt->val = varValue;
359 }
360 else if ( !settingIt->iniKey.isEmpty() && QSettings().contains( settingIt->iniKey ) && QSettings().value( settingIt->iniKey ).canConvert( settingIt->type ) )
361 {
362 settingIt->val = QSettings().value( settingIt->iniKey );
363 settingIt->src = QgsServerSettingsEnv::INI_FILE;
364 }
365 else
366 {
367 settingIt->val = QVariant();
369 }
370
371 // an empty string can be returned from QSettings. In this case, we want
372 // to use the default value
373 if ( settingIt->type == QMetaType::Type::QString && settingIt->val.toString().isEmpty() )
374 {
375 settingIt->val = QVariant();
377 }
378 }
379}
380
382{
383 const QMetaEnum metaEnumEnv( QMetaEnum::fromType<QgsServerSettingsEnv::EnvVar>() );
384 return metaEnumEnv.valueToKey( env );
385}
386
388{
389 const QMetaEnum metaEnumSrc( QMetaEnum::fromType<QgsServerSettingsEnv::Source>() );
390
391 QgsMessageLog::logMessage( "QGIS Server Settings: ", "Server", Qgis::MessageLevel::Info );
392 for ( const Setting &s : std::as_const( mSettings ) )
393 {
394 const QString src = metaEnumSrc.valueToKey( s.src );
395 const QString var = name( s.envVar );
396
397 const QString msg = " - " + var + " / '" + s.iniKey + "' (" + s.descr + "): '" + value( s.envVar ).toString() + "' (read from " + src + ")";
399 }
400
401 if ( !iniFile().isEmpty() )
402 {
403 const QString msg = "Ini file used to initialize settings: " + iniFile();
405 }
406}
407
408// getter
410{
411 return QSettings().fileName();
412}
413
418
420{
421 return value( QgsServerSettingsEnv::QGIS_SERVER_MAX_THREADS ).toInt();
422}
423
425{
426 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_FILE ).toString();
427}
428
430{
431 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_STDERR ).toBool();
432}
433
438
440{
441 return value( QgsServerSettingsEnv::QGIS_PROJECT_FILE ).toString();
442}
443
445{
446 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_SIZE ).toLongLong();
447}
448
450{
451 return value( QgsServerSettingsEnv::QGIS_SERVER_CACHE_DIRECTORY ).toString();
452}
453
458
463
468
473
478
483
488
493
495{
496 return value( QgsServerSettingsEnv::QGIS_SERVER_API_WFS3_MAX_LIMIT ).toLongLong();
497}
498
500{
502}
503
508
513
518
523
528
533
535{
536 return value( QgsServerSettingsEnv::QGIS_SERVER_LOG_PROFILE, false ).toBool();
537}
538
539QString QgsServerSettings::serviceUrl( const QString &service ) const
540{
541 QString result;
542 if ( service.compare( "WMS"_L1, Qt::CaseInsensitive ) == 0 )
543 {
544 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMS_SERVICE_URL ).toString();
545 }
546 else if ( service.compare( "WFS"_L1, Qt::CaseInsensitive ) == 0 )
547 {
548 result = value( QgsServerSettingsEnv::QGIS_SERVER_WFS_SERVICE_URL ).toString();
549 }
550 else if ( service.compare( "WCS"_L1, Qt::CaseInsensitive ) == 0 )
551 {
552 result = value( QgsServerSettingsEnv::QGIS_SERVER_WCS_SERVICE_URL ).toString();
553 }
554 else if ( service.compare( "WMTS"_L1, Qt::CaseInsensitive ) == 0 )
555 {
556 result = value( QgsServerSettingsEnv::QGIS_SERVER_WMTS_SERVICE_URL ).toString();
557 }
558
559 if ( result.isEmpty() )
560 {
561 result = value( QgsServerSettingsEnv::QGIS_SERVER_SERVICE_URL ).toString();
562 }
563
564 return result;
565}
566
571
573{
574 QString result = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_STRATEGY ).toString();
575 if ( result.compare( "filesystem"_L1 ) && result.compare( "periodic"_L1 ) && result.compare( "off"_L1 ) )
576 {
577 if ( !result.isEmpty() )
578 {
579 QgsMessageLog::logMessage( u"Invalid cache strategy '%1', expecting 'filesystem', 'periodic' or 'off'. Using 'filesystem' as default."_s.arg( result ), "Server", Qgis::MessageLevel::Warning );
580 }
581 else
582 {
583 QgsMessageLog::logMessage( u"No cache strategy was specified. Using 'filesystem' as default."_s, "Server", Qgis::MessageLevel::Info );
584 }
585 result = u"filesystem"_s;
586 }
587 return result;
588}
589
591{
592 bool ok;
593 int size = value( QgsServerSettingsEnv::QGIS_SERVER_PROJECT_CACHE_SIZE ).toInt( &ok );
594 if ( ok && size >= 1 )
595 return size;
596
597 QgsMessageLog::logMessage( u"Invalid project cache size, expecting integer - defaulting to 100"_s, "Server", Qgis::MessageLevel::Warning );
598 return 100;
599}
600
602{
603 const QString strVal { value( QgsServerSettingsEnv::QGIS_SERVER_ALLOWED_EXTRA_SQL_TOKENS ).toString().trimmed() };
604 if ( strVal.isEmpty() )
605 {
606 return QStringList();
607 }
608 return strVal.split( ',' );
609}
610
612{
613 return value( QgsServerSettingsEnv::QGIS_SERVER_APPLICATION_NAME ).toString().trimmed();
614}
615
617{
618 bool ok;
619 int size = value( QgsServerSettingsEnv::QGIS_SERVER_CAPABILITIES_CACHE_SIZE ).toInt( &ok );
620 if ( ok && size >= 1 )
621 return size;
622
623 QgsMessageLog::logMessage( u"Invalid capabilities cache size, expecting integer - defaulting to 40"_s, "Server", Qgis::MessageLevel::Warning );
624 return 40;
625}
MessageLevel
Level for messages This will be used both for message log and message bar in application.
Definition qgis.h:158
@ NoLevel
No level.
Definition qgis.h:163
@ Warning
Warning message.
Definition qgis.h:160
@ Info
Information message.
Definition qgis.h:159
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.