<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    if you want to rely on kamailio to memorize where to send the
    following register, the hash table is the right tool.<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <div class="moz-cite-prefix">On 16/09/14 03:37, Vik Killa wrote:<br>
    </div>
    <blockquote
cite="mid:CAC-LwPPy8f_JsFtyy6VbaeKtxtLgNoY65ZKFowmrhfe_qfdsMQ@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hello,
        <div>I'm learning Kamailio. My ultimate goal is to be able to
          route SIP messages from User Agents to specific FS boxes.</div>
        <div><br>
        </div>
        <div>I'm starting with routing REGISTER messages.</div>
        <div>I used app_perl to randomly lookup one of the FS box's IP
          Address from postgres database, then I stored the IP in avp
          and then in hash. It seemed like overkill but it was the only
          way I could keep the FS IP address in memory between the first
          REGISTER and REGISTER with Auth.</div>
        <div><br>
        </div>
        <div>my app_perl script sets the IP as follows:</div>
        <div><br>
        </div>
        <div>
          <div>my $sth = $dbh->prepare("SELECT ip_address FROM
            host_machine WHERE is_online = true ORDER BY random() LIMIT
            1");</div>
          <div>$sth->execute();</div>
          <div>my $host_ip_address = $sth->fetchrow();</div>
        </div>
        <div>Kamailio::AVP::add(10, <a class="moz-txt-link-rfc2396E" href="sip:$host_ip_address:5060">"sip:$host_ip_address:5060"</a>);<br>
        </div>
        <div><br>
        </div>
        <div>And here is my kamailio.cfg for REGISTERs</div>
        <div><br>
        </div>
        <div>
          <div>route[REGISTRAR]</div>
          <div>{</div>
          <div><br>
          </div>
          <div><span class="" style="white-space:pre"> </span>if
            (!is_method("REGISTER|PUBLISH"))</div>
          <div><span class="" style="white-space:pre"> </span>return;</div>
          <div><br>
          </div>
          <div><span class="" style="white-space:pre"> </span>if
            (is_present_hf("Authorization")) {</div>
          <div><span class="" style="white-space:pre"> </span>add_path_received();</div>
          <div><span class="" style="white-space:pre"> </span>$avp(i:10)
            = $sht(a=>$ci::dest_server);</div>
          <div><span class="" style="white-space:pre"> </span>avp_pushto("$du",
            "$avp(i:10)");</div>
          <div><span class="" style="white-space:pre"> </span>} else {</div>
          <div><span class="" style="white-space:pre"> </span>perl_exec("random_server");</div>
          <div><span class="" style="white-space:pre"> </span></div>
          <div><span class="" style="white-space:pre"> </span>avp_pushto("$du",
            "$avp(i:10)");</div>
          <div><span class="" style="white-space:pre"> </span>$sht(a=>$ci::dest_server)
            = $avp(i:10);</div>
          <div><br>
          </div>
          <div><span class="" style="white-space:pre"> </span>}</div>
          <div><span class="" style="white-space:pre"> </span></div>
          <div><span class="" style="white-space:pre"> </span>t_relay();<span
              class="" style="white-space:pre"> </span></div>
          <div><br>
          </div>
          <div><span class="" style="white-space:pre"> </span>exit;<br>
          </div>
          <div>}</div>
        </div>
        <div><br>
        </div>
        <div><br>
        </div>
        <div>"random_server" is the perl script to get the FS IP
          address...</div>
        <div>Seems crude but works... </div>
        <div>I'm sure there is probably a more elegant way to do what im
          trying so any advice and criticism is appreciated, thank you!</div>
        <div><br>
        </div>
        <div>/V</div>
        <div><br>
        </div>
        <div><br>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a>
<a class="moz-txt-link-freetext" href="http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users">http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla
<a class="moz-txt-link-freetext" href="http://twitter.com/#!/miconda">http://twitter.com/#!/miconda</a> - <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/miconda">http://www.linkedin.com/in/miconda</a>
Next Kamailio Advanced Trainings 2014 - <a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a>
Sep 22-25, Berlin, Germany</pre>
  </body>
</html>