dnsexit2: Invert conditions to improve readability
Instead of: if ($success1) { if ($success2) { if ($success3) { # yay } else { # fail } } else { # fail } } else { # fail } do: if (!$success1) { # fail } if (!$success2) { # fail } if (!$success3) { # fail } # yay
This commit is contained in:
parent
9b1a785c6d
commit
3e91fd02bf
1 changed files with 42 additions and 40 deletions
36
ddclient.in
36
ddclient.in
|
@ -4270,8 +4270,16 @@ sub nic_dnsexit2_update {
|
|||
my $response = decode_json($reply);
|
||||
|
||||
# It should at least have a 'code' and 'message'.
|
||||
if (defined($response->{'code'}) and defined($response->{'message'})) {
|
||||
if (exists $status{$response->{'code'}}) {
|
||||
if (!defined($response->{'code'}) || !defined($response->{'message'})) {
|
||||
failed("Did not receive expected \"code\" and \"message\" keys in server response.");
|
||||
failed("Response:");
|
||||
failed("%s", $response);
|
||||
next;
|
||||
}
|
||||
if (!exists($status{$response->{'code'}})) {
|
||||
failed("Status code %s is unknown!", $response->{'code'});
|
||||
next;
|
||||
}
|
||||
# Add the server response data to the applicable array
|
||||
push(@{$status{$response->{'code'}}}, $response->{'message'});
|
||||
if (defined($response->{'details'})) {
|
||||
|
@ -4289,15 +4297,8 @@ sub nic_dnsexit2_update {
|
|||
$config{$h}{'status-ipv6'} = $status if $ipv6;
|
||||
|
||||
# Handle statuses
|
||||
if ($status eq 'good') {
|
||||
success("%s", $message);
|
||||
$config{$h}{'mtime'} = $now;
|
||||
for my $ipv (keys %total_payload) {
|
||||
$config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content};
|
||||
$config{$h}{"status-ipv$ipv"} = 'good';
|
||||
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'}));
|
||||
}
|
||||
} elsif ($status eq 'warning') {
|
||||
if ($status ne 'good') {
|
||||
if ($status eq 'warning') {
|
||||
warning("%s", $message);
|
||||
warning("Server response: %s", $srv_message);
|
||||
} elsif ($status =~ m'^(badauth|error)$') {
|
||||
|
@ -4306,13 +4307,14 @@ sub nic_dnsexit2_update {
|
|||
} else {
|
||||
failed("This should not be possible");
|
||||
}
|
||||
} else {
|
||||
failed("Status code %s is unknown!", $response->{'code'});
|
||||
next;
|
||||
}
|
||||
} else {
|
||||
failed("Did not receive expected \"code\" and \"message\" keys in server response.");
|
||||
failed("Response:");
|
||||
failed("%s", $response);
|
||||
success("%s", $message);
|
||||
$config{$h}{'mtime'} = $now;
|
||||
for my $ipv (keys %total_payload) {
|
||||
$config{$h}{"ipv$ipv"} = $total_payload{$ipv}{content};
|
||||
$config{$h}{"status-ipv$ipv"} = 'good';
|
||||
success("Updated %s successfully to IPv%s address %s at time %s", $h, $ipv, $total_payload{$ipv}{content}, prettytime($config{$h}{'mtime'}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue