int DSMFactory::onLoad() { if (loaded) return 0; loaded = true; AmConfigReader cfg; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) return -1; // get application specific global parameters configureModule(cfg); DebugDSM = cfg.getParameter("debug_raw_dsm") == "yes"; if (!loadPrompts(cfg)) return -1; if (!loadPromptSets(cfg)) return -1; if (!loadDiags(cfg, MainScriptConfig.diags)) return -1; vector<string> registered_apps; if (!registerApps(cfg, MainScriptConfig.diags, registered_apps)) return -1; InboundStartDiag = cfg.getParameter("inbound_start_diag"); if (InboundStartDiag.empty()) { INFO("no 'inbound_start_diag' set in config. " "inbound calls with application 'dsm' disabled.\n"); } OutboundStartDiag = cfg.getParameter("outbound_start_diag"); if (OutboundStartDiag.empty()) { INFO("no 'outbound_start_diag' set in config. " "outbound calls with application 'dsm' disabled.\n"); } if (!InboundStartDiag.empty()) AmPlugIn::instance()->registerFactory4App("dsm",this); MainScriptConfig.config_vars.insert(cfg.begin(), cfg.end()); // for (std::map<string,string>::const_iterator it = // cfg.begin(); it != cfg.end(); it++) // MainScriptConfig.config_vars[it->first] = it->second; MainScriptConfig.RunInviteEvent = cfg.getParameter("run_invite_event")=="yes"; MainScriptConfig.SetParamVariables = cfg.getParameter("set_param_variables")=="yes"; #ifdef USE_MONITORING string monitoring_full_callgraph = cfg.getParameter("monitoring_full_stategraph"); MonitoringFullCallgraph = monitoring_full_callgraph == "yes"; DBG("%sogging full call graph (states) to monitoring.\n", MonitoringFullCallgraph?"L":"Not l"); string monitoring_full_transitions = cfg.getParameter("monitoring_full_transitions"); MonitoringFullTransitions = monitoring_full_transitions == "yes"; DBG("%sogging full call graph (transitions) to monitoring.\n", MonitoringFullTransitions?"L":"Not l"); string cfg_usecaller = cfg.getParameter("monitor_select_use_caller"); if (cfg_usecaller.empty() || cfg_usecaller=="from") MonSelectCaller = MonSelect_FROM; else if (cfg_usecaller=="no") MonSelectCaller = MonSelect_NONE; else if (cfg_usecaller=="pai") MonSelectCaller = MonSelect_PAI; else { ERROR("monitor_select_use_caller value '%s' not understood\n", cfg_usecaller.c_str()); } string cfg_usecallee = cfg.getParameter("monitor_select_use_callee"); if (cfg_usecallee.empty() || cfg_usecallee=="ruri") MonSelectCallee = MonSelect_RURI; else if (cfg_usecallee=="no") MonSelectCallee = MonSelect_NONE; else if (cfg_usecallee=="from") MonSelectCallee = MonSelect_FROM; else { ERROR("monitor_select_use_callee value '%s' not understood\n", cfg_usecallee.c_str()); } #endif string conf_d_dir = cfg.getParameter("conf_dir"); if (!conf_d_dir.empty()) { if (conf_d_dir[conf_d_dir.length()-1] != '/') conf_d_dir += '/'; DBG("processing configurations in '%s'...\n", conf_d_dir.c_str()); int err=0; struct dirent* entry; DIR* dir = opendir(conf_d_dir.c_str()); if(!dir){ ERROR("config loader (%s): %s\n", conf_d_dir.c_str(), strerror(errno)); return -1; } while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ string conf_name = string(entry->d_name); if(conf_name.find(".conf",conf_name.length()-5) == string::npos ){ continue; } string conf_file_name = conf_d_dir + conf_name; DBG("loading %s ...\n",conf_file_name.c_str()); if (!loadConfig(conf_file_name, conf_name, false, NULL)) return -1; } closedir(dir); } return 0; }
bool DSMFactory::loadConfig(const string& conf_file_name, const string& conf_name, bool live_reload, DSMStateDiagramCollection* m_diags) { string script_name = conf_name.substr(0, conf_name.length()-5); // - .conf DBG("loading %s from %s ...\n", script_name.c_str(), conf_file_name.c_str()); AmConfigReader cfg; if(cfg.loadFile(conf_file_name)) return false; DSMScriptConfig script_config; script_config.RunInviteEvent = cfg.getParameter("run_invite_event")=="yes"; script_config.SetParamVariables = cfg.getParameter("set_param_variables")=="yes"; script_config.config_vars.insert(cfg.begin(), cfg.end()); if (live_reload) { INFO("live DSM config reload does NOT reload prompts and prompt sets!\n"); INFO("(see http://tracker.iptel.org/browse/SEMS-68)\n"); } else { if (!loadPrompts(cfg)) return false; if (!loadPromptSets(cfg)) return false; } DSMStateDiagramCollection* used_diags; if (m_diags != NULL) used_diags = m_diags; // got this from caller (main diags) else { // create a new set of diags used_diags = script_config.diags = new DSMStateDiagramCollection(); } if (!loadDiags(cfg, used_diags)) return false; vector<string> registered_apps; if (!registerApps(cfg, used_diags, registered_apps)) return false; ScriptConfigs_mut.lock(); try { // set ScriptConfig to this for all registered apps' names for (vector<string>::iterator reg_app_it= registered_apps.begin(); reg_app_it != registered_apps.end(); reg_app_it++) { string& app_name = *reg_app_it; // dispose of the old one, if it exists map<string, DSMScriptConfig>::iterator it=ScriptConfigs.find(app_name); if (it != ScriptConfigs.end()) { // may be in use by active call - don't delete but save to // old_diags for garbage collection (destructor) if (it->second.diags != NULL) old_diags.insert(it->second.diags); } // overwrite with new config ScriptConfigs[app_name] = script_config; } } catch(...) { ScriptConfigs_mut.unlock(); throw; } ScriptConfigs_mut.unlock(); return true; }
int DSMFactory::onLoad() { if (loaded) return 0; loaded = true; if(cfg.loadFile(AmConfig::ModConfigPath + string(MOD_NAME ".conf"))) return -1; // get application specific global parameters configureModule(cfg); DebugDSM = cfg.getParameter("debug_raw_dsm") == "yes"; CheckDSM = cfg.getParameter("dsm_consistency_check", "yes") == "yes"; if (!loadPrompts(cfg)) return -1; if (!loadPromptSets(cfg)) return -1; if (!loadDiags(cfg, MainScriptConfig.diags)) return -1; vector<string> registered_apps; if (!registerApps(cfg, MainScriptConfig.diags, registered_apps)) return -1; InboundStartDiag = cfg.getParameter("inbound_start_diag"); if (InboundStartDiag.empty()) { INFO("no 'inbound_start_diag' set in config. " "inbound calls with application 'dsm' disabled.\n"); } OutboundStartDiag = cfg.getParameter("outbound_start_diag"); if (OutboundStartDiag.empty()) { INFO("no 'outbound_start_diag' set in config. " "outbound calls with application 'dsm' disabled.\n"); } if (!InboundStartDiag.empty()) AmPlugIn::instance()->registerFactory4App("dsm",this); MainScriptConfig.config_vars.insert(cfg.begin(), cfg.end()); // for (std::map<string,string>::const_iterator it = // cfg.begin(); it != cfg.end(); it++) // MainScriptConfig.config_vars[it->first] = it->second; MainScriptConfig.RunInviteEvent = cfg.getParameter("run_invite_event")=="yes"; MainScriptConfig.SetParamVariables = cfg.getParameter("set_param_variables")=="yes"; vector<string> system_dsms = explode(cfg.getParameter("run_system_dsms"), ","); for (vector<string>::iterator it=system_dsms.begin(); it != system_dsms.end(); it++) { string status; if (createSystemDSM("main", *it, false /* reload */, status)) { DBG("created SystemDSM '%s'\n", it->c_str()); } else { ERROR("creating system DSM '%s': '%s'\n", it->c_str(), status.c_str()); return -1; } } #ifdef USE_MONITORING string monitoring_full_callgraph = cfg.getParameter("monitoring_full_stategraph"); MonitoringFullCallgraph = monitoring_full_callgraph == "yes"; DBG("%sogging full call graph (states) to monitoring.\n", MonitoringFullCallgraph?"L":"Not l"); string monitoring_full_transitions = cfg.getParameter("monitoring_full_transitions"); MonitoringFullTransitions = monitoring_full_transitions == "yes"; DBG("%sogging full call graph (transitions) to monitoring.\n", MonitoringFullTransitions?"L":"Not l"); string cfg_usecaller = cfg.getParameter("monitor_select_use_caller"); if (cfg_usecaller.empty() || cfg_usecaller=="from") MonSelectCaller = MonSelect_FROM; else if (cfg_usecaller=="no") MonSelectCaller = MonSelect_NONE; else if (cfg_usecaller=="pai") MonSelectCaller = MonSelect_PAI; else { ERROR("monitor_select_use_caller value '%s' not understood\n", cfg_usecaller.c_str()); } string cfg_usecallee = cfg.getParameter("monitor_select_use_callee"); if (cfg_usecallee.empty() || cfg_usecallee=="ruri") MonSelectCallee = MonSelect_RURI; else if (cfg_usecallee=="no") MonSelectCallee = MonSelect_NONE; else if (cfg_usecallee=="from") MonSelectCallee = MonSelect_FROM; else { ERROR("monitor_select_use_callee value '%s' not understood\n", cfg_usecallee.c_str()); } MonSelectFilters = explode(cfg.getParameter("monitor_select_filters"), ","); string filters; for (vector<string>::iterator it = MonSelectFilters.begin(); it != MonSelectFilters.end(); it++) { if (it != MonSelectFilters.begin()) filters += ", "; filters+=*it; } if (MonSelectFilters.size()) { DBG("using additional monitor app select filters: %s\n", filters.c_str()); } else { DBG("not using additional monitor app select filters\n"); } MonSelectFallback = cfg.getParameter("monitor_select_fallback"); #endif string conf_d_dir = cfg.getParameter("conf_dir"); if (!conf_d_dir.empty()) { if (conf_d_dir[conf_d_dir.length()-1] != '/') conf_d_dir += '/'; DBG("processing configurations in '%s'...\n", conf_d_dir.c_str()); int err=0; struct dirent* entry; DIR* dir = opendir(conf_d_dir.c_str()); if(!dir){ INFO("DSM config files loader (%s): %s\n", conf_d_dir.c_str(), strerror(errno)); } else { while( ((entry = readdir(dir)) != NULL) && (err == 0) ){ string conf_name = string(entry->d_name); if (conf_name.find(".conf",conf_name.length()-5) == string::npos){ continue; } string conf_file_name = conf_d_dir + conf_name; DBG("loading %s ...\n",conf_file_name.c_str()); if (!loadConfig(conf_file_name, conf_name, false, NULL)) return -1; } closedir(dir); } } if(cfg.hasParameter("enable_session_timer") && (cfg.getParameter("enable_session_timer") == string("yes")) ){ DBG("enabling session timers\n"); session_timer_f = AmPlugIn::instance()->getFactory4Seh("session_timer"); if(session_timer_f == NULL){ ERROR("Could not load the session_timer module: disabling session timers.\n"); } } return 0; }