Hi Chris,
Yes, GoSub() is favored over Macro() in Asterisk 1.8, but Macro() still works
fine. The problem is Macro()'s can't be nested over 5 or so deep without
maxing out the stack. GoSub() has no such limitations.
As you say Asterisk 1.8 has a new REPLACE function, but I think that would be
just as clumsy as using URIENCODE / URIDECODE and less effective. Speaking of
REPLACE, it is useful for deleting unwanted characters, but not much more than
that since it doesn't work like the UNIX 'tr', ie, foo=xcatx
${REPLACE(foo,cat,CAT)} returns xCCCx and not xCATx as you might expect.
Lonnie
On Feb 10, 2012, at 1:42 PM, Chris Abnett wrote:
> I never did understand why asterisk went from the pipe to the comma..
> Just for that reason....
>
> When I ran into this I had to cleanse my caller ID names before letting
> scripts get hold of them... Esp since my caller ID names are often keyed
> into hotel PMS systems by people.. They use whatever delimiter they feel
> like to separate names...
>
> You can try the asterisk function replace.. It is supposed to find a
> character and replace it.. don¹t know if it is accruate, I have not tried
> it..
>
> I also thought that gosub is the preferred method instead of macro for all
> versions of asterisk going forward...
> -Christopher
>
> On 2/10/12 2:29 PM, "Lonnie Abelbeck" <[email protected]> wrote:
>
>> Update,
>>
>> I'm thinking this may be useful info, enclosed is an update. As David
>> suggests this appears to be a bug using Macro (and parsing), so let's try
>> GoSub()...
>> --
>> [macro-test]
>> exten => s,1,NOOP(ARG1=${ARG1})
>> exten => s,n,NOOP(ARG2=${ARG2})
>> exten => s,n,NOOP(ARG3=${ARG3})
>>
>> [sub-test]
>> exten => start,1,NOOP(ARG1=${ARG1})
>> same => n,NOOP(ARG2=${ARG2})
>> same => n,NOOP(ARG3=${ARG3})
>> same => n,Return()
>> --
>>
>> Test1 code: pass ${CALLERID(name)} by itself
>> --
>> exten => 9,1,Set(CALLERID(name)=Abelbeck, Lonnie)
>> exten => 9,n,Macro(test,${CALLERID(name)})
>> exten => 9,n,GoSub(sub-test,start,1(${CALLERID(name)}))
>> == Output ==
>> -- Executing [9@default:1] Set("SIP/10.10.50.1-0000000e",
>> "CALLERID(name)=Abelbeck, Lonnie") in new stack
>> -- Executing [9@default:2] Macro("SIP/10.10.50.1-0000000e",
>> "test,Abelbeck, Lonnie") in new stack
>> -- Executing [s@macro-test:1] NoOp("SIP/10.10.50.1-0000000e",
>> "ARG1=Abelbeck") in new stack
>> -- Executing [s@macro-test:2] NoOp("SIP/10.10.50.1-0000000e", "ARG2=
>> Lonnie") in new stack
>> -- Executing [s@macro-test:3] NoOp("SIP/10.10.50.1-0000000e", "ARG3=") in
>> new stack
>>
>> -- Executing [9@default:3] Gosub("SIP/10.10.50.1-0000000e",
>> "sub-test,start,1(Abelbeck, Lonnie)") in new stack
>> -- Executing [start@sub-test:1] NoOp("SIP/10.10.50.1-0000000e",
>> "ARG1=Abelbeck") in new stack
>> -- Executing [start@sub-test:2] NoOp("SIP/10.10.50.1-0000000e", "ARG2=
>> Lonnie") in new stack
>> -- Executing [start@sub-test:3] NoOp("SIP/10.10.50.1-0000000e", "ARG3=")
>> in new stack
>> -- Executing [start@sub-test:4] Return("SIP/10.10.50.1-0000000e", "") in
>> new stack
>> ==
>> Note both Macro and GoSub fail in the same way, the comma in the data is
>> parsed.
>>
>>
>> Test2 code: add quotes around "${CALLERID(name)}" when passing
>> --
>> exten => 9,1,Set(CALLERID(name)=Abelbeck, Lonnie)
>> exten => 9,n,Macro(test,"${CALLERID(name)}")
>> exten => 9,n,GoSub(sub-test,start,1("${CALLERID(name)}"))
>> == Output ==
>> -- Executing [9@default:1] Set("SIP/10.10.50.1-0000000b",
>> "CALLERID(name)=Abelbeck, Lonnie") in new stack
>> -- Executing [9@default:2] Macro("SIP/10.10.50.1-0000000b",
>> "test,"Abelbeck, Lonnie"") in new stack
>> -- Executing [s@macro-test:1] NoOp("SIP/10.10.50.1-0000000b",
>> "ARG1="Abelbeck") in new stack
>> -- Executing [s@macro-test:2] NoOp("SIP/10.10.50.1-0000000b", "ARG2=
>> Lonnie"") in new stack
>> -- Executing [s@macro-test:3] NoOp("SIP/10.10.50.1-0000000b", "ARG3=") in
>> new stack
>>
>> -- Executing [9@default:3] Gosub("SIP/10.10.50.1-0000000b",
>> "sub-test,start,1("Abelbeck, Lonnie")") in new stack
>> -- Executing [start@sub-test:1] NoOp("SIP/10.10.50.1-0000000b",
>> "ARG1="Abelbeck, Lonnie"") in new stack
>> -- Executing [start@sub-test:2] NoOp("SIP/10.10.50.1-0000000b", "ARG2=")
>> in new stack
>> -- Executing [start@sub-test:3] NoOp("SIP/10.10.50.1-0000000b", "ARG3=")
>> in new stack
>> -- Executing [start@sub-test:4] Return("SIP/10.10.50.1-0000000b", "") in
>> new stack
>> ==
>> Note Macro fails in the same way as Test1 with quoting but GoSub now
>> "works" (the comma is no longer parsed) but the downside is the "'s chars
>> are now added to ARG1.
>>
>>
>> Test3 code: pass ${CALLERID(name)} with URIENCODE() then URIDECODE()
>> --
>> [macro-test]
>> exten => s,1,NOOP(ARG1=${URIDECODE(${ARG1})})
>> exten => s,n,NOOP(ARG2=${ARG2})
>> exten => s,n,NOOP(ARG3=${ARG3})
>>
>> [sub-test]
>> exten => start,1,NOOP(ARG1=${URIDECODE(${ARG1})})
>> same => n,NOOP(ARG2=${ARG2})
>> same => n,NOOP(ARG3=${ARG3})
>> same => n,Return()
>>
>> exten => 9,1,Set(CALLERID(name)=Abelbeck, Lonnie)
>> exten => 9,n,Macro(test,${URIENCODE(${CALLERID(name)})})
>> exten => 9,n,GoSub(sub-test,start,1(${URIENCODE(${CALLERID(name)})}))
>> == Output ==
>> -- Executing [9@default:1] Set("SIP/10.10.50.1-00000014",
>> "CALLERID(name)=Abelbeck, Lonnie") in new stack
>> -- Executing [9@default:2] Macro("SIP/10.10.50.1-00000014",
>> "test,Abelbeck%2C%20Lonnie") in new stack
>> -- Executing [s@macro-test:1] NoOp("SIP/10.10.50.1-00000014",
>> "ARG1=Abelbeck, Lonnie") in new stack
>> -- Executing [s@macro-test:2] NoOp("SIP/10.10.50.1-00000014", "ARG2=") in
>> new stack
>> -- Executing [s@macro-test:3] NoOp("SIP/10.10.50.1-00000014", "ARG3=") in
>> new stack
>>
>> -- Executing [9@default:3] Gosub("SIP/10.10.50.1-00000014",
>> "sub-test,start,1(Abelbeck%2C%20Lonnie)") in new stack
>> -- Executing [start@sub-test:1] NoOp("SIP/10.10.50.1-00000014",
>> "ARG1=Abelbeck, Lonnie") in new stack
>> -- Executing [start@sub-test:2] NoOp("SIP/10.10.50.1-00000014", "ARG2=")
>> in new stack
>> -- Executing [start@sub-test:3] NoOp("SIP/10.10.50.1-00000014", "ARG3=")
>> in new stack
>> -- Executing [start@sub-test:4] Return("SIP/10.10.50.1-00000014", "") in
>> new stack
>> ==
>> Note the code is messy, but it now works with both Macro and GoSub
>> without any added chars to the args.
>>
>> For this special case, moving the ${CALLERID(name)} call into the Macro
>> rather than passing as an argument is the simplest.
>>
>> The moral to this story is in Asterisk 1.4 the pipe (|) character was
>> uncommon in the data and not much of a problem, while in Asterisk 1.8 the
>> comma (,) is quite common in data leading to unexpected results.
>>
>> Lonnie
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Astlinux-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/astlinux-users
Donations to support AstLinux are graciously accepted via PayPal to
[email protected].