Hi Daniel, <br><br>thanks for the quick fix and reply.<br><br>What is the easiest way to try this new patch? I&#39;m running kamailio 3.1.4 and there is no t_flush_flags() in tmx module in that version. I suppose I need to install Kamailio Devel from git (<a href="http://www.kamailio.org/dokuwiki/doku.php/install:kamailio-devel-from-git">http://www.kamailio.org/dokuwiki/doku.php/install:kamailio-devel-from-git</a>) to get t_flush flags() and your patch or is there a workaround to apply them to my 3.1.4 branch?<br>
<br>Cheers<br>Ozren<br><br><br><div class="gmail_quote">On Tue, Sep 6, 2011 at 2:18 PM, Daniel-Constantin Mierla <span dir="ltr">&lt;<a href="mailto:miconda@gmail.com">miconda@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    can you use t_flush_flags() after setting the accounting flag in
    falure_route? Automatic update was missing so far, reported by Alex
    Hermann as well. I just did a patch, so if you want to try it, see
    the commit:<br>
    <br>
<a href="http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c589ca35b2aa3097a3c9e2a5a050514337300c05" target="_blank">http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c589ca35b2aa3097a3c9e2a5a050514337300c05</a><br>

    <br>
    Actually, reporting if all goes fine with this patch, will help in
    backporting it to 3.1 branch.<br>
    <br>
    Thanks,<br>
    Daniel<div><div></div><div class="h5"><br>
    <br>
    On 9/5/11 2:41 PM, Ozren Lapcevic wrote:
    </div></div><blockquote type="cite"><div><div></div><div class="h5">Hi,<br>
      <br>
      I&#39;m having some problems accounting missed serial forked calls to
      mysql database. <br>
      <br>
      I have following setup. Each user can have up to two contacts:
      telephone number (routed to asterisk) and SIP URI. Users can
      specify which contact has higher priority - which one should ring
      first. There is also SEMS voicemail which is forked as 3rd serial
      call leg if there is no answer at first two contacts.<br>
      <br>
      For example, I have two users: <a href="mailto:oz@abc.hr" target="_blank">oz@abc.hr</a> and <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a>.
      <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a> also has set telephone number as
      alternative number if he is not reachable at <a href="mailto:sip%3Apero@abc.hr" target="_blank">sip:pero@abc.hr</a>. Moreover, <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a>
      has voicemail turned on. When <a href="mailto:oz@abc.hr" target="_blank">oz@abc.hr</a> calls <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a>,
      first <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a>&#39;s SIP client rings, then if
      there is no answer and after the timeout telephone number rings
      and finally, if there is no answer at telephone and after the
      timeout INVITE is forked to SEMS.<br>
      <br>
      There are two interesting scenarios accounting-wise which can
      happened:<br>
      1. <a href="mailto:oz@abc.hr" target="_blank">oz@abc.hr</a> calls <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a>, there
      are no answers and call is forked to voicemail.<br>
      2. <a href="mailto:oz@abc.hr" target="_blank">oz@abc.hr</a> calls <a href="mailto:pero@abc.hr" target="_blank">pero@abc.hr</a>, there
      is no answer at SIP client, but pero answers call at telephone.<br>
      <br>
      When scenario 1 happens, I want to have only one log (row) in
      missed_calls table.<br>
      <br>
      When scenario 2 happens, I don&#39;t want to have a log in
      missed_calls table.<br>
      <br>
      To accomplish this,<b> I want to log only the 2nd branch of the
        forked call. However, there is either a bug in acc module or I&#39;m
        doing something wrong, and I can&#39;t get Kamailio to log only the
        2nd branch</b>. I think that I am setting the FLT_ACCMISSED flag
      correctly - after the 2nd branch is handled and prior to calling
      the RELAY route. Logs show that FLT_ACCMISSED flag is set prior to
      calling t_relay(), and there are no errors in debug log. I am
      using $ru = &quot;something&quot; to rewrite URI prior to forking request. <br>
      <br>
      I can easily set up logging of every call (two missed calls for
      serially forked call to two locations) by setting FLT_ACCMISSED
      flag for each INVITE. I can set up logging of every call&#39;s 1st
      branch, by reseting FLT_ACCMISSED flag when handling 2nd branch of
      the call. Interestingly, logging of only the 2nd branch of the
      serial forked call works when there is no forking to voicemail! <br>
      <br>
      Any ideas how to solve this problem? <br>
      <br>
      Bellow are important parts of my config file. I&#39;m running kamailio
      3.1.4.<br>
      <br>
      Cheers<br>
      Ozren<br>
      <br>
      <br>
      # ----- acc params -----<br>
      /* what special events should be accounted ? */<br>
      modparam(&quot;acc&quot;, &quot;early_media&quot;, 0)<br>
      modparam(&quot;acc&quot;, &quot;report_ack&quot;, 1)<br>
      modparam(&quot;acc&quot;, &quot;report_cancels&quot;, 0)<br>
      modparam(&quot;acc&quot;, &quot;detect_direction&quot;, 0)<br>
      /* account triggers (flags) */<br>
      modparam(&quot;acc&quot;, &quot;log_flag&quot;, FLT_ACC)<br>
      modparam(&quot;acc&quot;, &quot;log_missed_flag&quot;, FLT_ACCMISSED)<br>
      modparam(&quot;acc&quot;, &quot;failed_transaction_flag&quot;, FLT_ACCFAILED)<br>
      modparam(&quot;acc&quot;,
&quot;log_extra&quot;,&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;, FLT_ACC)<br>
      modparam(&quot;acc&quot;, &quot;db_missed_flag&quot;, FLT_ACCMISSED)<br>
      modparam(&quot;acc&quot;, &quot;db_url&quot;, DBURL)<br>
      modparam(&quot;acc&quot;, &quot;db_extra&quot;,
      &quot;src_user=$fU;src_domain=$fd;dst_user=$tU;dst_domain=$td;src_ip=$si&quot;)<br>
      #!endif<br>
      <br>
      ...<br>
      <br>
      <br>
      # Main SIP request routing logic<br>
      # - processing of any incoming SIP request starts with this route<br>
      route {<br>
      <br>
              # per request initial checks<br>
              route(REQINIT);<br>
      <br>
              if (src_ip != ****) {<br>
                      # NAT detection<br>
                      route(NAT);<br>
              }<br>
      <br>
              # handle requests within SIP dialogs<br>
              route(WITHINDLG);<br>
      <br>
              ### only initial requests (no To tag)<br>
      <br>
              # CANCEL processing<br>
              if (is_method(&quot;CANCEL&quot;))<br>
              {<br>
                      if (t_check_trans())<br>
                              t_relay();<br>
                      exit;<br>
              }<br>
      <br>
              t_check_trans();<br>
      <br>
              # authentication<br>
              route(AUTH);<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>
              {<br>
                      setflag(FLT_ACC); # do accounting<br>
              }<br>
      <br>
              # dispatch requests to foreign domains<br>
              route(SIPOUT);<br>
      <br>
              ### requests for my local domains<br>
      <br>
              # handle presence related requests<br>
              route(PRESENCE);<br>
      <br>
              # handle registrations<br>
              route(REGISTRAR);<br>
      <br>
              if ($rU==$null)<br>
              {<br>
                      # request with no Username in RURI<br>
                      sl_send_reply(&quot;484&quot;,&quot;Address Incomplete&quot;);<br>
                      exit;<br>
              }<br>
      <br>
              # dispatch destinations to PSTN<br>
              route(PSTN);<br>
      <br>
              if ( is_method(&quot;INVITE&quot;) ) {<br>
                      route(DBALIASES);<br>
                      #check for user defined forking priorities and
      timers<br>
                      route(FORK);<br>
              }<br>
      <br>
              # user location service<br>
              route(LOCATION);<br>
      <br>
              route(RELAY);<br>
      }<br>
      <br>
      <br>
      <br>
      #check for user defined forking priorities and timers<br>
      route[FORK]{<br>
              sql_query(&quot;con&quot;, &quot;select * from usr_pref_custom where
      uuid=&#39;$tu&#39;&quot;, &quot;pref&quot;);<br>
      <br>
              $avp(uuid)=$dbr(pref=&gt;[0,0]);<br>
              $avp(email)=$dbr(pref=&gt;[0,1]);<br>
              $avp(prio1)=$dbr(pref=&gt;[0,2]);<br>
              $avp(prio2)=$dbr(pref=&gt;[0,3]);<br>
              $avp(timer1)=$dbr(pref=&gt;[0,5]);<br>
              $avp(timer2)=$dbr(pref=&gt;[0,6]);<br>
      <br>
              if (strlen($avp(prio1))&gt;5) {<br>
      <br>
                      # user has multiple contacts, do serial forking<br>
                      setflag(FLT_USRPREF);<br>
      <br>
                      # set counter<br>
                      if (!$avp(prio)) {<br>
                              $avp(prio) = 1;<br>
                      }<br>
      <br>
                      # overwrite request URI with highest priority
      contact<br>
                      if ($avp(prio1) =~ &quot;^<a>sip:00</a>&quot;) {<br>
                              $ru = $avp(prio1) + &quot;@host&quot;;<br>
                              xlog(&quot;L_INFO&quot;,&quot;PRIO 1 is tel number, RURI
      set: $ru&quot;);<br>
                      }<br>
                      else {<br>
                              $ru = $avp(prio1);<br>
                              xlog(&quot;L_INFO&quot;,&quot;PRIO 1 is SIP URI, RURI
      set: $ru&quot;);<br>
                      }<br>
              }<br>
      }<br>
      <br>
      <br>
      route[RELAY] {<br>
      #!ifdef WITH_NAT<br>
              if (check_route_param(&quot;nat=yes&quot;)) {<br>
                      setbflag(FLB_NATB);<br>
              }<br>
              if (isflagset(FLT_NATS) || isbflagset(FLB_NATB)) {<br>
                      route(RTPPROXY);<br>
              }<br>
      #!endif<br>
      <br>
              /* example how to enable some additional event routes */<br>
              if (is_method(&quot;INVITE&quot;)) {<br>
      <br>
                      t_on_reply(&quot;REPLY_ONE&quot;);<br>
                      t_on_failure(&quot;FAIL_ONE&quot;);<br>
      <br>
                      #if users have priorities set, use FAIL_FORK
      failure route<br>
                      if ( isflagset(FLT_USRPREF) ) {<br>
                              t_on_failure(&quot;FAIL_FORK&quot;);<br>
                      }<br>
              }<br>
      <br>
              if (isflagset(FLT_ACCMISSED)) xlog(&quot;L_INFO&quot;,&quot;RELAY, $rm
      $ru, ACCMISSED FLAG IS SET&quot;);<br>
              else xlog(&quot;L_INFO&quot;,&quot;RELAY, $rm $ru, ACCMISSED FLAG IS NOT
      SET&quot;);<br>
              if (!t_relay()) {<br>
                      sl_reply_error();<br>
              }<br>
              exit;<br>
      }<br>
      <br>
      <br>
      # Handle requests within SIP dialogs<br>
      route[WITHINDLG] {<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;WITHINDLG, loose_route()&quot;);<br>
                              if (is_method(&quot;BYE&quot;)) {<br>
                                      xlog(&quot;L_INFO&quot;,&quot;WITHINDLG, BYE, DO
      ACCOUNTING&quot;);<br>
                                      setflag(FLT_ACC); # do accounting
      ...<br>
                                      setflag(FLT_ACCFAILED); # ... even
      if the transaction fails<br>
                              }<br>
                              route(RELAY);<br>
                      } else {<br>
                              if (is_method(&quot;SUBSCRIBE&quot;) &amp;&amp; uri
      == myself) {<br>
                                      # in-dialog subscribe requests<br>
                                      route(PRESENCE);<br>
                                      exit;<br>
                              }<br>
                              if ( is_method(&quot;ACK&quot;) ) {<br>
                                      if ( t_check_trans() ) {<br>
                                              # no loose-route, but
      stateful ACK;<br>
                                              # must be an ACK after a
      487<br>
                                              # or e.g. 404 from
      upstream server<br>
                                              t_relay();<br>
                                              exit;<br>
                                      } else {<br>
                                              # ACK without matching
      transaction ... ignore and discard<br>
                                              exit;<br>
                                      }<br>
                              }<br>
                              sl_send_reply(&quot;404&quot;,&quot;Not here&quot;);<br>
                      }<br>
                      exit;<br>
              }<br>
      }<br>
      <br>
      <br>
      # USER location service<br>
      route[LOCATION] {<br>
      <br>
        #skip if $ru is telephone number<br>
              if ($ru =~ &quot;^<a>sip:00</a>&quot;) {<br>
                      xlog(&quot;L_INFO&quot;,&quot;SKIP lookup...&quot;);<br>
              }<br>
              else {<br>
                      if (!lookup(&quot;location&quot;)) {<br>
                              switch ($rc) {<br>
                                      case -1:<br>
                                      case -3:<br>
                                              t_newtran();<br>
                                              t_reply(&quot;404&quot;, &quot;Not
      Found&quot;);<br>
                                              exit;<br>
                                      case -2:<br>
                                              sl_send_reply(&quot;405&quot;,
      &quot;Method Not Allowed&quot;);<br>
                                              exit;<br>
                              }<br>
                      }<br>
              }<br>
      <br>
              # when routing via usrloc, log the missed calls also, but
      only if user doesn&#39;t have prios set<br>
              if ( is_method(&quot;INVITE&quot;) &amp;&amp;
      !(isflagset(FLT_USRPREF))) {<br>
                      setflag(FLT_ACCMISSED);<br>
              }<br>
      }<br>
      <br>
      <br>
      # Failure route for forked calls<br>
      failure_route[FAIL_FORK] {<br>
      #!ifdef WITH_NAT<br>
              if (is_method(&quot;INVITE&quot;) &amp;&amp; (isbflagset(FLB_NATB)
      || isflagset(FLT_NATS))) {<br>
                      unforce_rtp_proxy();<br>
              }<br>
      #!endif<br>
      <br>
              if ($avp(prio) &gt;= 1) {<br>
                      $avp(prio) = $avp(prio) + 1;<br>
      <br>
                      # handle 2nd branch<br>
                      if ( ($avp(prio) == 2) &amp;&amp; (
      isflagset(FLT_USRPREF) )) {<br>
                              t_on_failure(&quot;FAIL_FORK&quot;);<br>
      <br>
                              if ($avp(prio2) =~ &quot;^<a>sip:00</a>&quot;) {<br>
                                      xlog(&quot;L_INFO&quot;,&quot;FAIL FORK, PRIO 2
      is tel number&quot;);<br>
                                      $ru = $avp(prio2) + &quot;@host&quot;;<br>
                              }<br>
                              else {<br>
                                      xlog(&quot;L_INFO&quot;,&quot;FAIL FORK, PRIO 2
      is SIP URI&quot;);<br>
                                      $ru = $avp(prio2);<br>
                                      route(LOCATION);<br>
                              }<br>
                              setflag(FLT_ACCMISSED);<br>
                      }<br>
      <br>
                      else {<br>
                              $avp(prio) = 0;<br>
                              $ru = $(avp(uuid));<br>
                              rewritehostport(&quot;host:port&quot;);<br>
                              xlog(&quot;L_INFO&quot;,&quot;FAIL FORK, VOICEMAIL
      email:$avp(email), ru:$ru, br: $br&quot;);<br>
                              append_hf(&quot;P-App-Name: voicemail\r\n&quot;);<br>
                              append_hf(&quot;P-App-Param:
      Email-Address=$avp(email)\r\n&quot;);<br>
                      }<br>
                      route(RELAY);<br>
              }<br>
      <br>
              if (t_is_canceled()) {<br>
                      exit;<br>
              }<br>
      }
      <br>
      <fieldset></fieldset>
      <br>
      </div></div><pre>_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a href="mailto:sr-users@lists.sip-router.org" target="_blank">sr-users@lists.sip-router.org</a>
<a href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users" target="_blank">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote><font color="#888888">
    <br>
    <pre cols="72">-- 
Daniel-Constantin Mierla -- <a href="http://www.asipto.com" target="_blank">http://www.asipto.com</a>
Kamailio Advanced Training, Oct 10-13, Berlin: <a href="http://asipto.com/u/kat" target="_blank">http://asipto.com/u/kat</a>
<a href="http://linkedin.com/in/miconda" target="_blank">http://linkedin.com/in/miconda</a> -- <a href="http://twitter.com/miconda" target="_blank">http://twitter.com/miconda</a></pre>
  </font></div>

</blockquote></div><br>