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 my $parser = new XML
::Simple
(
20 listeners
=> 'service',
22 institutions
=> 'institution',
24 ForceArray
=> [ 'service', 'login', 'institution' ],
26 'error-detect' => 'enabled',
27 'min_servers' => 'value',
28 'max_servers' => 'value'
33 my ( $class, $config_file ) = @_;
34 my $cfg = $parser->XMLin($config_file);
37 # The key to the listeners hash is the 'port' component of the
38 # configuration, which is of the form '[host]:[port]/proto', and
39 # the 'proto' component could be upper-, lower-, or mixed-cased.
40 # Regularize it here to lower-case, and then do the same below in
41 # find_server() when building the keys to search the hash.
43 foreach my $service ( values %{ $cfg->{listeners
} } ) {
44 $listeners{ lc $service->{port
} } = $service;
46 $cfg->{listeners
} = \
%listeners;
48 return bless $cfg, $class;
53 return $self->{'error-detect'};
58 return values %{ $self->{accounts
} };
62 my ( $self, $sockaddr, $port, $proto ) = @_;
64 foreach my $addr ( '', '*:', "$sockaddr:", "[$sockaddr]:" ) {
65 $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
66 Sys
::Syslog
::syslog
( "LOG_DEBUG",
67 "Configuration::find_service: Trying $portstr" );
68 last if ( exists( ( $self->{listeners
} )->{$portstr} ) );
70 return $self->{listeners
}->{$portstr};