[asterisk-users] Asterisk perl AGI confusing variables

Sammy Govind govoiper at gmail.com
Sat Feb 11 23:40:53 CST 2012


Hey Ron,
Thanks for taking out time for this weird issue. No this is the only code
thats running and I simply copy pasted it here. I'll go through the artivle
you mentioned and other advices you gave may hopefully resolve this issue.
But in general its beyond my logic to see whats actually going on here.
Simply mind blowing trick for me :)

Just to add here, even changing the arrangement of verbose statement above
or below the Addheader statement changes the variables as well.

Additional Details:
I tested the code without enclosing it in a sub , in a very small agi just
for this and this same code was giving me 100% results. So that means that
the production AGI/perl code has something in it thats causing the issue !?

Regards,
Sammy

On Sat, Feb 11, 2012 at 11:20 PM, Ron Bergin <rkb at i.frys.com> wrote:

> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-users/attachments/20120212/d9f8229b/attachment.htm>


More information about the asterisk-users mailing list