[SR-Users] Get value from header and check value type

Karsten Horsmann khorsmann at gmail.com
Fri Oct 18 21:08:16 CEST 2019


Hi Joel,

Thanks for your quick response. Okay then I went this way and convert it to
int and do then the checking. The mailing list is a good source for best
practices questions.

I had some concerns about the core error warnings if the value is
alphanumeric or something else not numeric.

Cheers
Karsten Horsmann

Joel Serrano <joel at textplus.com> schrieb am Fr., 18. Okt. 2019, 20:12:

> Hey Karsten,
>
> I had a similar doubt and following Daniel's recommendation I went with
> the same route you did (using {s.int} to convert to integer).
>
> Quote from another thread: *"you can also convert the header value to
> integer using the transformation {s.int <http://s.int/>}, that's safer if
> you need to do other types of comparison such as > or <, because comparing
> string values might give the result you don't expect"*
>
> Hope this helps!
>
> Joel.
>
> On Fri, Oct 18, 2019 at 10:58 AM Karsten Horsmann <khorsmann at gmail.com>
> wrote:
>
>> Hi List,
>>
>> I use Kamailio 5.2.x and I want to fetch an value from an X Header and do
>> some checks like "is not empty" and "should be an integer".
>>
>> AFAIK per default all values are strings with the hdr function.
>>
>> What are the best way for some validations within Kamailio script
>> language?
>>
>>
>> if(is_present_hf("X-someheader")) {
>>                         $avp(routing_target) = $(hdr(X-someheader){s.int
>> });
>>
>>  if(!ds_list_exists("$avp(routing_target)"))
>> Cheers
>> Karsten Horsmann
>> _______________________________________________
>> Kamailio (SER) - Users Mailing List
>> sr-users at lists.kamailio.org
>> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>>
> _______________________________________________
> Kamailio (SER) - Users Mailing List
> sr-users at lists.kamailio.org
> https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20191018/6d7f8f63/attachment.html>


More information about the sr-users mailing list