diff --git a/libretroshare/src/plugins/pluginmanager.cc b/libretroshare/src/plugins/pluginmanager.cc index ea7099943..9af0f6cb0 100644 --- a/libretroshare/src/plugins/pluginmanager.cc +++ b/libretroshare/src/plugins/pluginmanager.cc @@ -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 RsPluginManager::_plugin_directories ; @@ -102,6 +103,7 @@ void RsPluginManager::loadPlugins(const std::vector& 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& 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 diff --git a/libretroshare/src/plugins/pluginmanager.h b/libretroshare/src/plugins/pluginmanager.h index 2735727ac..d1bf131de 100644 --- a/libretroshare/src/plugins/pluginmanager.h +++ b/libretroshare/src/plugins/pluginmanager.h @@ -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& 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 ; diff --git a/libretroshare/src/retroshare/rsplugin.h b/libretroshare/src/retroshare/rsplugin.h index 4f017f15b..0b2eedc50 100644 --- a/libretroshare/src/retroshare/rsplugin.h +++ b/libretroshare/src/retroshare/rsplugin.h @@ -31,6 +31,7 @@ #include #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& 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; diff --git a/libretroshare/src/util/rsversion.h b/libretroshare/src/util/rsversion.h index 3e39195af..ffbe19937 100644 --- a/libretroshare/src/util/rsversion.h +++ b/libretroshare/src/util/rsversion.h @@ -8,8 +8,8 @@ #include #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 { diff --git a/retroshare-gui/src/gui/settings/PluginItem.cpp b/retroshare-gui/src/gui/settings/PluginItem.cpp index 85b795ed7..67fa38b65 100644 --- a/retroshare-gui/src/gui/settings/PluginItem.cpp +++ b/retroshare-gui/src/gui/settings/PluginItem.cpp @@ -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(_configure_PB,SIGNAL(clicked()),this,SLOT(configurePlugin())) ; + QObject::connect(_about_PB,SIGNAL(clicked()),this,SLOT(aboutPlugin())) ; expandFrame->hide(); } @@ -46,6 +47,11 @@ void PluginItem::togglePlugin(bool b) emit( pluginEnabled(b,_hashLabel->text()) ) ; } +void PluginItem::aboutPlugin() +{ + emit( pluginAbout(_id) ) ; +} + void PluginItem::configurePlugin() { emit( pluginConfigure(_id) ) ; diff --git a/retroshare-gui/src/gui/settings/PluginItem.h b/retroshare-gui/src/gui/settings/PluginItem.h index 5f8c0d9f9..f1d9c3510 100644 --- a/retroshare-gui/src/gui/settings/PluginItem.h +++ b/retroshare-gui/src/gui/settings/PluginItem.h @@ -33,10 +33,12 @@ class PluginItem: public QWidget, public Ui::PluginItem protected slots: void togglePlugin(bool) ; void configurePlugin() ; + void aboutPlugin() ; signals: void pluginEnabled(bool,const QString&) ; void pluginConfigure(int) ; + void pluginAbout(int) ; private slots: void on_moreinfo_label_linkActivated(QString link); diff --git a/retroshare-gui/src/gui/settings/PluginItem.ui b/retroshare-gui/src/gui/settings/PluginItem.ui index 45bbf0b19..99568fdfc 100644 --- a/retroshare-gui/src/gui/settings/PluginItem.ui +++ b/retroshare-gui/src/gui/settings/PluginItem.ui @@ -6,8 +6,8 @@ 0 0 - 416 - 157 + 788 + 174 @@ -163,6 +163,13 @@ p, li { white-space: pre-wrap; } + + + + About + + + diff --git a/retroshare-gui/src/gui/settings/PluginsPage.cpp b/retroshare-gui/src/gui/settings/PluginsPage.cpp index 008c81830..22c27306b 100644 --- a/retroshare-gui/src/gui/settings/PluginsPage.cpp +++ b/retroshare-gui/src/gui/settings/PluginsPage.cpp @@ -21,6 +21,8 @@ #include +#include + #include "PluginsPage.h" #include "PluginItem.h" #include "rshare.h" @@ -47,14 +49,15 @@ PluginsPage::PluginsPage(QWidget * parent, Qt::WFlags flags) std::string file_name, file_hash, error_string ; 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 ; 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 ; case PLUGIN_STATUS_DLOPEN_ERROR: status_string = tr("Loading error.") ; 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(pluginConfigure(int)),this,SLOT(configurePlugin(int))) ; + QObject::connect(item,SIGNAL(pluginAbout(int)),this,SLOT(aboutPlugin(int))) ; } ui._pluginsLayout->update() ; @@ -129,6 +133,13 @@ void PluginsPage::toggleEnableAll(bool 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) { std::cerr << "Launching configuration window for plugin " << i << std::endl; diff --git a/retroshare-gui/src/gui/settings/PluginsPage.h b/retroshare-gui/src/gui/settings/PluginsPage.h index da50ead21..1e1bd571e 100644 --- a/retroshare-gui/src/gui/settings/PluginsPage.h +++ b/retroshare-gui/src/gui/settings/PluginsPage.h @@ -44,6 +44,7 @@ class PluginsPage : public ConfigPage public slots: void togglePlugin(bool b,const QString&) ; void configurePlugin(int i) ; + void aboutPlugin(int i) ; void toggleEnableAll(bool) ; private: