2018-05-26 08:45:43 -04:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/plugins: pluginmanager.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2012 Cyril Soler <csoler@users.sourceforge.net> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
2018-05-28 16:03:39 -04:00
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
2018-05-26 08:45:43 -04:00
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
2018-05-28 16:03:39 -04:00
|
|
|
* GNU Lesser General Public License for more details. *
|
2018-05-26 08:45:43 -04:00
|
|
|
* *
|
2018-05-28 16:03:39 -04:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
2018-05-26 08:45:43 -04:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2011-06-16 17:59:26 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string>
|
2011-07-05 16:29:07 -04:00
|
|
|
#include <set>
|
2011-06-16 17:59:26 -04:00
|
|
|
#include <vector>
|
|
|
|
#include <retroshare/rsplugin.h>
|
2011-07-05 16:29:07 -04:00
|
|
|
#include <pqi/p3cfgmgr.h>
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
class p3ConfigMgr ;
|
|
|
|
class p3ServiceServer ;
|
2011-07-09 20:41:39 -04:00
|
|
|
class p3LinkMgr ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2012-02-18 15:29:03 -05:00
|
|
|
class PluginInfo
|
2011-07-05 16:29:07 -04:00
|
|
|
{
|
2015-06-15 11:15:18 -04:00
|
|
|
public:
|
|
|
|
PluginInfo() : handle(NULL), plugin(NULL), API_version(0), svn_revision(0), status(0) {}
|
|
|
|
|
2012-02-18 15:29:03 -05:00
|
|
|
public:
|
2015-06-15 11:15:18 -04:00
|
|
|
// Handle of the loaded plugin.
|
|
|
|
//
|
|
|
|
void *handle;
|
|
|
|
|
2012-09-09 09:59:21 -04:00
|
|
|
// Main object provided by the plugin. NULL is the plugin could not be loaded.
|
|
|
|
//
|
2012-02-18 15:29:03 -05:00
|
|
|
RsPlugin *plugin ;
|
2012-09-09 09:59:21 -04:00
|
|
|
|
|
|
|
// Information related to the file. Do not require the plugin to be loaded nor the DSO to be openned.
|
|
|
|
//
|
2014-03-17 16:56:06 -04:00
|
|
|
RsFileHash file_hash ;
|
2012-02-18 15:29:03 -05:00
|
|
|
std::string file_name ;
|
2012-09-09 09:59:21 -04:00
|
|
|
|
|
|
|
// Information coming from directly loaded symbols. The plugin is responsible for providing them.
|
|
|
|
//
|
|
|
|
std::string creator ; // creator of the plugin
|
|
|
|
std::string name ; // name of the plugin
|
|
|
|
uint32_t API_version ; // API version.
|
|
|
|
uint32_t svn_revision ; // Coming from scripts. Same svn version but changing hash could be a security issue.
|
|
|
|
|
|
|
|
// This info is filled when accessing the .so, and loading the plugin.
|
|
|
|
//
|
|
|
|
uint32_t status ; // See the flags in retroshare/rsplugin.h
|
|
|
|
std::string info_string ;
|
2011-07-05 16:29:07 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
class RsPluginManager: public RsPluginHandler, public p3Config
|
2011-06-16 17:59:26 -04:00
|
|
|
{
|
|
|
|
public:
|
2017-07-21 12:09:54 -04:00
|
|
|
explicit RsPluginManager(const RsFileHash& current_executable_sha1_hash) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
virtual ~RsPluginManager() {}
|
|
|
|
|
2011-07-05 16:29:07 -04:00
|
|
|
// ------------ Derived from RsPluginHandler ----------------//
|
|
|
|
//
|
2011-06-16 17:59:26 -04:00
|
|
|
virtual int nbPlugins() const { return _plugins.size() ; }
|
2011-07-05 16:29:07 -04:00
|
|
|
virtual RsPlugin *plugin(int i) { return _plugins[i].plugin ; }
|
2011-06-17 15:59:01 -04:00
|
|
|
virtual const std::vector<std::string>& getPluginDirectories() const { return _plugin_directories ; }
|
2014-03-17 16:56:06 -04:00
|
|
|
virtual void getPluginStatus(int i, uint32_t& status,std::string& file_name, RsFileHash& hash,uint32_t& svn_revision,std::string& error_string) const ;
|
|
|
|
virtual void enablePlugin(const RsFileHash& hash) ;
|
|
|
|
virtual void disablePlugin(const RsFileHash &hash) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2018-10-06 19:34:05 -04:00
|
|
|
virtual void slowTickPlugins(rstime_t sec) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
virtual const std::string& getLocalCacheDir() const ;
|
|
|
|
virtual const std::string& getRemoteCacheDir() const ;
|
2014-04-20 10:20:13 -04:00
|
|
|
virtual RsServiceControl *getServiceControl() const ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2012-02-18 09:55:50 -05:00
|
|
|
virtual void allowAllPlugins(bool b) ;
|
|
|
|
virtual bool getAllowAllPlugins() const ;
|
|
|
|
|
2011-07-05 16:29:07 -04:00
|
|
|
// ---------------- Derived from p3Config -------------------//
|
|
|
|
//
|
|
|
|
bool saveList(bool& cleanup, std::list<RsItem*>& list) ;
|
|
|
|
bool loadList(std::list<RsItem*>& list) ;
|
|
|
|
virtual RsSerialiser* setupSerialiser() ;
|
|
|
|
|
|
|
|
// -------------------- Own members -------------------------//
|
|
|
|
//
|
|
|
|
virtual void addConfigurations(p3ConfigMgr *cfgMgr) ;
|
2017-03-16 17:55:18 -04:00
|
|
|
virtual bool loadConfiguration(RsFileHash &loadHash) ;
|
2011-07-05 16:29:07 -04:00
|
|
|
virtual void loadConfiguration() ;
|
|
|
|
|
2011-10-08 13:47:36 -04:00
|
|
|
/*!
|
|
|
|
* sets interfaces for all loaded plugins
|
|
|
|
* @param interfaces
|
|
|
|
*/
|
2012-09-09 09:59:21 -04:00
|
|
|
void setInterfaces(RsPlugInInterfaces& interfaces);
|
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
static bool acceptablePluginName(const std::string& s) ;
|
|
|
|
static void setCacheDirectories(const std::string& local,const std::string& remote) ;
|
2014-04-20 10:20:13 -04:00
|
|
|
static void setServiceControl(RsServiceControl *cm) { _service_control = cm ; }
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2011-12-22 15:17:59 -05:00
|
|
|
// Normal plugin loading system. Parses through the plugin directories and loads
|
|
|
|
// dso libraries, checks for the hash, and loads/rejects plugins according to
|
|
|
|
// the user's choice.
|
|
|
|
//
|
2011-06-16 17:59:26 -04:00
|
|
|
void loadPlugins(const std::vector<std::string>& plugin_directories) ;
|
|
|
|
|
2011-12-22 15:17:59 -05:00
|
|
|
// Explicit function to load a plugin programatically.
|
|
|
|
// No hash-checking is performed (there's no DSO file to hash!)
|
|
|
|
// Mostly convenient for insering plugins in development.
|
|
|
|
//
|
|
|
|
void loadPlugins(const std::vector<RsPlugin*>& explicit_plugin_entries) ;
|
|
|
|
|
2015-06-16 10:20:59 -04:00
|
|
|
void stopPlugins(p3ServiceServer *pqih);
|
2012-08-02 09:17:53 -04:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
void registerCacheServices() ;
|
|
|
|
void registerClientServices(p3ServiceServer *pqih) ;
|
2011-12-22 15:17:59 -05:00
|
|
|
|
2011-06-16 17:59:26 -04:00
|
|
|
private:
|
2011-12-22 15:17:59 -05:00
|
|
|
bool loadPlugin(RsPlugin *) ;
|
2017-07-29 17:12:56 -04:00
|
|
|
bool loadPlugin(const std::string& shared_library_name, bool first_time) ;
|
2014-03-17 16:56:06 -04:00
|
|
|
RsFileHash hashPlugin(const std::string& shared_library_name) ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
2011-07-05 16:29:07 -04:00
|
|
|
std::vector<PluginInfo> _plugins ;
|
2012-09-09 09:59:21 -04:00
|
|
|
|
|
|
|
// Should allow
|
|
|
|
// - searching
|
|
|
|
// - saving all hash
|
|
|
|
//
|
|
|
|
// At start
|
|
|
|
// * load reference executable hash. Compare with current executable.
|
|
|
|
// - if different => flush all plugin hashes from cache
|
|
|
|
// - if equal,
|
|
|
|
//
|
2014-03-17 16:56:06 -04:00
|
|
|
std::set<RsFileHash> _accepted_hashes ; // accepted hash values for reference executable hash.
|
|
|
|
std::set<RsFileHash> _rejected_hashes ; // rejected hash values for reference executable hash.
|
|
|
|
RsFileHash _current_executable_hash ; // At all times, the list of accepted plugins should be related to the current hash of the executable.
|
2012-02-18 09:55:50 -05:00
|
|
|
bool _allow_all_plugins ;
|
2011-06-16 17:59:26 -04:00
|
|
|
|
|
|
|
static std::string _plugin_entry_symbol ;
|
2012-09-04 17:59:49 -04:00
|
|
|
static std::string _plugin_revision_symbol ;
|
2012-09-09 09:59:21 -04:00
|
|
|
static std::string _plugin_API_symbol ;
|
2011-06-16 17:59:26 -04:00
|
|
|
static std::string _remote_cache_dir ;
|
|
|
|
static std::string _local_cache_dir ;
|
2014-04-20 10:20:13 -04:00
|
|
|
|
|
|
|
static RsServiceControl *_service_control ;
|
2011-06-17 15:59:01 -04:00
|
|
|
|
|
|
|
static std::vector<std::string> _plugin_directories ;
|
2011-06-16 17:59:26 -04:00
|
|
|
};
|
|
|
|
|