Hello,
is there any way to use or evaluate the return-statements of a perl-script in kamailio.cfg?
I tried the following in the Routing Logic in kamailio.cfg:
if (is_method("INVITE")) { if (perl_exec("my_perl_subroutine") == -1){ xlog("PERL returns -1 \n"); } }
Doesn't work.
The bad thing is that the return-values of the - perl_exec("XXX") - call are not the same that the perl subroutine "XXX" returns.
That's at least what I strongly believe after testing.
I do need to read/evaluate the return-value of the perl-subroutine in the Routing Logic to define different routes depending on what the perl-subroutine returns.
Is there any way to do that???
Thank you for your help in advance.
Regards,
Nicolas
On Tuesday 17 August 2010, Nicolas Rüger wrote:
is there any way to use or evaluate the return-statements of a perl-script in kamailio.cfg?
I tried the following in the Routing Logic in kamailio.cfg:
if (is_method("INVITE")) { if (perl_exec("my_perl_subroutine") == -1){ xlog("PERL returns -1 \n"); } }
Doesn't work.
The bad thing is that the return-values of the - perl_exec("XXX") - call are not the same that the perl subroutine "XXX" returns.
That's at least what I strongly believe after testing.
I do need to read/evaluate the return-value of the perl-subroutine in the Routing Logic to define different routes depending on what the perl-subroutine returns.
Is there any way to do that???
Hi Nicolas,
i just checked in the code of perl/perlfunc.c:perl_exec2(..) in the module, it seems that it according to the code it should return the result from the perl method, or -1 on internal error or wrong parameter before execution.
If this not work, then its probably a bug in the module. Maybe you can add some debugging information into this code statement to help with your tests.
Another idea, if you don't like to digg in the code, for returning some data from perl to the script would be to use OpenSER::AVP and fill the return value (maybe with some wrapper) in an AVP which you then read out later.
Cheers,
Henning
Hello Henning,
thanks for the help. Your idea kept me trying as the C-code shows that it should return the result from the PERL subroutine as you already mentioned in your answer.
Two points I want to name here:
1)
I'm still confused that the methods in perl/perlfunc.c are called "perl_exec1()" and "perl_exec2()" instead of "perl_exec" because that's the one for use in kamailio.cfg.
I grepped the whole kamailio source code and couldn't find a definition of "perl_exec".
2) More Important...
I finally solved my issue by using a variable in kamailio.cfg:
if (is_method("INVITE")) { $var(a) = perl_exec("my_perl_subroutine"); if ($var(a) == -1){ xlog("PERL returns -1 \n"); } }
That works!
So is this behavior of kamailio.cfg a bug?
It should at least be listed in the documentation cause it's really tricky.
PLEASE NOTE:
perl_exec("my_perl_subroutine") == -1 --> returns FALSE
BUT
$var(a) = perl_exec("my_perl_subroutine"); $var(a) == -1 --> returns TRUE
In this example the perl-subroutine itself returns -1
Thank you Henning!
Regards,
Nicolas
On Tuesday 17 August 2010, Nicolas Rüger wrote:
is there any way to use or evaluate the return-statements of a
perl-script
in kamailio.cfg?
I tried the following in the Routing Logic in kamailio.cfg:
if (is_method("INVITE")) { if (perl_exec("my_perl_subroutine") == -1){ xlog("PERL returns -1 \n"); } }
Doesn't work.
The bad thing is that the return-values of the - perl_exec("XXX") - call are not the same that the perl subroutine "XXX" returns.
That's at least what I strongly believe after testing.
I do need to read/evaluate the return-value of the perl-subroutine in
the
Routing Logic to define different routes depending on what the perl-subroutine returns.
Is there any way to do that???
Hi Nicolas,
i just checked in the code of perl/perlfunc.c:perl_exec2(..) in the module, it seems that it according to the code it should return the result from the perl method, or -1 on internal error or wrong parameter before execution.
If this not work, then its probably a bug in the module. Maybe you can add some debugging information into this code statement to help with your tests.
Another idea, if you don't like to digg in the code, for returning some data from perl to the script would be to use OpenSER::AVP and fill the return value (maybe with some wrapper) in an AVP which you then read out later.
Cheers,
Henning
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 Tuesday 17 August 2010, Nicolas Rüger wrote:
thanks for the help. Your idea kept me trying as the C-code shows that it should return the result from the PERL subroutine as you already mentioned in your answer.
Two points I want to name here:
I'm still confused that the methods in perl/perlfunc.c are called "perl_exec1()" and "perl_exec2()" instead of "perl_exec" because that's the one for use in kamailio.cfg.
Hey Nicolas,
this is not defined in the C, but in the module interface. Take a look to the perl.c:static cmd_export_t cmds[] variable.
- More Important...
I finally solved my issue by using a variable in kamailio.cfg:
if (is_method("INVITE")) { $var(a) = perl_exec("my_perl_subroutine"); if ($var(a) == -1){ xlog("PERL returns -1 \n"); } }
That works!
So is this behavior of kamailio.cfg a bug? It should at least be listed in the documentation cause it's really tricky.
PLEASE NOTE:
perl_exec("my_perl_subroutine") == -1 --> returns FALSE
BUT
$var(a) = perl_exec("my_perl_subroutine"); $var(a) == -1 --> returns TRUE
This is indeed strange. I'd say that evaluating the return value of a function is nothing that new, its has been a pretty long time there. Maybe the comparison went somehow mad because of some typing issue? Another idea, have you tried using the $rc PV, which also return the result of the last called function?
Regards,
Henning
Hello,
here are the results of my tests...
1.) Using $rc works...
Yes I tried using "$rc" instead of the assignment a new variable and it works well. One just has to be careful if one wants to use a "xlog()" after the "perl_exec()" and before evaluating "$rc", as that doesn't work in this case.
2.) Rather a bug than a typing issue...
I'm pretty sure that the wrong evaluation the direct return value of a function is a bug in this case cause I tested the following and therefore I guess we can screen out the possibilty of a typing issue...see below...
Using the following lines in kamailio.cfg....
$var(a)=perl_exec("compare_caller_with_user_from_db");
xlog("XLOG-->return value: $var(a) \n");
if ($var(a) == -1){ xlog("XLOG----------------> rc == -1 \n");} if ($var(a) != -1){ xlog("XLOG--> var(a) != -1 \n");} if ($var(a) eq -1) { xlog("XLOG--> var(a) eq -1 \n"); } if ($var(a) eq "-1"){ xlog("XLOG--> var(a) eq '-1' \n");} if ($var(a) ne -1) { xlog("XLOG--> var(a) ne -1 \n"); }
if (perl_exec("compare_caller_with_user_from_db") == -1){ xlog("XLOG--> perl_exec eq -1 \n"); }
if (perl_exec("compare_caller_with_user_from_db") != -1){ xlog("XLOG--> perl_exec != -1 \n"); }
...produces the following output:
5(9778) ERROR: <script>: XLOG--> return value: -1 5(9778) ERROR: <script>: XLOG--> rc == -1 5(9778) ERROR: <script>: XLOG--> var(a) eq '-1' 5(9778) ERROR: <script>: XLOG--> var(a) ne -1 5(9778) ERROR: <script>: XLOG--> perl_exec != -1
Especially the last line points out that the evaluation of the direct return value of a function doesn't work here.
Hope that helps someone to fix the bug. Will anyone do that???
Regards,
Nicolas
P.S.
Using one of the following statements drops an syntax error on kamailio startup already...just to complete test cases:
if (perl_exec("compare_caller_with_user_from_db") eq -1){ xlog("XLOG--> perl_exec eq -1 \n"); }
if (perl_exec("compare_caller_with_user_from_db") eq "-1"){ xlog("XLOG--> perl_exec eq '-1' \n"); }
if (perl_exec("compare_caller_with_user_from_db") ne -1){ xlog("XLOG--> perl_exec ne -1 \n"); }
-------- Original-Nachricht --------
Datum: Wed, 18 Aug 2010 13:53:42 +0200 Von: Henning Westerholt henning.westerholt@1und1.de An: "Nicolas Rüger" NicolasRueger@gmx.de CC: "sr-users@lists.sip-router.org" sr-users@lists.sip-router.org Betreff: Re: [SR-Users] Evaluate Perl Return Value in Routing Logic
On Tuesday 17 August 2010, Nicolas Rüger wrote:
thanks for the help. Your idea kept me trying as the C-code shows that
it
should return the result from the PERL subroutine as you already
mentioned
in your answer.
Two points I want to name here:
I'm still confused that the methods in perl/perlfunc.c are called "perl_exec1()" and "perl_exec2()" instead of "perl_exec" because that's the one for use in kamailio.cfg.
Hey Nicolas,
this is not defined in the C, but in the module interface. Take a look to the perl.c:static cmd_export_t cmds[] variable.
- More Important...
I finally solved my issue by using a variable in kamailio.cfg:
if (is_method("INVITE")) { $var(a) = perl_exec("my_perl_subroutine"); if ($var(a) == -1){ xlog("PERL returns -1 \n"); } }
That works!
So is this behavior of kamailio.cfg a bug? It should at least be listed in the documentation cause it's really
tricky.
PLEASE NOTE:
perl_exec("my_perl_subroutine") == -1 --> returns FALSE
BUT
$var(a) = perl_exec("my_perl_subroutine"); $var(a) == -1 --> returns TRUE
This is indeed strange. I'd say that evaluating the return value of a function is nothing that new, its has been a pretty long time there. Maybe the comparison went somehow mad because of some typing issue? Another idea, have you tried using the $rc PV, which also return the result of the last called function?
Regards,
Henning
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,
is there any chance to pass parameters (like from_uri or to_uri) from the kamailio routing logic to a perl script?
I know that the whole sip message is provided as parameter but I wonder if there's a way to pass just the caller's uri (from tag) or the callee's uri (to tag) as a second parameter to the perl script.
By using xlog it's clear that in $fu and $ru one can find the uri's.
xlog("from: $fu to: $ru \n")
OUTPUT: "from: sip:user01@mykamailio.de to:user02@mykamailio.de"
BUT using these variables as a second parameter in perl_exec() leads to an error on kamailio start-up cause of bad config file.
perl_exec("my_perl_script",$fu);
Any suggestions or ideas???
Thank you...
Regards,
Nicolas