If I have a string that contains pseudo variables, e.g,,
$var(uri_pattern) = "sip:$fU@tutpro.com";
is it somehow possible to replace them with their values, something like:
$var(uri) = eval("$var(uri_pattern)");
-- Juha
Juha,
Yes, either by separating the PV elements, e.g.
$var(x) = $fU + "abc";
... or with the newer $_s() PV created for this purpose:
$var(x) = $_s($fUabc);
-- Alex Balashov | Principal | Evariste Systems LLC 1447 Peachtree Street NE, Suite 700 Atlanta, GA 30309 United States
Tel: +1-800-250-5920 (toll-free) / +1-678-954-0671 (direct) Web: http://www.evaristesys.com/, http://www.csrpswitch.com/
Sent from my BlackBerry. Original Message From: Juha Heinanen Sent: Friday, April 1, 2016 08:14 To: sr-users@lists.sip-router.org Reply To: Kamailio (SER) - Users Mailing List Subject: [SR-Users] pseudo variables in strings
If I have a string that contains pseudo variables, e.g,,
$var(uri_pattern) = "sip:$fU@tutpro.com";
is it somehow possible to replace them with their values, something like:
$var(uri) = eval("$var(uri_pattern)");
-- Juha
_______________________________________________ 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
Alex Balashov writes:
Yes, either by separating the PV elements, e.g.
$var(x) = $fU + "abc";
Alex,
I cannot do that, because the string that contains pvs is result of a dp_translate call.
... or with the newer $_s() PV created for this purpose:
$var(x) = $_s($fUabc);
No luck with that either. This test
$var(pv_string) = "foo$var(pv)bar"; $var(pv) = "car"; $var(res_string) = $_s($var(pv_string)); xlog("L_INFO", "res_string is '$var(res_string)'\n");
produces to syslog:
Apr 2 11:07:26 lohi /usr/bin/sip-proxy[24536]: INFO: res_string is 'foo$var(pv)bar'
when I need to get 'foocarbar'.
-- Juha
Was the conclusion that it is not currently possible to evaluate a string value of a pseudo variable that contains pseudo variables?
If so, I'll add feature request, since that kind of capability would greatly increase dynamic nature of Kamailio configuration.
-- Juha
On 02/04/16 10:09, Juha Heinanen wrote:
Alex Balashov writes:
Yes, either by separating the PV elements, e.g.
$var(x) = $fU + "abc";
Alex,
I cannot do that, because the string that contains pvs is result of a dp_translate call.
Dialplan can evaluate variables, is it a special case you need to return variables and then evaluate after dp_translate() again?
It might work by returning a lua script string that you can evaluate with app_lua().
Cheers, Daniel
... or with the newer $_s() PV created for this purpose:
$var(x) = $_s($fUabc);
No luck with that either. This test
$var(pv_string) = "foo$var(pv)bar"; $var(pv) = "car"; $var(res_string) = $_s($var(pv_string)); xlog("L_INFO", "res_string is '$var(res_string)'\n");
produces to syslog:
Apr 2 11:07:26 lohi /usr/bin/sip-proxy[24536]: INFO: res_string is 'foo$var(pv)bar'
when I need to get 'foocarbar'.
-- Juha
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
Daniel-Constantin Mierla writes:
Dialplan can evaluate variables, is it a special case you need to return variables and then evaluate after dp_translate() again?
I made a test rule:
match_exp subst_exp repl_exp
^#11#$ (empty) $fu
and dp_translate(id) on sip:#11#@test.tutpro.com produced sip:$fu@test.tutpro.com.
Same with or without
modparam("dialplan", "match_dynamic", 1)
Also, I would prefer to have a function to evaluate strings rather than have a dp_translate specific feature.
-- Juha
I added pv_evalx() function in pv module which evaluates twice a string containing variables. No time to test it, so any feedback is appreciated. It will be also good to stress test it and check if there is a memory leak for pkg, as the result for first evaluation needs to be parsed again for other variables -- pv caching should prevent a leak, but to be safe is good to test if plans are to use in production.
Cheers, Daniel
On 04/04/16 07:35, Daniel-Constantin Mierla wrote:
On 02/04/16 10:09, Juha Heinanen wrote:
Alex Balashov writes:
Yes, either by separating the PV elements, e.g.
$var(x) = $fU + "abc";
Alex,
I cannot do that, because the string that contains pvs is result of a dp_translate call.
Dialplan can evaluate variables, is it a special case you need to return variables and then evaluate after dp_translate() again?
It might work by returning a lua script string that you can evaluate with app_lua().
Cheers, Daniel
... or with the newer $_s() PV created for this purpose:
$var(x) = $_s($fUabc);
No luck with that either. This test
$var(pv_string) = "foo$var(pv)bar"; $var(pv) = "car"; $var(res_string) = $_s($var(pv_string)); xlog("L_INFO", "res_string is '$var(res_string)'\n");
produces to syslog:
Apr 2 11:07:26 lohi /usr/bin/sip-proxy[24536]: INFO: res_string is 'foo$var(pv)bar'
when I need to get 'foocarbar'.
-- Juha
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
Daniel-Constantin Mierla writes:
I added pv_evalx() function in pv module which evaluates twice a string containing variables. No time to test it, so any feedback is appreciated. It will be also good to stress test it and check if there is a memory leak for pkg, as the result for first evaluation needs to be parsed again for other variables -- pv caching should prevent a leak, but to be safe is good to test if plans are to use in production.
Thank you very much. I'll give it a try later this week.
-- Juha
Daniel-Constantin Mierla writes:
I added pv_evalx() function in pv module which evaluates twice a string containing variables. No time to test it, so any feedback is appreciated. It will be also good to stress test it and check if there is a memory leak for pkg, as the result for first evaluation needs to be parsed again for other variables -- pv caching should prevent a leak, but to be safe is good to test if plans are to use in production.
I executed the call for about 10000 times and didn't see any reduction in the amount of free pkg memory.
-- Juha