[asterisk-users] Asterisk perl AGI confusing variables

Sammy Govind govoiper at gmail.com
Mon Feb 13 00:48:20 CST 2012


Hi again,
Just to update I fixed the issue. I read through your reply and the URL in
it and tried alot to make things working but in vain- then I took the tough
way and started looking at the production AGI from the first line
and amended all the warning and unwanted stuff, finally I figured out that
the agi->verbose() function just a few lines above the problematic code was
having a warning and once that was fixed all the code started working fine.

I still wonder what do variable assignments has to do with verbose function
warning, but its all working fine now.
Thanks for the help.

Regards,
Sammy

On Sun, Feb 12, 2012 at 10:40 AM, Sammy Govind <govoiper at gmail.com> wrote:

> 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/20120213/54b180f6/attachment.htm>


More information about the asterisk-users mailing list