summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TO_FIX.md2
-rwxr-xr-xgmi.pl86
2 files changed, 30 insertions, 58 deletions
diff --git a/TO_FIX.md b/TO_FIX.md
index cc0d880..b610871 100644
--- a/TO_FIX.md
+++ b/TO_FIX.md
@@ -23,5 +23,3 @@ check values for keys in config file
redirection via config
handle signals like interrupt better
-
-reduce complexity in listen_config()
diff --git a/gmi.pl b/gmi.pl
index 971bc63..b0ef88b 100755
--- a/gmi.pl
+++ b/gmi.pl
@@ -7,7 +7,7 @@ use warnings;
use 5.010;
#use diagnostics;
-our $VERSION = 'v0.15.1';
+our $VERSION = 'v0.15.2';
# Modules
use IO::Socket::SSL; # CPAN
@@ -861,23 +861,22 @@ sub timeout_secs {
}
}
-## no critic (Complex, DeepNest)
sub listen_config {
my ($conf_ref, $ssl_ref, $ip_ref) = @_;
my %listen;
my @default_bind;
my @default_ports;
- if (exists $conf_ref->{default}{bind} and $conf_ref->{default}{bind} ne 'no') {
- #@default_bind = give_array($conf_ref->{default}{bind});
- push @default_bind, give_array($conf_ref->{default}{bind});
- }
- elsif (exists $conf_ref->{default}{bind} and $conf_ref->{default}{bind} eq 'no') {
- ;
+
+ if (exists $conf_ref->{default}{bind}) {
+ if ($conf_ref->{default}{bind} ne 'no') {
+ push @default_bind, give_array($conf_ref->{default}{bind});
+ }
}
else {
# Listen to all
push @default_bind, '::';
}
+
if (exists $conf_ref->{default}{ports}) {
push @default_ports, give_array($conf_ref->{default}{ports});
}
@@ -886,74 +885,50 @@ sub listen_config {
}
if (exists $conf_ref->{default}{unix} and $conf_ref->{default}{unix} ne 'no') {
- #$listen{unix}{default}{path} = $conf_ref->{default}{unix};
$listen{unix}{path}{default} = $conf_ref->{default}{unix};
}
for my $vhost (keys %{ $conf_ref }) {
next if ($vhost eq 'default');
+ my $binds;
+ my $ports;
- # Vhost's port and vhost's bind or default's bind
if (exists $conf_ref->{$vhost}{ports}) {
- for my $port (give_array($conf_ref->{$vhost}{ports})) {
- # Vhost has bind
- if (exists $conf_ref->{$vhost}{bind} and $conf_ref->{$vhost}{bind} ne 'no') {
- for my $bind (give_array($conf_ref->{$vhost}{bind})) {
- push @{ $listen{$bind}{$port} }, $vhost;
- }
- }
- elsif (exists $conf_ref->{$vhost}{bind} and $conf_ref->{$vhost}{bind} eq 'no') {
- ;
- }
- # vhost does not have bind - use default
- else {
- if (@default_bind) {
- for my $bind (@default_bind) {
- push @{ $listen{$bind}{$port} }, $vhost;
- }
- }
- }
- }
+ @{ $ports } = give_array($conf_ref->{$vhost}{ports});
+ }
+ else {
+ $ports = \@default_ports;
}
- # vhost's bind and default ports
- elsif (exists $conf_ref->{$vhost}{bind}) {
+
+ if (exists $conf_ref->{$vhost}{bind}) {
if ($conf_ref->{$vhost}{bind} ne 'no') {
- for my $bind (give_array($conf_ref->{$vhost}{bind})) {
- for my $port (@default_ports) {
- push @{ $listen{$bind}{$port} }, $vhost;
- }
- }
- }
- elsif ($conf_ref->{$vhost}{bind} eq 'no') {
- ;
+ @{ $binds } = give_array($conf_ref->{$vhost}{bind});
}
}
- # vhost uses default everything
else {
- for my $port (@default_ports) {
- for my $bind (@default_bind) {
- push @{ $listen{$bind}{$port} }, $vhost;
- }
+ $binds = \@default_bind;
+ }
+ ### $ports
+ ### $binds
+
+ for my $port (give_array($ports)) {
+ for my $bind (give_array($binds)) {
+ push @{ $listen{$bind}{$port} }, $vhost;
}
}
# check vhost unix socket otherwise check for default unix socket
- if (exists $conf_ref->{$vhost}{unix}) {
- for my $unix_sock_path (give_array($conf_ref->{$vhost}{unix})) {
- if ($unix_sock_path ne 'no') {
- $listen{unix}{path}{$vhost} = $unix_sock_path;
- push @{ $listen{unix}{listen} }, $vhost;
- }
- }
+ if (exists $conf_ref->{$vhost}{unix} and $conf_ref->{$vhost}{unix} ne 'no') {
+ $listen{unix}{path}{$vhost} = $conf_ref->{$vhost}{unix};
+ push @{ $listen{unix}{listen} }, $vhost;
}
- elsif (exists $listen{unix}{path}{default} and $listen{unix}{path}{default} ne 'no') {
+ elsif (exists $listen{unix}{path}{default}) {
push @{ $listen{unix}{listen} }, $vhost;
}
}
# ## %listen
return \%listen;
}
-## use critic
sub give_array {
my ($ref) = @_;
@@ -963,13 +938,13 @@ sub give_array {
return @$ref;
}
elsif (ref $ref eq 'SCALAR') {
- return ( $ref );
+ return $ref;
}
elsif (ref \$ref eq 'ARRAY') {
return @$ref;
}
elsif (ref \$ref eq 'SCALAR') {
- return ( $ref );
+ return $ref;
}
else {
confess 'not array or scalar nor a reference to such.';
@@ -1025,7 +1000,6 @@ sub get_fh_data {
sub select_add_listen {
my ($sell, @srvv) = @_;
for my $lsn (@srvv) {
- ### $lsn
## no critic (DoubleSigil)
if (exists $lsn->{LocalAddr}) {
$sell->add(IO::Socket::IP->new(%$lsn))