[OpenSIPS-Users] Dispatcher pvar_hash parsing

Răzvan Crainea razvan at opensips.org
Tue Nov 8 10:52:39 UTC 2022


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



More information about the Users mailing list