Koha/C4/SIP/Sip/Configuration.pm
Kyle M Hall 315f544cdc
Bug 15253: Add Koha::Logger based logging for SIP2
Now that we have Koha::Logger, we should use it in our SIP server. This
has the potential to make debugging SIP issue much easier. We should add
the userid for the sipuser to the namespace so we can allow for separate
files per sip user if wanted.

Test Plan:
1) Apply this patch set
2) Update the modififed log4perl.conf to your system
3) Restart your sip server
4) Tail your sip2.log, run some queries
5) Note you still get the same output messages as before, with the
   addition of the ip address and username ( if available )
   prefixing the message.

Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Chris Cormack <chris@bigballofwax.co.nz>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
2020-05-12 11:46:35 +01:00

75 lines
1.9 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 C4::SIP::Sip qw(syslog);
my $parser = new XML::Simple(
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;
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 );
syslog( "LOG_DEBUG",
"Configuration::find_service: Trying $portstr" );
last if ( exists( ( $self->{listeners} )->{$portstr} ) );
}
return $self->{listeners}->{$portstr};
}
1;