[SR-Users] Evaluate Perl Return Value in Routing Logic

"Nicolas Rüger" NicolasRueger at gmx.de
Tue Aug 17 16:13:55 CEST 2010


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 at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

-- 
GMX DSL SOMMER-SPECIAL: Surf & Phone Flat 16.000 für nur 19,99 ¿/mtl.!*
http://portal.gmx.net/de/go/dsl



More information about the sr-users mailing list