- added help dialog to plugins

- added svn revision number checking to plugin system. If svn revision is > 0 and matches the compiled revision number, the plugin is always accepted.
- improved version number scripts to add the missing revision number as a int


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5512 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-09-04 21:59:49 +00:00
parent f7da165b86
commit 6782671951
9 changed files with 66 additions and 22 deletions

View file

@ -24,6 +24,7 @@
#endif
std::string RsPluginManager::_plugin_entry_symbol ;
std::string RsPluginManager::_plugin_revision_symbol ;
std::string RsPluginManager::_local_cache_dir ;
std::string RsPluginManager::_remote_cache_dir ;
std::vector<std::string> RsPluginManager::_plugin_directories ;
@ -102,6 +103,7 @@ void RsPluginManager::loadPlugins(const std::vector<std::string>& plugin_directo
{
_plugin_directories = plugin_directories ;
_plugin_entry_symbol = "RETROSHARE_PLUGIN_provide" ;
_plugin_revision_symbol = "RETROSHARE_PLUGIN_revision" ;
// 0 - get the list of files to read
@ -134,7 +136,7 @@ void RsPluginManager::loadPlugins(const std::vector<std::string>& plugin_directo
std::cerr << "Loaded a total of " << _plugins.size() << " plugins." << std::endl;
}
void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& hash,std::string& error_string) const
void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& hash,uint32_t& svn_revision,std::string& error_string) const
{
if((uint32_t)i >= _plugins.size())
return ;
@ -143,6 +145,7 @@ void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_n
error_string = _plugins[i].info_string ;
hash = _plugins[i].file_hash ;
file_name = _plugins[i].file_name ;
svn_revision = _plugins[i].svn_revision ;
}
bool RsPluginManager::getAllowAllPlugins() const
@ -214,15 +217,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
std::cerr << " -> hash = " << pinfo.file_hash << std::endl;
if((!_allow_all_plugins) && _accepted_hashes.find(pinfo.file_hash) == _accepted_hashes.end())
{
std::cerr << " -> hash is not in white list. Plugin is rejected. Go to config->plugins to authorise this plugin." << std::endl;
pinfo.status = PLUGIN_STATUS_UNKNOWN_HASH ;
pinfo.info_string = "" ;
return false ;
}
else
{
// The following choice is conservative by forcing RS to resolve all dependencies at
// the time of loading the plugin.
@ -239,9 +234,25 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
return false ;
}
void *pf = dlsym(handle,_plugin_entry_symbol.c_str()) ;
void *prev = dlsym(handle,_plugin_revision_symbol.c_str()) ;
pinfo.svn_revision = (prev == NULL) ? 0 : (*(uint32_t *)prev) ;
if(pf == NULL)
std::cerr << " -> plugin revision number: " << pinfo.svn_revision << std::endl;
std::cerr << " -> retroshare svn number: " << SVN_REVISION_NUMBER << std::endl;
if( (pinfo.svn_revision == 0 || pinfo.svn_revision != SVN_REVISION_NUMBER) && (!_allow_all_plugins) && _accepted_hashes.find(pinfo.file_hash) == _accepted_hashes.end())
{
std::cerr << " -> revision numbers do not match, and hash is not in white list. Plugin is rejected. Go to config->plugins to authorise this plugin." << std::endl;
pinfo.status = PLUGIN_STATUS_UNKNOWN_HASH ;
pinfo.info_string = "" ;
return false ;
}
// Now look for the plugin class symbol.
//
void *pfe = dlsym(handle,_plugin_entry_symbol.c_str()) ;
if(pfe == NULL)
{
std::cerr << dlerror() << std::endl ;
pinfo.status = PLUGIN_STATUS_MISSING_SYMBOL ;
@ -250,7 +261,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
}
std::cerr << " Added function entry for symbol " << _plugin_entry_symbol << std::endl ;
RsPlugin *p = ( (*(RetroSharePluginEntry)pf)() ) ;
RsPlugin *p = ( (*(RetroSharePluginEntry)pfe)() ) ;
if(p == NULL)
{
@ -266,7 +277,6 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
pinfo.info_string = "" ;
return true;
}
}
p3LinkMgr *RsPluginManager::getLinkMgr() const

View file

@ -17,6 +17,7 @@ class PluginInfo
std::string info_string ;
std::string file_hash ;
std::string file_name ;
uint32_t svn_revision ;
uint32_t status ;
};
@ -31,7 +32,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
virtual int nbPlugins() const { return _plugins.size() ; }
virtual RsPlugin *plugin(int i) { return _plugins[i].plugin ; }
virtual const std::vector<std::string>& getPluginDirectories() const { return _plugin_directories ; }
virtual void getPluginStatus(int i, uint32_t& status,std::string& file_name, std::string& hash,std::string& error_string) const ;
virtual void getPluginStatus(int i, uint32_t& status,std::string& file_name, std::string& hash,uint32_t& svn_revision,std::string& error_string) const ;
virtual void enablePlugin(const std::string& hash) ;
virtual void disablePlugin(const std::string& hash) ;
@ -91,6 +92,7 @@ class RsPluginManager: public RsPluginHandler, public p3Config
bool _allow_all_plugins ;
static std::string _plugin_entry_symbol ;
static std::string _plugin_revision_symbol ;
static std::string _remote_cache_dir ;
static std::string _local_cache_dir ;
static ftServer *_ftserver ;

View file

@ -31,6 +31,7 @@
#include <vector>
#include "retroshare/rspeers.h"
#include "retroshare/rsfiles.h"
#include "../../libretroshare/src/util/rsversion.h"
class RsPluginHandler ;
extern RsPluginHandler *rsPlugins ;
@ -40,6 +41,7 @@ class p3LinkMgr ;
class MainPage ;
class QIcon ;
class QString ;
class QDialog ;
class QWidget ;
class QTranslator;
class QApplication;
@ -111,6 +113,7 @@ class RsPlugin
virtual QIcon *qt_icon() const { return NULL ; } // the page icon. Todo: put icon as virtual in MainPage
virtual QWidget *qt_config_panel() const { return NULL ; } // Config panel, to appear config->plugins->[]->
virtual QDialog *qt_about_page() const { return NULL ; } // About/Help button in plugin entry will show this up
virtual ConfigPage *qt_config_page() const { return NULL ; } // Config tab to add in config panel.
virtual RsAutoUpdatePage *qt_transfers_tab() const { return NULL ; } // Tab to add in transfers, after turtle statistics.
virtual std::string qt_transfers_tab_name()const { return "Tab" ; } // Tab name
@ -126,6 +129,8 @@ class RsPlugin
//
// All these items appear in the config->plugins tab, as a description of the plugin.
//
uint32_t getSvnRevision() const { return SVN_REVISION_NUMBER ; } // This is read from libretroshare/util/rsversion.h
virtual std::string getShortPluginDescription() const = 0 ;
virtual std::string getPluginName() const = 0 ;
virtual void getPluginVersion(int& major,int& minor,int& svn_rev) const = 0 ;
@ -147,7 +152,7 @@ class RsPluginHandler
virtual int nbPlugins() const = 0 ;
virtual RsPlugin *plugin(int i) = 0 ;
virtual const std::vector<std::string>& getPluginDirectories() const = 0;
virtual void getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& file_hash,std::string& error_string) const = 0 ;
virtual void getPluginStatus(int i,uint32_t& status,std::string& file_name,std::string& file_hash,uint32_t& svn_revision,std::string& error_string) const = 0 ;
virtual void enablePlugin(const std::string& hash) = 0;
virtual void disablePlugin(const std::string& hash) = 0;

View file

@ -8,8 +8,8 @@
#include <string>
#define LIB_VERSION "0.5.3c"
#define SVN_REVISION "Revision: 5501 date : 21:01:27 09.04.12"
#define SVN_REVISION_NUMBER 0
#define SVN_REVISION "Revision: 5501 date : 22:25:46 09.04.12"
#define SVN_REVISION_NUMBER 5501
namespace RsUtil {