Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Server][Feature][needs-docs] Server Cache can be manage by plugins
First commit to add a way to manage the QGIS Server cache with plugins. In this commit only GetCapabilities document can be cached by plugins.
- Loading branch information
Showing
16 changed files
with
685 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/*************************************************************************** | ||
qgsservercachefilter.cpp | ||
------------------------ | ||
Cache interface for Qgis Server plugins | ||
begin : 2018-07-05 | ||
copyright : (C) 2018 by René-Luc D'Hont | ||
email : rldhont at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsservercachefilter.h" | ||
|
||
#include <QDomDocument> | ||
|
||
//! Constructor | ||
QgsServerCacheFilter::QgsServerCacheFilter( const QgsServerInterface *serverInterface ): | ||
mServerInterface( serverInterface ) | ||
{ | ||
} | ||
|
||
//! Returns cached document | ||
QByteArray QgsServerCacheFilter::getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const | ||
{ | ||
Q_UNUSED( project ); | ||
Q_UNUSED( request ); | ||
Q_UNUSED( key ); | ||
return QByteArray(); | ||
} | ||
|
||
//! Updates or inserts the document in cache | ||
bool QgsServerCacheFilter::setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const | ||
{ | ||
Q_UNUSED( doc ); | ||
Q_UNUSED( project ); | ||
Q_UNUSED( request ); | ||
Q_UNUSED( key ); | ||
return false; | ||
} | ||
|
||
//! Deletes the cached document | ||
bool QgsServerCacheFilter::deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const | ||
{ | ||
Q_UNUSED( project ); | ||
Q_UNUSED( request ); | ||
Q_UNUSED( key ); | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/*************************************************************************** | ||
qgsservercachefilter.h | ||
------------------------ | ||
Cache interface for Qgis Server plugins | ||
begin : 2018-07-05 | ||
copyright : (C) 2018 by René-Luc D'Hont | ||
email : rldhont at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSERVERCACHEPLUGIN_H | ||
#define QGSSERVERCACHEPLUGIN_H | ||
|
||
#include <QMultiMap> | ||
#include <QDomDocument> | ||
#include <QObject> | ||
#include "qgsproject.h" | ||
#include "qgsserverrequest.h" | ||
#include "qgis_server.h" | ||
#include "qgis_sip.h" | ||
|
||
SIP_IF_MODULE( HAVE_SERVER_PYTHON_PLUGINS ) | ||
|
||
class QgsServerInterface; | ||
|
||
|
||
/** | ||
* \ingroup server | ||
* \class QgsServerCacheFilter | ||
* \brief Class defining cache interface for QGIS Server plugins. | ||
*/ | ||
class SERVER_EXPORT QgsServerCacheFilter | ||
{ | ||
|
||
public: | ||
|
||
/** | ||
* Constructor | ||
* QgsServerInterface passed to plugins constructors | ||
* and must be passed to QgsServerCacheFilter instances. | ||
*/ | ||
QgsServerCacheFilter( const QgsServerInterface *serverInterface ); | ||
|
||
virtual ~QgsServerCacheFilter() = default; | ||
|
||
/** | ||
* Returns cached document (or 0 if document not in cache) like capabilities | ||
* \param project the project used to generate the document to provide path | ||
* \param request the request used to generate the document to provider parameters or data | ||
* \param key the key provided by the access control to identify differents documents for the same request | ||
* \returns QByteArray of the cached document or an empty one if no corresponding document found | ||
*/ | ||
virtual QByteArray getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const; | ||
|
||
/** | ||
* Updates or inserts the document in cache like capabilities | ||
* \param doc the document to cache | ||
* \param project the project used to generate the document to provide path | ||
* \param request the request used to generate the document to provider parameters or data | ||
* \param key the key provided by the access control to identify differents documents for the same request | ||
* \returns true if the document has been cached | ||
*/ | ||
virtual bool setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const; | ||
|
||
/** | ||
* Deletes the cached document | ||
* \param project the project used to generate the document to provide path | ||
* \param request the request used to generate the document to provider parameters or data | ||
* \param key the key provided by the access control to identify differents documents for the same request | ||
* \returns true if the document has been deleted | ||
*/ | ||
virtual bool deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const; | ||
|
||
private: | ||
|
||
//! The server interface | ||
const QgsServerInterface *mServerInterface = nullptr; | ||
|
||
}; | ||
|
||
//! The registry definition | ||
typedef QMultiMap<int, QgsServerCacheFilter *> QgsServerCacheFilterMap; | ||
|
||
#endif // QGSSERVERSECURITY_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/*************************************************************************** | ||
qgsservercachemanager.cpp | ||
------------------------- | ||
begin : 2018-07-05 | ||
copyright : (C) 2018 by René-Luc D'Hont | ||
email : rldhont at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsservercachemanager.h" | ||
|
||
//! Returns cached document (or 0 if document not in cache) like capabilities | ||
const QDomDocument *QgsServerCacheManager::getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const | ||
{ | ||
QgsServerCacheFilterMap::const_iterator scIterator; | ||
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator ) | ||
{ | ||
QByteArray content = scIterator.value()->getCachedDocument( project, request, key ); | ||
if ( !content.isEmpty() ) | ||
{ | ||
QDomDocument doc; | ||
if ( doc.setContent( content ) ) | ||
{ | ||
return &doc; | ||
} | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
//! Updates or inserts the document in cache like capabilities | ||
bool QgsServerCacheManager::setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const | ||
{ | ||
QgsServerCacheFilterMap::const_iterator scIterator; | ||
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator ) | ||
{ | ||
if ( scIterator.value()->setCachedDocument( doc, project, request, key ) ) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
//! Deletes the cached document | ||
bool QgsServerCacheManager::deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const | ||
{ | ||
QgsServerCacheFilterMap::const_iterator scIterator; | ||
for ( scIterator = mPluginsServerCaches->constBegin(); scIterator != mPluginsServerCaches->constEnd(); ++scIterator ) | ||
{ | ||
if ( scIterator.value()->deleteCachedDocument( project, request, key ) ) | ||
{ | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
//! Register a new access control filter | ||
void QgsServerCacheManager::registerServerCache( QgsServerCacheFilter *serverCache, int priority ) | ||
{ | ||
mPluginsServerCaches->insert( priority, serverCache ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/*************************************************************************** | ||
qgsservercachemanager.h | ||
----------------------- | ||
begin : 2018-07-05 | ||
copyright : (C) 2018 by René-Luc D'Hont | ||
email : rldhont at 3liz dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSERVERCACHEMANAGER_H | ||
#define QGSSERVERCACHEMANAGER_H | ||
|
||
#include "qgsservercachefilter.h" | ||
#include "qgsserverrequest.h" | ||
|
||
#include <QMultiMap> | ||
#include <QDomDocument> | ||
#include "qgsproject.h" | ||
#include "qgis_server.h" | ||
#include "qgis_sip.h" | ||
|
||
SIP_IF_MODULE( HAVE_SERVER_PYTHON_PLUGINS ) | ||
|
||
class QgsServerCachePlugin; | ||
|
||
|
||
/** | ||
* \ingroup server | ||
* \class QgsServerCacheManager | ||
* \brief A helper class that centralizes caches accesses given by all the server cache filter plugins. | ||
* \since QGIS 3.4 | ||
*/ | ||
class SERVER_EXPORT QgsServerCacheManager | ||
{ | ||
#ifdef SIP_RUN | ||
#include "qgsservercachefilter.h" | ||
#endif | ||
|
||
public: | ||
//! Constructor | ||
QgsServerCacheManager() | ||
{ | ||
mPluginsServerCaches = new QgsServerCacheFilterMap(); | ||
mResolved = false; | ||
} | ||
|
||
//! Constructor | ||
QgsServerCacheManager( const QgsServerCacheManager © ) | ||
{ | ||
mPluginsServerCaches = new QgsServerCacheFilterMap( *copy.mPluginsServerCaches ); | ||
mResolved = copy.mResolved; | ||
} | ||
|
||
|
||
~QgsServerCacheManager() | ||
{ | ||
delete mPluginsServerCaches; | ||
} | ||
|
||
/** | ||
* Returns cached document (or 0 if document not in cache) like capabilities | ||
* \param project the project used to generate the document to provide path | ||
* \param request the request used to generate the document to provider parameters or data | ||
* \param key the key provided by the access control to identify differents documents for the same request | ||
* \returns the cached document or 0 if no corresponding document found | ||
*/ | ||
const QDomDocument *getCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const; | ||
|
||
/** | ||
* Updates or inserts the document in cache like capabilities | ||
* \param doc the document to cache | ||
* \param project the project used to generate the document to provide path | ||
* \param request the request used to generate the document to provider parameters or data | ||
* \param key the key provided by the access control to identify differents documents for the same request | ||
* \returns true if the document has been cached | ||
*/ | ||
bool setCachedDocument( const QDomDocument *doc, const QgsProject *project, const QgsServerRequest &request, const QString &key ) const; | ||
|
||
/** | ||
* Deletes the cached document | ||
* \param project the project used to generate the document to provide path | ||
* \param request the request used to generate the document to provider parameters or data | ||
* \param key the key provided by the access control to identify differents documents for the same request | ||
* \returns true if the document has been deleted | ||
*/ | ||
bool deleteCachedDocument( const QgsProject *project, const QgsServerRequest &request, const QString &key ) const; | ||
|
||
/** | ||
* Register a server cache filter | ||
* \param serverCache the server cache to add | ||
* \param priority the priority used to define the order | ||
*/ | ||
void registerServerCache( QgsServerCacheFilter *serverCache, int priority = 0 ); | ||
|
||
private: | ||
//! The ServerCache plugins registry | ||
QgsServerCacheFilterMap *mPluginsServerCaches = nullptr; | ||
|
||
bool mResolved; | ||
}; | ||
|
||
#endif |
Oops, something went wrong.