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
qw(siplog);
15 my $parser = XML
::Simple
->new(
22 listeners
=> 'service',
24 institutions
=> 'institution',
26 ForceArray
=> [ 'service', 'login', 'institution' ],
28 'error-detect' => 'enabled',
29 'min_servers' => 'value',
30 'max_servers' => 'value'
35 my ( $class, $config_file ) = @_;
36 my $cfg = $parser->XMLin($config_file);
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 $listeners{ lc $service->{port
} } = $service;
48 $cfg->{listeners
} = \
%listeners;
50 return bless $cfg, $class;
55 return $self->{'error-detect'};
60 return values %{ $self->{accounts
} };
64 my ( $self, $sockaddr, $port, $proto ) = @_;
66 foreach my $addr ( '', '*:', "$sockaddr:", "[$sockaddr]:" ) {
67 $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
69 "Configuration::find_service: Trying $portstr" );
70 last if ( exists( ( $self->{listeners
} )->{$portstr} ) );
72 return $self->{listeners
}->{$portstr};