From 70fc8aac5b962467ddd62795ff5adb07202e767a Mon Sep 17 00:00:00 2001 From: Joe Atzberger Date: Thu, 7 Oct 2010 19:40:38 +0000 Subject: [PATCH] Die if no listeners in config, give better log messages Also tighten debug messages: one warning at the end listing all failed is good enough. Certainly better than just throwaway debug messages listing what we are going to try. Otherwise if we succeeded, we don't need to know about the ones that failed, just report the successful one. --- Sip/Configuration.pm | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Sip/Configuration.pm b/Sip/Configuration.pm index e15f895..4f36f1a 100644 --- a/Sip/Configuration.pm +++ b/Sip/Configuration.pm @@ -100,15 +100,19 @@ sub accounts { sub find_service { my ( $self, $sockaddr, $port, $proto ) = @_; my $portstr; - - $proto = lc($proto); - foreach my $addr ('', '*:', "$sockaddr:") { - $portstr = sprintf("%s%s/%s", $addr, $port, lc $proto); - Sys::Syslog::syslog("LOG_DEBUG", "Configuration::find_service: Trying $portstr"); - last if (exists(($self->{listeners})->{$portstr})); + $self->{listeners} or die "ERROR: " . __PACKAGE__ . " object has no {listeners} for find_service() to find!"; + + my @misses; + foreach my $addr ( '', '*:', "$sockaddr:" ) { + $portstr = sprintf( "%s%s/%s", $addr, $port, lc $proto ); + if (exists($self->{listeners}->{$portstr})) { + Sys::Syslog::syslog("LOG_DEBUG", "find_service: Matched $portstr" ); + return $self->{listeners}->{$portstr}; + } + push @misses, $portstr; } - - return $self->{listeners}->{$portstr}; + Sys::Syslog::syslog("LOG_WARN", "find_service: No match in: " . join(' ',@misses)); + return; } 1; -- 2.11.0