<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">With the below, we loop through all of the contacts that match $fu, but only unregister the one matching the $ci of the 200 OK that is associated with the unregister (Expires: 0) request from the upstream server. <div class=""><br class=""></div><div class="">It actually has 3 parts.  For completeness, I probably should have added them all.  Below:</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">route[REGISTRAR] {</div><div class=""><br class=""></div><div class="">….</div><div class="">do stuff</div><div class="">….</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">   </span>if (search_hf("Expires", "^0$", "a")) {</div><div class=""><br class="">                ….</div><div class=""><span class="Apple-tab-span" style="white-space:pre">           </span>do stuff</div><div class=""><span class="Apple-tab-span" style="white-space:pre">          </span>….</div><div class=""><br class=""></div><div class="">                t_on_reply("UNREGISTER");<br class="">                xlog("L_INFO", "Processing unregister event from $si To: $tu\n");<br class="">                route(RELAY);<br class="">                exit;<br class="">            }</div><div class="">….</div><div class="">do stuff</div><div class="">….</div><div class=""><br class=""></div><div class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">onreply_route[UNREGISTER] {<br class="">    if (t_check_status("200")) {<br class="">        route(UNREG);<br class="">    }<br class="">}</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">route[UNREG] {<br class="">    reg_fetch_contacts("location", "$fu", "un_reg");<br class="">    $var(i) = 0;<br class="">    while ($var(i) < $(ulc(un_reg=>count))) {<br class="">        $var(ul_callid) = $(ulc(un_reg=>callid)[$var(i)]);<br class="">        $var(ul_ruid) = $(ulc(un_reg=>ruid)[$var(i)]);<br class="">        if ($var(ul_callid) == $ci) {<br class="">            xlog("L_INFO", "Unregistering contact $tu Ruid: $var(ul_ruid)\n");<br class="">            unregister("location", "$fu", "$var(ul_ruid)");<br class="">            $sht(regs=>$fU@$fd~$ci)=$null;<br class="">        }<br class="">        $var(i) = $var(i) + 1;<br class="">    }<br class="">}<br class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class="Apple-interchange-newline">- Charles</div><div class=""><br class=""></div></div><br class="Apple-interchange-newline" style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class="Apple-interchange-newline">

</div>
<div><br class=""><blockquote type="cite" class=""><div class="">On Feb 21, 2021, at 8:45 AM, David Villasmil <<a href="mailto:david.villasmil.work@gmail.com" class="">david.villasmil.work@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="auto" class="">Beware that since you’re removing all contacts, if any are valid and if any of the contacts that did not unregister is called, Kamailio won’t find them.</div><div dir="auto" class=""><br class=""></div><div dir="auto" class="">If what you need is not force only one contact per user, maybe look at </div><div dir="auto" class=""><div class=""><a href="http://www.kamailio.net/docs/modules/5.4.x/modules/registrar.html#registrar.f.save" class="">http://www.kamailio.net/docs/modules/5.4.x/modules/registrar.html#registrar.f.save</a></div><br class=""></div><div class=""><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 21 Feb 2021 at 13:14, Charles Phillips <<a href="mailto:charles@rustybike.com" class="">charles@rustybike.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)"><div style="word-wrap:break-word;line-break:after-white-space" class="">Sorted it.  I needed to loop through the contacts, then select the correct ruid based on $ci<div class=""><br class=""></div><div class="">For completeness, here is my solution:</div><div class=""><br class=""></div>reg_fetch_contacts("location", "$fu", "un_reg");<br class="">    $var(i) = 0;<br class="">    while ($var(i) < $(ulc(un_reg=>count))) {<br class="">        $var(ul_callid) = $(ulc(un_reg=>callid)[$var(i)]);<br class="">        $var(ul_ruid) = $(ulc(un_reg=>ruid)[$var(i)]);<br class="">        if ($var(ul_callid) == $ci) {<br class="">            xlog("L_INFO", "Unregistering contact $tu Ruid: $var(ul_ruid)\n");<br class="">            unregister("location", "$fu", "$var(ul_ruid)");<br class="">            $sht(regs=>$fU@$fd~$ci)=$null;<br class="">        }<br class="">        $var(i) = $var(i) + 1;<br class=""><div class="">    } </div></div><div style="word-wrap:break-word;line-break:after-white-space" class=""><div class=""><br class=""><div class="">
<div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; word-wrap: break-word;" class=""><div style="font-family:Helvetica" class=""><br class="">- Charles </div><div style="font-family:Helvetica" class=""><br class=""></div></div><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-variant-east-asian: normal; font-variant-position: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px;" class=""><br class="">

</div>
<div class=""><br class=""><blockquote type="cite" class=""><div class="">On Feb 19, 2021, at 9:43 AM, Charles Phillips <<a href="mailto:charles@rustybike.com" target="_blank" class="">charles@rustybike.com</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word;line-break:after-white-space" class="">Happy Friday!<br class=""><div class=""><br class=""></div><div class="">To clean up contacts that have sent requests to unregister (Expires: 0) I am executing the following after a 200 OK response from the upstream server:<div class=""><br class=""></div><div class="">    reg_fetch_contacts("location", "$fu", "un_reg");<br class="">    xlog("L_INFO", "Removing unregistered contact From: $si To: $tu Ruid: $ulc(un_reg=>ruid)\n");<br class="">    unregister("location", "$fu", "$ulc(un_reg=>ruid)”);</div><div class=""><br class=""></div><div class="">This produces the desired result when there is only one contact per AoR, but when multiple contacts are present, it seems to delete the first ruid (which makes sense as I am only providing the $fu).  </div><div class=""><br class=""></div><div class="">So, the question, can I select the contact by call-id or some other unique identifier specific to the desired contact that I can grab from the transaction?  Reading the reg_fetch_contact and unregister docs, they do not seem to provide for selection beyond uri.</div><div class=""><br class=""></div><div class=""><div class="">
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word;line-break:after-white-space" class=""><div style="font-family:Helvetica" class=""><br class="">- Charles</div><div style="font-family:Helvetica" class=""><br class=""></div></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><br class="">

</div>

<br class=""></div></div></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">
Kamailio (SER) - Users Mailing List<br class="">
<a href="mailto:sr-users@lists.kamailio.org" target="_blank" class="">sr-users@lists.kamailio.org</a><br class="">
<a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users" rel="noreferrer" target="_blank" class="">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><br class="">
</blockquote></div></div>-- <br class=""><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class=""><div class="">Regards,</div><div class=""><br class=""></div>David Villasmil<div class="">email: <a href="mailto:david.villasmil.work@gmail.com" target="_blank" class="">david.villasmil.work@gmail.com</a></div><div class="">phone: +34669448337</div></div></div>
_______________________________________________<br class="">Kamailio (SER) - Users Mailing List<br class=""><a href="mailto:sr-users@lists.kamailio.org" class="">sr-users@lists.kamailio.org</a><br class="">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users<br class=""></div></blockquote></div><br class=""></div></body></html>