QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgswms.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgswms.cpp
3  -------------------------
4  begin : December 20 , 2016
5  copyright : (C) 2007 by Marco Hugentobler ( parts from qgswmshandler)
6  (C) 2014 by Alessandro Pasotti ( parts from qgswmshandler)
7  (C) 2016 by David Marteau
8  email : marco dot hugentobler at karto dot baug dot ethz dot ch
9  a dot pasotti at itopen dot it
10  david dot marteau at 3liz dot com
11  ***************************************************************************/
12 
13 /***************************************************************************
14  * *
15  * This program is free software; you can redistribute it and/or modify *
16  * it under the terms of the GNU General Public License as published by *
17  * the Free Software Foundation; either version 2 of the License, or *
18  * (at your option) any later version. *
19  * *
20  ***************************************************************************/
21 
22 #include "qgsmodule.h"
23 #include "qgsdxfwriter.h"
24 #include "qgswmsserviceexception.h"
25 #include "qgswmsgetcapabilities.h"
26 #include "qgswmsgetmap.h"
27 #include "qgswmsgetstyles.h"
28 #include "qgswmsgetcontext.h"
30 #include "qgswmsgetprint.h"
31 #include "qgswmsgetfeatureinfo.h"
32 #include "qgswmsdescribelayer.h"
34 #include "qgswmsparameters.h"
35 
36 #define QSTR_COMPARE( str, lit )\
37  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
38 
39 namespace QgsWms
40 {
41 
48  class Service: public QgsService
49  {
50  public:
51 
57  Service( const QString &version, QgsServerInterface *serverIface )
58  : mVersion( version )
59  , mServerIface( serverIface )
60  {}
61 
62  QString name() const override { return QStringLiteral( "WMS" ); }
63  QString version() const override { return mVersion; }
64 
65  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
66  const QgsProject *project ) override
67  {
68  const QgsWmsParameters parameters( QUrlQuery( request.url() ) );
69 
70  QString version = parameters.version();
71  if ( version.isEmpty() )
72  {
73  // WMTVER needs to be supported by WMS 1.1.1 for backwards
74  // compatibility with WMS 1.0.0
75  version = parameters.wmtver();
76  }
77 
78  // Set the default version
79  if ( version.isEmpty() || !parameters.versionIsValid( version ) )
80  {
81  version = mVersion;
82  }
83 
84  // Get the request
85  const QString req = parameters.request();
86  if ( req.isEmpty() )
87  {
89  QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
90  }
91 
92  if ( ( mVersion.compare( QLatin1String( "1.1.1" ) ) == 0 \
93  && QSTR_COMPARE( req, "capabilities" ) )
94  || QSTR_COMPARE( req, "GetCapabilities" ) )
95  {
96  writeGetCapabilities( mServerIface, project, version, request, response, false );
97  }
98  else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
99  {
100  //getProjectSettings extends WMS 1.3.0 capabilities
101  version = QStringLiteral( "1.3.0" );
102  writeGetCapabilities( mServerIface, project, version, request, response, true );
103  }
104  else if ( QSTR_COMPARE( req, "GetMap" ) )
105  {
106  QString format = parameters.formatAsString();
107  if QSTR_COMPARE( format, "application/dxf" )
108  {
109  writeAsDxf( mServerIface, project, version, request, response );
110  }
111  else
112  {
113  writeGetMap( mServerIface, project, version, request, response );
114  }
115  }
116  else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
117  {
118  writeGetFeatureInfo( mServerIface, project, version, request, response );
119  }
120  else if ( QSTR_COMPARE( req, "GetContext" ) )
121  {
122  writeGetContext( mServerIface, project, version, request, response );
123  }
124  else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
125  {
126  writeGetSchemaExtension( response );
127  }
128  else if ( QSTR_COMPARE( req, "GetStyle" ) )
129  {
130  writeGetStyle( mServerIface, project, version, request, response );
131  }
132  else if ( QSTR_COMPARE( req, "GetStyles" ) )
133  {
134  writeGetStyles( mServerIface, project, version, request, response );
135  }
136  else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
137  {
138  writeDescribeLayer( mServerIface, project, version, request, response );
139  }
140  else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
141  {
142  writeGetLegendGraphics( mServerIface, project, version, request, response );
143  }
144  else if ( QSTR_COMPARE( req, "GetPrint" ) )
145  {
146  if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
147  {
148  // GetPrint has been disabled
149  QgsDebugMsg( QStringLiteral( "WMS GetPrint request called, but it has been disabled." ) );
151  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
152  }
153  writeGetPrint( mServerIface, project, version, request, response );
154  }
155  else
156  {
157  // Operation not supported
159  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
160  }
161  }
162 
163  private:
164  QString mVersion;
165  QgsServerInterface *mServerIface = nullptr;
166  };
167 } // namespace QgsWms
168 
176 {
177  public:
178  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
179  {
180  QgsDebugMsg( QStringLiteral( "WMSModule::registerSelf called" ) );
181  registry.registerService( new QgsWms::Service( "1.3.0", serverIface ) );
182  }
183 };
184 
185 
186 // Entry points
188 {
189  static QgsWmsModule sModule;
190  return &sModule;
191 }
193 {
194  // Nothing to do
195 }
QgsWms::writeGetMap
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsgetmap.cpp:31
QgsServiceModule
Class defining the service module interface for QGIS server services.
Definition: qgsservicemodule.h:42
QgsWms::QgsWmsParameters
Provides an interface to retrieve and manipulate WMS parameters received from the client.
Definition: qgswmsparameters.h:324
QgsServerSettings::getPrintDisabled
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
Definition: qgsserversettings.cpp:512
QGISEXTERN
#define QGISEXTERN
Definition: qgis.h:815
QgsWms::writeDescribeLayer
void writeDescribeLayer(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsdescribelayer.cpp:31
QgsWms::QgsServiceException
Exception class for WMS service exceptions.
Definition: qgswmsserviceexception.h:37
QgsWms::writeAsDxf
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgsdxfwriter.cpp:24
QgsWms::QgsWmsParameters::wmtver
QString wmtver() const
Returns WMTVER parameter or an empty string if not defined.
Definition: qgswmsparameters.cpp:1918
QgsServerParameters::request
QString request() const
Returns REQUEST parameter as a string or an empty string if not defined.
Definition: qgsserverparameters.cpp:527
QSTR_COMPARE
#define QSTR_COMPARE(str, lit)
Definition: qgswms.cpp:36
QgsWms::Service::Service
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition: qgswms.cpp:57
QgsService
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:40
QgsServiceRegistry::registerService
void registerService(QgsService *service)
Register a service by its name and version.
Definition: qgsserviceregistry.cpp:118
qgswmsgetcapabilities.h
QgsServerRequest
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Definition: qgsserverrequest.h:39
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsWms::writeGetFeatureInfo
void writeGetFeatureInfo(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetFeatureInfo response.
Definition: qgswmsgetfeatureinfo.cpp:27
QgsWms::writeGetSchemaExtension
void writeGetSchemaExtension(QgsServerResponse &response)
Output GetSchemaExtension response.
Definition: qgswmsgetschemaextension.cpp:32
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:95
qgswmsgetfeatureinfo.h
QgsWms::Service::version
QString version() const override
Definition: qgswms.cpp:63
QgsServerParameters::version
QString version() const
Returns VERSION parameter as a string or an empty string if not defined.
Definition: qgsserverparameters.cpp:477
QgsWms::Service::executeRequest
void executeRequest(const QgsServerRequest &request, QgsServerResponse &response, const QgsProject *project) override
Execute the requests and set result in QgsServerRequest.
Definition: qgswms.cpp:65
qgswmsdescribelayer.h
QgsWms::Service
OGC web service specialized for WMS.
Definition: qgswms.cpp:49
qgswmsgetschemaextension.h
QgsWms::writeGetStyle
void writeGetStyle(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyle response.
Definition: qgswmsgetstyles.cpp:78
QgsWms::writeGetCapabilities
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response, bool projectSettings)
Output GetCapabilities response.
Definition: qgswmsgetcapabilities.cpp:93
QgsWmsModule::registerSelf
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswms.cpp:178
QGS_ServiceModule_Exit
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswms.cpp:192
QgsServerInterface::serverSettings
virtual QgsServerSettings * serverSettings()=0
Returns the server settings.
QGS_ServiceModule_Init
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswms.cpp:187
QgsWms::Service::name
QString name() const override
Definition: qgswms.cpp:62
qgswmsparameters.h
qgswmsgetlegendgraphics.h
qgswmsgetmap.h
QgsWms::writeGetContext
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetContext response.
Definition: qgswmsgetcontext.cpp:53
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:23
qgswmsgetcontext.h
QgsWms::writeGetLegendGraphics
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
Definition: qgswmsgetlegendgraphics.cpp:39
QgsWms::writeGetPrint
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QString &, const QgsServerRequest &request, QgsServerResponse &response)
Output GetPrint response.
Definition: qgswmsgetprint.cpp:28
qgswmsgetstyles.h
QgsServiceRegistry
QgsServiceRegistry Class defining the registry manager for QGIS server services.
Definition: qgsserviceregistry.h:50
qgswmsgetprint.h
QgsWms::QgsServiceException::OGC_OperationNotSupported
@ OGC_OperationNotSupported
Definition: qgswmsserviceexception.h:60
QgsServerRequest::url
QUrl url() const
Definition: qgsserverrequest.cpp:65
qgsdxfwriter.h
qgsmodule.h
QgsWms::QgsWmsParameters::formatAsString
QString formatAsString() const
Returns FORMAT parameter as a string.
Definition: qgswmsparameters.cpp:779
QgsWms::writeGetStyles
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QString &version, const QgsServerRequest &request, QgsServerResponse &response)
Output GetStyles response.
Definition: qgswmsgetstyles.cpp:44
qgswmsserviceexception.h
QgsWms::QgsWmsParameters::versionIsValid
bool versionIsValid(const QString version) const
Returns true if version is valid, false otherwise.
Definition: qgswmsparameters.cpp:774
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:61
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:44
QgsWmsModule
Module specialized for WMS service.
Definition: qgswms.cpp:176