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

"Nicolas Rüger" NicolasRueger at gmx.de
Thu Aug 19 15:30:23 CEST 2010


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 at 1und1.de>
> An: "Nicolas Rüger" <NicolasRueger at gmx.de>
> CC: "sr-users at lists.sip-router.org" <sr-users at 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:
> > 
> > 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.
> 
> 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.
> 
> > 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
> 
> 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 at lists.sip-router.org
> http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-users

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01



More information about the sr-users mailing list