Module: sems Branch: master Commit: 79d1e3a9495e27314f29ea2bd6650dcde2fed7b3 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=79d1e3a9495e27314f29ea2bd6650dcde2fed7b3
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Wed Sep 22 00:38:44 2010 +0200 SIP Session Timer support for ivr app --- apps/ivr/Ivr.cpp | 59 ++++++++++++++++++++++++++---------------------- apps/ivr/Ivr.h | 5 ++++ apps/ivr/etc/ivr.conf | 37 ++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 27 deletions(-) diff --git a/apps/ivr/Ivr.cpp b/apps/ivr/Ivr.cpp index 37a66b3..bf5428d 100644 --- a/apps/ivr/Ivr.cpp +++ b/apps/ivr/Ivr.cpp @@ -181,27 +181,8 @@ IvrFactory::IvrFactory(const string& _app_name) { } -// void IvrFactory::setScriptPath(const string& path) -// { -// string python_path = script_path = path; - - -// if(python_path.length()){ - -// python_path = AmConfig::PlugInPath + ":" + python_path; -// } -// else -// python_path = AmConfig::PlugInPath; - -// char* old_path=0; -// if((old_path = getenv("PYTHONPATH")) != 0) -// if(strlen(old_path)) -// python_path += ":" + string(old_path); - -// DBG("setting PYTHONPATH to: '%s'\n",python_path.c_str()); -// setenv("PYTHONPATH",python_path.c_str(),1); - -// } +AmConfigReader IvrFactory::cfg; +AmSessionEventHandlerFactory* IvrFactory::session_timer_f = NULL; void IvrFactory::import_object(PyObject* m, const char* name, PyTypeObject* type) { @@ -350,6 +331,7 @@ IvrDialog* IvrFactory::newDlg(const string& name) dlg->setPyPtrs(mod_desc.mod,dlg_inst); Py_DECREF(dlg_inst); + setupSessionTimer(dlg); return dlg; } @@ -452,9 +434,6 @@ int IvrFactory::onLoad() return -1; } - - AmConfigReader cfg; - if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1,MOD_NAME ".conf"))) return -1; @@ -522,6 +501,15 @@ int IvrFactory::onLoad() } } + 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"); + } + } + start_deferred_threads(); return 0; // don't stop sems from starting up @@ -557,6 +545,22 @@ int IvrDialog::drop() return res; } +void IvrFactory::setupSessionTimer(AmSession* s) { + if (NULL != session_timer_f) { + + AmSessionEventHandler* h = session_timer_f->getHandler(s); + if (NULL == h) + return; + + if(h->configure(cfg)){ + ERROR("Could not configure the session timer: disabling session timers.\n"); + delete h; + } else { + s->addHandler(h); + } + } +} + /** * Load a script using user name from URI. * Note: there is no default script. @@ -780,9 +784,10 @@ void IvrDialog::process(AmEvent* event) AmPluginEvent* plugin_event = dynamic_cast<AmPluginEvent*>(event); if(plugin_event && plugin_event->name == "timer_timeout") { - - callPyEventHandler("onTimer", "(i)", plugin_event->data.get(0).asInt()); - event->processed = true; + if (plugin_event->data.get(0).asInt() >= 0) { + callPyEventHandler("onTimer", "(i)", plugin_event->data.get(0).asInt()); + event->processed = true; + } } if (!event->processed) diff --git a/apps/ivr/Ivr.h b/apps/ivr/Ivr.h index bd87c72..82827c9 100644 --- a/apps/ivr/Ivr.h +++ b/apps/ivr/Ivr.h @@ -77,6 +77,8 @@ IvrScriptDesc(PyObject* mod, /** \brief session factory for python IVR sessions */ class IvrFactory: public AmSessionFactory { + static AmConfigReader cfg; + PyObject* ivr_module; //string script_path; string default_script; @@ -84,6 +86,7 @@ class IvrFactory: public AmSessionFactory map<string,IvrScriptDesc> mod_reg; AmDynInvokeFactory* user_timer_fact; + static AmSessionEventHandlerFactory* session_timer_f; void init_python_interpreter(const string& script_path); void set_sys_path(const string& script_path); @@ -111,6 +114,8 @@ class IvrFactory: public AmSessionFactory AmSession* onInvite(const AmSipRequest& req); void addDeferredThread(PyObject* pyCallable); + + void setupSessionTimer(AmSession* s); }; /** \brief python IVR wrapper for session base implementation */ diff --git a/apps/ivr/etc/ivr.conf b/apps/ivr/etc/ivr.conf index 7dabeed..164f501 100644 --- a/apps/ivr/etc/ivr.conf +++ b/apps/ivr/etc/ivr.conf @@ -1 +1,38 @@ +# script_path - *.py from this path is loaded as applications script_path=/usr/local/lib/sems/ivr/ + + +############################################################### +# RFC4028 Session Timer +# + +# - enables the session timer ([yes,no]; default: no) +# +# enable_session_timer=yes + +# - set the "Session-Expires" parameter for the session timer. +# +# session_expires=240 + +# - set the "Min-SE" parameter for the session timer. +# +# minimum_timer=90 + +# session refresh (Session Timer, RFC4028) method +# +# INVITE - use re-INVITE +# UPDATE - use UPDATE +# UPDATE_FALLBACK_INVITE - use UPDATE if indicated in Allow, re-INVITE otherwise +# +# Default: UPDATE_FALLBACK_INVITE +# +# Note: Session Timers are only supported in some applications +# +#session_refresh_method=UPDATE + +# accept_501_reply - accept 501 reply as successful refresh? [yes|no] +# +# Default: yes +# +#accept_501_reply=no + _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
