Koha/C4/SIP/Sip/Configuration.pm
Mason James fb2e8e3450 Bug 29564: Use List::MoreUtils so SIP U16/Xenial does not break
- run prove t/00-load.t, see error
 - apply patch

    00:07:08.189 koha_1       | #   Failed test 'use C4::SIP::Sip::Configuration;'
    00:07:08.189 koha_1       | #   at t/00-load.t line 46.
    00:07:08.189 koha_1       | #     Tried to use 'C4::SIP::Sip::Configuration'.
    00:07:08.189 koha_1       | #     Error:  "uniq" is not exported by the List::Util module

 - run prove t/00-load.t, see tests pass :0)

https://bugs.koha-community.org/show_bug.cgi?id=29478

https://bugs.koha-community.org/show_bug.cgi?id=29564

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2021-11-25 09:48:45 +01:00

83 lines
2.3 KiB
Perl

#
# parse-config: Parse an XML-format
# ACS configuration file and build the configuration
# structure.
#
package C4::SIP::Sip::Configuration;
use strict;
use warnings;
use XML::Simple qw(:strict);
use List::MoreUtils qw(uniq);
use C4::SIP::Sip qw(siplog);
use Koha::Libraries;
my $parser = XML::Simple->new(
KeyAttr => {
login => '+id',
institution => '+id',
service => '+port'
},
GroupTags => {
listeners => 'service',
accounts => 'login',
institutions => 'institution',
},
ForceArray => [ 'service', 'login', 'institution' ],
ValueAttr => {
'error-detect' => 'enabled',
'min_servers' => 'value',
'max_servers' => 'value'
}
);
sub new {
my ( $class, $config_file ) = @_;
my $cfg = $parser->XMLin($config_file);
my %listeners;
# The key to the listeners hash is the 'port' component of the
# configuration, which is of the form '[host]:[port]/proto', and
# the 'proto' component could be upper-, lower-, or mixed-cased.
# Regularize it here to lower-case, and then do the same below in
# find_server() when building the keys to search the hash.
foreach my $service ( values %{ $cfg->{listeners} } ) {
$listeners{ lc $service->{port} } = $service;
}
$cfg->{listeners} = \%listeners;
my @branchcodes = Koha::Libraries->search()->get_column('branchcode');
my @institutions = uniq( keys %{ $cfg->{institutions} } );
foreach my $i ( @institutions ) {
siplog("LOG_ERR", "ERROR: Institution $i does does not match a branchcode. This can cause unexpected behavior.") unless grep( /^$i$/, @branchcodes );
}
return bless $cfg, $class;
}
sub error_detect {
my $self = shift;
return $self->{'error-detect'};
}
sub accounts {
my $self = shift;
return values %{ $self->{accounts} };
}
sub find_service {
my ( $self, $sockaddr, $port, $proto ) = @_;
my $portstr;
foreach my $addr ( '', '*:', "$sockaddr:", "[$sockaddr]:" ) {
$portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
siplog( "LOG_DEBUG",
"Configuration::find_service: Trying $portstr" );
last if ( exists( ( $self->{listeners} )->{$portstr} ) );
}
return $self->{listeners}->{$portstr};
}
1;