From cdaa3e25d39dd6a846bec908269cf9e7aa4cec8a Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Tue, 24 Mar 2009 15:23:36 +0000 Subject: [PATCH] new core functions: * getRecordLength * getRecordDataSize new configuration "set_param_variables" that sets parameters from P-App-Param as variables in DSM session This work was kindly sponsored by Teltech Systems Inc. git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@1325 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- apps/dsm/DSM.cpp | 23 +++++++++++++++++++++++ apps/dsm/DSM.h | 4 +++- apps/dsm/DSMCoreModule.cpp | 16 ++++++++++++++++ apps/dsm/DSMCoreModule.h | 2 ++ apps/dsm/DSMDialog.cpp | 18 ++++++++++++++++++ apps/dsm/DSMDialog.h | 2 ++ apps/dsm/DSMSession.h | 2 ++ apps/dsm/doc/dsm_syntax.txt | 2 ++ apps/dsm/etc/dsm.conf | 6 ++++++ 9 files changed, 74 insertions(+), 1 deletion(-) diff --git a/apps/dsm/DSM.cpp b/apps/dsm/DSM.cpp index 95925813..c4953d8c 100644 --- a/apps/dsm/DSM.cpp +++ b/apps/dsm/DSM.cpp @@ -58,6 +58,7 @@ string DSMFactory::InboundStartDiag; string DSMFactory::OutboundStartDiag; map DSMFactory::config; bool DSMFactory::RunInviteEvent; +bool DSMFactory::SetParamVariables; DSMFactory::DSMFactory(const string& _app_name) : AmSessionFactory(_app_name),AmDynInvokeFactory(_app_name), @@ -221,6 +222,8 @@ int DSMFactory::onLoad() RunInviteEvent = cfg.getParameter("run_invite_event")=="yes"; + SetParamVariables = cfg.getParameter("set_param_variables")=="yes"; + return 0; } @@ -235,6 +238,19 @@ void DSMFactory::addVariables(DSMDialog* s, const string& prefix, s->var[prefix+it->first] = it->second; } +void DSMFactory::addParams(DSMDialog* s, const string& hdrs) { + // TODO: use real parser with quoting and optimize + map params; + vector items = explode(getHeader(hdrs, PARAM_HDR), ";"); + for (vector::iterator it=items.begin(); + it != items.end(); it++) { + vector kv = explode(*it, "="); + if (kv.size()==2) + params.insert(make_pair(kv[0], kv[1])); + } + addVariables(s, "", params); +} + AmSession* DSMFactory::onInvite(const AmSipRequest& req) { string start_diag; @@ -250,6 +266,10 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req) DSMDialog* s = new DSMDialog(&prompts, diags, start_diag, NULL); prepareSession(s); addVariables(s, "config.", config); + + if (SetParamVariables) + addParams(s, req.hdrs); + return s; } @@ -306,6 +326,9 @@ AmSession* DSMFactory::onInvite(const AmSipRequest& req, if (!vars.empty()) addVariables(s, "", vars); + if (SetParamVariables) + addParams(s, req.hdrs); + if (NULL == cred) { WARN("discarding unknown session parameters.\n"); } else { diff --git a/apps/dsm/DSM.h b/apps/dsm/DSM.h index d098fc6a..aba07d4f 100644 --- a/apps/dsm/DSM.h +++ b/apps/dsm/DSM.h @@ -65,7 +65,7 @@ class DSMFactory void prepareSession(DSMDialog* s); void addVariables(DSMDialog* s, const string& prefix, map& vars); - + void addParams(DSMDialog* s, const string& hdrs); vector preloaded_mods; public: @@ -73,6 +73,8 @@ public: static map config; static bool RunInviteEvent; + static bool SetParamVariables; + int onLoad(); AmSession* onInvite(const AmSipRequest& req); diff --git a/apps/dsm/DSMCoreModule.cpp b/apps/dsm/DSMCoreModule.cpp index 21ed20f2..6f0b8256 100644 --- a/apps/dsm/DSMCoreModule.cpp +++ b/apps/dsm/DSMCoreModule.cpp @@ -62,6 +62,8 @@ DSMAction* DSMCoreModule::getAction(const string& from_str) { DEF_CMD("playFile", SCPlayFileAction); DEF_CMD("recordFile", SCRecordFileAction); DEF_CMD("stopRecord", SCStopRecordAction); + DEF_CMD("getRecordLength", SCGetRecordLengthAction); + DEF_CMD("getRecordDataSize", SCGetRecordDataSizeAction); DEF_CMD("closePlaylist", SCClosePlaylistAction); DEF_CMD("addSeparator", SCAddSeparatorAction); DEF_CMD("connectMedia", SCConnectMediaAction); @@ -200,6 +202,20 @@ EXEC_ACTION_START(SCStopRecordAction) { sc_sess->stopRecord(); } EXEC_ACTION_END; +EXEC_ACTION_START(SCGetRecordLengthAction) { + string varname = resolveVars(arg, sess, sc_sess, event_params); + if (varname.empty()) + varname = "record_length"; + sc_sess->var[varname]=int2str(sc_sess->getRecordLength()); +} EXEC_ACTION_END; + +EXEC_ACTION_START(SCGetRecordDataSizeAction) { + string varname = resolveVars(arg, sess, sc_sess, event_params); + if (varname.empty()) + varname = "record_data_size"; + sc_sess->var[varname]=int2str(sc_sess->getRecordDataSize()); +} EXEC_ACTION_END; + EXEC_ACTION_START(SCClosePlaylistAction) { bool notify = resolveVars(arg, sess, sc_sess, event_params) == "true"; diff --git a/apps/dsm/DSMCoreModule.h b/apps/dsm/DSMCoreModule.h index f6967c25..56c17294 100644 --- a/apps/dsm/DSMCoreModule.h +++ b/apps/dsm/DSMCoreModule.h @@ -54,6 +54,8 @@ DEF_ACTION_1P(SCPlayPromptAction); DEF_ACTION_1P(SCPlayPromptLoopedAction); DEF_ACTION_1P(SCRecordFileAction); DEF_ACTION_1P(SCStopRecordAction); +DEF_ACTION_1P(SCGetRecordDataSizeAction); +DEF_ACTION_1P(SCGetRecordLengthAction); DEF_ACTION_1P(SCClosePlaylistAction); DEF_ACTION_1P(SCStopAction); DEF_ACTION_1P(SCConnectMediaAction); diff --git a/apps/dsm/DSMDialog.cpp b/apps/dsm/DSMDialog.cpp index 67d6e9b4..46cd230b 100644 --- a/apps/dsm/DSMDialog.cpp +++ b/apps/dsm/DSMDialog.cpp @@ -258,6 +258,24 @@ void DSMDialog::recordFile(const string& name) { SET_ERRNO(DSM_ERRNO_OK); } +unsigned int DSMDialog::getRecordLength() { + if (!rec_file) { + SET_ERRNO(DSM_ERRNO_FILE); + return 0; + } + SET_ERRNO(DSM_ERRNO_OK); + return rec_file->getLength(); +} + +unsigned int DSMDialog::getRecordDataSize() { + if (!rec_file) { + SET_ERRNO(DSM_ERRNO_FILE); + return 0; + } + SET_ERRNO(DSM_ERRNO_OK); + return rec_file->getDataSize(); +} + void DSMDialog::stopRecord() { if (rec_file) { setInput(&playlist); diff --git a/apps/dsm/DSMDialog.h b/apps/dsm/DSMDialog.h index daa71ae8..6adabf99 100644 --- a/apps/dsm/DSMDialog.h +++ b/apps/dsm/DSMDialog.h @@ -87,6 +87,8 @@ public: void addToPlaylist(AmPlaylistItem* item); void playFile(const string& name, bool loop); void recordFile(const string& name); + unsigned int getRecordLength(); + unsigned int getRecordDataSize(); void stopRecord(); void setPromptSet(const string& name); diff --git a/apps/dsm/DSMSession.h b/apps/dsm/DSMSession.h index ce63c1db..507253a7 100644 --- a/apps/dsm/DSMSession.h +++ b/apps/dsm/DSMSession.h @@ -65,6 +65,8 @@ class DSMSession { virtual void playPrompt(const string& name, bool loop = false) = 0; virtual void playFile(const string& name, bool loop) = 0; virtual void recordFile(const string& name) = 0; + virtual unsigned int getRecordLength() = 0; + virtual unsigned int getRecordDataSize() = 0; virtual void stopRecord() = 0; virtual void addToPlaylist(AmPlaylistItem* item) = 0; virtual void closePlaylist(bool notify) = 0; diff --git a/apps/dsm/doc/dsm_syntax.txt b/apps/dsm/doc/dsm_syntax.txt index 70a533d4..59f928f7 100644 --- a/apps/dsm/doc/dsm_syntax.txt +++ b/apps/dsm/doc/dsm_syntax.txt @@ -44,6 +44,8 @@ actions: playFile(filename) recordFile(filename) stopRecord() + getRecordLength([dst_varname]) -- only while recording! default dst var: record_length + getRecordDataSize([dst_varname]) -- only while recording! default dst var: record_data_size closePlaylist() addSeparator(id) fires event when playlist hits it diff --git a/apps/dsm/etc/dsm.conf b/apps/dsm/etc/dsm.conf index 34d8cda2..340bf191 100644 --- a/apps/dsm/etc/dsm.conf +++ b/apps/dsm/etc/dsm.conf @@ -35,3 +35,9 @@ load_prompts=/usr/local/etc/sems/etc/dsm_in_prompts.conf,/usr/local/etc/sems/etc # of delaying final reply # #run_invite_event=yes + +# set_param_variables controls whether application parameters +# from the P-App-Param header are set as variables in the DSM +# dialog. Default: no +# +#set_param_variables=yes