| 161 | | function get_enum_providers() { |
|---|
| 162 | | // parse enum.conf config file |
|---|
| 163 | | $localprefix_file = get_var($AGI, "ASTETCDIR")."/enum.conf"; |
|---|
| 164 | | if (file_exists($localprefix_file)) { |
|---|
| 165 | | $section="general"; |
|---|
| 166 | | parse_conf($localprefix_file, $conf, $section); |
|---|
| 167 | | if (count($conf) == 0) { |
|---|
| 168 | | $AGI->verbose("Could not parse config file $localprefix_file - using default e164.org", 0); |
|---|
| 169 | | return Array("e164.org"); |
|---|
| 170 | | } |
|---|
| 171 | | } else { |
|---|
| 172 | | $AGI->verbose("Could not open config file $localprefix_file - using default e164.org", 0); |
|---|
| 173 | | return Array("e164.org"); |
|---|
| 174 | | } |
|---|
| 175 | | |
|---|
| 176 | | $enums = Array(); |
|---|
| 177 | | // pickup search org from the conf array |
|---|
| 178 | | if (isset($conf["general"])) { |
|---|
| 179 | | foreach ($conf["general"] as $key=>$options) { |
|---|
| 180 | | if (isset($options["search"])) { |
|---|
| 181 | | foreach($options as $enumorgs) { |
|---|
| 182 | | $enums[]=$enumorgs; |
|---|
| 183 | | } // store each enumorg in array |
|---|
| 184 | | } // else, diff option |
|---|
| 185 | | } // else, this isn't the section we want |
|---|
| 186 | | } // else, no config for this section |
|---|
| 187 | | } |
|---|
| 188 | | |
|---|
| 189 | | function parse_conf($filename, &$conf, &$section) { |
|---|
| 190 | | global $AGI; |
|---|
| 191 | | $AGI->verbose("Parsing config file $filename",3); |
|---|
| 192 | | |
|---|
| 193 | | if (is_null($conf)) { $conf = array(); } |
|---|
| 194 | | |
|---|
| 195 | | if (is_null($section)) { $section = "general"; } |
|---|
| 196 | | |
|---|
| 197 | | if (file_exists($filename)) { |
|---|
| 198 | | $fd = fopen($filename, "r"); |
|---|
| 199 | | while ($line = fgets($fd, 1024)) { |
|---|
| 200 | | if (preg_match("/^\s*([a-zA-Z0-9-_]+)\s*=>\s*(.*?)\s*([;#].*)?$/",$line,$matches)) { |
|---|
| 201 | | // name => => value |
|---|
| 202 | | // keep [] to allow for duplicate options like search |
|---|
| 203 | | // could extend options to include for example: |
|---|
| 204 | | // skipgateway => slow-sip-gateway.com |
|---|
| 205 | | // earlyexit => yes (to return only 1 enum from dns lookup) |
|---|
| 206 | | $conf[$section][][$matches[1]] = $matches[2]; |
|---|
| 207 | | } else if (preg_match("/^\s*\[(.+)\]/",$line,$matches)) { |
|---|
| 208 | | // section name |
|---|
| 209 | | $section = strtolower($matches[1]); |
|---|
| 210 | | } else if (preg_match("/^\s*#include\s+(.*)\s*([;#].*)?/",$line,$matches)) { |
|---|
| 211 | | // include another file |
|---|
| 212 | | if ($matches[1][0] == "/") { |
|---|
| 213 | | // absolute path |
|---|
| 214 | | $filename = $matches[1]; |
|---|
| 215 | | } else { |
|---|
| 216 | | // relative path |
|---|
| 217 | | $filename = dirname($filename)."/".$matches[1]; |
|---|
| 218 | | } |
|---|
| 219 | | parse_conf($filename, $conf, $section); |
|---|
| 220 | | } |
|---|
| 221 | | } |
|---|
| 222 | | } |
|---|
| 223 | | } |
|---|
| 224 | | |
|---|