diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index d6bfebc7..9c459046 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -45,6 +45,7 @@ string AmConfig::SendMethod = SEND_METHOD; string AmConfig::SmtpServerAddress = SMTP_ADDRESS_IP; unsigned int AmConfig::SmtpServerPort = SMTP_PORT; string AmConfig::PlugInPath = PLUG_IN_PATH; +string AmConfig::LoadPlugins = ""; int AmConfig::DaemonMode = DEFAULT_DAEMON_MODE; string AmConfig::LocalIP = ""; string AmConfig::PrefixSep = PREFIX_SEPARATOR; @@ -176,6 +177,9 @@ int AmConfig::readConfiguration() // plugin_path PlugInPath = cfg.getParameter("plugin_path"); + // load_plugins + LoadPlugins = cfg.getParameter("load_plugins"); + // user_agent if (cfg.getParameter("use_default_signature")=="yes") Signature = DEFAULT_SIGNATURE; diff --git a/core/AmConfig.h b/core/AmConfig.h index bd4fdee1..2a78675c 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -62,6 +62,8 @@ struct AmConfig static unsigned int SmtpServerPort; /** Path where the plug-ins are. */ static string PlugInPath; + /** semicolon separated list of plugins to load */ + static string LoadPlugins; //static unsigned int MaxRecordTime; /** run the programm in daemon mode? */ static int DaemonMode; diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp index f82ae69b..fc4932d2 100644 --- a/core/AmPlugIn.cpp +++ b/core/AmPlugIn.cpp @@ -118,7 +118,7 @@ AmPlugIn* AmPlugIn::instance() } -int AmPlugIn::load(const string& directory) +int AmPlugIn::load(const string& directory, const string& plugins) { int err=0; struct dirent* entry; @@ -130,18 +130,53 @@ int AmPlugIn::load(const string& directory) } - while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ - - string plugin_file = directory + "/" + string(entry->d_name); - - if( plugin_file.find(".so",plugin_file.length()-3) == string::npos ){ - continue; + if (!plugins.length()) { + DBG("AmPlugIn: loading modules in directory '%s':\n", directory.c_str()); + + while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ + + string plugin_file = directory + "/" + string(entry->d_name); + + if( plugin_file.find(".so",plugin_file.length()-3) == string::npos ){ + continue; + } + + DBG("loading %s ...\n",plugin_file.c_str()); + if( (err = loadPlugIn(plugin_file)) < 0 ) + ERROR("while loading plug-in '%s'\n",plugin_file.c_str()); + } + } else { + DBG("AmPlugIn: loading modules '%s':\n", plugins.c_str()); + + size_t pos = 0; + + while (pos < plugins.length()) { + size_t pos2 = plugins.find(";", pos); + if (pos2 == string::npos) + pos2 = plugins.length(); + string plugin_file = plugins.substr(pos, pos2-pos); + if( plugin_file.find(".so",plugin_file.length()-3) == string::npos ) + plugin_file+=".so"; + + plugin_file = directory + "/" + plugin_file; + DBG("loading %s...\n",plugin_file.c_str()); + if( (err = loadPlugIn(plugin_file)) < 0 ) { + ERROR("while loading plug-in '%s'\n",plugin_file.c_str()); + // be strict here: if plugin not loaded, stop! + return err; + } + if (plugins[pos2]==';') + pos = pos2+1; + else + break; + + } } + closedir(dir); - DBG("loading %s ...\n",plugin_file.c_str()); - if( (err = loadPlugIn(plugin_file)) < 0 ) - ERROR("while loading plug-in '%s'\n",plugin_file.c_str()); - } + DBG("AmPlugIn: modules loaded.\n"); + + DBG("AmPlugIn: Initializing plugins...\n"); for(map::iterator it = name2seh.begin(); it != name2seh.end(); it++){ @@ -177,7 +212,10 @@ int AmPlugIn::load(const string& directory) break; } - closedir(dir); + if (!err) { + DBG("AmPlugIn: Initialized plugins.\n"); + } + return err; } diff --git a/core/AmPlugIn.h b/core/AmPlugIn.h index 30fb6ced..d668e5dc 100644 --- a/core/AmPlugIn.h +++ b/core/AmPlugIn.h @@ -98,7 +98,7 @@ private: * Loads all plug-ins from the directory given as parameter. * @return -1 if failed, else 0. */ - int load(const string& directory); + int load(const string& directory, const string& plugins); /** * Payload lookup function. diff --git a/core/sems.conf.sample b/core/sems.conf.sample index 27fd5c1e..956781a8 100644 --- a/core/sems.conf.sample +++ b/core/sems.conf.sample @@ -51,6 +51,14 @@ ser_socket_name=/tmp/ser_sock # - may be absolute or relative to CWD plugin_path=/usr/local/lib/sems/plug-in +# optional parameter: load_plugins= +# +# semicolon-separated list of modules to load +# If empty, all modules in plugin_path are loaded. +# +# example for announcement with g711 and ilbc codecs only +# load_plugins=wav;ilbc;announcement + # optional parameter: smtp_server= # # - sets address of smtp server diff --git a/core/sems.cpp b/core/sems.cpp index d41125bc..95d078c9 100644 --- a/core/sems.cpp +++ b/core/sems.cpp @@ -408,7 +408,7 @@ int main(int argc, char* argv[]) return -1; DBG("Loading plug-ins\n"); - if(AmPlugIn::instance()->load(AmConfig::PlugInPath)) + if(AmPlugIn::instance()->load(AmConfig::PlugInPath, AmConfig::LoadPlugins)) return -1; DBG("Starting session container\n");