<html>
  <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    <div class="moz-cite-prefix">On 16/09/14 18:37, Vik Killa wrote:<br>
    </div>
    <blockquote
cite="mid:CAC-LwPPERxdUvjJtn1UOdo+6C7tQnvRgzmfxaGzZPj8sJ75Hfg@mail.gmail.com"
      type="cite">
      <div dir="ltr">Thanks Daniel,
        <div>I want to remove the htable entry after the register goes
          through, and I also want to check if the htable entry exists
          later.</div>
        <div><br>
        </div>
        <div>I see</div>
        <div><br>
        </div>
        <div>sht_rm_value_re("ha=>.*"); <br>
        </div>
      </div>
    </blockquote>
    this is going to remove all the items from the hash table -- perhaps
    you don't want to do that.<br>
    <br>
    To remove the entry you added for register once the registration was
    successful, add reply_route where you check if it is REGISTER and
    the code is 200, then remove the item using the call id (same key as
    you used to add the item).<br>
    <br>
    $sht(a=>$ci::dest_server) = $null;<br>
    <br>
    Assigning $null removes the respective item from hash table.<br>
    <br>
    <blockquote
cite="mid:CAC-LwPPERxdUvjJtn1UOdo+6C7tQnvRgzmfxaGzZPj8sJ75Hfg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>to remove the htable entry but how do i later check if the
          key exists?</div>
      </div>
    </blockquote>
    <br>
    $null can be used to test if key exists or not, like
    if($sht(a=>x)==$null)<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <blockquote
cite="mid:CAC-LwPPERxdUvjJtn1UOdo+6C7tQnvRgzmfxaGzZPj8sJ75Hfg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div><br>
        </div>
        <div>Thanks</div>
        <div>/V</div>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Tue, Sep 16, 2014 at 11:52 AM,
          Daniel-Constantin Mierla <span dir="ltr"><<a
              moz-do-not-send="true" href="mailto:miconda@gmail.com"
              target="_blank">miconda@gmail.com</a>></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>
              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
              <div>
                <div class="h5"><br>
                  <br>
                  <div>On 16/09/14 03:37, Vik Killa wrote:<br>
                  </div>
                </div>
              </div>
              <blockquote type="cite">
                <div>
                  <div class="h5">
                    <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
                          moz-do-not-send="true">"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 style="white-space:pre-wrap"> </span>if

                          (!is_method("REGISTER|PUBLISH"))</div>
                        <div><span style="white-space:pre-wrap"> </span>return;</div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap"> </span>if

                          (is_present_hf("Authorization")) {</div>
                        <div><span style="white-space:pre-wrap"> </span>add_path_received();</div>
                        <div><span style="white-space:pre-wrap"> </span>$avp(i:10)

                          = $sht(a=>$ci::dest_server);</div>
                        <div><span style="white-space:pre-wrap"> </span>avp_pushto("$du",

                          "$avp(i:10)");</div>
                        <div><span style="white-space:pre-wrap"> </span>}
                          else {</div>
                        <div><span style="white-space:pre-wrap"> </span>perl_exec("random_server");</div>
                        <div><span style="white-space:pre-wrap"> </span></div>
                        <div><span style="white-space:pre-wrap"> </span>avp_pushto("$du",

                          "$avp(i:10)");</div>
                        <div><span style="white-space:pre-wrap"> </span>$sht(a=>$ci::dest_server)

                          = $avp(i:10);</div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap"> </span>}</div>
                        <div><span style="white-space:pre-wrap"> </span></div>
                        <div><span style="white-space:pre-wrap"> </span>t_relay();<span
                            style="white-space:pre-wrap"> </span></div>
                        <div><br>
                        </div>
                        <div><span style="white-space:pre-wrap"> </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></fieldset>
                    <br>
                  </div>
                </div>
                <pre>_______________________________________________
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list
<a moz-do-not-send="true" href="mailto:sr-users@lists.sip-router.org" target="_blank">sr-users@lists.sip-router.org</a>
<a moz-do-not-send="true" 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><span class="HOEnZb"><font color="#888888">
</font></span></pre>
                <span class="HOEnZb"><font color="#888888"> </font></span></blockquote>
              <span class="HOEnZb"><font color="#888888"> <br>
                  <pre cols="72">-- 
Daniel-Constantin Mierla
<a moz-do-not-send="true" href="http://twitter.com/#%21/miconda" target="_blank">http://twitter.com/#!/miconda</a> - <a moz-do-not-send="true" href="http://www.linkedin.com/in/miconda" target="_blank">http://www.linkedin.com/in/miconda</a>
Next Kamailio Advanced Trainings 2014 - <a moz-do-not-send="true" href="http://www.asipto.com" target="_blank">http://www.asipto.com</a>
Sep 22-25, Berlin, Germany</pre>
                </font></span></div>
            <br>
            _______________________________________________<br>
            SIP Express Router (SER) and Kamailio (OpenSER) - sr-users
            mailing list<br>
            <a moz-do-not-send="true"
              href="mailto:sr-users@lists.sip-router.org">sr-users@lists.sip-router.org</a><br>
            <a moz-do-not-send="true"
              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><br>
            <br>
          </blockquote>
        </div>
        <br>
      </div>
    </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>