[Asterisk-Users] Macros not working as expected with
extension "h" in some circumstances
John Todd
jtodd at loligo.com
Mon Apr 21 10:10:00 MST 2003
I don't think I'm using it in an improper way, and in any case take
another look at the logs I included; the "GotoIf" isn't even being
parsed; processing is stopping at the SetVar line, and not the GotoIf
line.
From README.variables:
exten => s,5,GotoIf,"$[${varc} = 6]?99|1:s|6"
From "show application GotoIf"
GotoIf(Condition?label1:label2): Go to label 1 if condition is
true, to label2 if condition is false. Either label1 or label2 may be
omitted (in that case, we just don't take the particular branch) but not
both. Look for the condition syntax in examples or documentation.
I have omitted the condition for 0, and it correctly behaves as the
documentation describes. If "1", then jump to extension "s" priority
6. If condition "0" then proceed to next priority.
The "|" character is what is used in the example to separate the
extension from the priority, and the ":" is used to separate the "1"
and "0" cases. Just to be complete about it, I did try putting in
an explicit jump to next priority on condition "0", and it results in
the same undesired results (processing stops after priority 1 in the
macro.)
So, I still may be doing something wrong, or this may be a bug, but
I don't think it's a mis-use of the GotoIf statement according to
what I can find in the docs and other examples.
JT
> > To make a question out of this: Why does it appear that I cannot
>use macros from within the "h" extension if the originating side
>hangs up first in a SIP->SIP call?
>Because you call GotoIf in the unproper way.
>
>The syntax is
>
>GotoIf, Condition?jump_if_condition_1:jump_if_condition_0
>
>Notice ":" not "|"
>
>In your example you have the condition for _1_, it's s|6
>jumping straight to NoOp ....
>
>Martin
>
>>
>> JT
>>
>>
>>
>> from extensions.conf:
>>
>> [intern-post]
>>
>> ; Make sure that if we are recording the channel, we properly clean up the
>> ; recorded files.
>> exten => h,1,Macro(record-cleanup)
>>
>> ; Include operator context
>> include => operator
>> .
>> .
>> .
>> (all extensions in this context are includes other than "h")
>>
>>
>>
>> [macro-record-cleanup]
>> ; If we have recorded a call, it is to our advantage to change the
>> ; format of the call from a two-file system (blah-in.wav blah-out.wav)
>> ; into a single file that contains both legs of the call, and then
>> ; compress the call into some reasonably small filesize using gsm
>> ; compression. This routine should be called out of the "h" priority
>> ; in a context. If the call was not recorded, this macro will
>> ; not cause any harm, so calling it on each hangup isn't a problem.
>> ;
>> ; First, did we record this call? If ${CALLFILENAME} is zero, then
>> ; we can be fairly certain that this call wasn't recorded, so just
>> ; jump to the end of this macro and return out of routine.
>> ;
>> exten => s,1,SetVar(MONITORDIR=/var/spool/asterisk/monitor)
>> exten => s,2,GotoIf($[${CALLFILENAME} = 0]?s|6)
>> ;
>> ; This part of the routine mixes the in and out .wav files into
>>one .wav, and then
>> ; cleans up the original files (removes them)
>> ;
>> exten => s,3,System(/usr/local/bin/wmix ${CALLFILENAME}-in.wav
>>${CALLFILENAME}-out.wav > ${CALLFILENAME})
>> exten => s,4,System(/bin/rm ${MONITORDIR}/${CALLFILENAME}-in.wav
>>${MONITORDIR}/${CALLFILENAME}-out.wav)
>> ;
>> ; This part of the routine compresses the .wav files into a .gsm file for
>> ; better storage (about 1/5 the size of a .wav file). Use
>>"untoast" to restore
>> ; to normal wav file format. (toast and untoast are fairly
>>standard on Linux systems)
>> ;
>> exten => s,5,System(/usr/bin/toast -F ${CALLFILENAME})
>> ;
>> ; End of routine, return to calling point (note: NoOp required for
>>GotoIf at priority 1)
>> exten => s,6,NoOp
>>
>>
>>
>>
>> Output when the originating side ends the call first (unexpectedly
>>stops at priority 1 in macro):
>>
>> (normal call setup and progress not shown - I show everything after hangup)
>>
>> *CLI> DEBUG[30737]: File rtp.c, Line 739 (ast_rtp_raw_write):
>>Difference is 10888, ms is 1381
> > DEBUG[30737]: File channel.c, Line 2015 (ast_channel_bridge):
>Didn't get a frame from channel: SIP/2203-751b
> > DEBUG[30737]: File channel.c, Line 2083 (ast_channel_bridge):
>Bridge stops bridging channels SIP/2203-751b and SIP/2205-12f1
> > == Spawn extension (intern-post, 2205, 1) exited non-zero on
>'SIP/2203-751b'
>> -- Executing Macro("SIP/2203-751b", "record-cleanup") in new stack
>> -- Executing SetVar("SIP/2203-751b",
>>"MONITORDIR=/var/spool/asterisk/monitor") in new stack
>> DEBUG[30737]: File app_macro.c, Line 166 (macro_exec): Extension
>>s, priority 1 returned normally even though call was hung up
>> DEBUG[7176]: File chan_sip.c, Line 503 (__sip_ack): Stopping
>>retransmission on '15125295754753e9727742e77c3d1c51 at 10.0.1.10' of
>>Request 103: Found
>>
>> *CLI>
>>
>>
>>
>> Output when destination side ends the call first (this works as it should):
>>
>> (normal call setup and progress not shown - I show everything after hangup)
>>
>> *CLI> DEBUG[31761]: File channel.c, Line 2015
>>(ast_channel_bridge): Didn't get a frame from channel: SIP/2205-75be
>> DEBUG[31761]: File channel.c, Line 2083 (ast_channel_bridge):
>>Bridge stops bridging channels SIP/2203-fcac and SIP/2205-75be
>> == Spawn extension (intern-post, 2205, 1) exited non-zero on
>>'SIP/2203-fcac'
>> -- Executing Macro("SIP/2203-fcac", "record-cleanup") in new stack
>> -- Executing SetVar("SIP/2203-fcac",
>>"MONITORDIR=/var/spool/asterisk/monitor") in new stack
>> -- Executing GotoIf("SIP/2203-fcac", "0?s|6") in new stack
>> WARNING[31761]: File pbx.c, Line 4190 (pbx_builtin_gotoif): Not
>>taking any branch
>> -- Executing System("SIP/2203-fcac", "/usr/local/bin/wmix
>>20030420-184036-2203-2205-in.wav
>>20030420-184036-2203-2205-out.wav > 20030420-184036-2203-2205") in
>>new stack
>> -- Executing System("SIP/2203-fcac", "/bin/rm
>>/var/spool/asterisk/monitor/20030420-184036-2203-2205-in.wav
>>/var/spool/asterisk/monitor/20030420-184036-2203-2205-out.wav") in
>>new stack
>> -- Executing System("SIP/2203-fcac", "/usr/bin/toast -F
>>20030420-184036-2203-2205") in new stack
>> -- Executing NoOp("SIP/2203-fcac", "") in new stack
>> DEBUG[7176]: File chan_sip.c, Line 503 (__sip_ack): Stopping
>>retransmission on '947298470 at 10.0.1.6' of Request 102: Found
>>
>> *CLI>
>>
>>
>>
>>
>> _______________________________________________
>> Asterisk-Users mailing list
>> Asterisk-Users at lists.digium.com
>> http://lists.digium.com/mailman/listinfo/asterisk-users
>>
>
>_______________________________________________
>Asterisk-Users mailing list
>Asterisk-Users at lists.digium.com
>http://lists.digium.com/mailman/listinfo/asterisk-users
More information about the asterisk-users
mailing list