From 7fe7fd0e188aa7071f78dacf96ddbceb8aa9e805 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Fri, 17 May 2024 22:24:12 -0400 Subject: [PATCH] header_ok: Refactor for readability --- ddclient.in | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/ddclient.in b/ddclient.in index a5b2800..cc21be6 100755 --- a/ddclient.in +++ b/ddclient.in @@ -3775,24 +3775,21 @@ sub nic_updateable { sub header_ok { my ($host, $line) = @_; $line =~ s/\r?\n.*//s; - my $ok = 0; - - if ($line =~ m%^s*HTTP/.*\s+(\d+)%i) { - my $result = $1; - - if ($result =~ m/^2\d\d$/) { - $ok = 1; - - } elsif ($result eq '401') { - failed("updating %s: authentication failed (%s)", $host, $line); - } elsif ($result eq '403') { - failed("updating %s: not authorized (%s)", $host, $line); - } - - } else { - failed("updating %s: unexpected line (%s)", $host, $line); + # TODO: What is this leading /s*/? Is it a typo of /\s*/? + my ($result) = ($line =~ qr%^s*HTTP/.*\s+(\d+)%i); + if (!defined($result)) { + failed('updating %s: unexpected HTTP response: %s', $host, $line); + return 0; + } elsif ($result eq '401') { + failed("updating %s: authentication failed (%s)", $host, $line); + return 0; + } elsif ($result eq '403') { + failed("updating %s: not authorized (%s)", $host, $line); + return 0; + } elsif ($result !~ qr/^2\d\d$/) { + return 0; } - return $ok; + return 1; } ######################################################################