[SR-Users] Hex to Dec conversion

Daniel-Constantin Mierla miconda at gmail.com
Thu Sep 17 10:46:18 CEST 2015


Hello,

On 16/09/15 10:59, Yufei Tao wrote:
> Hi,
>
> Thanks for the replies! The first thing I looked at was the
> encode/decode.hexa transformations but it only transforms between
> ASCII characters and Hex numbers. Then I used exec_avp to call a bash
> command (for example, 'echo $((0x123))' gives you 291) which works.
> But calling something external may not be optimal I thought?
>
an embedded script like lua (see app_lua module) could be the
alternative for anything that is not available as config function. Exec
might not be the most performat option that can be used, but it won't
have any relevant impact if you don't execute any long time taking
application.

Anyhow, I looked at the code and found an easy way to get this working
so, I pushed a patch that makes the cast operator (int) to detect and
convert hex:

  *
https://github.com/kamailio/kamailio/commit/33f159121193b3ed09e2ec7aa7b55aa543aeb852

You should be able to cherry pick that commit in your branch.

It can be used like:

    $var(x) = "0x10";
    $var(y) = (int)$var(x);
    xlog("hex x = $var(x); dec y = $var(y)\n");

Adding transformations would be another option to be done when time allows.

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
http://twitter.com/#!/miconda - http://www.linkedin.com/in/miconda
Book: SIP Routing With Kamailio - http://www.asipto.com
Kamailio Advanced Training, Sep 28-30, 2015, in Berlin - http://asipto.com/u/kat




More information about the sr-users mailing list