2 # parse-config: Parse an XML-format
3 # ACS configuration file and build the configuration
7 package C4
::SIP
::Sip
::Configuration
;
11 use XML
::Simple
qw(:strict);
13 use C4
::SIP
::Sip
::Configuration
::Institution
;
14 use C4
::SIP
::Sip
::Configuration
::Account
;
15 use C4
::SIP
::Sip
::Configuration
::Service
;
17 my $parser = new XML
::Simple
( KeyAttr
=> { login
=> '+id',
20 GroupTags
=> { listeners
=> 'service',
22 institutions
=> 'institution', },
23 ForceArray
=> [ 'service',
26 ValueAttr
=> { 'error-detect' => 'enabled',
27 'min_servers' => 'value',
28 'max_servers' => 'value'} );
31 my ($class, $config_file) = @_;
32 my $cfg = $parser->XMLin($config_file);
35 foreach my $acct (values %{$cfg->{accounts
}}) {
36 C4
::SIP
::Sip
::Configuration
::Account
->new( $acct );
39 # The key to the listeners hash is the 'port' component of the
40 # configuration, which is of the form '[host]:[port]/proto', and
41 # the 'proto' component could be upper-, lower-, or mixed-cased.
42 # Regularize it here to lower-case, and then do the same below in
43 # find_server() when building the keys to search the hash.
45 foreach my $service (values %{$cfg->{listeners
}}) {
46 C4
::SIP
::Sip
::Configuration
::Service
->new( $service );
47 $listeners{lc $service->{port
}} = $service;
49 $cfg->{listeners
} = \
%listeners;
51 foreach my $inst (values %{$cfg->{institutions
}}) {
52 C4
::SIP
::Sip
::Configuration
::Institution
->new( $inst );
54 return bless $cfg, $class;
59 return $self->{'error-detect'};
63 return values %{$self->{accounts
}};
68 # return values %{$self->{policy}};
72 my ($self, $sockaddr, $port, $proto) = @_;
74 foreach my $addr ('', '*:', "$sockaddr:", "[$sockaddr]:") {
75 $portstr = sprintf("%s%s/%s", $addr, $port, lc $proto);
76 Sys
::Syslog
::syslog
("LOG_DEBUG", "Configuration::find_service: Trying $portstr");
77 last if (exists(($self->{listeners
})->{$portstr}));
79 return $self->{listeners
}->{$portstr};
85 my $config = new Sip
::Configuration
$ARGV[0];
88 foreach my $acct ($config->accounts) {
89 print "Found account '", $acct->name, "', part of '"
90 print $acct->institution, "'\n";