[OpenSIPS-Users] Dispatcher pvar_hash parsing

Kevin Kennedy kennedy4260 at gmail.com
Tue Nov 8 17:48:50 UTC 2022


It looks like the {uri.param,tgrp} transforms do not look at Parameters
before the host.  I will have to go back to the Regex.

sip:1234567890;tgrp=1098765432;trunk-context=mydomain.com at 10.10.10.10:5060

The working scenario

modparam("dispatcher", "hash_pvar", "$avp(contacthash)")

        if (is_method("REGISTER|INVITE")) {
                $avp(contacturi) = $ct.fields(uri);
                $avp(str) = "tgrp=";
                $avp(str2) = "/sip:*.*;tgrp/tgrp/g";
                if ($(avp(contacturi){s.index, $avp(str)}) != NULL){
                        xlog("found $avp(str) in $avp(contacturi)\n");
                        $avp(contacthash) =
$(avp(contacturi){re.subst,$avp(str2)});
                        xlog("Contact Hash should be $avp(contacthash)\n");
                }
                else {
                        xlog("did not find $avp(str) in
$avp(contacturi)\n");
                        $avp(contacthash) = $(avp(contacturi));
                        }
                ds_select_dst(1, 7, , "default", 1);

The issue I am trying to run down now is the 200 OK Contact sent to the
user as I would like to keep the opensips server Stateful

Thank you.

Kevin

On Tue, Nov 8, 2022 at 8:18 AM Kevin Kennedy <kennedy4260 at gmail.com> wrote:

> Thank you for the response.  I did get the other way to work last night
> with a slight modification to the regex *$var(str2) =
> "/sip:*.*;tgrp/tgrp/g";* had to add an extra *.** after the first ***, as
> it wasn't matching the regex expression, causing the issue.  However your
> method looks a lot cleaner.  I will give that a try.
>
> The issue I am having now is that the Contact in the 200 OK when sending
> back to the phone is sending the SBC IP that is in the dispatcher.  How do
> I keep the replies stateful?  I was looking at the topology_hiding module,
> but that looks to be overkill.  Is there an easier way to do this?
>
> Thank you.
>
> Kevin
>
> On Tue, Nov 8, 2022 at 2:57 AM Răzvan Crainea <razvan at opensips.org> wrote:
>
>> Hi, Kevin!
>>
>> It would be simpler if you would have used the uri transformations:
>> https://www.opensips.org/Documentation/Script-Tran-3-2#toc32
>>
>> Simply grab the URI and do something like:
>>
>> if ($(var(contacturi){uri.param,tgrp}) != NULL) {
>>      $var(contacthash) = $(var(contacturi){uri.params});
>> } else {
>>      $var(contacthash) = $(var(contacturi));
>> }
>>
>> Răzvan Crainea
>> OpenSIPS Core Developer
>> http://www.opensips-solutions.com
>>
>> On 11/5/22 16:55, Kevin Kennedy wrote:
>> > I am trying to find a way to use the pvar_hash in the Dispatcher module
>> > to hash on the Contact URI.  Normally this can be done with using
>> > $ct.fields(uri) to hash on and this does work,
>> >
>> > The caveat that I have is that I am using RFC4904 (SIP Connect) with
>> > some customers and other customers have a normal Contact URI.
>> >
>> > RFC4904
>> > sip:1234567890;tgrp=1098765432;trunk-context=
>> mydomain.com at 10.10.10.10:5060 <http://mydomain.com@10.10.10.10:5060>
>> >
>> > Normal
>> > sip:1234567890 at 10.10.10.10:5060 <http://sip:1234567890@10.10.10.10:5060
>> >
>> >
>> > I am looking for a way to be able to identify if the Contact URI has
>> the
>> > TGRP parameter, and if it does build the hash with the SIP URI starting
>> > at the tgrp, ie
>> > tgrp=1098765432;trunk-context=mydomain.com at 192.168.1.122:5076
>> > <http://mydomain.com@192.168.1.122:5076>
>> >
>> > If it doesn't have the TGRP parameter, build the hash with the full
>> contact.
>> >
>> > I tried with this logic
>> >
>> > modparam("dispatcher", "hash_pvar", "$var(contacthash)")
>> >
>> >          if (is_method("REGISTER|INVITE")) {
>> >                  $var(contacturi) = $ct.fields(uri);
>> >                  $var(str) = "tgrp=";
>> >                  $var(str2) = "/sip:*;tgrp/tgrp/g";
>> >                  if ($(var(contacturi){s.index, $var(str)}) != NULL){
>> >                          xlog("found $var(str) in $var(contacturi)\n");
>> >
>> > $var(contacthash)=$(var(contacturi){re.subst,$var(str2)});
>> >                  }
>> >                  else {
>> >                          xlog("did not find $var(str) in
>> > $var(contacturi)\n");
>> >                          $var(contacthash) = $(var(contacturi));
>> >                  }
>> >                  ds_select_dst(3, 7, , "default", 1);
>> >                   t_relay()
>> >                  exit
>> >             }
>> >
>> > I am seeing that the hash is still being created on the full Contact
>> >
>> > DBG:core:parse_headers: flags=ffffffffffffffff
>> > found tgrp= in
>> > sip:1234567890;tgrp=1098765432;trunk-context=
>> mydomain.com at 192.168.1.122:5076 <http://mydomain.com@192.168.1.122:5076>
>> > DBG:core:tr_eval_re: Trying to apply regexp [/sip:*;tgrp/tgrp/g] on :
>> > [sip:1234567890;tgrp=1098765432;trunk-context=
>> mydomain.com at 192.168.1.122:5076 <http://mydomain.com@192.168.1.122:5076>]
>> > DBG:core:tr_eval_re: yay, we can use the pre-compile regexp
>> > DBG:core:subst_run: running. r=1
>> > DBG:core:subst_str: no match
>> > DBG:core:tr_eval_re: no match for subst expression
>> > DBG:core:grep_sock_info_ext: checking if host==us: 14==14 &&
>> > [10.255.100.241] == [10.255.100.240]
>> > DBG:core:grep_sock_info_ext: checking if port 5060 matches port 5060
>> > DBG:core:grep_sock_info_ext: checking if host==us: 14==14 &&
>> > [10.255.100.241] == [10.255.100.241]
>> > DBG:core:grep_sock_info_ext: checking if port 5060 matches port 5060
>> > DBG:core:comp_scriptvar: str 20: mydomain.com <http://mydomain.com>
>> > DBG:dispatcher:w_ds_select: ds_select: 3 7 1 1
>> > DBG:dispatcher:ds_select_dst: set [3], using alg [7], size [3], used
>> > size [2], active size [3]
>> > *DBG:dispatcher:ds_hash_pvar: Hashing
>> > sip:1234567890;tgrp=1098765432;trunk-context=
>> mydomain.com at 192.168.1.122:5076 <http://mydomain.com@192.168.1.122:5076
>> >!*
>> > DBG:dispatcher:ds_select_dst: hash [1435049604], candidate [-1], weight
>> > sum [20]
>> > DBG:dispatcher:ds_select_dst: candidate is [0]
>> > DBG:dispatcher:ds_select_dst: using destination [0]
>> > DBG:dispatcher:ds_select_dst: selected [7-3/0] <sip:sbc1.sbcdomain.com
>> > <http://sbc1.sbcdomain.com>>
>> >
>> > I am expecting to see the hash as
>> > *tgrp=1098765432;trunk-context=mydomain.com at 192.168.1.122:5076
>> > <http://mydomain.com@192.168.1.122:5076>!*
>> > that way it matches no matter what number is sent in the User field.
>> >
>> > Thank you.
>> >
>> > Kevin
>> >
>> > _______________________________________________
>> > Users mailing list
>> > Users at lists.opensips.org
>> > http://lists.opensips.org/cgi-bin/mailman/listinfo/users
>>
>> _______________________________________________
>> 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/20221108/60e7ee92/attachment-0001.html>


More information about the Users mailing list