Bug 14585: Fixing up online help on main page
[koha.git] / C4 / SIP / Sip / Configuration.pm
blob2b7bdcab51a8c0befe712a226694058895ddb132
2 # parse-config: Parse an XML-format
3 # ACS configuration file and build the configuration
4 # structure.
7 package C4::SIP::Sip::Configuration;
9 use strict;
10 use warnings;
11 use XML::Simple qw(:strict);
13 my $parser = new XML::Simple(
14 KeyAttr => {
15 login => '+id',
16 institution => '+id',
17 service => '+port'
19 GroupTags => {
20 listeners => 'service',
21 accounts => 'login',
22 institutions => 'institution',
24 ForceArray => [ 'service', 'login', 'institution' ],
25 ValueAttr => {
26 'error-detect' => 'enabled',
27 'min_servers' => 'value',
28 'max_servers' => 'value'
32 sub new {
33 my ( $class, $config_file ) = @_;
34 my $cfg = $parser->XMLin($config_file);
35 my %listeners;
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;
51 sub error_detect {
52 my $self = shift;
53 return $self->{'error-detect'};
56 sub accounts {
57 my $self = shift;
58 return values %{ $self->{accounts} };
61 sub find_service {
62 my ( $self, $sockaddr, $port, $proto ) = @_;
63 my $portstr;
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};