<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>I just updated the code to allow unregister() in all route block
      types.</p>
    <p>Cheers,<br>
      Daniel<br>
    </p>
    <div class="moz-cite-prefix">On 13.08.19 09:38, Joel Serrano wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAMtXxQmQ0xG9rKgUHggD-cfVrO6++w9SLB806O0kEYPW+=G6qQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Great!!! This is good to know!!
        <div><br>
        </div>
        <div>Thank you Daniel!</div>
        <div>Joel.</div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr" class="gmail_attr">On Tue, Aug 13, 2019 at 12:36
          AM Daniel-Constantin Mierla <<a
            href="mailto:miconda@gmail.com" moz-do-not-send="true">miconda@gmail.com</a>>
          wrote:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
          <div bgcolor="#FFFFFF">
            <p>Hello,</p>
            <p>that is a "known hack" to go around the route block type
              restrictions for functions.</p>
            <p>The purpose of the restrictions is to limit the usage in
              the blocks where the developer intended to allow the
              function to be used, like she/he tested for those route
              blocks or thought it is enough there and didn't analyze
              the effects when using in other route block types.</p>
            <p>However, many functions are just safe to use in other
              route block types than those imposed by the developer.</p>
            <p>Probably the unregister() is safe in onreply block,
              because it doesn't need to generate a reply or use
              information from request URI.</p>
            <p>Cheers,<br>
              Daniel<br>
            </p>
            <div class="gmail-m_-7613282557379430386moz-cite-prefix">On
              13.08.19 07:28, Joel Serrano wrote:<br>
            </div>
            <blockquote type="cite">
              <div dir="ltr">Forgot to add:<br>
                <div><br>
                </div>
                <div><font face="monospace">root@csbc01:~# kamailio -V<br>
                    version: kamailio 5.3.0-dev7 (x86_64/linux)<br>
                    flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP,
                    TLS_HOOKS, USE_RAW_SOCKS, DISABLE_NAGLE, USE_MCAST,
                    DNS_IP_HACK, SHM_MMAP, PKG_MALLOC, Q_MALLOC,
                    F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX,
                    FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE,
                    USE_DNS_FAILOVER, USE_NAPTR, USE_DST_BLACKLIST,
                    HAVE_RESOLV_RES<br>
                    ADAPTIVE_WAIT_LOOPS 1024, MAX_RECV_BUFFER_SIZE
                    262144, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT
                    PKG_SIZE 8MB<br>
                    poll method support: poll, epoll_lt, epoll_et,
                    sigio_rt, select.<br>
                    id: unknown<br>
                    compiled with gcc 8.3.0<br>
                    root@csbc01:~#</font><br>
                </div>
                <div><br>
                </div>
                <div><br>
                </div>
              </div>
              <br>
              <div class="gmail_quote">
                <div dir="ltr" class="gmail_attr">On Mon, Aug 12, 2019
                  at 2:13 PM Joel Serrano <<a
                    href="mailto:joel@textplus.com" target="_blank"
                    moz-do-not-send="true">joel@textplus.com</a>>
                  wrote:<br>
                </div>
                <blockquote class="gmail_quote" style="margin:0px 0px
                  0px 0.8ex;border-left:1px solid
                  rgb(204,204,204);padding-left:1ex">
                  <div dir="ltr">
                    <div dir="ltr">
                      <div dir="ltr">Hello, <br>
                        <div><br>
                        </div>
                        <div>I'm playing around with the unregister()
                          function from the registrar module:</div>
                        <div><br>
                        </div>
                        <div><a
href="https://www.kamailio.org/docs/modules/devel/modules/registrar.html#registrar.f.unregister"
                            target="_blank" moz-do-not-send="true">https://www.kamailio.org/docs/modules/devel/modules/registrar.html#registrar.f.unregister</a><br>
                        </div>
                        <div><br>
                        </div>
                        <div>Docs say that that it can be used
                          in REQUEST_ROUTE or FAILURE_ROUTE.</div>
                        <div><br>
                        </div>
                        <div>I needed it in REPLY_ROUTE, and before
                          reading the docs I tried it and got this
                          error:</div>
                        <div><br>
                        </div>
                        <div>Aug 12 15:52:44 csbc01 kamailio: CRITICAL:
                          <core> [core/cfg.y:3526]: yyerror_at():
                          parse error in config file
                          /etc/kamailio/csbc/reply_routes.cfg, line 27,
                          column 71: Command cannot be used in the
                          block#012<br>
                          Aug 12 15:52:44 csbc01 kamailio[12737]: ERROR:
                          bad config file (1 errors)<br>
                        </div>
                        <div><br>
                        </div>
                        <div>But, I have this working on another setup,
                          I compared, and my difference is that I'm
                          running unregister() inside a route, and
                          calling that route from reply_route, and that
                          works (and by works, I mean it also does what
                          it is supposed to do, which is unregister the
                          AoR).</div>
                        <div><br>
                        </div>
                        <div>So this doesn't work:</div>
                        <div><font face="monospace"><br>
                          </font></div>
                        <div><font face="monospace">...</font></div>
                        <div><font face="monospace">onreply_route[MANAGE_REG_REPLY]
                            {<br>
                          </font></div>
                        <div><font face="monospace">   
                             if(status=~"2[0-9][0-9]") {<br>
                                     if(($sel(contact.expires)==0) ||
                            ($hdr(Expires)==0)){<br>
                                        if (unregister("location",
                            "$sht(sipserver=>$fU::contact)")) {<br>
                                            xlog("L_NOTICE", "[usrloc]
                            removed user location\n");<br>
                                        }<br>
                                        route(DEL_SIPSERVER);<br>
                          </font></div>
                        <div><font face="monospace">}</font></div>
                        <div><font face="monospace">...</font></div>
                        <div><br>
                        </div>
                        <div>But this works:</div>
                        <div><br>
                        </div>
                        <div>
                          <div><font face="monospace">...</font></div>
                          <div><font face="monospace">onreply_route[MANAGE_REG_REPLY]
                              {<br>
                            </font></div>
                          <div><font face="monospace">   
                               if(status=~"2[0-9][0-9]") {<br>
                                       if(($sel(contact.expires)==0) ||
                              ($hdr(Expires)==0)){</font></div>
                          <div><font face="monospace">           
                              route(UNREG_CUSTOMER);<br>
                                          route(DEL_SIPSERVER);<br>
                            </font></div>
                          <div><font face="monospace">}</font></div>
                          <div><font face="monospace">...</font></div>
                          <div><font face="monospace"><br>
                            </font></div>
                          <div><font face="monospace">...</font></div>
                          <div>
                            <div><font face="monospace">route[UNREG_CUSTOMER]
                                {</font></div>
                          </div>
                          <div><font face="monospace">            if
                              (unregister("location",
                              "$sht(sipserver=>$fU::contact)")) {<br>
                                              xlog("L_NOTICE", "[usrloc]
                              removed user location\n");<br>
                                          }<br>
                            </font></div>
                          <div><font face="monospace">}</font></div>
                          <div><font face="monospace">...</font></div>
                        </div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div>So I'm in no-mans-land right now, docs say
                          it's not allowed in REPLY_ROUTE, and if I try
                          it it will fail, but if I try it inside a
                          route, it woks (hack?).</div>
                        <div><br>
                        </div>
                        <div>What is the correct approach here? Should
                          unregister() be valid in reply_route (like
                          other similar functions, for example: save())
                          and therefor docs should be updated and the
                          error in the logs should also be updated, or
                          if it's really not supported, shouldn't
                          Kamailio not let me use it anywhere that a
                          ends up being called from reply_route?</div>
                        <div><br>
                        </div>
                        <div>I hope I have explained myself correctly.
                          As always, please let me know if this should
                          be a GH issue instead and I'll happily create
                          it.</div>
                        <div><br>
                        </div>
                        <div>Thanks, </div>
                        <div>Joel.</div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                        <div><br>
                        </div>
                      </div>
                    </div>
                  </div>
                </blockquote>
              </div>
              <br>
              <fieldset
                class="gmail-m_-7613282557379430386mimeAttachmentHeader"></fieldset>
              <pre class="gmail-m_-7613282557379430386moz-quote-pre">_______________________________________________
Kamailio (SER) - Users Mailing List
<a class="gmail-m_-7613282557379430386moz-txt-link-abbreviated" href="mailto:sr-users@lists.kamailio.org" target="_blank" moz-do-not-send="true">sr-users@lists.kamailio.org</a>
<a class="gmail-m_-7613282557379430386moz-txt-link-freetext" href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" target="_blank" moz-do-not-send="true">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a>
</pre>
            </blockquote>
            <pre class="gmail-m_-7613282557379430386moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="gmail-m_-7613282557379430386moz-txt-link-abbreviated" href="http://www.asipto.com" target="_blank" moz-do-not-send="true">www.asipto.com</a>
<a class="gmail-m_-7613282557379430386moz-txt-link-abbreviated" href="http://www.twitter.com/miconda" target="_blank" moz-do-not-send="true">www.twitter.com/miconda</a> -- <a class="gmail-m_-7613282557379430386moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda" target="_blank" moz-do-not-send="true">www.linkedin.com/in/miconda</a></pre>
          </div>
        </blockquote>
      </div>
    </blockquote>
    <pre class="moz-signature" cols="72">-- 
Daniel-Constantin Mierla -- <a class="moz-txt-link-abbreviated" href="http://www.asipto.com">www.asipto.com</a>
<a class="moz-txt-link-abbreviated" href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a class="moz-txt-link-abbreviated" href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a></pre>
  </body>
</html>