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.
It actually has 3 parts. For completeness, I probably should have added them all.
Below:
route[REGISTRAR] {
….
do stuff
….
if (search_hf("Expires", "^0$", "a")) {
….
do stuff
….
t_on_reply("UNREGISTER");
xlog("L_INFO", "Processing unregister event from $si To:
$tu\n");
route(RELAY);
exit;
}
….
do stuff
….
}
onreply_route[UNREGISTER] {
if (t_check_status("200")) {
route(UNREG);
}
}
route[UNREG] {
reg_fetch_contacts("location", "$fu", "un_reg");
$var(i) = 0;
while ($var(i) < $(ulc(un_reg=>count))) {
$var(ul_callid) = $(ulc(un_reg=>callid)[$var(i)]);
$var(ul_ruid) = $(ulc(un_reg=>ruid)[$var(i)]);
if ($var(ul_callid) == $ci) {
xlog("L_INFO", "Unregistering contact $tu Ruid:
$var(ul_ruid)\n");
unregister("location", "$fu", "$var(ul_ruid)");
$sht(regs=>$fU@$fd~$ci)=$null;
}
$var(i) = $var(i) + 1;
}
}
- Charles
On Feb 21, 2021, at 8:45 AM, David Villasmil
<david.villasmil.work(a)gmail.com> wrote:
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.
If what you need is not force only one contact per user, maybe look at
http://www.kamailio.net/docs/modules/5.4.x/modules/registrar.html#registrar…
<http://www.kamailio.net/docs/modules/5.4.x/modules/registrar.html#registrar.f.save>
On Sun, 21 Feb 2021 at 13:14, Charles Phillips <charles(a)rustybike.com
<mailto:charles@rustybike.com>> wrote:
Sorted it. I needed to loop through the contacts, then select the correct ruid based on
$ci
For completeness, here is my solution:
reg_fetch_contacts("location", "$fu", "un_reg");
$var(i) = 0;
while ($var(i) < $(ulc(un_reg=>count))) {
$var(ul_callid) = $(ulc(un_reg=>callid)[$var(i)]);
$var(ul_ruid) = $(ulc(un_reg=>ruid)[$var(i)]);
if ($var(ul_callid) == $ci) {
xlog("L_INFO", "Unregistering contact $tu Ruid:
$var(ul_ruid)\n");
unregister("location", "$fu",
"$var(ul_ruid)");
$sht(regs=>$fU@$fd~$ci)=$null;
}
$var(i) = $var(i) + 1;
}
- Charles
On Feb 19, 2021, at 9:43 AM, Charles Phillips
<charles(a)rustybike.com <mailto:charles@rustybike.com>> wrote:
Happy Friday!
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:
reg_fetch_contacts("location", "$fu", "un_reg");
xlog("L_INFO", "Removing unregistered contact From: $si To: $tu Ruid:
$ulc(un_reg=>ruid)\n");
unregister("location", "$fu", "$ulc(un_reg=>ruid)”);
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).
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.
- Charles
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users(a)lists.kamailio.org <mailto:sr-users@lists.kamailio.org>
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
<https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users>
--
Regards,
David Villasmil
email: david.villasmil.work(a)gmail.com <mailto:david.villasmil.work@gmail.com>
phone: +34669448337
_______________________________________________
Kamailio (SER) - Users Mailing List
sr-users(a)lists.kamailio.org
https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users