| 450 | | exten => s,n,Set(E164NETWORKS=e164.arpa-e164.info-e164.org) ; enum networks to check |
|---|
| 451 | | exten => s,n,GotoIf($["${DIAL_NUMBER:0:1}" = "+"]?begin) ; Skip next line if it already is prefixed by a plus |
|---|
| 452 | | exten => s,n,Set(DIAL_NUMBER=+${DIAL_NUMBER}) ; Add a plus to the start, becasue ENUMLOOKUP needs it. |
|---|
| 453 | | |
|---|
| 454 | | ; start of main network loop |
|---|
| 455 | | exten => s,n(begin),NoOp(E164NETWORKS is ${E164NETWORKS}) |
|---|
| 456 | | exten => s,n,GotoIf($["${E164NETWORKS:1:2}"=""]?failedtotally) |
|---|
| 457 | | exten => s,n,Set(ENUMNET=${CUT(E164NETWORKS,-,1)}) |
|---|
| 458 | | exten => s,n,Set(E164NETWORKS=${CUT(E164NETWORKS,-,2-)}) |
|---|
| 459 | | |
|---|
| 460 | | exten => s,n,NoOp(E164NETWORKS is now ${E164NETWORKS}) |
|---|
| 461 | | exten => s,n,NoOp(ENUMNET is ${ENUMNET}) |
|---|
| 462 | | |
|---|
| 463 | | exten => s,n,Set(ENUMCOUNT=${ENUMLOOKUP(${DIAL_NUMBER},all,c,${ENUMNET})}) |
|---|
| 464 | | exten => s,n,Set(ENUMPTR=0) |
|---|
| 465 | | exten => s,n,Set(LOOKUPBUG=0) |
|---|
| 466 | | |
|---|
| 467 | | ; start of main lookup loop |
|---|
| 468 | | exten => s,n(startloop),GotoIf($["${ENUMPTR}"<"${ENUMCOUNT}"]?continue:failed) |
|---|
| 469 | | |
|---|
| 470 | | ; Now, let's start through them. |
|---|
| 471 | | exten => s,n(continue),Set(ENUMPTR=$[${ENUMPTR}+1]) |
|---|
| 472 | | exten => s,n,NoOp(Doing ENUMLOOKUP(${DIAL_NUMBER},all,${ENUMPTR},${ENUMNET})) |
|---|
| 473 | | exten => s,n,Set(ENUM=${ENUMLOOKUP(${DIAL_NUMBER},all,${ENUMPTR},${ENUMNET})}) |
|---|
| 474 | | |
|---|
| 475 | | ; Deal with reponse |
|---|
| 476 | | exten => s,n,GotoIf($["${ENUM:0:3}" = "sip" ]?sipuri) |
|---|
| 477 | | exten => s,n,GotoIf($["${ENUM:0:3}" = "iax" ]?iaxuri) |
|---|
| 478 | | ; It doesn't matter if you don't have h323 enabled, as when it tries to dial, it cares |
|---|
| 479 | | ; about dialstatus and retries if there are any enum results left. |
|---|
| 480 | | exten => s,n,GotoIf($["${ENUM:0:3}" = "h32" ]?h323uri) |
|---|
| 481 | | |
|---|
| 482 | | ; e164.org can return 'ADDRESS' lines. Because of *'s poor handling of Enum |
|---|
| 483 | | ; lookups, we want to DECREMENT the enum pointer. Yes. That means we try more |
|---|
| 484 | | ; times than there actually exists entries. |
|---|
| 485 | | exten => s,n,GotoIf($["${ENUM:0:3}" = "ADD" ]?enumbug) |
|---|
| 486 | | |
|---|
| 487 | | ; OK. If we're here, we've still got some enum entries to go through. Back to |
|---|
| 488 | | ; the start with you! |
|---|
| 489 | | exten => s,n,Goto(startloop) |
|---|
| 490 | | |
|---|
| 491 | | ; We're here because of the poor implementation of ENUMLOOKUP in Asterisk. It |
|---|
| 492 | | ; is quite possible to do three ENUMLOOKUPS and get the same entry each time. |
|---|
| 493 | | ; The only workaround I can think of is when we hit an invalid entry, do a |
|---|
| 494 | | ; DECREMENT of the pointer, and keep trying. |
|---|
| 495 | | exten => s,n(enumbug),Set(ENUMPTR=$[${ENUMPTR}-1]) |
|---|
| 496 | | exten => s,n,NoOp(If this is looping with the same ENUM value, The ENUMLOOKUP function is fixed!) |
|---|
| 497 | | exten => s,n,Set(LOOKUPBUG=$[${LOOKUPBUG}+1]) |
|---|
| 498 | | ; If we've done this more than, ooh, 5 times, then give up on this network. Sorry. |
|---|
| 499 | | exten => s,n,GotoIf($["${LOOKUPBUG}" > 5 ]?failed) |
|---|
| 500 | | exten => s,n,Goto(continue) |
|---|
| 501 | | |
|---|
| 502 | | ; If the prefix is 'sip:'... |
|---|
| 503 | | exten => s,n(sipuri),Set(DIALSTR=SIP/${ENUM:4}) |
|---|
| 504 | | exten => s,n,Goto(dodial) |
|---|
| 505 | | |
|---|
| 506 | | ; If it's IAX2... |
|---|
| 507 | | exten => s,n(iaxuri),Set(DIALSTR=IAX2/${ENUM:5}) |
|---|
| 508 | | exten => s,n,Goto(dodial) |
|---|
| 509 | | |
|---|
| 510 | | ; Or even if it's H323. |
|---|
| 511 | | exten => s,n(h323uri),Set(DIALSTR=H323/${ENUM:5}) |
|---|
| 512 | | |
|---|
| | 447 | ; Replacement for asterisk's ENUMLOOKUP function |
|---|
| | 448 | exten => s,n,DeadAGI(enumlookup.agi) |
|---|
| | 449 | ; Now we have the variable DIALARR set to a list of URI's that can be called, in order of priority |
|---|
| | 450 | ; Loop through them trying them in order. |
|---|
| | 451 | exten => s,n(dialloop),GotoIf($["foo${DIALARR}"="foo"]?end) |
|---|
| | 452 | exten => s,n,Set(TRYDIAL=${CUT(DIALARR,%,1)}) |
|---|
| | 453 | exten => s,n,Set(DIALARR=${CUT(DIALARR,%,2-)}) |
|---|
| | 454 | exten => s,n,Dial(${TRYDIAL}) |
|---|