[asterisk-users] Asterisk perl AGI confusing variables

Ron Bergin rkb at i.frys.com
Sat Feb 11 12:20:20 CST 2012


Sammy Govind wrote:
> Hello all,
>
> I'm struck with a very strange problem today. I've an AGI with some code
> subroutine snippet as follows:
>
>
> sub enable_sbc($) {
>         my $carrier = shift;
>         my $tmp = substr($carrier,1);
>         my $jkh = $tmp;
>         $server_port = $ast_agi->get_variable("SIPPEER($jkh,port)");
>         $ser_ip = $ast_agi->get_variable("SIPPEER($tmp,ip)");
>         $ast_agi->exec("SIPAddHeader","P-PORT: $server_port");
>         $ast_agi->exec("SIPAddHeader","P-IPADDRESS: $ser_ip");
>         return 0;
> }
>
>
> Where $carrier resolves to "@my-carrier"
>
> Strangely and very weird get variable is returning correct values on
> console as given below but the variables containing the values gets lost
> or
> confused with each other !
>
> <SIP/sipproxy3.32-00000000>AGI Rx << GET VARIABLE SIPPEER(my-carrier,port)
> <SIP/sipproxy3.32-00000000>AGI Tx >> 200 result=1 (5060)
> <SIP/sipproxy3.32-00000000>AGI Rx << GET VARIABLE SIPPEER(my-carrier,ip)
> <SIP/sipproxy3.32-00000000>AGI Tx >> 200 result=1 (192.168.2.19)
> <SIP/sipproxy3.32-00000000>AGI Rx << EXEC SIPAddHeader "P-PORT: "
>     -- AGI Script Executing Application: (SIPAddHeader) Options: (P-PORT:
> )
> <SIP/sipproxy3.32-00000000>AGI Tx >> 200 result=0
> <SIP/sipproxy3.32-00000000>AGI Rx << EXEC SIPAddHeader "P-IPADDRESS: 5060"
>     -- AGI Script Executing Application: (SIPAddHeader) Options:
> (P-IPADDRESS: 5060)
> <SIP/sipproxy3.32-00000000>AGI Tx >> 200 result=0
>
>
> Anyone please help. Am I doing anything wrong ?
>
>
> Regards,
> Sammy.
> --
> _____________________________________________________________________

Did you copy/paste the code in the email posting, or did you retype it?

Is it possible that you have multiple versions of the script and the wrong
one is being executed?

First step I'd suggest, after checking the above possibility, is to remove
the prototype.  It is almost never needed/wanted and can introduce bugs if
not used correctly.
http://www.modernperlbooks.com/mt/2009/08/the-problem-with-prototypes.html

Next, are you using the strict and warnings pragmas?  If not, you should
add them and fix the problems that they point out.

Next, declare $server_port and $ser_ip as lexical vars in the sub.

Finally, add a couple debugging statements after the get_variable
statements to verify/dump the vars.

---
Ron Bergin




More information about the asterisk-users mailing list