Author: sayer
Date: 2009-03-24 16:23:36 +0100 (Tue, 24 Mar 2009)
New Revision: 1325
Modified:
trunk/apps/dsm/DSM.cpp
trunk/apps/dsm/DSM.h
trunk/apps/dsm/DSMCoreModule.cpp
trunk/apps/dsm/DSMCoreModule.h
trunk/apps/dsm/DSMDialog.cpp
trunk/apps/dsm/DSMDialog.h
trunk/apps/dsm/DSMSession.h
trunk/apps/dsm/doc/dsm_syntax.txt
trunk/apps/dsm/etc/dsm.conf
Log:
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.
Modified: trunk/apps/dsm/DSM.cpp
===================================================================
--- trunk/apps/dsm/DSM.cpp 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSM.cpp 2009-03-24 15:23:36 UTC (rev 1325)
@@ -58,6 +58,7 @@
string DSMFactory::OutboundStartDiag;
map<string, string> DSMFactory::config;
bool DSMFactory::RunInviteEvent;
+bool DSMFactory::SetParamVariables;
DSMFactory::DSMFactory(const string& _app_name)
: AmSessionFactory(_app_name),AmDynInvokeFactory(_app_name),
@@ -221,6 +222,8 @@
RunInviteEvent = cfg.getParameter("run_invite_event")=="yes";
+ SetParamVariables = cfg.getParameter("set_param_variables")=="yes";
+
return 0;
}
@@ -235,6 +238,19 @@
s->var[prefix+it->first] = it->second;
}
+void DSMFactory::addParams(DSMDialog* s, const string& hdrs) {
+ // TODO: use real parser with quoting and optimize
+ map<string, string> params;
+ vector<string> items = explode(getHeader(hdrs, PARAM_HDR), ";");
+ for (vector<string>::iterator it=items.begin();
+ it != items.end(); it++) {
+ vector<string> 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 @@
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 @@
if (!vars.empty())
addVariables(s, "", vars);
+ if (SetParamVariables)
+ addParams(s, req.hdrs);
+
if (NULL == cred) {
WARN("discarding unknown session parameters.\n");
} else {
Modified: trunk/apps/dsm/DSM.h
===================================================================
--- trunk/apps/dsm/DSM.h 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSM.h 2009-03-24 15:23:36 UTC (rev 1325)
@@ -65,15 +65,17 @@
void prepareSession(DSMDialog* s);
void addVariables(DSMDialog* s, const string& prefix,
map<string, string>& vars);
+ void addParams(DSMDialog* s, const string& hdrs);
-
vector<DSMModule*> preloaded_mods;
public:
static DSMFactory* instance();
static map<string, string> config;
static bool RunInviteEvent;
+ static bool SetParamVariables;
+
int onLoad();
AmSession* onInvite(const AmSipRequest& req);
AmSession* onInvite(const AmSipRequest& req,
Modified: trunk/apps/dsm/DSMCoreModule.cpp
===================================================================
--- trunk/apps/dsm/DSMCoreModule.cpp 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSMCoreModule.cpp 2009-03-24 15:23:36 UTC (rev 1325)
@@ -62,6 +62,8 @@
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 @@
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";
Modified: trunk/apps/dsm/DSMCoreModule.h
===================================================================
--- trunk/apps/dsm/DSMCoreModule.h 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSMCoreModule.h 2009-03-24 15:23:36 UTC (rev 1325)
@@ -54,6 +54,8 @@
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);
Modified: trunk/apps/dsm/DSMDialog.cpp
===================================================================
--- trunk/apps/dsm/DSMDialog.cpp 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSMDialog.cpp 2009-03-24 15:23:36 UTC (rev 1325)
@@ -258,6 +258,24 @@
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);
Modified: trunk/apps/dsm/DSMDialog.h
===================================================================
--- trunk/apps/dsm/DSMDialog.h 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSMDialog.h 2009-03-24 15:23:36 UTC (rev 1325)
@@ -87,6 +87,8 @@
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);
Modified: trunk/apps/dsm/DSMSession.h
===================================================================
--- trunk/apps/dsm/DSMSession.h 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/DSMSession.h 2009-03-24 15:23:36 UTC (rev 1325)
@@ -65,6 +65,8 @@
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;
Modified: trunk/apps/dsm/doc/dsm_syntax.txt
===================================================================
--- trunk/apps/dsm/doc/dsm_syntax.txt 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/doc/dsm_syntax.txt 2009-03-24 15:23:36 UTC (rev 1325)
@@ -44,6 +44,8 @@
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
Modified: trunk/apps/dsm/etc/dsm.conf
===================================================================
--- trunk/apps/dsm/etc/dsm.conf 2009-03-24 15:21:50 UTC (rev 1324)
+++ trunk/apps/dsm/etc/dsm.conf 2009-03-24 15:23:36 UTC (rev 1325)
@@ -35,3 +35,9 @@
# 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
_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev