[SR-Users] Partial/regex match on hash table key?

Anthony Joseph Messina amessina at messinet.com
Thu Feb 1 00:21:01 CET 2018


Ok, thank you Dmitri.

I'll need to use iteration then, which is ok too.  I have a set of known 
contacts in Horde Groupware (https://www.horde.org/) that I would like to set 
the identity for when the callerid number matches.  That way when someone 
calls, instead of getting "WIRELESS CALLER" for the callerid, I would get 
"John Q Public"

Since the DB query for every incoming call is rather costly, I wanted to use 
something like http://acalustra.com/kamailio-from-tables-to-htables.html but 
store the hashtable like:

key:   1234567
value: John Q Public

Though the $fU might be any of +1234567, 1234567, or 234567 (differing 
prefixes)

I might play with something like:
sht_iterator_start("i1", "h1");
while(sht_iterator_next("i1")) {
    if(h1[$shtitkey(i1)]=~$fU) {
        xlog("CallerID is: $shtitval(i1)\n");
        append_hf("P-Asserted-Identity: tel:$shtitval(i1)\r\n");
    }
    break;
}
sht_iterator_end("i1");


On Wednesday, January 31, 2018 4:52:02 PM CST Dmitri Savolainen wrote:
> Hi, Anthony
> Masks are not possible for getting values. But sometimes "array" approach
> may be usefull
> 
>     $var(i) = 0;
>     $var(cache_mask) = "slice_a";
>     $var(cache_size) = $sht(mycache=>$var(cache_mask)::size);
>     while( $var(i) < $var(cache_size) ){
>         # do smth with $sht(mycache=>$var(cache_mask)[$var(i)])
>         $var(i) = $var(i) + 1;
>     }
> 
> 
> 2018-01-31 21:36 GMT+03:00 Anthony Joseph Messina <amessina at messinet.com>:
> Is is possible (without iterating through all entries in a hash table) to
> return the value based on a partial or regex match to the key?
> 
> Something like...
> $var(one)=$sht(a=>*$var(two))
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20180131/c2a7620c/attachment.sig>


More information about the sr-users mailing list