<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <tt>Hi Muhammad,<br>
      <br>
      you can try to use set the 't_on_branch_failure' in your branch
      and then catch the 302 message in the
      'event_route[tm:branch-failure:id]'. From there you should be able
      to do what you need.<br>
      <br>
      Regards<br>
      Marco<br>
    </tt><br>
    <div class="moz-cite-prefix">On 2/26/20 6:37 PM, Muhammad Zaka
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:VE1PR03MB5199E5638245BB269012AAD2EDEA0@VE1PR03MB5199.eurprd03.prod.outlook.com">
      <pre class="moz-quote-pre" wrap="">Hi Alex,

We have a similar issue (slightly complex) as it involves sip parallel forking.

The issue is that failure_route[] occurs when all sip forked are exhausted even though "302 Moved Temporarily" has been responded back by one of the SIP endpoint quite quickly.

So, we wish to handle 302 onreply_route[] as it is received quite promptly but as you pointed out Kamailio doesn’t let us set the contact header or append_to_reply.

Please can you suggest me is there any way out we can change the sip contact when using sip parallel forking.

Many Thanks

Regards
Muhammad Adil M Zaka

-----Original Message-----
From: sr-users <a class="moz-txt-link-rfc2396E" href="mailto:sr-users-bounces@lists.kamailio.org"><sr-users-bounces@lists.kamailio.org></a> On Behalf Of Alex Balashov
Sent: 16 January 2020 22:32
To: <a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
Subject: Re: [SR-Users] Trouble with 302 Redirect

Try doing this in a failure_route[]; onreply_route[] isn't really meant to transform replies, just to passively observe or drop them.

Also, you'll want to use append_to_reply():

   <a class="moz-txt-link-freetext" href="https://kamailio.org/docs/modules/5.3.x/modules/textops.html#textops.f.append_to_reply">https://kamailio.org/docs/modules/5.3.x/modules/textops.html#textops.f.append_to_reply</a>

Note that the conditions that give rise to the invocation of a failure_route are broader and somewhat more abstract than any given SIP reply -- e.g. transaction reply timeouts. So, you would want to structure your failure_route like this:

   failure_route[REDIRECT_HANDLE] {
      if(t_is_canceled())
         exit;

      if(t_branch_timeout()) {
         # Handle the timeout case...
         
         exit;
      }

      # Use $T_rpl to access reply code ($rs) and reply reason if needed
      # ($rs), per:
      #
      # <a class="moz-txt-link-freetext" href="https://www.kamailio.org/wiki/cookbooks/5.3.x/pseudovariables#t_rpl_pv">https://www.kamailio.org/wiki/cookbooks/5.3.x/pseudovariables#t_rpl_pv</a>

      if($T_rpl($rs) == 486) {
         append_to_reply("Contact: <a class="moz-txt-link-rfc2396E" href="sip:..."><sip:...></a>\r\n");
         t_reply("302", "Moved Temporarily");
         exit;
      }

      # Some other case.
   }

-- Alex

On Thu, Jan 16, 2020 at 03:54:54PM -0500, Jim Leahy wrote:

</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">Hi All,
   I'm having some issues trying to properly send a '302 Moved Temporarily'
reply to the calling UAC (UAC1) when the remote UAC (UAC2) returns a 
486 status (Do Not Disturb). The goal is to redirect UAC1 to a 
voicemail server when UAC2 is in DND.
Here are the pertinent parts of my config:

route {
        # drop some things right away
        route(DROP);

        # perform sanity check
        route(SANITYCHECK);

        # handle registrations
        if(is_method("REGISTER")) {
                route(REGISTRATION);
                exit;
        }

        # handle invites
        if(is_method("INVITE")) {
                route("INVITE");
                exit;
        }

        route(RELAY);
}

route[INVITE] {
        # add this proxy to the record-route so it stays in the loop
        record_route();

        # if we can find this user in the location DB...
        if(lookup("location")) {
                # relay the invite to the new dURI
                t_on_failure("FOURDIGITFAIL");
                t_on_reply("FOURDIGITREPLY");
                route(RELAY);
                # go back to the main route
                return;
        }

onreply_route[FOURDIGITREPLY] {
        if(t_check_status("4[0-9]{2}")) {
                t_reply("302", "Moved Temporarily");
        }
}

I'm having issues with the t_reply in the onreply_route. It 
successfully sends the reply, but I can't seem to set the Contact 
header properly. I'm trying to set it to the location of the user's 
mailbox on the voicemail sever (ie <a class="moz-txt-link-freetext" href="sip:1000@vmpbx.domain.com">sip:1000@vmpbx.domain.com</a>), but nothing I try works. I've tried:
     remove_hf("Contact");
     insert_hf("Contact: <a class="moz-txt-link-freetext" href="sip:1000@vmpbx.domain.com">sip:1000@vmpbx.domain.com</a>");
     t_reply("302", "Moved Temporarily");

But as I understand it, that just changes the header in the reply from 
UAC2, not the reply I'm sending to UAC1

Then I tried:
     append_to_reply("Contact: <a class="moz-txt-link-freetext" href="sip:1000@vmpbx.domain.com">sip:1000@vmpbx.domain.com</a>" );
     t_reply("302", "Moved Temporarily");

But I can't use append_to_reply in an onreply block.
How can I change the Contact header in the reply that's sent? Am I 
just going about this the wrong way? Any help would be appreciated. 
Thanks
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">
</pre>
      <blockquote type="cite">
        <pre class="moz-quote-pre" wrap="">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
      </blockquote>
      <pre class="moz-quote-pre" wrap="">

--
Alex Balashov | Principal | Evariste Systems LLC

Tel: +1-706-510-6800 / +1-800-250-5920 (toll-free)
Web: <a class="moz-txt-link-freetext" href="http://www.evaristesys.com/">http://www.evaristesys.com/</a>, <a class="moz-txt-link-freetext" href="http://www.csrpswitch.com/">http://www.csrpswitch.com/</a>

_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a>
<a class="moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <br>
    <div class="moz-signature">-- <br>
      <div style="line-height:16px; margin:6px 0; padding:8px 8px 8px
        8px; border-top:1px #aeb1a6 dotted; border-bottom:1px #aeb1a6
        dotted; font-family: 'Lucida Sans', Lucida Grande, Verdana,
        Arial, Sans-Serif; font-size:11px; color:#555555;"> <strong
          style="color:#333333; text-transform:uppercase;
          font-size:10px;"> Marco Capetta </strong> <br>
        VoIP Developer
        <p> <a href="http://www.sipwise.com" style="color:rgb(0, 136,
            204) !important; text-decoration:none !important;
            border-bottom:1px dotted #AAA;"> Sipwise GmbH </a> , Campus
          21/Europaring F15<br>
          AT-2345 Brunn am Gebirge </p>
        <p> Phone:  <a href="tel:+4313012044" style="color:rgb(0, 136,
            204) !important; text-decoration:none !important;
            border-bottom:1px dotted #AAA;"> +43(0)1 301 2044 </a> <br>
          Email:  <a href="mailto:mcapetta@sipwise.com"
            style="color:rgb(0, 136, 204) !important;
            text-decoration:none !important; border-bottom:1px dotted
            #AAA;"> mcapetta@sipwise.com </a> <br>
          Website:  <a href="http://www.sipwise.com"
            style="color:rgb(0, 136, 204) !important;
            text-decoration:none !important; border-bottom:1px dotted
            #AAA;"> www.sipwise.com </a> </p>
        <p>
          Particulars according Austrian Companies Code paragraph 14<br>
          "Sipwise GmbH" - Europaring F15 - 2345 Brunn am Gebirge<br>
          FN:305595f, Commercial Court Vienna, ATU64002206
        </p>
      </div>
    </div>
  </body>
</html>