<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <tt>Hi Jayesh,<br>
      <br>
      do :<br>
      &nbsp;&nbsp;&nbsp; if($var(branch_id) == 1) {<br>
      <br>
      as $var(branch_id) returns an integer, not a string.<br>
      <br>
      Regards,</tt><br>
    <pre class="moz-signature" cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
    <br>
    On 09/04/2012 04:36 PM, Jayesh Nambiar wrote:
    <blockquote
cite="mid:CALvF6vCaidoKBrYUXVsFnuFuEBjw_6wu3h45qDWCcTgYYyaZEQ@mail.gmail.com"
      type="cite">Hi Bogdan,
      <div>Firstly I am using Opensips 1.7.2. And here the observations
        after I tried several things as suggested by you.</div>
      <div>Observation 1:</div>
      <div>
        <blockquote type="cite">
          <div class="gmail_quote">
            <div>lookup("location");</div>
            <div>#$branch = $ru;</div>
            <div><br>
            </div>
            <div>You suggested the above line is not required as it will
              automatically be treated as branch 0 and hence I commented
              it, but is not behaving as expected. So when I comment the
              above line and then add the code as below:</div>
            <div><br>
            </div>
            <div>avp_db_query("SELECT cli, phone_number FROM users WHERE
              user_id = '$rU', "$avp(cli), $avp(parallel_number)");</div>
          </div>
        </blockquote>
        <blockquote type="cite">
          <div class="gmail_quote">
            <div>$rU = $avp(parallel_number);</div>
            <div>$rd = my_gateway_ip;</div>
            <div>$var(uri) = "sip:"+$rU+"@"+$rd;</div>
            <div><br>
            </div>
            <div>$branch = $var(ruri);</div>
            <div>xlog("L_INFO", "Branch URI 0=$(branch(uri)[0]) AND
              Branch URI 1=$(branch(uri)[1])");</div>
          </div>
        </blockquote>
        <blockquote type="cite">
          <div class="gmail_quote">
            <div>The above line prints in syslog "Branch URI
              0=<a class="moz-txt-link-freetext" href="sip:123456789@mygateway_ip">sip:123456789@mygateway_ip</a> and Branch URI 1 = NULL"</div>
            <div>This means that when I actually call "$branch =
              some_uri" that is when the branch is created with an id.
              Because I checked adding that $branch = $ru line again and
              then syslog printed &nbsp;"Branch URI 0=<a
                moz-do-not-send="true"
                href="http://sip:1111@1.2.3.4:25380">sip:1111@1.2.3.4:25380</a>
              and Branch URI 1=<a class="moz-txt-link-freetext" href="sip:123456789@mygateway_ip">sip:123456789@mygateway_ip</a>".</div>
            <div><br>
            </div>
            <div>t_on_branch("1");</div>
            <div>t_relay();</div>
            <div>exit;</div>
            <div><br>
            </div>
          </div>
        </blockquote>
        Observation 2:</div>
      <div>Inside the branch route I write the following code:</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp;branch_route[1] {</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;$var(branch_id) = $T_branch_idx;</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if($var(branch_id) == "1") {</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xlog("L_INFO",
        "Branch-ID=$T_branch_idx")</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;insert_hf("Forwarded: Yes\r\n",
        "Call-ID");</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;uac_replace_from("<a
          moz-do-not-send="true">sip:$avp(cli)@</a><a
          moz-do-not-send="true" href="http://mydomain.com/"
          target="_blank">mydomain.com</a>");&nbsp; &nbsp;&nbsp;</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div>
      <div>&nbsp; &nbsp; &nbsp; &nbsp;}</div>
      <div><br>
      </div>
      <div><br>
      </div>
      <div>Now here I can confirm that when the branch_id is 1, it gets
        into this condition since the xlog prints &nbsp;"Branch-ID=1"
        properly when its inside the branch route; but when branch_0
        gets relayed out this header gets inserted and From header gets
        replaced whereas when branch_1 is relayed the header mentioned
        in this condition is not inserted and also the From header is
        not replaced.</div>
      <div>Basically, it behaves exactly opposite as expected !! Please
        note in this case I am creating branch twice using the $branch
        command so that $branch(uri)[0] is the one fetched from location
        and $branch(uri)[1] is the PSTN uri where the call has to be
        parallel&nbsp;forwarded.</div>
      <div>Is there something I am still doing wrong because as I
        understood; inside the branch_route based on branch_id I am
        inserting a custom header and replacing From header but this
        custom header and From header is being replaced on the
        unintended branch !!</div>
      <div>Could be that something is wrong in opensips-1.7.x. Please
        help me out here.</div>
      <div><br>
      </div>
      <div>Thanks,</div>
      <div><br>
      </div>
      <div>--- Jayesh<br>
        <blockquote type="cite">
          <div class="gmail_quote">
            <div><br>
            </div>
          </div>
        </blockquote>
        <div class="gmail_quote">On Tue, Sep 4, 2012 at 12:18 AM, Jayesh
          Nambiar <span dir="ltr">&lt;<a moz-do-not-send="true"
              href="mailto:jayesh.voip@gmail.com" target="_blank">jayesh.voip@gmail.com</a>&gt;</span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
            0.8ex; border-left: 1px solid rgb(204, 204, 204);
            padding-left: 1ex;">
            Thanks Bogdan. Will definitely try this out.<span
              class="HOEnZb"><font color="#888888">
                <div><br>
                </div>
              </font></span>
            <div><span class="HOEnZb"><font color="#888888">--- Jayesh</font></span>
              <div>
                <div class="h5"><span></span><br>
                  <br>
                  On Monday, September 3, 2012, Bogdan-Andrei Iancu
                  wrote:<br>
                  <blockquote class="gmail_quote" style="margin: 0pt 0pt
                    0pt 0.8ex; border-left: 1px solid rgb(204, 204,
                    204); padding-left: 1ex;">
                    <div bgcolor="#ffffff" text="#000000"> <tt>Hi
                        Jayesh,<br>
                        <br>
                        See my inline comments.<br>
                        <br>
                        Regards,</tt><br>
                      <pre cols="72">Bogdan-Andrei Iancu
OpenSIPS Founder and Developer
<a moz-do-not-send="true" href="http://www.opensips-solutions.com" target="_blank">http://www.opensips-solutions.com</a></pre>
                      <br>
                      On 08/31/2012 03:02 PM, Jayesh Nambiar wrote:
                      <blockquote type="cite">
                        <div class="gmail_quote">
                          <div>Hi Binan,</div>
                          <div>Thank you very much for your reply. What
                            you wrote is what I understand from all the
                            documentation present but probably the
                            concept is not working for me or probably
                            just not getting into my head. This is a
                            snippet of what I'm trying to do:</div>
                          <div><br>
                          </div>
                          <div>lookup("location");</div>
                          <div>$branch = $ru;</div>
                        </div>
                      </blockquote>
                      You do not need this last line as the $ru will be
                      automatically be considered branch 0.<br>
                      <br>
                      <blockquote type="cite">
                        <div class="gmail_quote">
                          <div><br>
                          </div>
                          <div>avp_db_query("SELECT cli, phone_number
                            FROM users WHERE user_id = '$rU',
                            "$avp(cli), $avp(parallel_number)");</div>
                          <div>$rU = $avp(parallel_number);</div>
                          <div>$rd = my_gateway_ip;</div>
                          <div>$var(uri) = "sip:"+$rU+"@"+$rd;</div>
                          <div><br>
                          </div>
                          <div>$branch = $var(ruri);</div>
                          <div><br>
                          </div>
                          <div>t_on_branch("1"); # --This is confusing
                            me---</div>
                        </div>
                      </blockquote>
                      This is correct, you are arming the branch 1,
                      which will be executed inside t_relay(), once for
                      each branch.<br>
                      <br>
                      <blockquote type="cite">
                        <div class="gmail_quote">
                          <div>t_relay();</div>
                          <div>exit;</div>
                          <div><br>
                          </div>
                          <div>branch_route[1] { #---Need to know how to
                            check for branch id here---</div>
                          <div>&nbsp; &nbsp; &nbsp; &nbsp;if(branch_id == 1) { #--- How do I
                            check for this condition??</div>
                        </div>
                      </blockquote>
                      See $T_branch_idx (<a moz-do-not-send="true"
                        href="http://www.opensips.org/html/docs/modules/1.8.x/tm.html#id294499"
                        target="_blank">http://www.opensips.org/html/docs/modules/1.8.x/tm.html#id294499</a>)<br>
                      <br>
                      <blockquote type="cite">
                        <div class="gmail_quote">
                          <div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uac_replace_from("<a
                              moz-do-not-send="true">sip:$avp(cli)@</a><a
                              moz-do-not-send="true"
                              href="http://mydomain.com" target="_blank">mydomain.com</a>");</div>
                          <div>&nbsp; &nbsp; &nbsp; &nbsp;}</div>
                          <div>}</div>
                          <div><br>
                          </div>
                          <div>The problem is I dont know how to
                            identify the branch id in the branch route.
                            Even if I set branch flag for second branch
                            using setbflag(1,1) and I check for this
                            flag in the branch route using
                            isbflagset(1,1), by the time the first
                            branch goes into branch_route, the second
                            branch is created and the condition
                            isbflagset(1,1) becomes true and the
                            uac_replace_from() gets executed for first
                            branch also. My requirement is to execute
                            this branch_route only for second branch
                            which is branch_id 1.</div>
                          <div>Isn't there any straight forward way of
                            checking the id of the branch when it comes
                            to the branch route??</div>
                          <div><br>
                          </div>
                          <div>Any help is really appreciated. Thanks.</div>
                          <div><br>
                          </div>
                          <div>--- Jayesh</div>
                          <blockquote class="gmail_quote" style="margin:
                            0pt 0pt 0pt 0.8ex; border-left: 1px solid
                            rgb(204, 204, 204); padding-left: 1ex;"> Hi,<br>
                            <br>
                            lets say you have 2 branches 0 towards user
                            in location and 1 towards PSTN.<br>
                            ?<br>
                            I suggest to use branch flags which are used
                            to activate some functions in branch level<br>
                            <br>
                            when creating the branches in main route use
                            this variable $branch() to set branch flags
                            to each indivisual branch depending on its
                            index 0 for branch 0 and 1 for branch 1.<br>
                            <br>
                            use branch routing blocks to execute certain
                            logic (it could be the manipulation ) for
                            each branch before forwarding the request.<br>
                            <br>
                            // Binan<br>
                            <br>
                            --- On Thu, 8/30/12, Jayesh Nambiar &lt;<a
                              moz-do-not-send="true">jayesh.voip@gmail.com</a>&gt;

                            wrote:<br>
                            <br>
                            From: Jayesh Nambiar &lt;<a
                              moz-do-not-send="true">jayesh.voip@gmail.com</a>&gt;<br>
                            Subject: [OpenSIPS-Users] Parallel forking
                            and per branch manipulation<br>
                            To: "OpenSIPS users mailling list" &lt;<a
                              moz-do-not-send="true">users@lists.opensips.org</a>&gt;<br>
                            Date: Thursday, August 30, 2012, 8:11 AM<br>
                            <br>
                            Hi All,I have a scenario to do parellel
                            forking between the user found in location
                            and towards a PSTN gateway. The requirement
                            here is, I have unique manipulations to be
                            done before routing the call which I believe
                            can be done using branch routes, but I'm
                            just wondering how.?<br>
                            For eg: The branch that goes to the user
                            found from location should have no FROM
                            Header manipulation and the branch that goes
                            out to PSTN gateway needs a
                            uac_replace_from("<a moz-do-not-send="true">sip:123456789@1.2.3.4</a>"),

                            and insert_hf("P-Asserted_Identity: <a
                              moz-do-not-send="true">sip:123456789@1.2.3.4</a>\r\n")

                            before calling t_relay(). There are many
                            other manipulations like this.<br>
                            How do I take the script logic to individual
                            branch routes before calling t_relay,
                            because whats happening with me is once the
                            location is looked up, I go ahead for
                            manipulations that is supposed to be done
                            for the gateway branch, but it gets
                            applicable for the branch that goes out to
                            the user as well !!<br>
                            <br>
                            Probably I am missing something on my
                            understanding on how to call branch_routes
                            while doing parallel forking.<br>
                            Thanks for any help.<br>
                            --- Jayesh<br>
                            <br>
                          </blockquote>
                        </div>
                        <pre><fieldset></fieldset>
_______________________________________________
Users mailing list
<a moz-do-not-send="true">Users@lists.opensips.org</a>
<a moz-do-not-send="true" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users" target="_blank">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
                      </blockquote>
                    </div>
                  </blockquote>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
    </blockquote>
  </body>
</html>