[OpenSIPS-Users] can't get is_contact_registered() to return true

Jeff Pyle jeff at ugnd.org
Thu Oct 8 13:40:02 EST 2020

Here's what I have working so far, based on the remove_branch() example
from the documentation.

route {
        # Preserve this before fix_nated_contact() breaks it
        $var(ct_uri) = $(ct.fields(uri){nameaddr.uri});
        *...other things...*

route[preauth] {
        if (is_gflag(0)) xlog("L_NOTICE", "[C5] Entering preauth route $fU
-> $rU\n");

        if (!lookup("location", "B", $fu)) {
                if (is_gflag(0)) xlog("L_NOTICE", "[C5] ...lookup failed,
returning -1\n");

        $var(i) = 0;
        while ($(branch(uri)[$var(i)]) != null) {
                if ($var(ct_uri) == $(branch(uri)[$var(i)]{nameaddr.uri})
                    $si == $(branch(duri)[$var(i)]{uri.host}) &&
                    $sp == $(branch(duri)[$var(i)]{uri.port})) {
                        if (is_gflag(0)) xlog("L_NOTICE", "[C5] ...found
match $(branch(uri)[$var(i)]) ($(branch(duri)[$var(i)])) \n");
                $var(i) = $var(i) + 1;

        $var(i) = 0;
        while ($(branch(uri)[$var(i)]) != null) {

        if (isflagset("PREAUTH_OK")) {
        } else {

This loads the registered contacts as branches, which allows me to iterate
through each and compare 1) the base URI from the inbound INVITE with the
base URI of the registered contact, 2) the received IP and 3) the received
port.  Assuming one matches, that's enough to satisfy me that we've
received a message from a registered endpoint.  I'm calling this route on
initial INVITEs and so far, so good.  There are optimizations that could
occur, such as exiting the while loop once we've found a match, but at
least this works.

- Jeff

On Thu, Oct 8, 2020 at 3:58 AM Liviu Chircu <liviu at opensips.org> wrote:

> On 08.10.2020 00:42, Jeff Pyle wrote:
> The registered contact of a user is
> "sip:+12162454107 at;rinstance=946433DE"
> <sip:+12162454107 at;rinstance=946433DE>.  When I place
> a call from that user, its INVITE's Contact is "
> sip:+12162454107 at".  is_contact_registered() fails.
> Is that caused by the lack of the rinstance param, or something else?
> Indeed, the matching now fails strictly because of that extra chunk:
> ";rinstance=946433DE".  According to the RFC 3261 URI matching rules,
> they are indeed different contacts.
> However, if you really want to go the extra mile and tolerate those
> inconsistent INVITE Contacts (with the missing URI params) by somehow still
> matching them against Contact URIs with the params, I don't see a clean
> solution *)
> *) of course, you could use the local cache and store a
> "non-param-Contact: full-Contact" key-value pair on each REGISTER.  During
> INVITE processing, you would use the cache to look up and "fix" any
> non-param-Contact with its proper value, buffered in the local cache.
> However, it's still a hacky solution: what if you restart the registrar?
> Then, for a while, some INVITEs won't route out because the Contact
> conversion won't work until they re-register and populate the cache.
> --
> Liviu Chircuwww.twitter.com/liviuchircu | www.opensips-solutions.com
> _______________________________________________
> Users mailing list
> Users at lists.opensips.org
> http://lists.opensips.org/cgi-bin/mailman/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.opensips.org/pipermail/users/attachments/20201008/887a183f/attachment.html>

More information about the Users mailing list