<br>Hi,<br><br>I&#39;ve been struggling with this problem very long time and I am starting to be quite desperate.<br><br>I&#39;m trying to implement voicemail redirection after 15 secs of ringing. So I set fr_inv_timer, set the event handler with t_on_failure. But after 15secs of ringing the failture_route block does not execute at all, the transaction is lost and after these 15 secs it has strange behaviour (the phone is still ringing, even after the other side has cancelled the call). <br>
<br>I&#39;m attaching the configuration without sensitive data. Please tell me whether problem is in the configuration or somewhere outside of kamailio. Thanks for any suggestion.<br><br>#!ifdef ACCDB_COMMENT<br>  ALTER TABLE acc ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT &#39;&#39;;<br>
  ALTER TABLE acc ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT &#39;&#39;;<br>  ALTER TABLE acc ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT &#39;&#39;;<br>  ALTER TABLE acc ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT &#39;&#39;;<br>
  ALTER TABLE acc ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT &#39;&#39;;<br>  ALTER TABLE missed_calls ADD COLUMN src_user VARCHAR(64) NOT NULL DEFAULT &#39;&#39;;<br>  ALTER TABLE missed_calls ADD COLUMN src_domain VARCHAR(128) NOT NULL DEFAULT &#39;&#39;;<br>
  ALTER TABLE missed_calls ADD COLUMN dst_ouser VARCHAR(64) NOT NULL DEFAULT &#39;&#39;;<br>  ALTER TABLE missed_call ADD COLUMN dst_user VARCHAR(64) NOT NULL DEFAULT &#39;&#39;;<br>  ALTER TABLE missed_calls ADD COLUMN dst_domain VARCHAR(128) NOT NULL DEFAULT &#39;&#39;;<br>
#!endif<br><br># -----------------------------------------------------------------------------------------<br>#!define WITH_MYSQL<br>#!define WITH_AUTH<br>#!define WITH_USRLOCDB<br>#!define WITH_NAT<br># -----------------------------------------------------------------------------------------<br>
<br>####### Global Parameters #########<br><br>#!ifdef WITH_DEBUG<br>debug=4<br>log_stderror=yes<br>#!else<br>debug=2<br>log_stderror=no<br>#!endif<br><br>memdbg=5<br>memlog=5<br><br>log_facility=LOG_LOCAL7<br><br>fork=yes<br>
#fork=yes<br>children=4<br><br>/* uncomment the next line to disable TCP (default on) */<br>#disable_tcp=yes<br><br>/* uncomment the next line to disable the auto discovery of local aliases<br>   based on revers DNS on IPs (default on) */<br>
#auto_aliases=no<br><br><br>/* uncomment and configure the following line if you want Kamailio to <br>   bind on a specific interface/port/proto (default bind on all available) */<br><br>listen=udp:<a href="http://1.1.1.1:5060">1.1.1.1:5060</a><br>
<br># -----------------------------------------------------------------------------------------<br>alias=test<br># -----------------------------------------------------------------------------------------<br>port=5060<br>
<br>####### Custom Parameters #########<br><br># These parameters can be modified runtime via RPC interface<br># - see the documentation of &#39;cfg_rpc&#39; module.<br>#<br># Format: <a href="http://group.id">group.id</a> = value &#39;desc&#39; description<br>
# Access: $sel(<a href="http://cfg_get.group.id">cfg_get.group.id</a>) or @<a href="http://cfg_get.group.id">cfg_get.group.id</a><br>#<br><br>####### Modules Section ########<br><br>#set module path<br>#mpath=&quot;/usr/local/lib/kamailio/modules_k/:/usr/local/lib/kamailio/modules/&quot;<br>
mpath=&quot;/lib/kamailio/modules_k/:/lib/kamailio/modules/&quot;<br><br>/* uncomment next line for MySQL DB support */<br>#!ifdef WITH_MYSQL<br>loadmodule &quot;db_mysql.so&quot;<br>#!endif<br>loadmodule &quot;mi_fifo.so&quot;<br>
loadmodule &quot;kex.so&quot;<br>loadmodule &quot;tm.so&quot;<br>loadmodule &quot;tmx.so&quot;<br>loadmodule &quot;sl.so&quot;<br>loadmodule &quot;rr.so&quot;<br>loadmodule &quot;pv.so&quot;<br>loadmodule &quot;maxfwd.so&quot;<br>
loadmodule &quot;usrloc.so&quot;<br>loadmodule &quot;registrar.so&quot;<br>loadmodule &quot;textops.so&quot;<br>loadmodule &quot;uri_db.so&quot;<br>loadmodule &quot;siputils.so&quot;<br>loadmodule &quot;xlog.so&quot;<br>loadmodule &quot;sanity.so&quot;<br>
loadmodule &quot;ctl.so&quot;<br>loadmodule &quot;mi_rpc.so&quot;<br>loadmodule &quot;acc.so&quot;<br><br># Addition modules<br># -----------------------------------------------------------------------------------------<br>
loadmodule &quot;avpops.so&quot;<br>loadmodule &quot;regex.so&quot;<br><br>loadmodule &quot;sqlops.so&quot;<br>loadmodule &quot;dialog.so&quot;<br>loadmodule &quot;call_control.so&quot;<br>loadmodule &quot;mediaproxy.so&quot;<br>
loadmodule &quot;siptrace.so&quot;<br>loadmodule &quot;mi_datagram.so&quot;<br>loadmodule &quot;group.so&quot;<br>loadmodule &quot;permissions.so&quot;<br><br># -----------------------------------------------------------------------------------------<br>
modparam(&quot;mi_datagram&quot;, &quot;socket_name&quot;, &quot;/var/run/kamailio/kamailio.sock&quot;)    # The name of a UNIX SOCKET used by Callcontrol<br><br>modparam(&quot;dialog&quot;, &quot;dlg_flag&quot;, 4)<br>#modparam(&quot;call_control&quot;, &quot;disable&quot;, 0)<br>
#modparam(&quot;call_control&quot;, &quot;signaling_ip_avp&quot;, &quot;$avp(s:signaling_ip)&quot;)<br><br># -----------------------------------------------------------------------------------------<br>modparam(&quot;sqlops&quot;,&quot;sqlcon&quot;,&quot;ca=&gt;mysql:/&quot;)        # The definition of a DB connection<br>
modparam(&quot;mediaproxy&quot;, &quot;mediaproxy_socket&quot;, &quot;/var/run/mediaproxy/dispatcher.sock&quot;)    # Path to the filesystem socket where the mediaproxy dispatcher listens for commands<br><br># -----------------------------------------------------------------------------------------<br>
modparam(&quot;tm&quot;, &quot;ruri_matching&quot;, 1)<br>modparam(&quot;tm&quot;, &quot;restart_fr_on_each_reply&quot;, 0)         # Final response timer will be re-triggered for each received provisional reply<br>#modparam(&quot;tm&quot;, &quot;fr_timer&quot;, 15000)            # Timer which hits if no final reply for an INVITE arrives (15 sec)<br>
modparam(&quot;tm&quot;, &quot;fr_inv_timer&quot;, 15000)            # Timer which hits if no final reply for an INVITE arrives (15 sec)<br># -----------------------------------------------------------------------------------------<br>
modparam(&quot;siptrace&quot;, &quot;db_url&quot;, &quot;&quot;)        # Database URL<br>modparam(&quot;siptrace&quot;, &quot;traced_user_avp&quot;, &quot;$avp(s:traced_user)&quot;)<br>modparam(&quot;siptrace&quot;, &quot;trace_on&quot;,        1)<br>
modparam(&quot;siptrace&quot;, &quot;trace_flag&quot;,      22)                # Flag is used to mark messages to trace<br><br># -----------------------------------------------------------------------------------------<br>
# Radius settings<br><br>modparam(&quot;acc&quot;, &quot;failed_transaction_flag&quot;, 1)<br>modparam(&quot;acc&quot;, &quot;report_cancels&quot;,     0)<br>modparam(&quot;acc&quot;, &quot;report_ack&quot;,         0)<br>
modparam(&quot;acc&quot;, &quot;early_media&quot;,        0)<br><br>modparam(&quot;acc&quot;, &quot;log_level&quot;,          1)<br>modparam(&quot;acc&quot;, &quot;log_flag&quot;,           1)<br>modparam(&quot;acc&quot;, &quot;log_missed_flag&quot;,    1)<br>
<br>modparam(&quot;acc&quot;, &quot;radius_config&quot;,      &quot;/etc/radiusclient-ng/radiusclient.conf&quot;)        # This is the location of the configuration file of radius client <br>modparam(&quot;acc&quot;, &quot;radius_flag&quot;,        1)<br>
modparam(&quot;acc&quot;, &quot;radius_missed_flag&quot;, 1)<br><br>modparam(&quot;acc&quot;, &quot;radius_extra&quot;, &quot;User-Name=$Au; \<br>                 Calling-Station-Id=$from; \<br>                 Called-Station-Id=$to; \<br>
                 Sip-Translated-Request-URI=$avp(s:translated_uri); \<br>                 Sip-RPid=$avp(s:rpid); \<br>                 Source-IP=$si; \<br>                 Source-Port=$sp; \<br>                 Canonical-URI=$avp(s:can_uri); \<br>
                 Billing-Party=$avp(s:billing_party); \<br>                 Divert-Reason=$avp(s:divert_reason); \<br>                 X-RTP-Stat=$hdr(X-RTP-Stat); \<br>                 Contact=$hdr(contact); \<br>                 Event=$hdr(event); \<br>
                 SIP-Proxy-IP=$avp(s:sip_proxy_ip); \<br>                 ENUM-TLD=$avp(s:enum_tld)&quot;)<br># -----------------------------------------------------------------------------------------<br><br>#!ifdef WITH_AUTH<br>
loadmodule &quot;auth.so&quot;<br>loadmodule &quot;auth_db.so&quot;<br>#!endif<br>/* uncomment next line for aliases support<br>   NOTE: a DB (like db_mysql) module must be also loaded */<br>#loadmodule &quot;alias_db.so&quot;<br>
/* uncomment next line for multi-domain support<br>   NOTE: a DB (like db_mysql) module must be also loaded<br>   NOTE: be sure and enable multi-domain support in all used modules<br>         (see &quot;multi-module params&quot; section ) */<br>
loadmodule &quot;domain.so&quot;<br>#!ifdef WITH_PRESENCE<br>loadmodule &quot;presence.so&quot;<br>loadmodule &quot;presence_xml.so&quot;<br>#!endif<br><br>#!ifdef WITH_NAT<br>loadmodule &quot;nathelper.so&quot;<br>#!endif<br>
<br>loadmodule &quot;uac.so&quot;<br><br># ----------------- setting module-specific parameters ---------------<br><br># --- enable CLI with append_rpid_hf ---<br>modparam(&quot;auth&quot;, &quot;rpid_prefix&quot;, &quot;&lt;sip:&quot;)<br>
modparam(&quot;auth&quot;, &quot;rpid_suffix&quot;, &quot;@<a href="http://1.1.1.1">1.1.1.1</a>;user=phone&gt;;party=calling; screen=yes; privacy=off&quot;)<br>#modparam(&quot;auth&quot;, &quot;rpid_avp&quot;, &quot;$avp(s:rpid)&quot;)<br>
<br># ----- mi_fifo params -----<br># -----------------------------------------------------------------------------------------<br>modparam(&quot;mi_fifo&quot;, &quot;fifo_name&quot;, &quot;/tmp/kamailio_fifo&quot;)<br># -----------------------------------------------------------------------------------------<br>
<br><br># ----- rr params -----<br># add value to ;lr param to cope with most of the UAs<br>modparam(&quot;rr&quot;, &quot;enable_full_lr&quot;, 1)<br># do not append from tag to the RR (no need for this script)<br>modparam(&quot;rr&quot;, &quot;append_fromtag&quot;, 1)<br>
<br><br># ----- rr params -----<br>modparam(&quot;registrar&quot;, &quot;method_filtering&quot;, 1)<br>/* uncomment the next line to disable parallel forking via location */<br># modparam(&quot;registrar&quot;, &quot;append_branches&quot;, 0)<br>
/* uncomment the next line not to allow more than 10 contacts per AOR */<br>#modparam(&quot;registrar&quot;, &quot;max_contacts&quot;, 10)<br><br><br># ----- uri_db params -----<br>/* by default we disable the DB support in the module as we do not need it<br>
   in this configuration */<br>modparam(&quot;uri_db&quot;, &quot;use_uri_table&quot;, 0)<br>modparam(&quot;uri_db&quot;, &quot;db_url&quot;, &quot;mysql://&quot;)<br>modparam(&quot;domain&quot;, &quot;db_url&quot;, &quot;mysql://&quot;)<br>
<br><br># ----- acc params -----<br>/* what sepcial events should be accounted ? */<br>modparam(&quot;acc&quot;, &quot;early_media&quot;, 1)<br>modparam(&quot;acc&quot;, &quot;report_ack&quot;, 1)<br>modparam(&quot;acc&quot;, &quot;report_cancels&quot;, 1)<br>
/* by default ww do not adjust the direct of the sequential requests.<br>   if you enable this parameter, be sure the enable &quot;append_fromtag&quot;<br>   in &quot;rr&quot; module */<br>modparam(&quot;acc&quot;, &quot;detect_direction&quot;, 0)<br>
/* account triggers (flags) */<br>modparam(&quot;acc&quot;, &quot;failed_transaction_flag&quot;, 3)<br>modparam(&quot;acc&quot;, &quot;log_flag&quot;, 1)<br>modparam(&quot;acc&quot;, &quot;log_missed_flag&quot;, 2)<br>modparam(&quot;acc&quot;, &quot;log_extra&quot;, <br>
    &quot;src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd&quot;)<br>/* enhanced DB accounting */<br>#!ifdef WITH_ACCDB<br>modparam(&quot;acc&quot;, &quot;db_flag&quot;, 1)<br>modparam(&quot;acc&quot;, &quot;db_missed_flag&quot;, 2)<br>
modparam(&quot;acc&quot;, &quot;db_url&quot;,<br>    &quot;mysql://&quot;)<br><br>modparam(&quot;acc&quot;, &quot;db_extra&quot;,<br>    &quot;src_user=$fU;src_domain=$fd;dst_ouser=$tU;dst_user=$rU;dst_domain=$rd&quot;)<br>
#!endif<br><br># ----- usrloc params -----<br>/* enable DB persistency for location entries */<br>#!ifdef WITH_USRLOCDB<br>modparam(&quot;usrloc&quot;, &quot;db_mode&quot;,   2)<br>modparam(&quot;usrloc&quot;, &quot;db_url&quot;,<br>
    &quot;mysql://&quot;)<br>#!endif<br><br># ----- auth_db params -----<br>/* enable the DB based authentication */<br>#!ifdef WITH_AUTH<br>modparam(&quot;auth_db&quot;, &quot;calculate_ha1&quot;, yes)<br>modparam(&quot;auth_db&quot;, &quot;password_column&quot;, &quot;password&quot;)<br>
modparam(&quot;auth_db&quot;, &quot;db_url&quot;,<br>    &quot;mysql://&quot;)<br>modparam(&quot;auth_db&quot;, &quot;load_credentials&quot;, &quot;rpid&quot;)<br>#!endif<br><br># -- group params --<br>/* for grp mysql table usage - groups - siptrace, blocked*/<br>
modparam(&quot;group&quot;, &quot;db_url&quot;, &quot;mysql://&quot;)<br>modparam(&quot;group&quot;, &quot;table&quot;, &quot;grp&quot;)<br>modparam(&quot;group&quot;, &quot;user_column&quot;, &quot;username&quot;)<br>modparam(&quot;group&quot;, &quot;domain_column&quot;, &quot;domain&quot;)<br>
modparam(&quot;group&quot;, &quot;group_column&quot;, &quot;grp&quot;)<br><br># -- permissions params --<br>/* for trusted table usage and other functions - other modparam are default */<br>modparam(&quot;permissions&quot;, &quot;db_url&quot;, &quot;mysql://&quot;)<br>
modparam(&quot;permissions&quot;, &quot;db_mode&quot;, 1)<br><br># ----- alias_db params -----<br>/* uncomment the following lines if you want to enable the DB based<br>   aliases */<br>#modparam(&quot;alias_db&quot;, &quot;db_url&quot;,<br>
#    &quot;mysql://&quot;)<br><br><br># ----- domain params -----<br>/* uncomment the following lines to enable multi-domain detection<br>   support */<br>#modparam(&quot;domain&quot;, &quot;db_url&quot;,<br>#    &quot;mysql://&quot;)<br>
#modparam(&quot;domain&quot;, &quot;db_mode&quot;, 1)   # Use caching<br><br><br># ----- multi-module params -----<br>/* uncomment the following line if you want to enable multi-domain support<br>   in the modules (dafault off) */<br>
#modparam(&quot;alias_db|auth_db|usrloc|uri_db&quot;, &quot;use_domain&quot;, 1)<br><br><br># ----- presence params -----<br>/* enable presence server support */<br>#!ifdef WITH_PRESENCE<br>modparam(&quot;presence|presence_xml&quot;, &quot;db_url&quot;,<br>
    &quot;mysql://&quot;)<br>modparam(&quot;presence_xml&quot;, &quot;force_active&quot;, 1)<br>modparam(&quot;presence&quot;, &quot;server_address&quot;, &quot;sip:<a href="http://10.0.0.10:5060">10.0.0.10:5060</a>&quot;)<br>
#!endif<br><br># ----- nathelper -----<br>#!ifdef WITH_NAT<br>#modparam(&quot;nathelper&quot;, &quot;rtpproxy_sock&quot;, &quot;udp:<a href="http://127.0.0.1:7722">127.0.0.1:7722</a>&quot;)<br>#modparam(&quot;nathelper&quot;, &quot;natping_interval&quot;, 30)<br>
#modparam(&quot;nathelper&quot;, &quot;ping_nated_only&quot;, 1)<br>#modparam(&quot;nathelper&quot;, &quot;sipping_bflag&quot;, 7)<br>#modparam(&quot;nathelper&quot;, &quot;sipping_from&quot;, &quot;<a href="mailto:sip%3Apinger@kamailio.org">sip:pinger@kamailio.org</a>&quot;)<br>
modparam(&quot;registrar|nathelper&quot;, &quot;received_avp&quot;, &quot;$avp(i:80)&quot;)<br>modparam(&quot;usrloc&quot;, &quot;nat_bflag&quot;, 6)<br>#!endif<br><br>####### Routing Logic ########<br><br><br># main request routing logic<br>
<br>route{    <br>#------------SANITY CHECK----------------------------------------------------------------<br><br>    xlog(&quot;L_INFO&quot;,&quot;XLOG ****************START*($rm)*S_IP($si)*CallID($ci)*********************&quot;);        <br>
    if (!mf_process_maxfwd_header(&quot;10&quot;)) {<br>        sl_send_reply(&quot;483&quot;,&quot;Too Many Hops&quot;);<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: Too many hops man&quot;);<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
        exit;<br>    }<br><br>    if(!sanity_check(&quot;1511&quot;, &quot;7&quot;))<br>    {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: Malformed SIP message&quot;);<br>        xlog(&quot;Malformed SIP message from $si:$sp\n&quot;);<br>
        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>        exit;<br>    }<br><br><br>    # NAT detection<br>    xlog(&quot;L_INFO&quot;, &quot;XLOG: Performing NAT detection&quot;);<br>
    route(NAT);<br>        <br>    if (has_totag()) {<br>        # sequential request withing a dialog should<br>        # take the path determined by record-routing<br>        if (loose_route()) {<br>            xlog(&quot;L_INFO&quot;, &quot;XLOG: loose_route()&quot;);<br>
            if (is_method(&quot;BYE&quot;)) {<br>                xlog(&#39;L_INFO&#39;, &#39;XLOG: Method is BYE&#39;);<br>                setflag(1); # do accounting ...<br>                setflag(3); # ... even if the transaction fails<br>
#                end_media_session();<br>            }<br>            route(RELAY);<br>        } else {<br>            <br>            if (is_method(&quot;SUBSCRIBE&quot;) &amp;&amp; uri == myself) {<br>                xlog(&#39;L_INFO&#39;, &#39;XLOG: Method is SUBSCRIBE and uri == myself&#39;);<br>
                # in-dialog subscribe requests<br>                route(PRESENCE);<br>                #!ifndef WITH_PRESENCE<br>                #added by yenkee<br>                    sl_send_reply(&quot;403&quot;, &quot;Not Allowed&quot;);<br>
                #!endif<br>                xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>                exit;<br>            }<br>            if ( is_method(&quot;ACK&quot;) ) {<br>
                xlog(&#39;L_INFO&#39;, &#39;XLOG: Method is ACK&#39;);<br>                if ( t_check_trans() ) {<br>                    # non loose-route, but stateful ACK; must be an ACK after a 487 or e.g. 404 from upstream server<br>
                    xlog(&#39;L_INFO&#39;, &#39;XLOG: t_check_trans()&#39;);<br>                    t_relay();<br>                    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
                    exit;<br>                } else {<br>                    xlog(&#39;L_INFO&#39;, &#39;XLOG: ACK without matching transaction ... ignore and discard.&#39;);<br>                        #added by yenkee<br>
                        sl_send_reply(&quot;403&quot;, &quot;Not Allowed&quot;);<br>                    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>                    exit;<br>
                }<br>            }<br>            sl_send_reply(&quot;404&quot;,&quot;Not here&quot;);<br>            xlog(&quot;L_INFO&quot;, &quot;XLOG: 404 Not Here ----------------------------------&quot;);<br>            <br>
        }<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>        exit;<br>    }<br><br>    #initial requests<br><br>    # CANCEL processing<br>    if (is_method(&quot;CANCEL&quot;))<br>
    {<br>        xlog(&#39;L_INFO&#39;, &#39;XLOG: Method is CANCEL&#39;);<br>        if (t_check_trans())<br>            t_relay();<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
        exit;<br>    }<br><br>    t_check_trans();<br><br>    # authentication<br>    route(AUTH);<br><br>    setflag(1);<br><br>    # record routing for dialog forming requests (in case they are routed)<br>    # - remove preloaded route headers<br>
    remove_hf(&quot;Route&quot;);<br>    if (is_method(&quot;INVITE|SUBSCRIBE&quot;))<br>        record_route();<br><br>    # account only INVITEs<br>    if (is_method(&quot;INVITE&quot;)) {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: Method is INVITE&quot;);<br>
        setflag(1); # do accounting    <br># -----------------------------------------------------------------------------------------<br>        $avp(s:can_uri) = $ru;        # Canonical-URI will be used for rating the session<br>
        xlog(&quot;L_INFO&quot;, &quot;XLOG: Engaging Media Proxy&quot;);<br>        engage_media_proxy();        # Automatically call use_media_proxy / end_media_proxy on every request and reply that belongs to the dialog<br>
# -----------------------------------------------------------------------------------------<br>    }<br><br>    if (!uri==myself)<br>    /* replace with following line if multi-domain support is used */<br>    ##if (!is_uri_host_local())<br>
    {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: Appeding Hf P-hing: outbound&quot;);<br>        append_hf(&quot;P-hint: outbound\r\n&quot;); <br>        route(RELAY);<br>    }<br><br>    # requests for my domain<br><br>
    if( is_method(&quot;PUBLISH|SUBSCRIBE&quot;))<br>        route(PRESENCE);<br><br>    if (is_method(&quot;REGISTER&quot;))<br>    {<br>        if(isflagset(5))<br>        {<br>            setbflag(&quot;6&quot;);<br>            # uncomment next line to do SIP NAT pinging <br>
            ## setbflag(&quot;7&quot;);<br>        }<br>        if (!save(&quot;location&quot;))<br>            sl_reply_error();<br><br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
        exit;<br>    }<br><br>    if ($rU==$null) {<br>        # request with no Username in RURI<br>        sl_send_reply(&quot;484&quot;,&quot;Address Incomplete&quot;);<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
        exit;<br>    }<br><br># ---------ENABLING SIP TRACE--------------------------------------------------------------<br># Enable sip tracing for users in grp siptrace in mysql db ( nema vplyv na zapisovanie acc informacii )<br>
    if (is_user_in(&quot;From&quot;, &quot;siptrace&quot;) ) {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: Starting sip_trace for From-URI:($fu)&quot;);<br>        setflag(22);<br>#        sip_trace();            # mne sip_trace nefungoval iba setflag , ak sa nastavi flag na hodnotu v modparam bude robit cdr tool sip tracy<br>
        }<br><br><br>#    route(PSTN);<br># -----------------------------------------------------------------------------------------<br><br>    # apply DB based aliases (uncomment to enable)<br>    ##alias_db_lookup(&quot;dbaliases&quot;);<br>
    <br>    if (is_method(&quot;INVITE&quot;)) {<br><br>#------------BLOCK NUMBER-----------------------------------------------------------------    <br>    # Block username<br>    if ( is_user_in(&quot;From&quot;, &quot;blocked&quot;)) {<br>
        xlog(&quot;L_INFO&quot;, &quot;XLOG: [main route] Account ($fu) to ($ru) is blocked&quot;);<br>        sl_send_reply(&quot;403&quot;, &quot; Account blocked &quot;);<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
        exit;<br>    }<br><br># -----------------------------------------------------------------------------------------<br>        # Call control allows one to limit the duration of calls and automatically end them when they exceed the imposed limit<br>
        xlog(&quot;L_INFO&quot;,&quot;XLOG: Before call_control() var rm = ($rm)&quot;);<br>        call_control();<br>        switch ($retcode) {<br>            case 2:<br>                # Call with no limit<br><br>                xlog(&quot;L_INFO&quot;, &quot;XLOG: [call_control] Call with no limit&quot;);<br>
                break;<br>            case 1:<br>                # Call with a limit under callcontrol management (either prepaid or postpaid)<br><br>                xlog(&quot;L_INFO&quot;, &quot;XLOG: [call_control] Call with a limit under callcontrol management&quot;);<br>
                break;<br>            case -1:<br>                # Not enough credit (prepaid call)<br><br>                xlog(&quot;L_INFO&quot;, &quot;XLOG: Call control: not enough credit for prepaid call&quot;);<br>
                acc_rad_request(&quot;402&quot;);<br>                sl_send_reply(&quot;402&quot;, &quot;Not enough credit&quot;);<br>                xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
                exit;<br>                break;<br>            case -2:<br>                # Locked by call in progress (prepaid call)<br><br>                xlog(&quot;L_INFO&quot;, &quot;XLOG: Call control: prepaid call locked by another call in progress&quot;);<br>
                acc_rad_request(&quot;403&quot;);<br>                sl_send_reply(&quot;403&quot;, &quot;Call locked by another call in progress&quot;);<br>                xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
                exit;<br>                break;<br>            default:<br>                # Internal error (message parsing, communication, ...)<br><br>                xlog(&quot;L_INFO&quot;, &quot;XLOG: Call control: internal server error&quot;);<br>
                acc_rad_request(&quot;500&quot;);<br>                sl_send_reply(&quot;500&quot;, &quot;Internal server error&quot;);<br>                xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
                exit;<br>        }<br><br># -----------------------------------------------------------------------------------------<br><br># -----------------------------------------------------------------------------------------<br>
        # Return error message when you are calling on your own number    <br>        # fU - From username<br>        # tU - To username<br><br>        if ($fU==$tU) {            <br>            sl_send_reply(&quot;403&quot;,&quot;Forbidden calling own number&quot;);<br>
<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: Call on your own number: Request-URI:($ru) From-URI:($fu). Sending 403 Forbidden&quot;);<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
            exit;<br>        }<br><br># -----------------------------------------------------------------------------------------<br><br>    }<br># -----------------------------------------------------------------------------------------<br>
# -----------------------------------------------------------------------------------------<br><br><br><br><br># -----------------------------------------------------------------------------------------<br># -----------------------------------------------------------------------------------------<br>
    xlog(&quot;L_INFO&quot;,&quot;XLOG: Performing lookup( location) &quot;);<br>    if (!lookup(&quot;location&quot;)) {<br>        <br>        switch ($rc) {<br>            case -1:<br>            case -3:<br>                    t_newtran();<br>
                    t_reply(&quot;404&quot;, &quot;[local failed] Not Found&quot;);<br>                    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>                    exit;<br>
                break;<br>            # commented - not used with PSTN<br>            case -2:<br>                sl_send_reply(&quot;405&quot;, &quot;Method Not Allowed&quot;);<br>                xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
                exit;<br>        }<br><br># -----------------------------------------------------------------------------------------<br># -----------------------------------------------------------------------------------------<br>
<br># -----------------------------------------------------------------------------------------<br>        # Replacing plus sign with 00<br><br>        if ($ru=~&quot;.*sip:\+.*@.*&quot;) {                # Check if URI contains plus sign <br>
            $avp(s:to)=$ru;    <br>            avp_subst(&quot;$avp(s:to)&quot;, &quot;/(sip:)\+/sip:00/&quot;);    # Replace plus sign with 00<br>            avp_pushto(&quot;$ru&quot;, &quot;$avp(s:to)&quot;);        # Push the value of AVP with name into the SIP message as Request-URI<br>
<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: Replacing plus sign in Request-URI ($ru)&quot;);<br>        }<br><br># -----------------------------------------------------------------------------------------<br># -----------------------------------------------------------------------------------------<br>
    } <br><br>    # when routing via usrloc, log the missed calls also<br>    setflag(2);<br><br>    route(RELAY);<br>}<br><br><br>route[RELAY] {<br>xlog(&quot;L_INFO&quot;, &quot;XLOG: [RELAY] Jumped to route(RELAY)&quot;);<br>
<br>#!ifdef WITH_NAT<br>    if (check_route_param(&quot;nat=yes&quot;)) {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: [RELAY] check_route_param(&#39;nat=yes&#39;) == 1&quot;);<br>        setbflag(&quot;6&quot;);<br>    }<br>
    if (isflagset(5) || isbflagset(&quot;6&quot;)) {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: [RELAY] isflagset(5) &amp;&amp; isbflagset(6)&quot;);<br>        route(RTPPROXY);<br>    }<br>#!endif<br><br>    <br># -----------------------------------------------------------------------------------------<br>
    /* example how to enable some additional event routes */<br>    if (is_method(&quot;INVITE&quot;)) {<br>#        $avp(s:callee_fr_inv_timer) = 10;<br>        xlog(&quot;L_INFO&quot;, &quot;XLOG: [RELAY] Routing of failure and reply messages&quot;);<br>
#        t_on_branch(&quot;BRANCH_ONE&quot;);<br>        t_set_fr(10000);<br>        t_on_reply(&quot;REPLY_ONE&quot;);<br>        t_on_failure(&quot;1&quot;);        # Registering failure route<br>    }<br><br>    if (!t_relay()) {<br>
        sl_reply_error();<br>    }<br>    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting FROM RELAY ------------------------------------&quot;);<br>    exit;<br>}<br><br><br># Presence server route<br>route[PRESENCE]<br>{<br>
#!ifdef WITH_PRESENCE<br>    if (!t_newtran())<br>    {<br>        sl_reply_error();<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>        exit;<br>    };<br><br>
    if(is_method(&quot;PUBLISH&quot;))<br>    {<br>        handle_publish();<br>        t_release();<br>    }<br>    else<br>    if( is_method(&quot;SUBSCRIBE&quot;))<br>    {<br>        handle_subscribe();<br>        t_release();<br>
    }<br>    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>    exit;<br>#!endif<br>    <br>    # if presence enabled, this part will not be executed<br>    if (is_method(&quot;PUBLISH&quot;) || $rU==$null)<br>
    {<br>        sl_send_reply(&quot;404&quot;, &quot;Not here&quot;);<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>        exit;<br>    }<br>    return;<br>}<br>
<br># Authentication route<br><br>route[AUTH] {<br>xlog(&quot;L_INFO&quot;, &quot;XLOG: Jumped to route[AUTH]&quot;);<br>#!ifdef WITH_AUTH<br>    if (is_method(&quot;REGISTER&quot;))<br>    {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: [AUTH] Register pred ifom From-URI:($fu)&quot;);<br>
        # authenticate the REGISTER requests (uncomment to enable auth)<br>        if (!www_authorize(&quot;&quot;, &quot;subscriber&quot;))<br>        {<br>            xlog(&quot;L_INFO&quot;, &quot;XLOG: [AUTH] www_challenge()&quot;);<br>
            www_challenge(&quot;&quot;, &quot;0&quot;);<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>            exit;<br>        }<br><br>        if ($au!=$tU)<br>
        {<br>            xlog(&quot;L_INFO&quot;, &quot;XLOG: [AUTH] Forbidden auth ID From-URI:($fu)&quot;);<br>            sl_send_reply(&quot;403&quot;,&quot;Forbidden auth ID&quot;);<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
            exit;<br>        }<br>    } else {<br>        # authenticate if from local subscriber (uncomment to enable auth)<br>        if (from_uri==myself)<br>        {<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: [AUTH] Message is not REGISTER, and from_uri == myself&quot;);<br>
            if (!proxy_authorize(&quot;&quot;, &quot;subscriber&quot;)) {<br>                xlog(&quot;L_INFO&quot;, &quot;XLOG: [AUTH] proxy_challenge()&quot;);<br>                xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>
                proxy_challenge(&quot;&quot;, &quot;0&quot;);<br>                exit;<br>            }<br>            if (is_method(&quot;PUBLISH&quot;))<br>            {<br>                if ($au!=$tU) {<br>                    sl_send_reply(&quot;403&quot;,&quot;Forbidden auth ID&quot;);<br>
                    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>                    exit;<br>                }<br>            } else {<br>                if ($au!=$fU) {<br>
                    sl_send_reply(&quot;403&quot;,&quot;Forbidden auth ID&quot;);<br>                    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>                    exit;<br>
                }<br>            }<br>            xlog(&quot;L_INFO&quot;,&quot;XLOG: [AUTH] consumer_credentials()&quot;);<br>            consume_credentials();<br>            # caller authenticated<br>        }<br>    }<br>
#!endif<br>    return;<br>}<br><br># Caller NAT detection route<br>route[NAT]{<br>#!ifdef WITH_NAT<br>    force_rport();<br>    xlog(&quot;L_INFO&quot;, &quot;XLOG: Checking nat_uac_test(&#39;19&#39;)&quot;);<br>    if (nat_uac_test(&quot;19&quot;)) {<br>
        if (method==&quot;REGISTER&quot;) {<br>            xlog(&quot;L_INFO&quot;, &quot;XLOG: fix_nated_register()&quot;);<br>            fix_nated_register();<br>        } else {<br>            xlog(&quot;L_INFO&quot;, &quot;XLOG: fix_nated_contact()&quot;);<br>
            fix_nated_contact();<br>        }<br>        setflag(5);<br>    }<br>#!endif<br>    return;<br>}<br><br># RTPProxy control<br>route[RTPPROXY] {<br>xlog(&quot;L_INFO&quot;,&quot;XLOG: Jumped to route[RTPPROXY]&quot;);<br>
#!ifdef WITH_NAT<br>#    if (is_method(&quot;BYE&quot;)) {<br>#        unforce_rtp_proxy();<br>#    } else if (is_method(&quot;INVITE&quot;)){<br>#        force_rtp_proxy();<br>#    }<br>    if (!has_totag()) {<br>        add_rr_param(&quot;;nat=yes&quot;);<br>
        xlog(&quot;L_INFO&quot;,&quot;XLOG: Adding RR param(&#39;;nat=yes&#39;)&quot;);<br>    }<br>#!endif<br>    return;<br>}<br><br># PSTN GW routing<br>route[PSTN] {<br>#!ifdef WITH_PSTN<br>    # check if PSTN GW IP is defined<br>
    if (strempty($sel(cfg_get.pstn.gw_ip))) {<br>        xlog(&quot;SCRIPT: PSTN rotuing enabled but pstn.gw_ip not defined\n&quot;);<br>        return;<br>    }<br><br>    # route to PSTN dialed numbers starting with &#39;+&#39; or &#39;00&#39;<br>
    #     (international format)<br>    # - update the condition to match your dialing rules for PSTN routing<br>    if(!($rU=~&quot;^(\+|00)[1-9][0-9]{3,20}$&quot;))<br>        return;<br><br>    # only local users allowed to call<br>
    if(from_uri!=myself) {<br>        sl_send_reply(&quot;403&quot;, &quot;Not Allowed&quot;);<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>        exit;<br>    }<br>
<br>    $ru = &quot;sip:&quot; + $rU + &quot;@&quot; + $sel(cfg_get.pstn.gw_ip);<br><br>    route(RELAY);<br>    xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>    exit;<br>
#!endif<br><br>    return;<br>}<br><br># Sample branch router<br>branch_route[BRANCH_ONE] {<br>    xlog(&quot;L_INFO&quot;,&quot;XLOG: BRANCH ROUTE &quot;);<br>    exit;<br>}<br><br># Sample onreply route<br>onreply_route[REPLY_ONE] {<br>
    #xdbg(&quot;incoming reply\n&quot;);<br>    xlog(&quot;L_INFO&quot;,&quot;XLOG: REPLY ROUTE &quot;);<br>#!ifdef WITH_NAT<br>#    if ((isflagset(5) || isbflagset(&quot;6&quot;)) &amp;&amp; status=~&quot;(183)|(2[0-9][0-9])&quot;) {<br>
#        force_rtp_proxy();<br>#    }<br>    if (isbflagset(&quot;6&quot;)) {<br>        fix_nated_contact();<br>    }<br>#!endif<br>}<br><br># Sample failure route<br>failure_route[1] {<br>#!ifdef WITH_NAT<br>#    if (is_method(&quot;INVITE&quot;)<br>
#            &amp;&amp; (isbflagset(&quot;6&quot;) || isflagset(5))) {<br>#        unforce_rtp_proxy();<br>#    }<br>#!endif<br><br>    xlog(&quot;L_INFO&quot;,&quot;XLOG ****************FAILROUTE*($rm)*S_IP($si)**CallID($ci)********************&quot;);        <br>
<br>    if (t_is_canceled()) {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: exiting ----------------------------------------&quot;);<br>        exit;<br>    }<br><br># -----------------------------------------------------------------------------------------<br>
    # Forward call on Voicemail when spefified SIP Status Code is returned. Failure route registered using t_on_failure.<br>    # 486 - Busy Here<br>    # 408 - Request Timeout<br>    # 480 Temporarily Unavailable<br><br>
#    if (t_check_status(&quot;486|408|480&quot;)) {<br>    if (t_check_status(&quot;486|408&quot;)) {<br>        xlog(&quot;L_INFO&quot;,&quot;XLOG: [failure route] Forwarding on Voicemail&quot;);<br><br>    }<br><br># -----------------------------------------------------------------------------------------<br>
}<br>