~ubuntu-branches/ubuntu/saucy/dahdi-tools/saucy

« back to all changes in this revision

Viewing changes to .pc/echocan_oslec/xpp/perl_modules/Dahdi/Config/Params.pm

  • Committer: Stefan Lesicnik
  • Date: 2011-05-08 12:22:46 UTC
  • mfrom: (2.1.4 sid)
  • Revision ID: stefan@lsd.co.za-20110508122246-lh6k2x1uy8pl3vdi
Tags: 1:2.4.1-1ubuntu1
* Merge from Debian. Remaining changes:
  - Bug Fix: If linux-headers are not installed, don't block, and print
    information for the user.
  - added debian/dahdi.postinst
  - added --error-handler=init_failed to debian/rules
  - Changes from Debian:
    - debian/control: Change Maintainer
    - debian/control: Removed Uploaders field.
    - debian/control: Removed Debian Vcs-Svn entry and replaced with
      ubuntu-voip Vcs-Bzr, to reflect divergence in packages.
    - debian/control: Package dahdi Depends on dahdi-dkms | dahdi-source
* debian/control: Added gawk as dependency for dkms build (LP: #493304)
* New upstream release (Closes: #581076, #582094).
* Patches hardware_rescan, perl_fix_noserial, perl_fix_transportdir,
  astribank_allow_ignoreend, init_unload_modules and wcb4xxp_extra_trunk
  dropped: merged upstream.
* dahdi-linux 2.3.0 is required (extra config options for dahdi_cfg).
* Convert to dpkg v.3 format.
* Standards version: 3.9.1.0 (No change needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Dahdi::Config::Params;
 
2
#
 
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.
 
7
#
 
8
# $Id: Params.pm 7224 2009-09-27 15:01:20Z tzafrir $
 
9
#
 
10
use strict;
 
11
 
 
12
=head1 NAME
 
13
 
 
14
Dahdi::Config::Params -- Object oriented representation of F<genconf_parameters> file.
 
15
 
 
16
=head1 SYNOPSIS
 
17
 
 
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
 
23
 
 
24
=head1 DESCRIPTION
 
25
 
 
26
The constructor must be given a configuration file name:
 
27
 
 
28
=over 4
 
29
 
 
30
=item * Missing file is B<not> an error.
 
31
 
 
32
=item * Other opening errors cause a C<die> to be thrown.
 
33
 
 
34
=item * The file name is saved as the value of C<GENCONF_FILE> key.
 
35
 
 
36
=back
 
37
 
 
38
The access to config keys should only be done via the C<item()> method:
 
39
 
 
40
=over 4
 
41
 
 
42
=item * It contains all hard-coded defaults.
 
43
 
 
44
=item * All these values are overriden by directives in the config file.
 
45
 
 
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.
 
48
 
 
49
=back
 
50
 
 
51
=cut
 
52
 
 
53
sub new($$) {
 
54
        my $pack = shift || die;
 
55
        my $cfg_file = shift || die;
 
56
        my $self = {
 
57
                        GENCONF_FILE    => $cfg_file,
 
58
                };
 
59
        bless $self, $pack;
 
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
 
64
                }
 
65
                die "$pack: Failed to open '$cfg_file': $!\n";
 
66
        }
 
67
        #print STDERR "$pack: $cfg_file\n";
 
68
        my $array_key;
 
69
        while(<F>) {
 
70
                my ($key, $val);
 
71
                chomp;
 
72
                s/#.*$//;
 
73
                s/\s+$//;       # trim tail whitespace
 
74
                next unless /\S/;
 
75
                if(defined $array_key && /^\s+/) {
 
76
                        s/^\s+//;       # trim beginning whitespace
 
77
                        push(@{$self->{$array_key}}, $_);
 
78
                        next; 
 
79
                }
 
80
                undef $array_key;
 
81
                ($key, $val) = split(/\s+/, $_, 2);
 
82
                $key = lc($key);
 
83
                if(! defined $val) {
 
84
                        $array_key = $key;
 
85
                        next;
 
86
                }
 
87
                die "$cfg_file:$.: Duplicate key '$key'\n", if exists $self->{$key};
 
88
                $self->{$key} = $val;
 
89
        }
 
90
        close F;
 
91
        return $self;
 
92
}
 
93
 
 
94
sub item($$@) {
 
95
        my $self = shift || die;
 
96
        my $key = shift || die;
 
97
        my %options = @_;
 
98
        my %defaults = (
 
99
                        base_exten              => '4000',
 
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',
 
105
                        lc_country              => 'us',
 
106
                        context_lines           => 'from-pstn',
 
107
                        context_phones          => 'from-internal',
 
108
                        context_input           => 'astbank-input',
 
109
                        context_output          => 'astbank-output',
 
110
                        group_phones            => '5',
 
111
                        group_lines             => '0',
 
112
                        brint_overlap           => 'no',
 
113
                        bri_sig_style           => 'bri_ptmp',
 
114
                        echo_can                => 'mg2',
 
115
                        bri_hardhdlc            => 'auto',
 
116
                        pri_connection_type     => 'PRI',
 
117
                        r2_idle_bits            => '1101',
 
118
                        tdm_framing             => 'esf',
 
119
                        'pri_termtype'          => [ 'SPAN/* TE' ],
 
120
                );
 
121
        return $self->{$key} if exists($self->{$key}) or $options{NODEFAULTS};
 
122
        return $defaults{$key};
 
123
}
 
124
 
 
125
sub dump($) {
 
126
        my $self = shift || die;
 
127
        printf STDERR "%s dump:\n", ref $self;
 
128
        my $width = 30;
 
129
        foreach my $k (sort keys %$self) {
 
130
                my $val = $self->{$k};
 
131
                my $ref = ref $val;
 
132
                #print STDERR "DEBUG: '$k', '$ref', '$val'\n";
 
133
                if($ref eq '') {
 
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;
 
139
                        my $i = 0;
 
140
                        foreach my $v (@{$val}) {
 
141
                                printf STDERR "%-${width}s %s\n", "$k\->[$i]", $v;
 
142
                                $i++;
 
143
                        }
 
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};
 
148
                        }
 
149
                } else {
 
150
                        printf STDERR "%-${width}s (-> %s)\n", $k, $ref;
 
151
                }
 
152
        }
 
153
}
 
154
 
 
155
1;
 
156