QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 #include "qgswmsrequest.h"
36 #include "qgswmsutils.h"
37 
38 #define QSTR_COMPARE( str, lit )\
39  (str.compare( QLatin1String( lit ), Qt::CaseInsensitive ) == 0)
40 
41 namespace QgsWms
42 {
43 
50  class Service: public QgsService
51  {
52  public:
53 
59  Service( const QString &version, QgsServerInterface *serverIface )
60  : mVersion( version )
61  , mServerIface( serverIface )
62  {}
63 
64  QString name() const override { return QStringLiteral( "WMS" ); }
65  QString version() const override { return mVersion; }
66 
67  void executeRequest( const QgsServerRequest &request, QgsServerResponse &response,
68  const QgsProject *project ) override
69  {
70  // Get the request
71  const QgsWmsRequest wmsRequest( request );
72  const QString req = wmsRequest.wmsParameters().request();
73 
74  if ( req.isEmpty() )
75  {
77  QStringLiteral( "Please add or check the value of the REQUEST parameter" ), 501 );
78  }
79 
80  if ( QSTR_COMPARE( req, "GetCapabilities" ) )
81  {
82  writeGetCapabilities( mServerIface, project, wmsRequest, response );
83  }
84  else if ( QSTR_COMPARE( req, "GetProjectSettings" ) )
85  {
86  writeGetCapabilities( mServerIface, project, request, response, true );
87  }
88  else if ( QSTR_COMPARE( req, "GetMap" ) )
89  {
90  if QSTR_COMPARE( wmsRequest.wmsParameters().formatAsString(), "application/dxf" )
91  {
92  writeAsDxf( mServerIface, project, request, response );
93  }
94  else
95  {
96  writeGetMap( mServerIface, project, request, response );
97  }
98  }
99  else if ( QSTR_COMPARE( req, "GetFeatureInfo" ) )
100  {
101  writeGetFeatureInfo( mServerIface, project, request, response );
102  }
103  else if ( QSTR_COMPARE( req, "GetContext" ) )
104  {
105  writeGetContext( mServerIface, project, request, response );
106  }
107  else if ( QSTR_COMPARE( req, "GetSchemaExtension" ) )
108  {
109  writeGetSchemaExtension( response );
110  }
111  else if ( QSTR_COMPARE( req, "GetStyle" ) || QSTR_COMPARE( req, "GetStyles" ) )
112  {
113  writeGetStyles( mServerIface, project, request, response );
114  }
115  else if ( QSTR_COMPARE( req, "DescribeLayer" ) )
116  {
117  writeDescribeLayer( mServerIface, project, request, response );
118  }
119  else if ( QSTR_COMPARE( req, "GetLegendGraphic" ) || QSTR_COMPARE( req, "GetLegendGraphics" ) )
120  {
121  writeGetLegendGraphics( mServerIface, project, request, response );
122  }
123  else if ( QSTR_COMPARE( req, "GetPrint" ) )
124  {
125  if ( mServerIface->serverSettings() && mServerIface->serverSettings()->getPrintDisabled() )
126  {
127  // GetPrint has been disabled
128  QgsDebugMsg( QStringLiteral( "WMS GetPrint request called, but it has been disabled." ) );
130  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
131  }
132  writeGetPrint( mServerIface, project, request, response );
133  }
134  else
135  {
136  // Operation not supported
138  QStringLiteral( "Request %1 is not supported" ).arg( req ), 501 );
139  }
140  }
141 
142  private:
143  QString mVersion;
144  QgsServerInterface *mServerIface = nullptr;
145  };
146 } // namespace QgsWms
147 
155 {
156  public:
157  void registerSelf( QgsServiceRegistry &registry, QgsServerInterface *serverIface ) override
158  {
159  QgsDebugMsg( QStringLiteral( "WMSModule::registerSelf called" ) );
160  registry.registerService( new QgsWms::Service( QgsWms::implementationVersion(), serverIface ) ); // 1.3.0 default version
161  registry.registerService( new QgsWms::Service( QStringLiteral( "1.1.1" ), serverIface ) ); // second supported version
162  }
163 };
164 
165 
166 // Entry points
168 {
169  static QgsWmsModule sModule;
170  return &sModule;
171 }
173 {
174  // Nothing to do
175 }
QgsServiceModule
Class defining the service module interface for QGIS server services.
Definition: qgsservicemodule.h:41
QgsServerSettings::getPrintDisabled
bool getPrintDisabled() const
Returns true if WMS GetPrint request is disabled and the project's reading flag QgsProject::ReadFlag:...
Definition: qgsserversettings.cpp:604
QgsWms::writeGetLegendGraphics
void writeGetLegendGraphics(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetLegendGRaphics response.
Definition: qgswmsgetlegendgraphics.cpp:57
QGISEXTERN
#define QGISEXTERN
Definition: qgis.h:2834
QgsWms::QgsServiceException
Exception class for WMS service exceptions.
Definition: qgswmsserviceexception.h:49
QgsWms::writeGetMap
void writeGetMap(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsgetmap.cpp:48
qgswmsutils.h
QSTR_COMPARE
#define QSTR_COMPARE(str, lit)
Definition: qgswms.cpp:38
QgsWms::Service::Service
Service(const QString &version, QgsServerInterface *serverIface)
Constructor for WMS service.
Definition: qgswms.cpp:59
QgsWms::writeAsDxf
void writeAsDxf(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgsdxfwriter.cpp:39
QgsService
QgsService Class defining interfaces for QGIS server services.
Definition: qgsservice.h:39
QgsServiceRegistry::registerService
void registerService(QgsService *service)
Register a service by its name and version.
Definition: qgsserviceregistry.cpp:120
qgswmsgetcapabilities.h
QgsServerRequest
QgsServerRequest Class defining request interface passed to services QgsService::executeRequest() met...
Definition: qgsserverrequest.h:38
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsWms::writeGetSchemaExtension
void writeGetSchemaExtension(QgsServerResponse &response)
Output GetSchemaExtension response.
Definition: qgswmsgetschemaextension.cpp:49
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
qgswmsgetfeatureinfo.h
QgsWms::Service::version
QString version() const override
Definition: qgswms.cpp:65
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:67
qgswmsdescribelayer.h
QgsWms::Service
OGC web service specialized for WMS.
Definition: qgswms.cpp:50
QgsWms::implementationVersion
QString implementationVersion()
Returns the highest version supported by this implementation.
Definition: qgswmsutils.cpp:50
qgswmsgetschemaextension.h
QgsWmsModule::registerSelf
void registerSelf(QgsServiceRegistry &registry, QgsServerInterface *serverIface) override
Asks the module to register all provided services.
Definition: qgswms.cpp:157
QGS_ServiceModule_Exit
QGISEXTERN void QGS_ServiceModule_Exit(QgsServiceModule *)
Definition: qgswms.cpp:172
QgsServerInterface::serverSettings
virtual QgsServerSettings * serverSettings()=0
Returns the server settings.
QGS_ServiceModule_Init
QGISEXTERN QgsServiceModule * QGS_ServiceModule_Init()
Definition: qgswms.cpp:167
QgsWms::Service::name
QString name() const override
Definition: qgswms.cpp:64
qgswmsparameters.h
qgswmsgetlegendgraphics.h
qgswmsgetmap.h
QgsWms
Median cut implementation.
Definition: qgsdxfwriter.cpp:22
QgsWms::writeGetPrint
void writeGetPrint(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetPrint response.
Definition: qgswmsgetprint.cpp:46
QgsWms::writeGetStyles
void writeGetStyles(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetStyles response.
Definition: qgswmsgetstyles.cpp:62
QgsWms::writeGetCapabilities
void writeGetCapabilities(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response, bool projectSettings)
Output GetCapabilities response.
Definition: qgswmsgetcapabilities.cpp:111
qgswmsgetcontext.h
QgsWms::writeGetContext
void writeGetContext(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetContext response.
Definition: qgswmsgetcontext.cpp:71
qgswmsgetstyles.h
QgsServiceRegistry
QgsServiceRegistry Class defining the registry manager for QGIS server services.
Definition: qgsserviceregistry.h:49
qgswmsgetprint.h
QgsWms::QgsServiceException::OGC_OperationNotSupported
@ OGC_OperationNotSupported
Definition: qgswmsserviceexception.h:73
QgsWms::QgsWmsRequest::wmsParameters
const QgsWmsParameters & wmsParameters() const
Returns the parameters interpreted for the WMS service.
Definition: qgswmsrequest.cpp:45
qgsdxfwriter.h
qgsmodule.h
QgsWms::QgsWmsParameters::formatAsString
QString formatAsString() const
Returns FORMAT parameter as a string.
Definition: qgswmsparameters.cpp:832
qgswmsserviceexception.h
QgsWms::QgsWmsParameters::request
QString request() const override
Returns REQUEST parameter as a string or an empty string if not defined.
Definition: qgswmsparameters.cpp:809
QgsWms::QgsWmsRequest
Class defining request interface passed to WMS service.
Definition: qgswmsrequest.h:49
QgsWms::writeGetFeatureInfo
void writeGetFeatureInfo(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetFeatureInfo response.
Definition: qgswmsgetfeatureinfo.cpp:44
qgswmsrequest.h
QgsServerInterface
QgsServerInterface Class defining interfaces exposed by QGIS Server and made available to plugins.
Definition: qgsserverinterface.h:60
QgsServerResponse
QgsServerResponse Class defining response interface passed to services QgsService::executeRequest() m...
Definition: qgsserverresponse.h:43
QgsWmsModule
Module specialized for WMS service.
Definition: qgswms.cpp:154
QgsWms::writeDescribeLayer
void writeDescribeLayer(QgsServerInterface *serverIface, const QgsProject *project, const QgsWmsRequest &request, QgsServerResponse &response)
Output GetMap response in DXF format.
Definition: qgswmsdescribelayer.cpp:49