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);
12 use List::MoreUtils qw(uniq);
14 use C4::SIP::Sip qw(siplog);
17 my $parser = XML::Simple->new(
24 listeners => 'service',
26 institutions => 'institution',
28 ForceArray => [ 'service', 'login', 'institution' ],
30 'error-detect' => 'enabled',
31 'min_servers' => 'value',
32 'max_servers' => 'value'
37 my ( $class, $config_file ) = @_;
38 my $cfg = $parser->XMLin($config_file);
41 # The key to the listeners hash is the 'port' component of the
42 # configuration, which is of the form '[host]:[port]/proto', and
43 # the 'proto' component could be upper-, lower-, or mixed-cased.
44 # Regularize it here to lower-case, and then do the same below in
45 # find_server() when building the keys to search the hash.
47 foreach my $service ( values %{ $cfg->{listeners} } ) {
48 $listeners{ lc $service->{port} } = $service;
50 $cfg->{listeners} = \%listeners;
52 my @branchcodes = Koha::Libraries->search()->get_column('branchcode');
53 my @institutions = uniq( keys %{ $cfg->{institutions} } );
54 foreach my $i ( @institutions ) {
55 siplog("LOG_ERR", "ERROR: Institution $i does does not match a branchcode. This can cause unexpected behavior.") unless grep( /^$i$/, @branchcodes );
58 return bless $cfg, $class;
63 return $self->{'error-detect'};
68 return values %{ $self->{accounts} };
72 my ( $self, $sockaddr, $port, $proto ) = @_;
74 foreach my $addr ( '', '*:', "$sockaddr:", "[$sockaddr]:" ) {
75 $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
77 "Configuration::find_service: Trying $portstr" );
78 last if ( exists( ( $self->{listeners} )->{$portstr} ) );
80 return $self->{listeners}->{$portstr};