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

Joel Serrano joel at textplus.com
Fri Oct 18 20:10:59 CEST 2019


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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.kamailio.org/pipermail/sr-users/attachments/20191018/be07d2db/attachment.html>


More information about the sr-users mailing list