In an Asterisk $[]
expression, undefined variables do not return an implicit empty string or zero. They expand as "nothing" prior to evaluation of the expression, so after the variable is expanded (to nothing), it isn't visible to the expression parser. This causes the error already noted by Pablo Alsina:
GotoIf("IAX2/AtlantaTeliax-10086", "?CLOSED,1")
There are two ways to avoid this:
- Always give your variables reasonable defaults before you use them (as Pablo suggested).
- In any
$[]
expression, enclose your variables and literals with double-quotes. This will cause an undefined variable to be handled as an empty string, which can still be used for comparison purposes.
Personally, I try to do both. For example:
exten => START,n,Set(FORCE_CLOSED=FALSE)
exten => START,n,GotoIf($["${FORCE_CLOSED}"="TRUE"]?CLOSED,1)
Note the double-quotes around ${FORCE_CLOSED}
and the comparison value. Even if the variable is undefined, the expression will have ""
(an empty string) to compare against "TRUE"
.
Really, you can use any character you like, because it will just be tacked onto the variable expansion. It just gives you a literal value that is guaranteed to be there in case the variable is undefined. I like quotes because it makes the code resemble other programming languages. You could just as easily use something like $[x${FORCE_CLOSED}=xTRUE]
, which is commonly seen in Bourne shell scripting. The end result is the same.
This is my new extensions.conf which seems to have solved the problem
[default]
exten => s,1,System(asterisk -rx 'sip reload') ; hack to force sip reload
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Playback(vm-extension)
exten => s,n,WaitExten()
exten => 0011,1,Goto(outbound,s,1)
exten => 11,1,Dial(SIP/mysipuser/5555555555,30,g) ;calls 555-555-5555
exten => 11,n,Goto(closechannel,s,1)
exten => 77,1,Dial(SIP/mysipuser/1111111111,30,g) ;calls 111-111-1111
exten => 77,n,Goto(closechannel,s,1)
[outbound]
exten => s,1,Answer
exten => s,n,Wait(1)
exten => s,n,Playback(vm-extension)
exten => s,n,WaitExten()
exten => _NXXNXXNXXX,1,Dial(SIP/mysipuser/${EXTEN})
exten => _NXXNXXNXXX,n,Hangup
[closechannel]
exten => s,1,System(asterisk -rx 'sip reload')
exten => s,n,Hangup()
So the three changes I made were the addition of the exten => s,1,System(asterisk -rx 'sip reload')
statement, [closechannel]
context, and the ,30,g
to the Dial() command. The System command forces a sip reload every time someone tries to call in. The ,g
flag tells asterisk to continue executing code after calling parties disconnect.
This seems to work "most" of the times.
Best Answer
Usual reasons I can think of to limit concurrent calls would be: