Module: kamailio Branch: master Commit: 33f159121193b3ed09e2ec7aa7b55aa543aeb852 URL: https://github.com/kamailio/kamailio/commit/33f159121193b3ed09e2ec7aa7b55aa5...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2015-09-17T00:15:19+02:00
core: cast operator (int) converts hex strings as well
- in addition to dec string
---
Modified: rvalue.c
---
Diff: https://github.com/kamailio/kamailio/commit/33f159121193b3ed09e2ec7aa7b55aa5... Patch: https://github.com/kamailio/kamailio/commit/33f159121193b3ed09e2ec7aa7b55aa5...
---
diff --git a/rvalue.c b/rvalue.c index 52c12ed..e4524f5 100644 --- a/rvalue.c +++ b/rvalue.c @@ -997,16 +997,20 @@ int rval_get_int(struct run_act_ctx* h, struct sip_msg* msg, /* if "" => 0 (most likely case) */ if (likely(s->len==0)) *i=0; else if (unlikely(str2sint(s, i)!=0)){ - /* error converting to int => non numeric => 0 */ - *i=0; + /* dec to int failed, try hex to int */ + if(!(s->len>2 && s->s[0]=='0' && (s->s[1]=='x' || s->s[1]=='X') + && (hexstr2int(s->s+2, s->len-2, (unsigned int*)i)==0))) { + /* error converting to int => non numeric => 0 */ + *i=0; #ifdef RV_STR2INT_VERBOSE_ERR - WARN("automatic string to int conversion for "%.*s" failed\n", + WARN("automatic string to int conversion for "%.*s" failed\n", s->len, ZSW(s->s)); - /* return an error code */ + /* return an error code */ #endif #ifdef RV_STR2INT_ERR - ret=-1; + ret=-1; #endif + } } if (destroy_pval) pv_value_destroy(&pval);