Module: sems Branch: master Commit: 686c11838227c0c1dbf22545f2799b49d9941778 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=686c11838227c0c1dbf22545f2799b49d9941778
Author: Stefan Sayer <[email protected]> Committer: Stefan Sayer <[email protected]> Date: Fri Oct 29 01:51:21 2010 +0200 call timer implemented in sbc app --- apps/sbc/SBC.cpp | 66 ++++++++++++++++++++++++++++- apps/sbc/SBC.h | 14 ++++-- apps/sbc/etc/auth_b2b.sbcprofile.conf | 7 +++- apps/sbc/etc/call_timer.sbcprofile.conf | 50 ++++++++++++++++++++++ apps/sbc/etc/sst_b2b.sbcprofile.conf | 5 ++ apps/sbc/etc/transparent.sbcprofile.conf | 5 ++ doc/Readme.call_timer.txt | 7 +++ doc/Readme.sbc.txt | 1 + 8 files changed, 146 insertions(+), 9 deletions(-) diff --git a/apps/sbc/SBC.cpp b/apps/sbc/SBC.cpp index 3534e95..3d812d7 100644 --- a/apps/sbc/SBC.cpp +++ b/apps/sbc/SBC.cpp @@ -70,6 +70,10 @@ bool SBCCallProfile::readFromConfiguration(const string& name, const string prof return false; } + ruri = cfg.getParameter("RURI"); + from = cfg.getParameter("From"); + to = cfg.getParameter("To"); + string hf_type = cfg.getParameter("header_filter", "transparent"); if (hf_type=="transparent") headerfilter = Transparent; @@ -109,9 +113,8 @@ bool SBCCallProfile::readFromConfiguration(const string& name, const string prof auth_credentials.user = cfg.getParameter("auth_user"); auth_credentials.pwd = cfg.getParameter("auth_pwd"); - ruri = cfg.getParameter("RURI"); - from = cfg.getParameter("From"); - to = cfg.getParameter("To"); + call_timer_enabled = cfg.getParameter("enable_call_timer", "no") == "yes"; + call_timer = cfg.getParameter("call_timer"); INFO("SBC: loaded SBC profile '%s':\n", name.c_str()); @@ -124,6 +127,10 @@ bool SBCCallProfile::readFromConfiguration(const string& name, const string prof FilterType2String(messagefilter), messagefilter_list.size()); INFO("SBC: SST %sabled\n", sst_enabled?"en":"dis"); INFO("SBC: SIP auth %sabled\n", auth_enabled?"en":"dis"); + INFO("SBC: call timer %sabled\n", call_timer_enabled?"en":"dis"); + if (call_timer_enabled) { + INFO("SBC: %s seconds\n", call_timer.c_str()); + } return true; } @@ -450,6 +457,33 @@ void SBCDialog::onInvite(const AmSipRequest& req) ruri_parser, from_parser, to_parser); } + if (call_profile.call_timer_enabled) { + call_profile.call_timer = + replaceParameters("call_timer", call_profile.call_timer, req, app_param, + ruri_parser, from_parser, to_parser); + if (str2i(call_profile.call_timer, call_timer)) { + ERROR("invalid call_timer value '%s'\n", call_profile.call_timer.c_str()); + throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR); + } + + if (!call_timer) { + // time=0 + throw AmSession::Exception(503, "Service Unavailable"); + } + + AmDynInvokeFactory* fact = + AmPlugIn::instance()->getFactory4Di("user_timer"); + if (NULL == fact) { + ERROR("load session_timer module for call timers\n"); + throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR); + } + m_user_timer = fact->getInstance(); + if(!m_user_timer) { + ERROR("could not get a timer reference\n"); + throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR); + } + } + DBG("SBC: connecting to <%s>\n",ruri.c_str()); DBG(" From: <%s>\n",from.c_str()); DBG(" To: <%s>\n",to.c_str()); @@ -458,6 +492,18 @@ void SBCDialog::onInvite(const AmSipRequest& req) void SBCDialog::process(AmEvent* ev) { + + AmPluginEvent* plugin_event = dynamic_cast<AmPluginEvent*>(ev); + if(plugin_event && plugin_event->name == "timer_timeout") { + int timer_id = plugin_event->data.get(0).asInt(); + if (timer_id == SBC_TIMER_ID_CALL_TIMER && + getCalleeStatus() == Connected) { + DBG("SBC: %us call timer hit - ending call\n", call_timer); + terminateOtherLeg(); + terminateLeg(); + } + } + AmB2BCallerSession::process(ev); } @@ -531,6 +577,20 @@ bool SBCDialog::onOtherReply(const AmSipReply& reply) else if(reply.code < 300) { if(getCalleeStatus() == Connected) { m_state = BB_Connected; + if (call_profile.call_timer_enabled) { + if (NULL == m_user_timer) { + ERROR("internal implementation error: invalid timer reference\n"); + terminateOtherLeg(); + terminateLeg(); + return ret; + } + DBG("SBC: starting call timer of %u seconds\n", call_timer); + AmArg di_args,ret; + di_args.push((int)SBC_TIMER_ID_CALL_TIMER); + di_args.push((int)call_timer); // in seconds + di_args.push(getLocalTag().c_str()); + m_user_timer->invoke("setTimer", di_args, ret); + } } } else if(reply.code == 487 && dlg.getStatus() == AmSipDialog::Pending) { diff --git a/apps/sbc/SBC.h b/apps/sbc/SBC.h index 95d7635..f884f8f 100644 --- a/apps/sbc/SBC.h +++ b/apps/sbc/SBC.h @@ -37,11 +37,16 @@ using std::string; +#define SBC_TIMER_ID_CALL_TIMER 1 struct SBCCallProfile { AmConfigReader cfg; + string ruri; /* updated if set */ + string from; /* updated if set */ + string to; /* updated if set */ + FilterType headerfilter; set<string> headerfilter_list; @@ -54,11 +59,9 @@ struct SBCCallProfile { bool auth_enabled; UACAuthCred auth_credentials; - string ruri; /* updated if set */ - string from; /* updated if set */ - string to; /* updated if set */ + bool call_timer_enabled; + string call_timer; - // todo: call duration timer // todo: accounting // todo: RTP forwarding mode // todo: RTP transcoding mode @@ -110,7 +113,8 @@ class SBCDialog : public AmB2BCallerSession string from; string to; - /* AmDynInvoke* m_user_timer; */ + unsigned int call_timer; + AmDynInvoke* m_user_timer; SBCCallProfile call_profile; diff --git a/apps/sbc/etc/auth_b2b.sbcprofile.conf b/apps/sbc/etc/auth_b2b.sbcprofile.conf index 79c0e51..34fcfa4 100644 --- a/apps/sbc/etc/auth_b2b.sbcprofile.conf +++ b/apps/sbc/etc/auth_b2b.sbcprofile.conf @@ -27,6 +27,11 @@ header_list=P-App-Param,P-App-Name message_filter=transparent #message_list= +## call timer +#enable_call_timer=yes +#call_timer=60 +# or, e.g.: call_timer=$P(t) + # set this for session timer: #enable_session_timer=yes #session_expires=120 @@ -34,7 +39,7 @@ message_filter=transparent #session_refresh_method=UPDATE_FALLBACK_INVITE #accept_501_reply=yes - +################################################################# #This profile implements a pure B2BUA application that does an #identity change and authenticates on the second leg of the call, #like this diff --git a/apps/sbc/etc/call_timer.sbcprofile.conf b/apps/sbc/etc/call_timer.sbcprofile.conf new file mode 100644 index 0000000..dd8da9e --- /dev/null +++ b/apps/sbc/etc/call_timer.sbcprofile.conf @@ -0,0 +1,50 @@ +# call_timer SBC profile +# +# call_timer is a back-to-back user agent application +# that ends the call after a call timer expired. +# The timer value can be configured either statically, +# or it may be taken from e.g. the P-App-Param header +# (e.g. $P(t) for t= parameter of P-App-Param), or some +# other message part (e.g. R-URI user by using $rU). +# This application is known from the call_timer app. + +# defaults: transparent +#RURI=$r +#From=$f +#To=$t + +## filters: +#header_filter=blacklist +#header_list=P-App-Param,P-App-Name +#message_filter=transparent +#message_list= + +## call timer +enable_call_timer=yes +# maximum call time in seconds. +# take the timer value from "t" parameter of P-App-Param, +# e.g. P-App-Param: t=120 +call_timer=$P(t) +# +# Kamailio/sip-router script: +# remove_hf("P-App-Param"); +# append_hf("P-App-Param: t=120\r\n"); +# t_relay_to_udp("10.0.0.3","5070"); +# +#For a static value, set it like this +#call_timer=120 + +## authentication: +#enable_auth=yes +#auth_user=$P(u) +#auth_pwd=$P(p) + +## session timer: +#enable_session_timer=yes +# if session_expires is not configured here, +# the values from sbc.conf are used, or the +# default values +#session_expires=120 +#minimum_timer=90 +#session_refresh_method=UPDATE_FALLBACK_INVITE +#accept_501_reply=yes diff --git a/apps/sbc/etc/sst_b2b.sbcprofile.conf b/apps/sbc/etc/sst_b2b.sbcprofile.conf index 9deb044..a712453 100644 --- a/apps/sbc/etc/sst_b2b.sbcprofile.conf +++ b/apps/sbc/etc/sst_b2b.sbcprofile.conf @@ -20,6 +20,11 @@ #auth_user=$P(u) #auth_pwd=$P(p) +## call timer +#enable_call_timer=yes +#call_timer=60 +# or, e.g.: call_timer=$P(t) + ## session timer: enable_session_timer=yes # if session_expires is not configured here, diff --git a/apps/sbc/etc/transparent.sbcprofile.conf b/apps/sbc/etc/transparent.sbcprofile.conf index aa5a8a6..7fc1ec6 100644 --- a/apps/sbc/etc/transparent.sbcprofile.conf +++ b/apps/sbc/etc/transparent.sbcprofile.conf @@ -18,6 +18,11 @@ #auth_user=$P(u) #auth_pwd=$P(p) +## call timer +#enable_call_timer=yes +#call_timer=60 +# or, e.g.: call_timer=$P(t) + ## session timer: #enable_session_timer=yes # if session_expires is not configured here, diff --git a/doc/Readme.call_timer.txt b/doc/Readme.call_timer.txt index 12d0ba7..bb22be1 100644 --- a/doc/Readme.call_timer.txt +++ b/doc/Readme.call_timer.txt @@ -1,6 +1,13 @@ call_timer application ---------------------- +------------------------------------------------- +This application has been obsoleted by the sbc +module and will be discontinued in the next version. +Please use the sbc module with the call_timer call +profile for the same functionality. +------------------------------------------------- + call_timer is a simple back-to-back user agent application that ends the call after a call timer expired. diff --git a/doc/Readme.sbc.txt b/doc/Readme.sbc.txt index 0a1121f..63e6ed4 100644 --- a/doc/Readme.sbc.txt +++ b/doc/Readme.sbc.txt @@ -129,6 +129,7 @@ Example profiles transparent - completely transparent B2BUA auth_b2b - identity change and SIP authentication (obsoletes auth_b2b app) sst_b2b - B2BUA with SIP Session Timers (obsoletes sst_b2b app) + call_timer - call timer (obsoletes call_timer app) Dependencies ------------ _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
