1 package NCIP::Configuration;
3 # Copyright 2013 Catalyst IT <chrisc@catalyst.net.nz>
5 # This file is part of NCIPServer
7 # NCIPServer is free software; you can redistribute it and/or modify it under the
8 # terms of the GNU General Public License as published by the Free Software
9 # Foundation; either version 2 of the License, or (at your option) any later
12 # NCIPServer is distributed in the hope that it will be useful, but WITHOUT ANY
13 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License along
17 # with NCIPServer; if not, write to the Free Software Foundation, Inc.,
18 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 use NCIP::Configuration;
28 my $config = NCIP::Configuration->new($config_dir);
33 use NCIP::Configuration::Service;
34 use base qw(Config::Merge);
38 my $self = $class->SUPER::new(@_);
41 # we might have a few services set them up safely
42 if ( ref( $self->('NCIP.listeners.service') ) eq 'ARRAY' ) {
43 @services = $self->('NCIP.listeners.service');
46 @services = ( $self->('NCIP.listeners')->{'service'} );
49 foreach my $service (@services) {
50 my $serv_object = NCIP::Configuration::Service->new($service);
51 $listeners{ lc $service->{'port'} } = $serv_object;
53 $self->{'listeners'} = \%listeners;
61 my $service = $config->($sockaddr, $port, $proto);
63 Used to find which service you should be using to answer an incoming request
68 my ( $self, $sockaddr, $port, $proto ) = @_;
70 foreach my $addr ( '', '*:', "$sockaddr:" ) {
71 $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto );
72 Sys::Syslog::syslog( "LOG_DEBUG",
73 "Configuration::find_service: Trying $portstr" );
74 last if ( exists( ( $self->{listeners} )->{$portstr} ) );
76 return $self->{listeners}->{$portstr};