view · edit · print · history

; ENUM dialout macro:
;   ${ARG1} - dial number
;   ${ARG2} - toll provider
;   ${ARG3} - timeout
;   ${ARG4} - options
exten => s,1,Set(DIAL_NUMBER=+${ARG1}) ; Add a plus to the start, becasue ENUMLOOKUP needs it.
exten => s,n,Set(E164NETWORKS=e164.arpa-e164.info-e164.org)
; Checking here to see if there are any e164 networks left to check.
exten => s,n(begin),GotoIf($[ ${LEN(${E164NETWORKS})} < 2 ]?failed)
; There are, so we take the first one
exten => s,n,Set(ENUMNET=${CUT(E164NETWORKS,,1)})
; And trim it from the front of E164NETWORKS
exten => s,n,Set(E164NETWORKS=${CUT(E164NETWORKS,,2-)})
; OK, this is now quite complex. To remain compliant, we have to iterate
; through, in order, the returned records. Since we want to make this
; call over the network, we can ignore tel: lines. Even if it's first
; priority.
; Documentation is wrong. It can return nothing if the enum lookup fails.
exten => s,n,GotoIf($[ x${ENUMCOUNT} = x ]?begin)
; Now the count may be zero, so if it is, check the next network
exten => s,n,GotoIf($[ ${ENUMCOUNT} = 0 ]?begin)
; Now, let's start through them.
exten => s,n,Set(ENUMPTR=1)
exten => s,n(startloop),Set(ENUM=${ENUMLOOKUP(${DIAL_NUMBER},ALL,${ENUMPTR},${ENUMNET})})
; Sanity check the return, make sure there's something in there.
exten => s,n,GotoIf($[${LEN(${ENUM})} = 0 ]?continue)
exten => s,n,GotoIf($[${ENUM:0:3} = sip ]?sipuri)
exten => s,n,GotoIf($[${ENUM:0:3} = iax ]?iaxuri)
; If we're here, it's not a protocol we know about. Let's increment the pointer
; and if it's more than ENUMCOUNT, we know we've run out of options. Try the
; next e164 network.
exten => s,n(continue),Set(ENUMPTR=$[${ENUMPTR} + 1])
exten => s,n,GotoIf($[${ENUMPTR} > ${ENUMCOUNT}]?begin)
; OK. If we're here, we've still got some enum entries to go through.
; Back to the start with you!
exten => s,n,Goto(startloop)
; If the prefix is 'sip:'...
exten => s,n(sipuri),Set(DIALSTR=SIP/${ENUM:4})
exten => s,n,Goto(dodial)
; If it's IAX2...
exten => s,n(iaxuri),Set(DIALSTR=IAX2/${ENUM:5})

exten => s,n(dodial),Dial(${DIALSTR},${ARG3},${ARG4}) ; attempting free IP call
exten => s,n,NoOp(Enum dial ${DIALSTR} exited in macro-enumdialout with ${DIALSTATUS})
; Now, if we're still here, that means the Dial failed for some reason.
; If it's CONGESTION or CHANUNAVAIL we probably want to try again on a
; different channel. However, if it's the last one, we don't have any
; left, and I didn't keep any previous dialstatuses, so hopefully
; someone looking throught the logs would have seen the NoOp's
exten => s,n,GotoIf($[${ENUMPTR} = ${ENUMCOUNT}]?noneleft)
exten => s,n,GotoIf($[ $[ ${DIALSTATUS} = CHANUNAVAIL ] | $[ ${DIALSTATUS} = CONGESTION ] ]?continue)
; If we're here, then it's BUSY or NOANSWER or something else and we'll deal with it.
exten => s,n(noneleft),Goto(s-${DIALSTATUS},1)

; Here are the exit points for the macro.
exten => s,n(failed),NoOp(EnumLookups failed)
exten => s,n(dotolldial),Playback(this-call-will-cost)
exten => s,n,Playback(dollars)
exten => s,n,Dial(${ARG2},${ARG3},${ARG4}) ; attempting toll PSTN call
exten => s,n,NoOp(Toll dial ${ARG2} exited in macro-enumdialout with ${DIALSTATUS})
exten => s,n,Macro(failann,${DIALSTATUS})

exten => s-BUSY,1,Macro(failann,${DIALSTATUS})
exten => s-NOANSWER,1,Macro(failann,${DIALSTATUS})
exten => _s-.,1,Goto(dotolldial)

view · edit · print · history · Last edited by cdoban.
Originally by cdoban.
Page last modified on November 16, 2006, at 01:38 AM