<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    <div class="moz-cite-prefix">On 9/17/13 1:52 PM, Steve Davies wrote:<br>
    </div>
    <blockquote
cite="mid:CABFTEGVB4OEFnHwAOO988Kx3SPR4bHK5fp5j6++3XTkJx9k7-g@mail.gmail.com"
      type="cite">
      <div dir="ltr">Hi Daniel, Olle,<br>
        <div class="gmail_extra"><br>
          <br>
          <div class="gmail_quote">On 16 September 2013 21:30,
            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>
            <div> </div>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
              <div bgcolor="#FFFFFF" text="#000000">you can call save()
                for 200ok received from downstream. In case you deal
                with nat or multiple local sockets, you need to call the
                functions for fixing the registration as well as storing
                the local socket.<br>
                <br>
                The processing can be like:<br>
                - forward register<br>
                - if getting 200ok, call save() for it<br>
                - if local timeout, call save in failure route -- you
                will have to call it via a sub-route, because save() is
                only allowed in request route and reply route, although
                failure_route should be safe for it<br>
                - if other reply from downstram, let it go to the phone<br>
              </div>
            </blockquote>
            <div><br>
            </div>
            <div><br>
            </div>
            <div>I've made a start with this but need a little more
              help.</div>
            <div><br>
            </div>
            <div>In route block [SIPOUT], in the case of a request going
              to a foreign domain I added:</div>
            <div><br>
            </div>
            <div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">#
                we need to track the reply to the REGISTER since we need
                to also save locally<br>
                if ( is_method("REGISTER") ) {<br>
                <span class="" style="white-space:pre"> </span>t_on_reply("REGISTER_REPLY");<br>
                <span class="" style="white-space:pre"> </span>t_on_failure("REGISTER_FAILURE");<br>
                }</blockquote>
            </div>
            <div><br>
            </div>
            <div>So this "captures" the reply or failure.</div>
            <div><br>
            </div>
            <div>Then:</div>
            <div><br>
            </div>
            <div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
                onreply_route[REGISTER_REPLY] {<br>
                <span class="" style="white-space:pre"> </span># Got a
                reply to a register from upstream.  Save locally if its
                an OK<br>
                <span class="" style="white-space:pre"> </span>if
                (t_check_status("200")) {<br>
                <span class="" style="white-space:pre"> </span>save("location",
                "0x02", "<a class="moz-txt-link-freetext" href="sip:$">sip:$</a><a moz-do-not-send="true"
                  href="mailto:tU@local.domain.com">tU@local.domain.com</a>");<br>
                <span class="" style="white-space:pre"> </span>append_hf("X-Runway-Trace:
                Runway saved registration as $<a moz-do-not-send="true"
                  href="mailto:tU@local.domain.com">tU@local.domain.com</a>\r\n");<br>
                <span class="" style="white-space:pre"> </span>}<br>
                }</blockquote>
            </div>
            <div><br>
            </div>
            <div>The problem I have is that the save operates based on
              the content of the 200 OK reply.</div>
            <div><br>
            </div>
            <div>So what goes into my DB for a register is like so:</div>
            <div><br>
            </div>
            <div>
              <div><font face="courier new, monospace">           id: 31</font></div>
              <div><font face="courier new, monospace">         ruid:
                  uloc-52383743-20e9-2</font></div>
              <div><font face="courier new, monospace">     username:
                  2686959</font></div>
              <div><font face="courier new, monospace">       domain:
                  NULL</font></div>
              <div><font face="courier new, monospace">      contact:
                  <a class="moz-txt-link-freetext" href="sip:2686959@172.16.230.1:36574;rinstance=212220b8566c4337;transport=udp">sip:2686959@172.16.230.1:36574;rinstance=212220b8566c4337;transport=udp</a></font></div>
              <div><font face="courier new, monospace">     received:
                  sip:<a moz-do-not-send="true"
                    href="http://10.64.5.16:5060">10.64.5.16:5060</a></font></div>
              <div><font face="courier new, monospace">         path:
                  NULL</font></div>
              <div><font face="courier new, monospace">      expires:
                  2013-09-17 14:32:24</font></div>
              <div><font face="courier new, monospace">            q:
                  -1.00</font></div>
              <div><font face="courier new, monospace">       callid:
                  MDA1MzRmZDQzZmMxNzhlNWUwMGUzNmYwNGYwZTM1YTc</font></div>
              <div><font face="courier new, monospace">         cseq: 2</font></div>
              <div><font face="courier new, monospace">last_modified:
                  2013-09-17 13:32:24</font></div>
              <div><font face="courier new, monospace">        flags: 0</font></div>
              <div><font face="courier new, monospace">       cflags: 0</font></div>
              <div><font face="courier new, monospace">   user_agent:
                  n/a</font></div>
              <div><font face="courier new, monospace">       socket:
                  udp:<a moz-do-not-send="true"
                    href="http://10.64.5.16:5060">10.64.5.16:5060</a></font></div>
              <div><font face="courier new, monospace">      methods:
                  NULL</font></div>
              <div><font face="courier new, monospace">     instance:
                  NULL</font></div>
              <div><font face="courier new, monospace">       reg_id: 0</font></div>
            </div>
            <div><br>
            </div>
            <div>So this is OK, but the received and socket are both
              wrong (they are the "outside" interface of my proxy, where
              the reply came in.  The registering phone actually talks
              to Kamailio on the 172.16.230.128 interface).</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    For the received field, you should call fix_nated_register() when
    you get the REGISTER (not for the reply). Or build the value for
    received_avp
    (<a class="moz-txt-link-freetext" href="http://kamailio.org/docs/modules/stable/modules/registrar.html#idp84696">http://kamailio.org/docs/modules/stable/modules/registrar.html#idp84696</a>)
    manually in config from source ip, source port and transport.<br>
    <br>
    With the socket is a bit more complex in this case, with multiple
    network interfaces, it can be set via a header, but
    msg_apply_changes() works on reply only with development version.
    Practically is about using the two parameters of registrar module:<br>
    <br>
    -
    <a class="moz-txt-link-freetext" href="http://kamailio.org/docs/modules/stable/modules/registrar.html#idp115832">http://kamailio.org/docs/modules/stable/modules/registrar.html#idp115832</a><br>
    <br>
    It might me easier to make a patch to provide custom socket value
    via an avp (like for received value), instead of header (this with
    header was added long time ago for replicated registrations).<br>
    <br>
    Is the subscriber having more than one phone? Or is restricted to
    have only one device? IIRC, with some (old?) versions of asterisk,
    only one phone was used. If it is only for one phone, you can try a
    different approach:<br>
    <br>
    - use save() with no reply flag for REGISTER<br>
    - forward the register downstream<br>
    - in failure route, if it is a reply received from downstream, use
    unregister()<br>
    <br>
    There will be a short time window that the phone is registered
    locally. You can optimize it to call save() only when Authorization
    header is present in REGISTER, as you know downstream is always
    authenticating.<br>
    <br>
    The development version (to be 4.1.0 in aprox. 2months) works better
    with this approach, allowing even multiple phones for same
    subscriber. That because save() returns an unique id (ruid) for the
    contact, that can be passed as 3rd parameter to unregister() to
    remove only that specific contact.<br>
    <br>
    <blockquote
cite="mid:CABFTEGVB4OEFnHwAOO988Kx3SPR4bHK5fp5j6++3XTkJx9k7-g@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div><br>
            </div>
            <div>More of a problem is what happens for an "unregister".</div>
            <div><br>
            </div>
            <div>Here's the REGISTER as forwarded by Kamailio and the
              reply that comes back and is processed in the
              onreply_route:</div>
            <div><br>
            </div>
            <div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">U
                2013/09/17 13:22:58.004730 <a moz-do-not-send="true"
                  href="http://10.64.5.16:5060">10.64.5.16:5060</a>
                -> x.x.x.60:5060<br>
                REGISTER sip:<a moz-do-not-send="true"
                  href="http://vc2.connection-telecom.com">vc2.connection-telecom.com</a>
                SIP/2.0.<br>
                Via: SIP/2.0/UDP
                10.64.5.16;branch=z9hG4bK66a6.f18d2a5.0.<br>
                Via: SIP/2.0/UDP
172.16.230.1:50108;branch=z9hG4bK-d8754z-f3d2c8070cecc90e-1---d8754z-;rport=50108.<br>
                Max-Forwards: 16.<br>
                Contact:
<a class="moz-txt-link-rfc2396E" href="sip:2686959@172.16.230.1:50108;rinstance=36d56481f191d185;transport=udp"><sip:2686959@172.16.230.1:50108;rinstance=36d56481f191d185;transport=udp></a>;expires=0.<br>
                To: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@xxxx.connection-telecom.com">sip:2686959@xxxx.connection-telecom.com</a>>.<br>
                From: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@xxxx.connection-telecom.com">sip:2686959@xxxx.connection-telecom.com</a>>;tag=114bde0a.<br>
                Call-ID: ZmUyY2JiOWQzMWE3OTM3YTNjNTM1OGUxOTE5Njc2ZTk.<br>
                CSeq: 4 REGISTER.<br>
                Allow: INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY,
                MESSAGE, SUBSCRIBE, INFO.<br>
                User-Agent: Bria 3 release 3.5.4 stamp 70878.<br>
                Authorization: Digest username="2686959",realm="<a
                  moz-do-not-send="true"
                  href="http://xxxx.connection-telecom.com">xxxx.connection-telecom.com</a>",nonce="52383baf2e3b9efcb10180e2ad059ff0ae7fa675",uri="sip:<a
                  moz-do-not-send="true"
                  href="http://vc2.connection-telecom.com">vc2.connection-telecom.com</a>",response="bad296f5041c869c330f015c4dcb6351",algorithm=MD5.<br>
                Content-Length: 0.<br>
                P-hint: outbound.</blockquote>
              <div>.</div>
              <div><br>
              </div>
              <div><br>
              </div>
              <blockquote class="gmail_quote" style="margin:0px 0px 0px
0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
                U 2013/09/17 13:22:58.226378 x.x.x.60:5060 -> <a
                  moz-do-not-send="true" href="http://10.64.5.16:5060">10.64.5.16:5060</a><br>
                SIP/2.0 200 OK.<br>
                Via: SIP/2.0/UDP
                10.64.5.16;branch=z9hG4bK66a6.f18d2a5.0;rport=5060.<br>
                Via: SIP/2.0/UDP
172.16.230.1:50108;branch=z9hG4bK-d8754z-f3d2c8070cecc90e-1---d8754z-;rport=50108.<br>
                To: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@xxxx.connection-telecom.com">sip:2686959@xxxx.connection-telecom.com</a>>;tag=4bb452afea88ea368a51bf5f3eee867d.8da4.<br>
                From: "vc2 2686959"<<a moz-do-not-send="true"
                  href="mailto:sip%3A2686959@xxxx.connection-telecom.com">sip:2686959@xxxx.connection-telecom.com</a>>;tag=114bde0a.<br>
                Call-ID: ZmUyY2JiOWQzMWE3OTM3YTNjNTM1OGUxOTE5Njc2ZTk.<br>
                CSeq: 4 REGISTER.<br>
                Server: Telviva SIP proxy.<br>
                Content-Length: 0.</blockquote>
              <div><br>
              </div>
            </div>
            <div>So the 200 OK does not have the Contact header.</div>
            <div>
              <br>
            </div>
            <div>On the save Kamailio does not remove the existing
              registration from the location table, so the unregister
              isn't effective for the local location table.</div>
            <div><br>
            </div>
            <div>Is there a way to get the save to find the original
              request?  Can I pull the original request back via tm
              module somehow?  Other ideas on getting this right?</div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    You can call unregister() if the reply for REGISTER has no contacts.<br>
    <br>
    Cheers,<br>
    Daniel<br>
    <br>
    <blockquote
cite="mid:CABFTEGVB4OEFnHwAOO988Kx3SPR4bHK5fp5j6++3XTkJx9k7-g@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div class="gmail_extra">
          <div class="gmail_quote">
            <div><br>
            </div>
            <div>Thanks,</div>
            <div>Steve</div>
            <div><br>
            </div>
            <div><br>
            </div>
            <div> </div>
          </div>
        </div>
      </div>
    </blockquote>
    <br>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla - <a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a>
<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>
Kamailio Advanced Trainings - Berlin, Oct 21-24; Miami, Nov 11-13, 2013
  - more details about Kamailio trainings at <a class="moz-txt-link-freetext" href="http://www.asipto.com">http://www.asipto.com</a> -
</pre>
  </body>
</html>