|
|
|
|
@ -31,6 +31,7 @@
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "AmConfigReader.h"
|
|
|
|
|
#include "DSMDialog.h"
|
|
|
|
|
#include "DSMChartReader.h"
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
@ -54,6 +55,7 @@ DSMFactory* DSMFactory::instance()
|
|
|
|
|
|
|
|
|
|
string DSMFactory::InboundStartDiag;
|
|
|
|
|
string DSMFactory::OutboundStartDiag;
|
|
|
|
|
map<string, string> DSMFactory::config;
|
|
|
|
|
|
|
|
|
|
DSMFactory::DSMFactory(const string& _app_name)
|
|
|
|
|
: AmSessionFactory(_app_name),
|
|
|
|
|
@ -61,6 +63,12 @@ DSMFactory::DSMFactory(const string& _app_name)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DSMFactory::~DSMFactory() {
|
|
|
|
|
for (map<string, AmPromptCollection*>::iterator it=
|
|
|
|
|
prompt_sets.begin(); it != prompt_sets.end(); it++)
|
|
|
|
|
delete it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int DSMFactory::onLoad()
|
|
|
|
|
{
|
|
|
|
|
if (loaded)
|
|
|
|
|
@ -95,12 +103,61 @@ int DSMFactory::onLoad()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string prompt_sets_path = cfg.getParameter("prompts_sets_path");
|
|
|
|
|
|
|
|
|
|
vector<string> prompt_sets_names =
|
|
|
|
|
explode(cfg.getParameter("load_prompts_sets"), ",");
|
|
|
|
|
for (vector<string>::iterator it=
|
|
|
|
|
prompt_sets_names.begin(); it != prompt_sets_names.end(); it++) {
|
|
|
|
|
string fname = prompt_sets_path.empty() ? "": prompt_sets_path + "/";
|
|
|
|
|
fname += *it;
|
|
|
|
|
DBG("loading prompts for '%s' (file '%s')\n", it->c_str(), fname.c_str());
|
|
|
|
|
std::ifstream ifs(fname.c_str());
|
|
|
|
|
string s;
|
|
|
|
|
if (!ifs.good()) {
|
|
|
|
|
WARN("prompts set file '%s' could not be read\n", fname.c_str());
|
|
|
|
|
}
|
|
|
|
|
AmPromptCollection* pc = new AmPromptCollection();
|
|
|
|
|
while (ifs.good() && !ifs.eof()) {
|
|
|
|
|
getline(ifs, s);
|
|
|
|
|
if (s.length() && s.find_first_not_of(" \t")!= string::npos &&
|
|
|
|
|
s[s.find_first_not_of(" \t")] != '#') {
|
|
|
|
|
vector<string> p=explode(s, "=");
|
|
|
|
|
if (p.size()==2) {
|
|
|
|
|
pc->setPrompt(p[0], p[1], MOD_NAME);
|
|
|
|
|
DBG("set '%s' added prompt '%s' as '%s'\n",
|
|
|
|
|
it->c_str(), p[0].c_str(), p[1].c_str());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
prompt_sets[*it] = pc;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string DiagPath = cfg.getParameter("diag_path");
|
|
|
|
|
if (DiagPath.length() && DiagPath[DiagPath.length()-1] != '/')
|
|
|
|
|
DiagPath += '/';
|
|
|
|
|
|
|
|
|
|
string ModPath = cfg.getParameter("mod_path");
|
|
|
|
|
|
|
|
|
|
string preload_mods = cfg.getParameter("preload_mods");
|
|
|
|
|
vector<string> preload_names = explode(preload_mods, ",");
|
|
|
|
|
if (preload_names.size()) {
|
|
|
|
|
DSMChartReader reader;
|
|
|
|
|
for (vector<string>::iterator it=
|
|
|
|
|
preload_names.begin(); it != preload_names.end(); it++) {
|
|
|
|
|
DBG("preloading '%s'...\n");
|
|
|
|
|
if (!reader.importModule("import("+*it+")", ModPath)) {
|
|
|
|
|
ERROR("importing module '%s' for preload\n", it->c_str());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
DSMModule* last_loaded = reader.mods.back();
|
|
|
|
|
if (last_loaded) {
|
|
|
|
|
last_loaded->preload();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// TODO: pass preloaded mods to chart reader
|
|
|
|
|
|
|
|
|
|
string LoadDiags = cfg.getParameter("load_diags");
|
|
|
|
|
vector<string> diags_names = explode(LoadDiags, ",");
|
|
|
|
|
for (vector<string>::iterator it=
|
|
|
|
|
@ -121,9 +178,19 @@ int DSMFactory::onLoad()
|
|
|
|
|
INFO("no 'outbound_start_diag' set in config. outbound calls disabled.\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (std::map<string,string>::const_iterator it =
|
|
|
|
|
cfg.begin(); it != cfg.end(); it++)
|
|
|
|
|
config[it->first] = it->second;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DSMFactory::prepareSession(DSMDialog* s) {
|
|
|
|
|
s->setPromptSets(prompt_sets);
|
|
|
|
|
for (map<string, string>::iterator it =
|
|
|
|
|
config.begin(); it != config.end(); it++)
|
|
|
|
|
s->var["config."+it->first] = it->second;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AmSession* DSMFactory::onInvite(const AmSipRequest& req)
|
|
|
|
|
{
|
|
|
|
|
@ -131,7 +198,9 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req)
|
|
|
|
|
ERROR("no inbound calls allowed\n");
|
|
|
|
|
throw AmSession::Exception(488, "Not Acceptable Here");
|
|
|
|
|
}
|
|
|
|
|
return new DSMDialog(prompts, diags, InboundStartDiag, NULL);
|
|
|
|
|
DSMDialog* s = new DSMDialog(prompts, diags, InboundStartDiag, NULL);
|
|
|
|
|
prepareSession(s);
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AmSession* DSMFactory::onInvite(const AmSipRequest& req,
|
|
|
|
|
@ -149,8 +218,9 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req,
|
|
|
|
|
cred = dynamic_cast<UACAuthCred*>(cred_obj);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AmSession* s = new DSMDialog(prompts, diags, OutboundStartDiag, cred);
|
|
|
|
|
|
|
|
|
|
DSMDialog* s = new DSMDialog(prompts, diags, OutboundStartDiag, cred);
|
|
|
|
|
prepareSession(s);
|
|
|
|
|
|
|
|
|
|
if (NULL == cred) {
|
|
|
|
|
WARN("discarding unknown session parameters.\n");
|
|
|
|
|
} else {
|
|
|
|
|
|