aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Bottomley <JBottomley@Parallels.com>2013-05-01 10:59:41 -0700
committerJames Bottomley <JBottomley@Parallels.com>2013-05-01 10:59:41 -0700
commitfe99a5d46c132d1f4ea4c84370a4250b9685f2e6 (patch)
tree8208a39311ebd359250db86f85bfbb0086654ee2
parent21fcd04002628e492e432cc867ab05ab2719cf81 (diff)
downloadasterisk-aastra-fe99a5d46c132d1f4ea4c84370a4250b9685f2e6.tar.gz
ConfigFile: Add handler for asterisk configuration files
Add simple parser for all asterisk config files. Signed-off-by: James Bottomley <JBottomley@Parallels.com>
-rw-r--r--Makefile3
-rw-r--r--include/ConfigFile.class.php51
2 files changed, 53 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index e1fa776..67b1f90 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,8 @@ base-files = \
include/AastraIPPhoneTextScreen.class.php \
include/BaseAastra.class.php \
include/BaseList.class.php \
- include/DatabaseListManager.class.php
+ include/DatabaseListManager.class.php \
+ include/ConfigFile.class.php
base-doc-files = \
etc/apache-asterisk \
diff --git a/include/ConfigFile.class.php b/include/ConfigFile.class.php
new file mode 100644
index 0000000..6f4826e
--- /dev/null
+++ b/include/ConfigFile.class.php
@@ -0,0 +1,51 @@
+<?php
+##
+# Copyright 2013 by James Bottomley
+##
+# Class implementing a wrapper for managing asterisk config files
+##
+class ConfigFile {
+ var $file;
+ var $entries;
+
+ function __construct($file) {
+ $this->file = $file;
+ $this->entries = array();
+ $raw = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
+ foreach($raw as $line) {
+ if (preg_match("/^\s*[#;]/", $line)) {
+ continue;
+ }
+ if (preg_match("/^\s*\[(.*)\]/", $line, $m)) {
+ $section = $m[1];
+ $this->entries[$section] = array();
+ }
+ if (preg_match("/^\s*(\S+)\s*=>*\s*(.*)/", $line, $m)) {
+ $var = $m[1];
+ $val = $m[2];
+ if (preg_match("/^(.*)\s*[#;]/", $line, $m)) {
+ $val = $m[1];
+ }
+ $this->entries[$section][$var] = $val;
+ }
+ }
+ }
+
+ function section($sec) {
+ if (!isset($this->entries[$sec])) {
+ return null;
+ }
+ return $this->entries[$sec];
+ }
+
+ function value($sec, $var) {
+ if (!isset($this->entries[$sec])) {
+ return null;
+ }
+ if (!isset($this->entries[$sec][$var])) {
+ return null;
+ }
+ return $this->entries[$sec][$var];
+ }
+}
+?>