- 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 #endif
std::string RsPluginManager::_plugin_entry_symbol ; std::string RsPluginManager::_plugin_entry_symbol ;
std::string RsPluginManager::_plugin_revision_symbol ;
std::string RsPluginManager::_local_cache_dir ; std::string RsPluginManager::_local_cache_dir ;
std::string RsPluginManager::_remote_cache_dir ; std::string RsPluginManager::_remote_cache_dir ;
std::vector<std::string> RsPluginManager::_plugin_directories ; 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_directories = plugin_directories ;
_plugin_entry_symbol = "RETROSHARE_PLUGIN_provide" ; _plugin_entry_symbol = "RETROSHARE_PLUGIN_provide" ;
_plugin_revision_symbol = "RETROSHARE_PLUGIN_revision" ;
// 0 - get the list of files to read // 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; 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()) if((uint32_t)i >= _plugins.size())
return ; return ;
@ -143,6 +145,7 @@ void RsPluginManager::getPluginStatus(int i,uint32_t& status,std::string& file_n
error_string = _plugins[i].info_string ; error_string = _plugins[i].info_string ;
hash = _plugins[i].file_hash ; hash = _plugins[i].file_hash ;
file_name = _plugins[i].file_name ; file_name = _plugins[i].file_name ;
svn_revision = _plugins[i].svn_revision ;
} }
bool RsPluginManager::getAllowAllPlugins() const bool RsPluginManager::getAllowAllPlugins() const
@ -214,15 +217,7 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
std::cerr << " -> hash = " << pinfo.file_hash << std::endl; 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 following choice is conservative by forcing RS to resolve all dependencies at
// the time of loading the plugin. // the time of loading the plugin.
@ -239,9 +234,25 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
return false ; 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 ; std::cerr << dlerror() << std::endl ;
pinfo.status = PLUGIN_STATUS_MISSING_SYMBOL ; 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 ; std::cerr << " Added function entry for symbol " << _plugin_entry_symbol << std::endl ;
RsPlugin *p = ( (*(RetroSharePluginEntry)pf)() ) ; RsPlugin *p = ( (*(RetroSharePluginEntry)pfe)() ) ;
if(p == NULL) if(p == NULL)
{ {
@ -266,7 +277,6 @@ bool RsPluginManager::loadPlugin(const std::string& plugin_name)
pinfo.info_string = "" ; pinfo.info_string = "" ;
return true; return true;
}
} }
p3LinkMgr *RsPluginManager::getLinkMgr() const p3LinkMgr *RsPluginManager::getLinkMgr() const

View File

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

View File

@ -31,6 +31,7 @@
#include <vector> #include <vector>
#include "retroshare/rspeers.h" #include "retroshare/rspeers.h"
#include "retroshare/rsfiles.h" #include "retroshare/rsfiles.h"
#include "../../libretroshare/src/util/rsversion.h"
class RsPluginHandler ; class RsPluginHandler ;
extern RsPluginHandler *rsPlugins ; extern RsPluginHandler *rsPlugins ;
@ -40,6 +41,7 @@ class p3LinkMgr ;
class MainPage ; class MainPage ;
class QIcon ; class QIcon ;
class QString ; class QString ;
class QDialog ;
class QWidget ; class QWidget ;
class QTranslator; class QTranslator;
class QApplication; 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 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 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 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 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 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. // 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 getShortPluginDescription() const = 0 ;
virtual std::string getPluginName() const = 0 ; virtual std::string getPluginName() const = 0 ;
virtual void getPluginVersion(int& major,int& minor,int& svn_rev) 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 int nbPlugins() const = 0 ;
virtual RsPlugin *plugin(int i) = 0 ; virtual RsPlugin *plugin(int i) = 0 ;
virtual const std::vector<std::string>& getPluginDirectories() const = 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 enablePlugin(const std::string& hash) = 0;
virtual void disablePlugin(const std::string& hash) = 0; virtual void disablePlugin(const std::string& hash) = 0;

View File

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

View File

@ -37,6 +37,7 @@ PluginItem::PluginItem(const QString& pluginVersion, int id, const QString& plug
QObject::connect(_enabled_CB,SIGNAL(toggled(bool)),this,SLOT(togglePlugin(bool))) ; QObject::connect(_enabled_CB,SIGNAL(toggled(bool)),this,SLOT(togglePlugin(bool))) ;
QObject::connect(_configure_PB,SIGNAL(clicked()),this,SLOT(configurePlugin())) ; QObject::connect(_configure_PB,SIGNAL(clicked()),this,SLOT(configurePlugin())) ;
QObject::connect(_about_PB,SIGNAL(clicked()),this,SLOT(aboutPlugin())) ;
expandFrame->hide(); expandFrame->hide();
} }
@ -46,6 +47,11 @@ void PluginItem::togglePlugin(bool b)
emit( pluginEnabled(b,_hashLabel->text()) ) ; emit( pluginEnabled(b,_hashLabel->text()) ) ;
} }
void PluginItem::aboutPlugin()
{
emit( pluginAbout(_id) ) ;
}
void PluginItem::configurePlugin() void PluginItem::configurePlugin()
{ {
emit( pluginConfigure(_id) ) ; emit( pluginConfigure(_id) ) ;

View File

@ -33,10 +33,12 @@ class PluginItem: public QWidget, public Ui::PluginItem
protected slots: protected slots:
void togglePlugin(bool) ; void togglePlugin(bool) ;
void configurePlugin() ; void configurePlugin() ;
void aboutPlugin() ;
signals: signals:
void pluginEnabled(bool,const QString&) ; void pluginEnabled(bool,const QString&) ;
void pluginConfigure(int) ; void pluginConfigure(int) ;
void pluginAbout(int) ;
private slots: private slots:
void on_moreinfo_label_linkActivated(QString link); void on_moreinfo_label_linkActivated(QString link);

View File

@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>416</width> <width>788</width>
<height>157</height> <height>174</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_7"> <layout class="QVBoxLayout" name="verticalLayout_7">
@ -163,6 +163,13 @@ p, li { white-space: pre-wrap; }
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QPushButton" name="_about_PB">
<property name="text">
<string>About</string>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -21,6 +21,8 @@
#include <iostream> #include <iostream>
#include <QDialog>
#include "PluginsPage.h" #include "PluginsPage.h"
#include "PluginItem.h" #include "PluginItem.h"
#include "rshare.h" #include "rshare.h"
@ -47,14 +49,15 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags)
std::string file_name, file_hash, error_string ; std::string file_name, file_hash, error_string ;
uint32_t status ; uint32_t status ;
uint32_t svn_revision ;
rsPlugins->getPluginStatus(i,status,file_name,file_hash,error_string) ; rsPlugins->getPluginStatus(i,status,file_name,file_hash,svn_revision,error_string) ;
QString status_string ; QString status_string ;
switch(status) switch(status)
{ {
case PLUGIN_STATUS_UNKNOWN_HASH: status_string = tr("Hash rejected. Add to white list.") ; case PLUGIN_STATUS_UNKNOWN_HASH: status_string = tr("SVN revision number ")+QString::number(svn_revision)+tr(" does not match current. Please manually enable the plugin at your own risk.") ;
break ; break ;
case PLUGIN_STATUS_DLOPEN_ERROR: status_string = tr("Loading error.") ; case PLUGIN_STATUS_DLOPEN_ERROR: status_string = tr("Loading error.") ;
break ; break ;
@ -107,6 +110,7 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags)
QObject::connect(item,SIGNAL(pluginEnabled(bool,const QString&)),this,SLOT(togglePlugin(bool,const QString&))) ; QObject::connect(item,SIGNAL(pluginEnabled(bool,const QString&)),this,SLOT(togglePlugin(bool,const QString&))) ;
QObject::connect(item,SIGNAL(pluginConfigure(int)),this,SLOT(configurePlugin(int))) ; QObject::connect(item,SIGNAL(pluginConfigure(int)),this,SLOT(configurePlugin(int))) ;
QObject::connect(item,SIGNAL(pluginAbout(int)),this,SLOT(aboutPlugin(int))) ;
} }
ui._pluginsLayout->update() ; ui._pluginsLayout->update() ;
@ -129,6 +133,13 @@ void PluginsPage::toggleEnableAll(bool b)
{ {
rsPlugins->allowAllPlugins(b) ; rsPlugins->allowAllPlugins(b) ;
} }
void PluginsPage::aboutPlugin(int i)
{
std::cerr << "Launching about window for plugin " << i << std::endl;
if(rsPlugins->plugin(i) != NULL && rsPlugins->plugin(i)->qt_about_page() != NULL)
rsPlugins->plugin(i)->qt_about_page()->exec() ;
}
void PluginsPage::configurePlugin(int i) void PluginsPage::configurePlugin(int i)
{ {
std::cerr << "Launching configuration window for plugin " << i << std::endl; std::cerr << "Launching configuration window for plugin " << i << std::endl;

View File

@ -44,6 +44,7 @@ class PluginsPage : public ConfigPage
public slots: public slots:
void togglePlugin(bool b,const QString&) ; void togglePlugin(bool b,const QString&) ;
void configurePlugin(int i) ; void configurePlugin(int i) ;
void aboutPlugin(int i) ;
void toggleEnableAll(bool) ; void toggleEnableAll(bool) ;
private: private: