dyndns2: Simplify response parsing
This commit is contained in:
parent
0892655fd6
commit
db3472a7ce
1 changed files with 44 additions and 47 deletions
19
ddclient.in
19
ddclient.in
|
@ -4109,8 +4109,14 @@ sub nic_dyndns2_update {
|
|||
next;
|
||||
}
|
||||
next if !header_ok($hosts, $reply);
|
||||
my @reply = split /\n/, $reply;
|
||||
my $state = 'header';
|
||||
# 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 @reply = split(qr/\n/, $body);
|
||||
if (!@reply) {
|
||||
failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'});
|
||||
next;
|
||||
}
|
||||
# From <https://help.dyn.com/remote-access-api/return-codes/>:
|
||||
#
|
||||
# If updating multiple hostnames, hostname-specific return codes are given one per line,
|
||||
|
@ -4127,12 +4133,6 @@ sub nic_dyndns2_update {
|
|||
# TODO: The logic below applies the last line's status to all hosts. Change it to apply
|
||||
# each status to its corresponding host.
|
||||
for my $line (@reply) {
|
||||
if ($state eq 'header') {
|
||||
$state = 'body';
|
||||
} elsif ($state eq 'body') {
|
||||
$state = 'results' if $line eq '';
|
||||
} elsif ($state =~ /^results/) {
|
||||
$state = 'results2';
|
||||
# bug #10: some dyndns providers does not return the IP so
|
||||
# we can't use the returned IP
|
||||
my ($status, $returnedips) = split / /, lc $line;
|
||||
|
@ -4181,9 +4181,6 @@ sub nic_dyndns2_update {
|
|||
}
|
||||
}
|
||||
}
|
||||
failed("updating %s: Could not connect to %s.", $hosts, $groupcfg{'server'})
|
||||
if $state ne 'results2';
|
||||
}
|
||||
}
|
||||
|
||||
######################################################################
|
||||
|
|
Loading…
Reference in a new issue