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.
|
# handling update per host.
|
||||||
for my $h (@_) {
|
for my $h (@_) {
|
||||||
$config{$h}{'zone'} //= $h;
|
$config{$h}{'zone'} //= $h;
|
||||||
|
dnsexit2_update_host($h);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sub dnsexit2_update_host {
|
||||||
|
my ($h) = @_;
|
||||||
my $name = $h;
|
my $name = $h;
|
||||||
# Remove the zone suffix from $name. If the zone eq $name, $name can be left alone or
|
# 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
|
# 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)) {
|
unless ($reply && header_ok($h, $reply)) {
|
||||||
failed("updating %s: Could not connect to %s", $h, $url);
|
failed("updating %s: Could not connect to %s", $h, $url);
|
||||||
next;
|
return;
|
||||||
};
|
};
|
||||||
debug("%s", $reply);
|
debug("%s", $reply);
|
||||||
(my $http_status) = ($reply =~ m%^s*HTTP/.*\s+(\d+)%i);
|
(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("Failed to update Host\n%s", $h);
|
||||||
failed("HTTP response code\n%s", $http_status);
|
failed("HTTP response code\n%s", $http_status);
|
||||||
failed("Full reply\n%s", $reply) unless opt('verbose');
|
failed("Full reply\n%s", $reply) unless opt('verbose');
|
||||||
next;
|
return;
|
||||||
}
|
}
|
||||||
my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr);
|
my $body = ($reply =~ s/^.*?\r?\n\r?\n//sr);
|
||||||
my $response = eval { decode_json($body); };
|
my $response = eval { decode_json($body); };
|
||||||
if (!$response) {
|
if (!$response) {
|
||||||
failed("failed to parse response: $@");
|
failed("failed to parse response: $@");
|
||||||
next;
|
return;
|
||||||
}
|
}
|
||||||
if (!defined($response->{'code'}) || !defined($response->{'message'})) {
|
if (!defined($response->{'code'}) || !defined($response->{'message'})) {
|
||||||
failed("Did not receive expected 'code' and 'message' keys in server response:\n%s",
|
failed("Did not receive expected 'code' and 'message' keys in server response:\n%s",
|
||||||
$body);
|
$body);
|
||||||
next;
|
return;
|
||||||
}
|
}
|
||||||
my %codemeaning = (
|
my %codemeaning = (
|
||||||
'0' => ['good', 'Success! Actions got executed successfully.'],
|
'0' => ['good', 'Success! Actions got executed successfully.'],
|
||||||
|
@ -4251,7 +4257,7 @@ sub nic_dnsexit2_update {
|
||||||
);
|
);
|
||||||
if (!exists($codemeaning{$response->{'code'}})) {
|
if (!exists($codemeaning{$response->{'code'}})) {
|
||||||
failed("Status code %s is unknown!", $response->{'code'});
|
failed("Status code %s is unknown!", $response->{'code'});
|
||||||
next;
|
return;
|
||||||
}
|
}
|
||||||
my ($status, $message) = @{$codemeaning{$response->{'code'}}};
|
my ($status, $message) = @{$codemeaning{$response->{'code'}}};
|
||||||
info("Status: %s -- Message: %s", $status, $message);
|
info("Status: %s -- Message: %s", $status, $message);
|
||||||
|
@ -4267,7 +4273,7 @@ sub nic_dnsexit2_update {
|
||||||
} else {
|
} else {
|
||||||
failed("Unexpected status: %s", $status);
|
failed("Unexpected status: %s", $status);
|
||||||
}
|
}
|
||||||
next;
|
return;
|
||||||
}
|
}
|
||||||
success("%s", $message);
|
success("%s", $message);
|
||||||
$config{$h}{'mtime'} = $now;
|
$config{$h}{'mtime'} = $now;
|
||||||
|
@ -4277,7 +4283,6 @@ sub nic_dnsexit2_update {
|
||||||
$config{$h}{"status-ipv$ipv"} = 'good';
|
$config{$h}{"status-ipv$ipv"} = 'good';
|
||||||
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $ip, prettytime($config{$h}{'mtime'}));
|
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $ip, prettytime($config{$h}{'mtime'}));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
Loading…
Reference in a new issue