dyndns2: Simplify response parsing

This commit is contained in:
Richard Hansen 2024-07-13 04:01:22 -04:00
parent 60f931e7da
commit 45e3603918

View file

@ -4073,15 +4073,14 @@ sub nic_dyndns2_update {
next;
}
next if !header_ok($hosts, $reply);
my @reply = split /\n/, $reply;
my $state = 'header';
for my $line (@reply) {
if ($state eq 'header') {
$state = 'body';
} elsif ($state eq 'body') {
$state = 'results' if $line eq '';
} elsif ($state =~ /^results/) {
$state = 'results2';
# Some services can return 200 OK even if there is an error (e.g., bad authentication,
# updates too frequent) so the body of the response must also be checked.
(my $body = $reply) =~ s/^.*?\n\n//s;
my ($line) = grep(qr/^results/, split(qr/\n/, $body));
if (!$line) {
failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'});
next;
}
# bug #10: some dyndns providers does not return the IP so
# we can't use the returned IP
my ($status, $returnedips) = split / /, lc $line;
@ -4125,10 +4124,6 @@ sub nic_dyndns2_update {
failed("updating %s: unexpected status (%s)", $hosts, $line);
}
}
}
failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'})
if $state ne 'results2';
}
}
######################################################################