Bug 25898: Prohibit indirect object notation
[koha.git] / C4 / SIP / Sip / Configuration.pm
blob3f5bdaaa4bd8a0be04b5068be1b87a191d13c92f
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 use C4::SIP::Sip qw(siplog);
15 my $parser = XML::Simple->new(
16 KeyAttr => {
17 login => '+id',
18 institution => '+id',
19 service => '+port'
21 GroupTags => {
22 listeners => 'service',
23 accounts => 'login',
24 institutions => 'institution',
26 ForceArray => [ 'service', 'login', 'institution' ],
27 ValueAttr => {
28 'error-detect' => 'enabled',
29 'min_servers' => 'value',
30 'max_servers' => 'value'
34 sub new {
35 my ( $class, $config_file ) = @_;
36 my $cfg = $parser->XMLin($config_file);
37 my %listeners;
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;
53 sub error_detect {
54 my $self = shift;
55 return $self->{'error-detect'};
58 sub accounts {
59 my $self = shift;
60 return values %{ $self->{accounts} };
63 sub find_service {
64 my ( $self, $sockaddr, $port, $proto ) = @_;
65 my $portstr;
66 foreach my $addr ( '', '*:', "$sockaddr:", "[$sockaddr]:" ) {
67 $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
68 siplog( "LOG_DEBUG",
69 "Configuration::find_service: Trying $portstr" );
70 last if ( exists( ( $self->{listeners} )->{$portstr} ) );
72 return $self->{listeners}->{$portstr};