From fe1768316a395d576b3b1e55977f2e5b28e3f89f Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 30 Jun 2024 23:40:46 -0400 Subject: [PATCH] Use protocol-specific default when known Different protocols can have different default values for a particular variable. Grab the protocol-specific variable definition if given a hostname when looking up the variable's default. --- ddclient.in | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ddclient.in b/ddclient.in index 67279ba..e0f6c9a 100755 --- a/ddclient.in +++ b/ddclient.in @@ -2350,7 +2350,12 @@ sub split_by_comma { return (); } sub default { - my $v = shift; + my ($v, $h) = @_; + if (defined($h) && $config{$h}) { + my $proto = $protocols{$config{$h}{'protocol'}}; + my $var = $proto->{variables}{$v} if $proto; + return $var->{default} if $var; + } return undef if !defined($variables{'merged'}{$v}); # TODO: This might grab an arbitrary protocol-specific variable definition, which could cause # surprising behavior. @@ -2363,7 +2368,7 @@ sub opt { # TODO: Why check %opt before %globals? Valid variables from %opt are merged into %globals by # init_config(), so it shouldn't be necessary. Also, it runs the risk of collision with a # non-variable command line option like `--version`, `--help`, etc. - return $opt{$v} // $globals{$v} // default($v); + return $opt{$v} // $globals{$v} // default($v, $h); } sub min { my $min = shift;