1
package Dahdi::Config::Params;
3
# Written by Oron Peled <oron@actcom.co.il>
4
# Copyright (C) 2009, Xorcom
5
# This program is free software; you can redistribute and/or
6
# modify it under the same terms as Perl itself.
8
# $Id: Params.pm 7224 2009-09-27 15:01:20Z tzafrir $
14
Dahdi::Config::Params -- Object oriented representation of F<genconf_parameters> file.
18
use Dahdi::Config::Params;
19
my $params = Dahdi::Config::Params->new('the-config-file');
20
print $params->item{'some-key'};
21
print $params->item{'some-key', NODEFAULTS => 1};
22
$params->dump; # For debugging
26
The constructor must be given a configuration file name:
30
=item * Missing file is B<not> an error.
32
=item * Other opening errors cause a C<die> to be thrown.
34
=item * The file name is saved as the value of C<GENCONF_FILE> key.
38
The access to config keys should only be done via the C<item()> method:
42
=item * It contains all hard-coded defaults.
44
=item * All these values are overriden by directives in the config file.
46
=item * Calling it with C<NODEFAULTS =E<gt> 1> option, returns C<undef> for keys that
47
do not appear in the configuration file.
54
my $pack = shift || die;
55
my $cfg_file = shift || die;
57
GENCONF_FILE => $cfg_file,
60
if(!open(F, $cfg_file)) {
61
if(defined($!{ENOENT})) {
62
#print STDERR "No $cfg_file. Assume empty config\n";
63
return $self; # Empty configuration
65
die "$pack: Failed to open '$cfg_file': $!\n";
67
#print STDERR "$pack: $cfg_file\n";
73
s/\s+$//; # trim tail whitespace
75
if(defined $array_key && /^\s+/) {
76
s/^\s+//; # trim beginning whitespace
77
push(@{$self->{$array_key}}, $_);
81
($key, $val) = split(/\s+/, $_, 2);
87
die "$cfg_file:$.: Duplicate key '$key'\n", if exists $self->{$key};
95
my $self = shift || die;
96
my $key = shift || die;
100
freepbx => 'no', # Better via -F command line
101
fxs_immediate => 'no',
102
fxs_default_start => 'ks',
103
fxo_default_start => 'ks',
104
em_signalling => 'none',
106
context_lines => 'from-pstn',
107
context_phones => 'from-internal',
108
context_input => 'astbank-input',
109
context_output => 'astbank-output',
112
brint_overlap => 'no',
113
bri_sig_style => 'bri_ptmp',
115
bri_hardhdlc => 'auto',
116
pri_connection_type => 'PRI',
117
r2_idle_bits => '1101',
118
tdm_framing => 'esf',
119
'pri_termtype' => [ 'SPAN/* TE' ],
121
return $self->{$key} if exists($self->{$key}) or $options{NODEFAULTS};
122
return $defaults{$key};
126
my $self = shift || die;
127
printf STDERR "%s dump:\n", ref $self;
129
foreach my $k (sort keys %$self) {
130
my $val = $self->{$k};
132
#print STDERR "DEBUG: '$k', '$ref', '$val'\n";
134
printf STDERR "%-${width}s %s\n", $k, $val;
135
} elsif($ref eq 'SCALAR') {
136
printf STDERR "%-${width}s %s\n", $k, ${$val};
137
} elsif($ref eq 'ARRAY') {
138
#printf STDERR "%s:\n", $k;
140
foreach my $v (@{$val}) {
141
printf STDERR "%-${width}s %s\n", "$k\->[$i]", $v;
144
} elsif($ref eq 'HASH') {
145
#printf STDERR "%s:\n", $k;
146
foreach my $k1 (keys %{$val}) {
147
printf STDERR "%-${width}s %s\n", "$k\->\{$k1\}", ${$val}{$k1};
150
printf STDERR "%-${width}s (-> %s)\n", $k, $ref;