From 823238100bbbbfa86f5d9168306018d90e45a880 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 2 Jan 2008 18:06:06 +0000 Subject: [PATCH] bloacklist for module loading config parameter. allows to exclude some modules from loading git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@574 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/AmConfig.cpp | 4 ++++ core/AmConfig.h | 2 ++ core/AmPlugIn.cpp | 24 ++++++++++++++++++++---- core/sems.conf.sample | 8 ++++++++ 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index 85870b64..7761f5d2 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -43,6 +43,7 @@ string AmConfig::SmtpServerAddress = SMTP_ADDRESS_IP; unsigned int AmConfig::SmtpServerPort = SMTP_PORT; string AmConfig::PlugInPath = PLUG_IN_PATH; string AmConfig::LoadPlugins = ""; +string AmConfig::ExcludePlugins = ""; int AmConfig::DaemonMode = DEFAULT_DAEMON_MODE; string AmConfig::LocalIP = ""; string AmConfig::PrefixSep = PREFIX_SEPARATOR; @@ -188,6 +189,9 @@ int AmConfig::readConfiguration() // load_plugins LoadPlugins = cfg.getParameter("load_plugins"); + // exclude_plugins + ExcludePlugins = cfg.getParameter("exclude_plugins"); + // user_agent if (cfg.getParameter("use_default_signature")=="yes") Signature = DEFAULT_SIGNATURE; diff --git a/core/AmConfig.h b/core/AmConfig.h index b05a75e5..624f1969 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -56,6 +56,8 @@ struct AmConfig static string PlugInPath; /** semicolon separated list of plugins to load */ static string LoadPlugins; + /** semicolon separated list of plugins to exclude from loading */ + static string ExcludePlugins; //static unsigned int MaxRecordTime; /** run the programm in daemon mode? */ static int DaemonMode; diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp index 07666449..3c62a1a2 100644 --- a/core/AmPlugIn.cpp +++ b/core/AmPlugIn.cpp @@ -44,6 +44,9 @@ #include #include +#include +using std::set; + static unsigned int pcm16_bytes2samples(long h_codec, unsigned int num_bytes) { return num_bytes / 2; @@ -137,13 +140,26 @@ int AmPlugIn::load(const string& directory, const string& plugins) if (!plugins.length()) { DBG("AmPlugIn: loading modules in directory '%s':\n", directory.c_str()); - while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ + vector excluded_plugins = explode(AmConfig::ExcludePlugins, ";"); + set excluded_plugins_s; + for (vector::iterator it = excluded_plugins.begin(); + it != excluded_plugins.end();it++) + excluded_plugins_s.insert(*it); - string plugin_file = directory + "/" + string(entry->d_name); + while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ + string plugin_name = string(entry->d_name); - if( plugin_file.find(".so",plugin_file.length()-3) == string::npos ){ + if(plugin_name.find(".so",plugin_name.length()-3) == string::npos ){ continue; } + + if (excluded_plugins_s.find(plugin_name.substr(0, plugin_name.length()-3)) + != excluded_plugins_s.end()) { + DBG("skipping excluded plugin %s\n", plugin_name.c_str()); + continue; + } + + string plugin_file = directory + "/" + plugin_name; DBG("loading %s ...\n",plugin_file.c_str()); if( (err = loadPlugIn(plugin_file)) < 0 ) { @@ -578,7 +594,7 @@ int AmPlugIn::loadCtrlFacPlugIn(AmPluginFactory* f) return -1; } if (ctrlIface) { - ERROR("once control interface already loaded (`%s'): can not load a " + ERROR("one control interface already loaded (`%s'): can not load a " "second one (`%s').\n", (ctrlIface->getName()).c_str(), (_ctrlIface->getName()).c_str()); return -1; diff --git a/core/sems.conf.sample b/core/sems.conf.sample index 70c6f15b..82bcf6c5 100644 --- a/core/sems.conf.sample +++ b/core/sems.conf.sample @@ -77,6 +77,14 @@ plugin_path=/usr/local/lib/sems/plug-in/ # example for announcement with g711 and ilbc codecs only # load_plugins=wav;ilbc;announcement +# optional parameter: exclude_plugins= +# +# semicolon-separated list of modules to exclude from loading +# ('blacklist'). This has only effect it load_plugins is empty. +# If empty, all modules in plugin_path are loaded. +# +exclude_plugins=binrpcctrl; + # optional parameter: smtp_server= # # - sets address of smtp server