Ticket #3423: mypatch.diff

File mypatch.diff, 3.0 kB (added by matka, 3 years ago)

proposed changes

  • enumlookup.agi

    old new  
    2020$AGI = new AGI(); 
    2121$lookup = get_var( $AGI, "DIAL_NUMBER" ); 
    2222 
    23 $enums = Array( 
    24   'e164.org',  
    25   //'e164.arpa',  
    26   //'e164.info', 
    27 ); 
     23// parse enum.conf config file 
     24$localprefix_file = get_var($AGI, "ASTETCDIR")."/enum.conf"; 
     25if (file_exists($localprefix_file)) { 
     26        $section="general"; 
     27  parse_conf($localprefix_file, $conf, $section); 
     28  if (count($conf) == 0) { 
     29    $AGI->verbose("Could not parse config file $localprefix_file", 0); 
     30    exit(1); 
     31    } 
     32  } else { 
     33    $AGI->verbose("Could not open config file $localprefix_file", 0); 
     34    exit(1); 
     35
     36 
     37$enums = Array(); 
     38// pickup search org from the conf array 
     39if (isset($conf["general"])) { 
     40  foreach ($conf["general"] as $key=>$options) { 
     41    if (isset($options["search"])) { 
     42      foreach($options as $enumorgs) { 
     43        $enums[]=$enumorgs; 
     44      } // store each enumorg in array   
     45    } // else, diff option  
     46  } // else, this isn't the section we want 
     47} // else, no config for this section 
    2848 
    29 // Go through the ENUM providers and look for the number. 
    3049 
    3150$dialstr = ""; 
    3251 
     
    5877    foreach ($arr as $key => $row) { 
    5978      if (eregi('SIP|IAX', $row['tech'])) { 
    6079        $URI = $row['URI']; 
    61         $dialstr .= $nextURI[$URI]."|"; 
     80        // string delimiter defined in [macro-dialout-enum] 
     81                                $dialstr .= $nextURI[$URI]."%"; 
    6282      } 
    6383    } 
    6484  } 
     
    7090function get_dig($lookup, $enum) { 
    7191  global $AGI; 
    7292 
    73   $AGI->verbose("Looking up $lookup on $enum via shell command DIG",3);; 
     93  $AGI->verbose("Looking up $lookup on $enum via shell command DIG",3); 
    7494  $arpa = ""; 
    7595  for ($i = 0; $i < strlen($lookup); $i++) { 
    7696    $arpa = $lookup[$i].".".$arpa; 
     
    143163  else return ''; 
    144164} 
    145165 
     166function parse_conf($filename, &$conf, &$section) { 
     167        global $AGI; 
     168 
     169  $AGI->verbose("Parsing config file $filename",3); 
     170 
     171  if (is_null($conf)) { 
     172    $conf = array(); 
     173  } 
     174   
     175      if (is_null($section)) { 
     176    $section = "general"; 
     177        } 
     178   
     179  if (file_exists($filename)) { 
     180    $fd = fopen($filename, "r"); 
     181    while ($line = fgets($fd, 1024)) { 
     182      if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=>\s*(.*?)\s*([;#].*)?$/",$line,$matches)) { 
     183        // name => => value 
     184        // keep [] to allow for duplicate options like search 
     185        // could extend options to include for example: 
     186        // skipgateway => slow-sip-gateway.com 
     187        // earlyexit => yes (to return only 1 enum from dns lookup)  
     188        $conf[$section][][$matches[1]] = $matches[2]; 
     189      } else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) { 
     190        // section name 
     191        $section = strtolower($matches[1]); 
     192      } else if (preg_match("/^\s*#include\s+(.*)\s*([;#].*)?/",$line,$matches)) { 
     193        // include another file 
     194        if ($matches[1][0] == "/") { 
     195          // absolute path 
     196          $filename = $matches[1]; 
     197        } else { 
     198          // relative path 
     199          $filename =  dirname($filename)."/".$matches[1]; 
     200        } 
     201        parse_conf($filename, $conf, $section); 
     202      } 
     203    } 
     204  } 
     205} 
     206 
    146207?>