Changeset 3499

Show
Ignore:
Timestamp:
01/03/07 00:19:36 (5 years ago)
Author:
qldrob
Message:

Finish replacement of Asterisk's ENUMLOOKUP function.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • freepbx/trunk/amp_conf/agi-bin/enumlookup.agi

    r3498 r3499  
    1212 
    1313$AGI = new AGI(); 
    14 $lookup = get_var( $AGI, "ENUM" ); 
     14$lookup = get_var( $AGI, "DIAL_NUMBER" ); 
    1515 
    1616$enums = Array('e164.org', 'e164.arpa', 'e164.info'); 
     
    4949} 
    5050 
    51 $AGI->verbose("Setting DIALSTR to $dialstr", 3); 
    52 $AGI->set_variable("DIALSTR", $dialstr); 
     51$AGI->verbose("Setting DIALARR to $dialstr", 3); 
     52$AGI->set_variable("DIALARR", $dialstr); 
    5353 
    5454function get_dig($lookup, $enum) { 
  • freepbx/trunk/amp_conf/astetc/extensions.conf

    r3420 r3499  
    434434; arg1 = trunk number, arg2 = number 
    435435[macro-dialout-enum] 
    436 ; This has been violently beaten upon by Rob Thomas, xrobau@gmail.com 
    437 ; to 1: Be compliant with all the depreciated bits in asterisk 1.2 and 
    438 ; above, and 2: to give a good shot at attempting to be compliant with 
    439 ; RFC3761 by honouring the order in which records are returned. 
     436; Re-written to use enumlookup.agi 
    440437exten => s,1,GotoIf($["${ARG3}" = ""]PASSWD?NOPASSWD); arg3 is pattern password  
    441438exten => s,n(PASSWD),Authenticate(${ARG3})  
     
    448445exten => s,n,Set(DIAL_TRUNK=${ARG1}) 
    449446exten => s,n,DeadAGI(fixlocalprefix)  ; this sets DIAL_NUMBER to the proper dial string for this trunk 
    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 
     448exten => 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. 
     451exten => s,n(dialloop),GotoIf($["foo${DIALARR}"="foo"]?end) 
     452exten => s,n,Set(TRYDIAL=${CUT(DIALARR,%,1)}) 
     453exten => s,n,Set(DIALARR=${CUT(DIALARR,%,2-)}) 
     454exten => s,n,Dial(${TRYDIAL}) 
    513455exten => s,n(dodial),Dial(${DIALSTR}) 
    514456exten => s,n,NoOp(Dial exited in macro-enum-dialout with ${DIALSTATUS}) 
    515457 
    516458; Now, if we're still here, that means the Dial failed for some reason.  
    517 ; If it's CONGESTION or CHANUNAVAIL we probably want to try again on a 
    518 ; different channel. However, if it's the last one, we don't have any 
    519 ; left, and I didn't keep any previous dialstatuses, so hopefully  
    520 ; someone looking throught the logs would have seen the NoOp's 
    521 exten => s,n,GotoIf($["${ENUMPTR}"<"${ENUMCOUNT}"]?maybemore:dialfailed) 
    522 exten => s,n(maybemore),GotoIf($[ $[ "${DIALSTATUS}" = "CHANUNAVAIL" ] | $[ "${DIALSTATUS}" = "CONGESTION" ] ]?continue) 
     459; If it's CONGESTION or CHANUNAVAIL we want to try again on a different 
     460; different channel. If there's no more left, the dialloop tag will exit. 
     461exten => s,n,GotoIf($[ $[ "${DIALSTATUS}" = "CHANUNAVAIL" ] | $[ "${DIALSTATUS}" = "CONGESTION" ] ]?dialloop) 
    523462 
    524463; If we're here, then it's BUSY or NOANSWER or something and well, deal with it. 
     
    526465 
    527466; Here are the exit points for the macro. 
    528 exten => s,n(failed),NoOp(EnumLookup failed on network ${ENUMNET}) 
    529 exten => s,n,Goto(begin) 
    530467 
    531468exten => s,n(failedtotally),NoOp(EnumLookup failed -- no more networks to try)