2011-06-16 17:59:26 -04:00
# include <string.h>
# include "pluginmanager.h"
# include <dirent.h>
2014-03-29 11:34:37 -04:00
#if 0
2011-07-05 16:29:07 -04:00
# include <serialiser/rsserial.h>
# include <serialiser/rstlvbase.h>
# include <serialiser/rstlvtypes.h>
2014-03-29 11:34:37 -04:00
# endif
2011-07-05 16:29:07 -04:00
# include <serialiser/rspluginitems.h>
2014-03-29 11:34:37 -04:00
2014-01-07 17:51:22 -05:00
# include <rsserver/p3face.h>
2011-07-05 16:29:07 -04:00
# include <util/rsdir.h>
2015-01-14 18:26:51 -05:00
# include <util/rsversioninfo.h>
2011-06-16 17:59:26 -04:00
# include <util/folderiterator.h>
# include <ft/ftserver.h>
# include <dbase/cachestrapper.h>
# include <retroshare/rsplugin.h>
# include <retroshare/rsfiles.h>
# include <pqi/pqiservice.h>
2012-02-02 19:15:49 -05:00
# include <plugins/rscacheservice.h>
# include <plugins/rspqiservice.h>
2011-06-16 17:59:26 -04:00
// lets disable the plugin system for now, as it's unfinished.
2011-06-17 14:51:22 -04:00
# ifdef WINDOWS_SYS
# include "dlfcn_win32.h"
# else
2011-06-16 17:59:26 -04:00
# include <dlfcn.h>
# endif
2012-10-20 09:37:53 -04:00
// #define DEBUG_PLUGIN_MANAGER 1
2012-09-09 09:59:21 -04:00
std : : string RsPluginManager : : _plugin_entry_symbol = " RETROSHARE_PLUGIN_provide " ;
std : : string RsPluginManager : : _plugin_revision_symbol = " RETROSHARE_PLUGIN_revision " ;
std : : string RsPluginManager : : _plugin_API_symbol = " RETROSHARE_PLUGIN_api " ;
2011-06-16 17:59:26 -04:00
std : : string RsPluginManager : : _local_cache_dir ;
std : : string RsPluginManager : : _remote_cache_dir ;
2011-06-17 15:59:01 -04:00
std : : vector < std : : string > RsPluginManager : : _plugin_directories ;
2014-04-20 10:20:13 -04:00
RsServiceControl * RsPluginManager : : _service_control = NULL ;
2011-06-16 17:59:26 -04:00
typedef RsPlugin * ( * RetroSharePluginEntry ) ( void ) ;
RsPluginHandler * rsPlugins ;
2014-03-17 16:56:06 -04:00
RsPluginManager : : RsPluginManager ( const RsFileHash & hash )
2014-03-29 01:20:57 -04:00
: p3Config ( ) , _current_executable_hash ( hash )
2011-07-05 16:29:07 -04:00
{
2012-02-18 09:55:50 -05:00
_allow_all_plugins = false ;
2011-07-05 16:29:07 -04:00
}
void RsPluginManager : : loadConfiguration ( )
{
2014-03-17 16:56:06 -04:00
RsFileHash dummyHash ;
2011-07-05 16:29:07 -04:00
p3Config : : loadConfiguration ( dummyHash ) ;
}
2011-10-08 13:47:36 -04:00
void RsPluginManager : : setInterfaces ( RsPlugInInterfaces & interfaces )
{
std : : cerr < < " RsPluginManager::setInterfaces() " < < std : : endl ;
for ( uint32_t i = 0 ; i < _plugins . size ( ) ; + + i )
2012-02-27 13:41:21 -05:00
if ( _plugins [ i ] . plugin ! = NULL )
{
std : : cerr < < " setting iterface for plugin " < < _plugins [ i ] . plugin - > getPluginName ( ) < < " , with RS_ID " < < _plugins [ i ] . plugin - > rs_service_id ( ) < < std : : endl ;
_plugins [ i ] . plugin - > setInterfaces ( interfaces ) ;
}
2011-10-08 13:47:36 -04:00
}
2011-06-16 17:59:26 -04:00
void RsPluginManager : : setCacheDirectories ( const std : : string & local_cache , const std : : string & remote_cache )
{
_local_cache_dir = local_cache ;
_remote_cache_dir = remote_cache ;
}
bool RsPluginManager : : acceptablePluginName ( const std : : string & name )
{
// Needs some windows specific code here
//
# ifdef WINDOWS_SYS
2011-06-17 20:58:09 -04:00
return name . size ( ) > 4 & & name . substr ( name . size ( ) - 4 ) = = " .dll " ;
2011-06-16 17:59:26 -04:00
# else
return name . size ( ) > 3 & & ! strcmp ( name . c_str ( ) + name . size ( ) - 3 , " .so " ) ;
# endif
}
2014-03-17 16:56:06 -04:00
void RsPluginManager : : disablePlugin ( const RsFileHash & hash )
2011-07-05 16:29:07 -04:00
{
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > : : iterator it = _accepted_hashes . find ( hash ) ;
2011-07-05 16:29:07 -04:00
if ( it ! = _accepted_hashes . end ( ) )
{
std : : cerr < < " RsPluginManager::disablePlugin(): removing hash " < < hash < < " from white list " < < std : : endl ;
_accepted_hashes . erase ( it ) ;
IndicateConfigChanged ( ) ;
}
2012-09-13 14:52:03 -04:00
if ( _rejected_hashes . find ( hash ) = = _rejected_hashes . end ( ) )
{
std : : cerr < < " RsPluginManager::enablePlugin(): inserting hash " < < hash < < " in black list " < < std : : endl ;
_rejected_hashes . insert ( hash ) ;
IndicateConfigChanged ( ) ;
}
2011-07-05 16:29:07 -04:00
}
2014-03-17 16:56:06 -04:00
void RsPluginManager : : enablePlugin ( const RsFileHash & hash )
2011-07-05 16:29:07 -04:00
{
if ( _accepted_hashes . find ( hash ) = = _accepted_hashes . end ( ) )
{
std : : cerr < < " RsPluginManager::enablePlugin(): inserting hash " < < hash < < " in white list " < < std : : endl ;
_accepted_hashes . insert ( hash ) ;
IndicateConfigChanged ( ) ;
}
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > : : const_iterator it ( _rejected_hashes . find ( hash ) ) ;
2012-09-13 14:52:03 -04:00
if ( it ! = _rejected_hashes . end ( ) )
{
std : : cerr < < " RsPluginManager::enablePlugin(): removing hash " < < hash < < " from black list " < < std : : endl ;
_rejected_hashes . erase ( it ) ;
IndicateConfigChanged ( ) ;
}
2011-07-05 16:29:07 -04:00
}
2011-06-16 17:59:26 -04:00
void RsPluginManager : : loadPlugins ( const std : : vector < std : : string > & plugin_directories )
{
2011-06-17 15:59:01 -04:00
_plugin_directories = plugin_directories ;
2011-06-16 17:59:26 -04:00
_plugin_entry_symbol = " RETROSHARE_PLUGIN_provide " ;
2012-09-04 17:59:49 -04:00
_plugin_revision_symbol = " RETROSHARE_PLUGIN_revision " ;
2011-06-16 17:59:26 -04:00
// 0 - get the list of files to read
for ( uint32_t i = 0 ; i < plugin_directories . size ( ) ; + + i )
{
librs : : util : : FolderIterator dirIt ( plugin_directories [ i ] ) ;
if ( ! dirIt . isValid ( ) )
{
std : : cerr < < " Plugin directory : " < < plugin_directories [ i ] < < " does not exist. " < < std : : endl ;
2011-06-17 15:59:01 -04:00
continue ;
2011-06-16 17:59:26 -04:00
}
while ( dirIt . readdir ( ) )
{
std : : string fname ;
dirIt . d_name ( fname ) ;
2012-09-19 17:24:12 -04:00
char lc = plugin_directories [ i ] [ plugin_directories [ i ] . length ( ) - 1 ] ; // length cannot be 0 here.
std : : string fullname = ( lc = = ' / ' | | lc = = ' \\ ' ) ? ( plugin_directories [ i ] + fname ) : ( plugin_directories [ i ] + " / " + fname ) ;
2011-06-16 17:59:26 -04:00
if ( ! acceptablePluginName ( fullname ) )
continue ;
std : : cerr < < " Found plugin " < < fullname < < std : : endl ;
std : : cerr < < " Loading plugin... " < < std : : endl ;
loadPlugin ( fullname ) ;
}
dirIt . closedir ( ) ;
}
2012-09-09 09:59:21 -04:00
std : : cerr < < " Examined a total of " < < _plugins . size ( ) < < " plugins. " < < std : : endl ;
// Save list of accepted hashes and reference value
// Calling IndicateConfigChanged() at this point is not sufficient because the config flags are cleared
// at start of the p3config thread, and this thread has not yet started.
//
saveConfiguration ( ) ;
2011-06-16 17:59:26 -04:00
}
2012-08-02 09:17:53 -04:00
void RsPluginManager : : stopPlugins ( )
{
std : : cerr < < " Stopping plugins. " < < std : : endl ;
for ( uint32_t i = 0 ; i < _plugins . size ( ) ; + + i )
{
if ( _plugins [ i ] . plugin ! = NULL )
{
_plugins [ i ] . plugin - > stop ( ) ;
// delete _plugins[i].plugin;
// _plugins[i].plugin = NULL;
}
2015-06-15 19:16:39 -04:00
// Causes a crash
// if (_plugins[i].handle)
// {
// dlclose(_plugins[i].handle);
// _plugins[i].handle = NULL;
// }
2012-08-02 09:17:53 -04:00
}
}
2014-03-17 16:56:06 -04:00
void RsPluginManager : : getPluginStatus ( int i , uint32_t & status , std : : string & file_name , RsFileHash & hash , uint32_t & svn_revision , std : : string & error_string ) const
2011-06-16 17:59:26 -04:00
{
2011-07-05 16:29:07 -04:00
if ( ( uint32_t ) i > = _plugins . size ( ) )
return ;
2011-06-16 17:59:26 -04:00
2011-07-05 16:29:07 -04:00
status = _plugins [ i ] . status ;
error_string = _plugins [ i ] . info_string ;
hash = _plugins [ i ] . file_hash ;
file_name = _plugins [ i ] . file_name ;
2012-09-04 17:59:49 -04:00
svn_revision = _plugins [ i ] . svn_revision ;
2011-07-05 16:29:07 -04:00
}
2011-06-16 17:59:26 -04:00
2012-02-18 09:55:50 -05:00
bool RsPluginManager : : getAllowAllPlugins ( ) const
{
return _allow_all_plugins ;
}
void RsPluginManager : : allowAllPlugins ( bool b )
{
_allow_all_plugins = b ;
IndicateConfigChanged ( ) ;
}
2011-07-05 16:29:07 -04:00
RsSerialiser * RsPluginManager : : setupSerialiser ( )
{
RsSerialiser * rss = new RsSerialiser ;
2012-02-18 09:55:50 -05:00
rss - > addSerialType ( new RsPluginSerialiser ( ) ) ;
rss - > addSerialType ( new RsGeneralConfigSerialiser ( ) ) ;
2011-06-16 17:59:26 -04:00
2011-07-05 16:29:07 -04:00
return rss ;
}
2011-06-16 17:59:26 -04:00
2011-12-22 15:17:59 -05:00
void RsPluginManager : : loadPlugins ( const std : : vector < RsPlugin * > & plugins )
{
for ( uint32_t i = 0 ; i < plugins . size ( ) ; + + i )
loadPlugin ( plugins [ i ] ) ;
}
bool RsPluginManager : : loadPlugin ( RsPlugin * p )
{
std : : cerr < < " Loading programmatically inserted plugin " < < std : : endl ;
PluginInfo pinfo ;
pinfo . plugin = p ;
pinfo . file_name = " No file " ;
2014-04-20 12:34:26 -04:00
pinfo . file_hash . clear ( ) ;
2011-12-22 15:17:59 -05:00
pinfo . info_string = " " ;
p - > setPlugInHandler ( this ) ; // WIN fix, cannot share global space with shared libraries
// The following choice is conservative by forcing RS to resolve all dependencies at
// the time of loading the plugin.
pinfo . status = PLUGIN_STATUS_LOADED ;
_plugins . push_back ( pinfo ) ;
return true ;
}
2011-07-05 16:29:07 -04:00
bool RsPluginManager : : loadPlugin ( const std : : string & plugin_name )
{
std : : cerr < < " Loading plugin " < < plugin_name < < std : : endl ;
PluginInfo pf ;
pf . plugin = NULL ;
pf . file_name = plugin_name ;
2012-02-18 15:29:03 -05:00
pf . info_string = " " ;
2011-07-05 16:29:07 -04:00
std : : cerr < < " -> hashing. " < < std : : endl ;
uint64_t size ;
2012-09-09 09:59:21 -04:00
// Stage 1 - get information related to file (hash, name, ...)
//
2011-07-05 16:29:07 -04:00
if ( ! RsDirUtil : : getFileHash ( plugin_name , pf . file_hash , size ) )
2011-06-16 17:59:26 -04:00
{
2011-07-05 16:29:07 -04:00
std : : cerr < < " -> cannot hash file. Plugin read canceled. " < < std : : endl ;
return false ;
2011-06-16 17:59:26 -04:00
}
2011-07-05 16:29:07 -04:00
_plugins . push_back ( pf ) ;
PluginInfo & pinfo ( _plugins . back ( ) ) ;
2011-06-16 17:59:26 -04:00
2011-07-05 16:29:07 -04:00
std : : cerr < < " -> hash = " < < pinfo . file_hash < < std : : endl ;
2011-06-16 17:59:26 -04:00
2012-09-09 09:59:21 -04:00
if ( ! _allow_all_plugins )
{
if ( _accepted_hashes . find ( pinfo . file_hash ) = = _accepted_hashes . end ( ) & & _rejected_hashes . find ( pinfo . file_hash ) = = _rejected_hashes . end ( ) )
2014-03-17 16:56:06 -04:00
if ( ! RsServer : : notify ( ) - > askForPluginConfirmation ( pinfo . file_name , pinfo . file_hash . toStdString ( ) ) )
2012-09-09 09:59:21 -04:00
_rejected_hashes . insert ( pinfo . file_hash ) ; // accepted hashes are treated at the end, for security.
2012-09-04 17:59:49 -04:00
2012-09-09 09:59:21 -04:00
if ( _rejected_hashes . find ( pinfo . file_hash ) ! = _rejected_hashes . end ( ) )
2011-07-05 16:29:07 -04:00
{
2012-09-09 09:59:21 -04:00
pinfo . status = PLUGIN_STATUS_REJECTED_HASH ;
std : : cerr < < " -> hash rejected. Giving up plugin. " < < std : : endl ;
2011-07-05 16:29:07 -04:00
return false ;
}
2012-09-09 09:59:21 -04:00
}
else
std : : cerr < < " -> ALLOW_ALL_PLUGINS Enabled => plugin loaded by default. " < < std : : endl ;
2011-07-05 16:29:07 -04:00
2012-09-09 09:59:21 -04:00
std : : cerr < < " -> hash authorized. Loading plugin. " < < std : : endl ;
2012-09-04 17:59:49 -04:00
2012-09-09 09:59:21 -04:00
// Stage 2 - open with dlopen, and get some basic info.
//
2012-09-04 17:59:49 -04:00
2012-09-09 09:59:21 -04:00
// The following choice is conservative by forcing RS to resolve all dependencies at
// the time of loading the plugin.
2012-09-04 17:59:49 -04:00
2012-09-09 09:59:21 -04:00
int link_mode = RTLD_NOW | RTLD_GLOBAL ;
2011-07-05 16:29:07 -04:00
2012-09-09 09:59:21 -04:00
void * handle = dlopen ( plugin_name . c_str ( ) , link_mode ) ;
2011-07-05 16:29:07 -04:00
2012-09-09 09:59:21 -04:00
if ( handle = = NULL )
{
const char * val = dlerror ( ) ;
std : : cerr < < " Cannot open plugin: " < < val < < std : : endl ;
pinfo . status = PLUGIN_STATUS_DLOPEN_ERROR ;
pinfo . info_string = val ;
return false ;
}
2011-07-05 16:29:07 -04:00
2012-09-09 09:59:21 -04:00
void * prev = dlsym ( handle , _plugin_revision_symbol . c_str ( ) ) ; pinfo . svn_revision = ( prev = = NULL ) ? 0 : ( * ( uint32_t * ) prev ) ;
void * papi = dlsym ( handle , _plugin_API_symbol . c_str ( ) ) ; pinfo . API_version = ( papi = = NULL ) ? 0 : ( * ( uint32_t * ) papi ) ;
2011-06-16 17:59:26 -04:00
2012-09-09 09:59:21 -04:00
std : : cerr < < " -> plugin revision number: " < < pinfo . svn_revision < < std : : endl ;
2013-10-15 16:28:30 -04:00
std : : cerr < < " plugin API number : " < < std : : hex < < pinfo . API_version < < std : : dec < < std : : endl ;
2013-10-24 20:42:49 -04:00
std : : cerr < < " retroshare svn number: " < < RsUtil : : retroshareRevision ( ) < < std : : endl ;
2012-09-09 09:59:21 -04:00
// Check that the plugin provides a svn revision number and a API number
//
if ( pinfo . API_version = = 0 )
{
std : : cerr < < " -> No API version number. " < < std : : endl ;
pinfo . status = PLUGIN_STATUS_MISSING_API ;
pinfo . info_string = " " ;
2015-06-15 11:15:18 -04:00
dlclose ( handle ) ;
2012-09-09 09:59:21 -04:00
return false ;
}
if ( pinfo . svn_revision = = 0 )
{
std : : cerr < < " -> No svn revision number. " < < std : : endl ;
pinfo . status = PLUGIN_STATUS_MISSING_SVN ;
2011-07-05 16:29:07 -04:00
pinfo . info_string = " " ;
2015-06-15 11:15:18 -04:00
dlclose ( handle ) ;
2012-09-09 09:59:21 -04:00
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 ;
pinfo . info_string = _plugin_entry_symbol ;
2015-06-15 11:15:18 -04:00
dlclose ( handle ) ;
2012-09-09 09:59:21 -04:00
return false ;
}
std : : cerr < < " -> Added function entry for symbol " < < _plugin_entry_symbol < < std : : endl ;
RsPlugin * p = ( ( * ( RetroSharePluginEntry ) pfe ) ( ) ) ;
if ( p = = NULL )
{
std : : cerr < < " Plugin entry function " < < _plugin_entry_symbol < < " returns NULL ! It should return an object of type RsPlugin* " < < std : : endl ;
pinfo . status = PLUGIN_STATUS_NULL_PLUGIN ;
pinfo . info_string = " Plugin entry " + _plugin_entry_symbol + " () return NULL " ;
2015-06-15 11:15:18 -04:00
dlclose ( handle ) ;
2012-09-09 09:59:21 -04:00
return false ;
}
pinfo . status = PLUGIN_STATUS_LOADED ;
pinfo . plugin = p ;
2015-06-15 11:15:18 -04:00
pinfo . handle = handle ;
2012-09-09 09:59:21 -04:00
p - > setPlugInHandler ( this ) ; // WIN fix, cannot share global space with shared libraries
pinfo . info_string = " " ;
2011-07-05 16:29:07 -04:00
2012-09-09 09:59:21 -04:00
_accepted_hashes . insert ( pinfo . file_hash ) ; // do it now, to avoid putting in list a plugin that might have crashed during the load.
return true ;
2011-06-16 17:59:26 -04:00
}
const std : : string & RsPluginManager : : getLocalCacheDir ( ) const
{
assert ( ! _local_cache_dir . empty ( ) ) ;
return _local_cache_dir ;
}
const std : : string & RsPluginManager : : getRemoteCacheDir ( ) const
{
assert ( ! _remote_cache_dir . empty ( ) ) ;
return _remote_cache_dir ;
}
2014-04-20 10:20:13 -04:00
RsServiceControl * RsPluginManager : : getServiceControl ( ) const
{
assert ( _service_control ) ;
return _service_control ;
}
2011-06-16 17:59:26 -04:00
void RsPluginManager : : slowTickPlugins ( time_t seconds )
{
for ( uint32_t i = 0 ; i < _plugins . size ( ) ; + + i )
2011-07-05 16:29:07 -04:00
if ( _plugins [ i ] . plugin ! = NULL & & _plugins [ i ] . plugin - > rs_cache_service ( ) ! = NULL & & ( seconds % _plugins [ i ] . plugin - > rs_cache_service ( ) - > tickDelay ( ) ) )
2011-06-16 17:59:26 -04:00
{
2012-10-20 09:37:53 -04:00
# ifdef DEBUG_PLUGIN_MANAGER
2011-07-05 16:29:07 -04:00
std : : cerr < < " ticking plugin " < < _plugins [ i ] . plugin - > getPluginName ( ) < < std : : endl ;
2012-10-20 09:37:53 -04:00
# endif
2011-07-05 16:29:07 -04:00
_plugins [ i ] . plugin - > rs_cache_service ( ) - > tick ( ) ;
2011-06-16 17:59:26 -04:00
}
}
void RsPluginManager : : registerCacheServices ( )
{
std : : cerr < < " Registering cache services. " < < std : : endl ;
for ( uint32_t i = 0 ; i < _plugins . size ( ) ; + + i )
2011-07-05 16:29:07 -04:00
if ( _plugins [ i ] . plugin ! = NULL & & _plugins [ i ] . plugin - > rs_cache_service ( ) ! = NULL )
2011-06-16 17:59:26 -04:00
{
2011-07-05 16:29:07 -04:00
rsFiles - > getCacheStrapper ( ) - > addCachePair ( CachePair ( _plugins [ i ] . plugin - > rs_cache_service ( ) , _plugins [ i ] . plugin - > rs_cache_service ( ) , CacheId ( _plugins [ i ] . plugin - > rs_service_id ( ) , 0 ) ) ) ;
std : : cerr < < " adding new cache pair for plugin " < < _plugins [ i ] . plugin - > getPluginName ( ) < < " , with RS_ID " < < _plugins [ i ] . plugin - > rs_service_id ( ) < < std : : endl ;
2011-06-16 17:59:26 -04:00
}
}
void RsPluginManager : : registerClientServices ( p3ServiceServer * pqih )
{
std : : cerr < < " Registering pqi services. " < < std : : endl ;
for ( uint32_t i = 0 ; i < _plugins . size ( ) ; + + i )
2014-08-25 17:07:07 -04:00
//if(_plugins[i].plugin != NULL && _plugins[i].plugin->rs_pqi_service() != NULL)
if ( _plugins [ i ] . plugin ! = NULL & & _plugins [ i ] . plugin - > p3_service ( ) ! = NULL )
2011-06-16 17:59:26 -04:00
{
2014-08-25 17:07:07 -04:00
//pqih->addService(_plugins[i].plugin->rs_pqi_service(), true) ;
pqih - > addService ( _plugins [ i ] . plugin - > p3_service ( ) , true ) ;
2011-07-05 16:29:07 -04:00
std : : cerr < < " Added pqi service for plugin " < < _plugins [ i ] . plugin - > getPluginName ( ) < < std : : endl ;
2011-06-16 17:59:26 -04:00
}
}
void RsPluginManager : : addConfigurations ( p3ConfigMgr * ConfigMgr )
{
std : : cerr < < " Registering configuration files. " < < std : : endl ;
for ( uint32_t i = 0 ; i < _plugins . size ( ) ; + + i )
2011-07-05 16:29:07 -04:00
if ( _plugins [ i ] . plugin ! = NULL & & _plugins [ i ] . plugin - > configurationFileName ( ) . length ( ) > 0 )
2011-06-16 17:59:26 -04:00
{
2012-02-18 15:29:03 -05:00
if ( _plugins [ i ] . plugin - > rs_cache_service ( ) ! = NULL )
ConfigMgr - > addConfiguration ( _plugins [ i ] . plugin - > configurationFileName ( ) , _plugins [ i ] . plugin - > rs_cache_service ( ) ) ;
2014-08-25 17:07:07 -04:00
//else if(_plugins[i].plugin->rs_pqi_service() != NULL)
// ConfigMgr->addConfiguration(_plugins[i].plugin->configurationFileName(), _plugins[i].plugin->rs_pqi_service());
else if ( _plugins [ i ] . plugin - > p3_config ( ) ! = NULL )
ConfigMgr - > addConfiguration ( _plugins [ i ] . plugin - > configurationFileName ( ) , _plugins [ i ] . plugin - > p3_config ( ) ) ;
2012-02-18 15:29:03 -05:00
else
continue ;
2011-07-05 16:29:07 -04:00
std : : cerr < < " Added configuration for plugin " < < _plugins [ i ] . plugin - > getPluginName ( ) < < " , with file " < < _plugins [ i ] . plugin - > configurationFileName ( ) < < std : : endl ;
2011-06-16 17:59:26 -04:00
}
}
2011-07-05 16:29:07 -04:00
bool RsPluginManager : : loadList ( std : : list < RsItem * > & list )
{
2014-03-17 16:56:06 -04:00
std : : set < RsFileHash > accepted_hash_candidates ;
std : : set < RsFileHash > rejected_hash_candidates ;
2011-07-05 16:29:07 -04:00
std : : cerr < < " RsPluginManager::loadList(): " < < std : : endl ;
2014-03-17 16:56:06 -04:00
RsFileHash reference_executable_hash ;
2011-07-05 16:29:07 -04:00
std : : list < RsItem * > : : iterator it ;
2014-10-24 18:07:26 -04:00
for ( it = list . begin ( ) ; it ! = list . end ( ) ; + + it )
2011-07-05 16:29:07 -04:00
{
2012-02-18 09:55:50 -05:00
RsConfigKeyValueSet * witem = dynamic_cast < RsConfigKeyValueSet * > ( * it ) ;
if ( witem )
for ( std : : list < RsTlvKeyValue > : : const_iterator kit = witem - > tlvkvs . pairs . begin ( ) ; kit ! = witem - > tlvkvs . pairs . end ( ) ; + + kit )
2012-09-09 09:59:21 -04:00
{
2012-02-18 09:55:50 -05:00
if ( ( * kit ) . key = = " ALLOW_ALL_PLUGINS " )
{
_allow_all_plugins = ( kit - > value = = " YES " ) ;
2012-09-09 09:59:21 -04:00
if ( _allow_all_plugins )
std : : cerr < < " WARNING: Allowing all plugins. No hash will be checked. Be careful! " < < std : : endl ;
2012-02-18 09:55:50 -05:00
}
2012-09-09 09:59:21 -04:00
else if ( ( * kit ) . key = = " REFERENCE_EXECUTABLE_HASH " )
{
2014-04-20 12:34:26 -04:00
reference_executable_hash = RsFileHash ( kit - > value ) ;
2012-09-09 09:59:21 -04:00
std : : cerr < < " Reference executable hash: " < < kit - > value < < std : : endl ;
}
else if ( ( * kit ) . key = = " ACCEPTED " )
{
2014-03-17 16:56:06 -04:00
accepted_hash_candidates . insert ( RsFileHash ( ( * kit ) . value ) ) ;
2012-09-09 09:59:21 -04:00
std : : cerr < < " Accepted hash: " < < ( * kit ) . value < < std : : endl ;
}
else if ( ( * kit ) . key = = " REJECTED " )
{
2014-03-17 16:56:06 -04:00
rejected_hash_candidates . insert ( RsFileHash ( ( * kit ) . value ) ) ;
2012-09-09 09:59:21 -04:00
std : : cerr < < " Rejected hash: " < < ( * kit ) . value < < std : : endl ;
}
}
2012-02-18 09:55:50 -05:00
2011-07-05 16:29:07 -04:00
delete ( * it ) ;
}
2012-09-09 09:59:21 -04:00
if ( reference_executable_hash = = _current_executable_hash )
{
std : : cerr < < " (II) Executable hash matches. Updating the list of accepted/rejected plugins. " < < std : : endl ;
_accepted_hashes = accepted_hash_candidates ;
_rejected_hashes = rejected_hash_candidates ;
}
else
std : : cerr < < " (WW) Executable hashes do not match. Executable hash has changed. Discarding the list of accepted/rejected plugins. " < < std : : endl ;
2011-07-05 16:29:07 -04:00
return true ;
}
bool RsPluginManager : : saveList ( bool & cleanup , std : : list < RsItem * > & list )
{
2012-09-09 09:59:21 -04:00
std : : cerr < < " PluginManager: saving list. " < < std : : endl ;
2011-07-05 16:29:07 -04:00
cleanup = true ;
2012-02-18 09:55:50 -05:00
RsConfigKeyValueSet * witem = new RsConfigKeyValueSet ;
RsTlvKeyValue kv ;
kv . key = " ALLOW_ALL_PLUGINS " ;
kv . value = _allow_all_plugins ? " YES " : " NO " ;
witem - > tlvkvs . pairs . push_back ( kv ) ;
2012-09-09 09:59:21 -04:00
kv . key = " REFERENCE_EXECUTABLE_HASH " ;
2014-03-17 16:56:06 -04:00
kv . value = _current_executable_hash . toStdString ( ) ;
2012-09-09 09:59:21 -04:00
witem - > tlvkvs . pairs . push_back ( kv ) ;
std : : cerr < < " Saving current executable hash: " < < kv . value < < std : : endl ;
// now push accepted and rejected hashes.
2014-03-17 16:56:06 -04:00
for ( std : : set < RsFileHash > : : const_iterator it ( _accepted_hashes . begin ( ) ) ; it ! = _accepted_hashes . end ( ) ; + + it )
2012-09-09 09:59:21 -04:00
{
2014-03-17 16:56:06 -04:00
witem - > tlvkvs . pairs . push_back ( RsTlvKeyValue ( " ACCEPTED " , ( * it ) . toStdString ( ) ) ) ;
2012-09-09 09:59:21 -04:00
std : : cerr < < " " < < * it < < " : " < < " ACCEPTED " < < std : : endl ;
}
2014-03-17 16:56:06 -04:00
for ( std : : set < RsFileHash > : : const_iterator it ( _rejected_hashes . begin ( ) ) ; it ! = _rejected_hashes . end ( ) ; + + it )
2012-09-09 09:59:21 -04:00
{
2014-03-17 16:56:06 -04:00
witem - > tlvkvs . pairs . push_back ( RsTlvKeyValue ( " REJECTED " , ( * it ) . toStdString ( ) ) ) ;
2012-09-09 09:59:21 -04:00
std : : cerr < < " " < < * it < < " : " < < " REJECTED " < < std : : endl ;
}
2012-02-18 09:55:50 -05:00
list . push_back ( witem ) ;
2011-07-05 16:29:07 -04:00
return true ;
}
2014-04-20 10:20:13 -04:00
// RsCacheService::RsCacheService(uint16_t service_type,uint32_t tick_delay, RsPluginHandler* pgHandler)
// : CacheSource(service_type, true, pgHandler->getFileServer()->getCacheStrapper(), pgHandler->getLocalCacheDir()),
// CacheStore (service_type, true, pgHandler->getFileServer()->getCacheStrapper(), pgHandler->getFileServer()->getCacheTransfer(), pgHandler->getRemoteCacheDir()),
// p3Config(),
// _tick_delay_in_seconds(tick_delay)
// {
// }
2011-06-16 17:59:26 -04:00
2014-03-29 01:20:57 -04:00
RsPQIService : : RsPQIService ( uint16_t service_type , uint32_t /*tick_delay_in_seconds*/ , RsPluginHandler * /*pgHandler*/ )
: p3Service ( ) , p3Config ( )
2012-02-18 15:29:03 -05:00
{
}