dnsexit2: Move body of for
loop to a separate function
For improved readability.
This commit is contained in:
parent
11d0c84639
commit
73a67b728d
1 changed files with 101 additions and 96 deletions
19
ddclient.in
19
ddclient.in
|
@ -4179,6 +4179,12 @@ sub nic_dnsexit2_update {
|
|||
# handling update per host.
|
||||
for my $h (@_) {
|
||||
$config{$h}{'zone'} //= $h;
|
||||
dnsexit2_update_host($h);
|
||||
}
|
||||
}
|
||||
|
||||
sub dnsexit2_update_host {
|
||||
my ($h) = @_;
|
||||
my $name = $h;
|
||||
# Remove the zone suffix from $name. If the zone eq $name, $name can be left alone or
|
||||
# set to the empty string; both have identical semantics. For consistency, always
|
||||
|
@ -4217,7 +4223,7 @@ sub nic_dnsexit2_update {
|
|||
);
|
||||
unless ($reply && header_ok($h, $reply)) {
|
||||
failed("updating %s: Could not connect to %s", $h, $url);
|
||||
next;
|
||||
return;
|
||||
};
|
||||
debug("%s", $reply);
|
||||
(my $http_status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i);
|
||||
|
@ -4226,18 +4232,18 @@ sub nic_dnsexit2_update {
|
|||
failed("Failed to update Host\n%s", $h);
|
||||
failed("HTTP response code\n%s", $http_status);
|
||||
failed("Full reply\n%s", $reply) unless opt('verbose');
|
||||
next;
|
||||
return;
|
||||
}
|
||||
my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr);
|
||||
my $response = eval { decode_json($body); };
|
||||
if (!$response) {
|
||||
failed("failed to parse response: $@");
|
||||
next;
|
||||
return;
|
||||
}
|
||||
if (!defined($response->{'code'}) || !defined($response->{'message'})) {
|
||||
failed("Did not receive expected 'code' and 'message' keys in server response:\n%s",
|
||||
$body);
|
||||
next;
|
||||
return;
|
||||
}
|
||||
my %codemeaning = (
|
||||
'0' => ['good', 'Success! Actions got executed successfully.'],
|
||||
|
@ -4251,7 +4257,7 @@ sub nic_dnsexit2_update {
|
|||
);
|
||||
if (!exists($codemeaning{$response->{'code'}})) {
|
||||
failed("Status code %s is unknown!", $response->{'code'});
|
||||
next;
|
||||
return;
|
||||
}
|
||||
my ($status, $message) = @{$codemeaning{$response->{'code'}}};
|
||||
info("Status: %s -- Message: %s", $status, $message);
|
||||
|
@ -4267,7 +4273,7 @@ sub nic_dnsexit2_update {
|
|||
} else {
|
||||
failed("Unexpected status: %s", $status);
|
||||
}
|
||||
next;
|
||||
return;
|
||||
}
|
||||
success("%s", $message);
|
||||
$config{$h}{'mtime'} = $now;
|
||||
|
@ -4278,7 +4284,6 @@ sub nic_dnsexit2_update {
|
|||
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $ip, prettytime($config{$h}{'mtime'}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
######################################################################
|
||||
## nic_noip_update
|
||||
|
|
Loading…
Reference in a new issue