Hi list,
How can I extract a specific part of my message body? I know that "textops" has the function "search_body(re)" but it returns True/False upon finding "re" in the body of the text, how can I return the actual text that regular expression matches?
As an example, my message body is
rate is 172#012
I want to extract the number "172" out of this.
Thanks Alireza
On 08/14/2014 02:59 PM, AliReza Khoshgoftar Monfared wrote:
Hi list,
How can I extract a specific part of my message body? I know that "textops" has the function "search_body(re)" but it returns True/False upon finding "re" in the body of the text, how can I return the actual text that regular expression matches?
As an example, my message body is
rate is 172#012
I want to extract the number "172" out of this.
There is no general means of accomplishing that. Your best bet is to feed the message body to another language using one of the language interface modules, such as Lua, Perl or Python, and parse stuff out of it there.
For all of its features, Kamailio route script is not a general-purpose programming runtime.
Thanks very much Alex. You are right. In general kamailio does not offer much functionality of a general purpose language. The other option for the task that I found was "s.rm" transformation. Although it works the other way :) you need to match what needs to be removed :)
Now a general question ( or request for a word of advice :) ): if you have ultimate flexibility and want to send an integer from one proxy to another. What functions ( modules ) are the best to append and recover it? ( i don't care where it is appended, body or header, etc )
On Thursday, August 14, 2014, Alex Balashov abalashov@evaristesys.com wrote:
On 08/14/2014 02:59 PM, AliReza Khoshgoftar Monfared wrote:
Hi list,
How can I extract a specific part of my message body? I know that "textops" has the function "search_body(re)" but it returns True/False upon finding "re" in the body of the text, how can I return the actual text that regular expression matches?
As an example, my message body is
rate is 172#012
I want to extract the number "172" out of this.
There is no general means of accomplishing that. Your best bet is to feed the message body to another language using one of the language interface modules, such as Lua, Perl or Python, and parse stuff out of it there.
For all of its features, Kamailio route script is not a general-purpose programming runtime.
-- Alex Balashov - Principal Evariste Systems LLC Tel: +1-678-954-0670 Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
Please be kind to the English language:
http://www.entrepreneur.com/article/232906
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Hello AliReza,
On 08/15/2014 12:13 AM, AliReza Khoshgoftar Monfared wrote:
Now a general question ( or request for a word of advice :) ): if you have ultimate flexibility and want to send an integer from one proxy to another. What functions ( modules ) are the best to append and recover it? ( i don't care where it is appended, body or header, etc )
If you just want to send such values around in standard SIP requests, i.e. insert them to an INVITE, I would say that the most canonical and widespread way to do this is via custom SIP headers, e.g.
On the sender:
append_hf("X-Alireza-Rate: 172\r\n");
On the receiver:
if(is_present_hf("X-Alireza-Rate")) { xlog("L_INFO", "Extracted rate is $hdr(X-Alireza-Rate)\n");
# Don't pass this header further upstream.
remove_hf("X-Alireza-Rate"); }
Thanks very much Alex and Hugh,
I think what Hugh mentioned is the best way to process text in Kamailio without relying on an external tool and it's good to know it, and Alex's suggestion is great for transferring a single number.
Cheers, Alireza
On Fri, Aug 15, 2014 at 7:36 AM, Alex Balashov abalashov@evaristesys.com wrote:
is_present_hf("X-Alireza-Rate")
On 08/15/2014 02:43 PM, AliReza Khoshgoftar Monfared wrote:
Thanks very much Alex and Hugh,
I think what Hugh mentioned is the best way to process text in Kamailio without relying on an external tool and it's good to know it, and Alex's suggestion is great for transferring a single number.
It does not have to be a single number. A header can have any value you like, e.g.
X-AliReza-Custom-Header: param1=x;param2=y;param3=z
Which you could then extract with string transformations[1]:
$var(param1) = $(hdr(X-AliReza-Custom-Header){s.select,0,;}); $var(param2) = $(hdr(X-AliReza-Custom-Header){s.select,1,;}); $var(param3) = $(hdr(X-AliReza-Custom-Header){s.select,2,;});
-- Alex
[1] http://www.kamailio.org/wiki/cookbooks/4.1.x/transformations#sselect_index_s...
Awesome, and I assume to recover the integer value, I need sth like, as well:
$var(param1) = $(var(param1){s.int});
Thanks very much, Alireza
On Fri, Aug 15, 2014 at 2:48 PM, Alex Balashov abalashov@evaristesys.com wrote:
On 08/15/2014 02:43 PM, AliReza Khoshgoftar Monfared wrote:
Thanks very much Alex and Hugh,
I think what Hugh mentioned is the best way to process text in Kamailio without relying on an external tool and it's good to know it, and Alex's suggestion is great for transferring a single number.
It does not have to be a single number. A header can have any value you like, e.g.
X-AliReza-Custom-Header: param1=x;param2=y;param3=z
Which you could then extract with string transformations[1]:
$var(param1) = $(hdr(X-AliReza-Custom-Header){s.select,0,;}); $var(param2) = $(hdr(X-AliReza-Custom-Header){s.select,1,;}); $var(param3) = $(hdr(X-AliReza-Custom-Header){s.select,2,;});
-- Alex
[1] http://www.kamailio.org/wiki/cookbooks/4.1.x/ transformations#sselect_index_separator
-- Alex Balashov - Principal Evariste Systems LLC Tel: +1-678-954-0670 Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
Please be kind to the English language:
http://www.entrepreneur.com/article/232906
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
On 08/15/2014 02:54 PM, AliReza Khoshgoftar Monfared wrote:
Awesome, and I assume to recover the integer value, I need sth like, as well:
$var(param1) = $(var(param1){s.int <http://s.int>});
Yep. In fact, you can chain transformations:
$(hdr(X-AliReza-Custom-Header){s.select,0,;}{s.int});
Awesome,
Thanks very much
On Fri, Aug 15, 2014 at 2:56 PM, Alex Balashov abalashov@evaristesys.com wrote:
On 08/15/2014 02:54 PM, AliReza Khoshgoftar Monfared wrote:
Awesome, and I assume to recover the integer value, I need sth like, as
well:
$var(param1) = $(var(param1){s.int <http://s.int>});
Yep. In fact, you can chain transformations:
$(hdr(X-AliReza-Custom-Header){s.select,0,;}{s.int});
-- Alex Balashov - Principal Evariste Systems LLC Tel: +1-678-954-0670 Web: http://www.evaristesys.com/, http://www.alexbalashov.com/
Please be kind to the English language:
http://www.entrepreneur.com/article/232906
SIP Express Router (SER) and Kamailio (OpenSER) - sr-users mailing list sr-users@lists.sip-router.org http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users
Sure thing.
The main issue you were having is access to the information you want in the part of the message body where you want it.
Assuming you can get that and that it's formatted in a way that the transformation functions in Kamailio can operate on it, i.e. split by delimiter versus regex extraction, you can pass around anything any way you like. :-)
Hi, The re.subst transformation can be used on variables to extract data. http://www.kamailio.org/wiki/cookbooks/devel/transformations#resubst_express...
$rb is the variable that contains the request body, but you can use $var or $avp variables if doing multiple operations.
$var(data) = (int)$(rb{re.subst,/^rate is ([0-9+).*$/\1});
Regards, Hugh
From: sr-users-bounces@lists.sip-router.org [mailto:sr-users-bounces@lists.sip-router.org] On Behalf Of AliReza Khoshgoftar Monfared Sent: 14 August 2014 20:00 To: Kamailio (SER) - Users Mailing List Subject: [SR-Users] Text Operations on a Message
Hi list,
How can I extract a specific part of my message body? I know that "textops" has the function "search_body(re)" but it returns True/False upon finding "re" in the body of the text, how can I return the actual text that regular expression matches?
As an example, my message body is
rate is 172#012
I want to extract the number "172" out of this.
Thanks Alireza ________________________________ This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you for understanding.
I think my keyboard battery is failing, it keeps dropping characters… Here’s a better example.
$var(data) = $(rb{re.subst,/^rate is ([0-9]+).*$/\1/});
Regards, Hugh
From: sr-users-bounces@lists.sip-router.org [mailto:sr-users-bounces@lists.sip-router.org] On Behalf Of Waite, Hugh Sent: 15 August 2014 10:43 To: Kamailio (SER) - Users Mailing List Subject: Re: [SR-Users] Text Operations on a Message
Hi, The re.subst transformation can be used on variables to extract data. http://www.kamailio.org/wiki/cookbooks/devel/transformations#resubst_express...
$rb is the variable that contains the request body, but you can use $var or $avp variables if doing multiple operations.
$var(data) = (int)$(rb{re.subst,/^rate is ([0-9+).*$/\1});
Regards, Hugh
From: sr-users-bounces@lists.sip-router.orgmailto:sr-users-bounces@lists.sip-router.org [mailto:sr-users-bounces@lists.sip-router.org] On Behalf Of AliReza Khoshgoftar Monfared Sent: 14 August 2014 20:00 To: Kamailio (SER) - Users Mailing List Subject: [SR-Users] Text Operations on a Message
Hi list,
How can I extract a specific part of my message body? I know that "textops" has the function "search_body(re)" but it returns True/False upon finding "re" in the body of the text, how can I return the actual text that regular expression matches?
As an example, my message body is
rate is 172#012
I want to extract the number "172" out of this.
Thanks Alireza ________________________________ This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you for understanding. ________________________________ This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you for understanding.