| 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"; |
|---|
| | 25 | if (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 |
|---|
| | 39 | if (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 |
|---|
| | 166 | function 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 | |
|---|