From 52864f2bb1e987fd44ff4e0d21fc6ece589acbee Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 19 May 2024 00:14:01 -0400 Subject: [PATCH 1/6] Delete redundant variable definitions --- ddclient.in | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/ddclient.in b/ddclient.in index 49e032f..b2f06d0 100755 --- a/ddclient.in +++ b/ddclient.in @@ -771,7 +771,6 @@ my %services = ( 'variables' => { %{$variables{'service-common-defaults'}}, 'server' => setv(T_FQDNP, 1, 0, 'www.dslreports.com', undef), - 'host' => setv(T_NUMBER, 1, 1, 0, undef), }, }, 'domeneshop' => { @@ -947,22 +946,9 @@ my %services = ( 'examples' => \&nic_noip_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'atime' => setv(T_NUMBER, 0, 1, 0, undef), 'custom' => setv(T_BOOL, 0, 1, 0, undef), - 'host' => setv(T_STRING, 1, 1, '', undef), - 'ip' => setv(T_IP, 0, 1, undef, undef), - 'login' => setv(T_LOGIN, 1, 0, '', undef), - 'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0), - 'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0), - 'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0), - 'mtime' => setv(T_NUMBER, 0, 1, 0, undef), - 'password' => setv(T_PASSWD, 1, 0, '', undef), 'server' => setv(T_FQDNP, 1, 0, 'dynupdate.no-ip.com', undef), 'static' => setv(T_BOOL, 0, 1, 0, undef), - 'status' => setv(T_ANY, 0, 1, '', undef), - 'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef), - 'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef), - 'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')), }, }, 'nsupdate' => { @@ -983,8 +969,6 @@ my %services = ( 'examples' => \&nic_ovh_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'login' => setv(T_LOGIN, 1, 0, '', undef), - 'password' => setv(T_PASSWD, 1, 0, '', undef), 'script' => setv(T_STRING, 1, 1, '/nic/update', undef), 'server' => setv(T_FQDNP, 1, 0, 'www.ovh.com', undef), }, From 5e3e10d32ec11a9cd9d1275b73e111907bdafa4c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 19 May 2024 00:47:41 -0400 Subject: [PATCH 2/6] Replace unnecessary `merge` function with hash initializers --- ddclient.in | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/ddclient.in b/ddclient.in index b2f06d0..826fbcf 100755 --- a/ddclient.in +++ b/ddclient.in @@ -1050,10 +1050,10 @@ my %services = ( 'updateable' => undef, 'update' => \&nic_keysystems_update, 'examples' => \&nic_keysystems_examples, - 'variables' => merge( - $variables{'keysystems-common-defaults'}, - $variables{'service-common-defaults'}, - ), + 'variables' => { + %{$variables{'service-common-defaults'}}, + %{$variables{'keysystems-common-defaults'}}, + }, }, 'dnsexit2' => { 'updateable' => undef, @@ -1072,10 +1072,10 @@ my %services = ( 'updateable' => undef, 'update' => \&nic_regfishde_update, 'examples' => \&nic_regfishde_examples, - 'variables' => merge( - $variables{'regfishde-common-defaults'}, - $variables{'service-common-defaults'}, - ), + 'variables' => { + %{$variables{'service-common-defaults'}}, + %{$variables{'regfishde-common-defaults'}}, + }, }, 'enom' => { 'updateable' => undef, @@ -1816,7 +1816,7 @@ sub _read_config { my ($host, $login, $password) = @args; ## add in any globals.. - %locals = %{merge(\%locals, \%globals)}; + %locals = (%globals, %locals); ## override login and password if specified the old way. $locals{'login'} = $login if defined $login; @@ -1826,7 +1826,7 @@ sub _read_config { foreach my $h (split_by_comma($host)) { if ($config{$h}) { ## host already defined, merging configs - $config{$h} = { %{merge($config{$h}, \%locals)} }; + $config{$h} = {%locals, %{$config{$h}}}; } else { ## save a copy of the current globals $config{$h} = { %locals }; @@ -1916,11 +1916,11 @@ sub init_config { ## merge options into host definitions or globals if (@hosts) { foreach my $h (@hosts) { - $config{$h} = merge(\%options, $config{$h}); + $config{$h} = {%{$config{$h}}, %options}; } $opt{'host'} = join(',', @hosts); } else { - %globals = %{merge(\%options, \%globals)}; + %globals = (%globals, %options); } } @@ -2353,7 +2353,6 @@ sub sendmail { } ###################################################################### ## split_by_comma -## merge ## default ## minimum ## opt @@ -2364,15 +2363,6 @@ sub split_by_comma { return split /\s*[, ]\s*/, $string if defined $string; return (); } -sub merge { - my %merged = (); - foreach my $h (@_) { - foreach my $k (keys %$h) { - $merged{$k} = $h->{$k} unless exists $merged{$k}; - } - } - return \%merged; -} sub default { my $v = shift; return $variables{'merged'}{$v}{'default'}; From 6da30367d018572c242a9444fa2eeb4cf45ea79a Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 19 May 2024 00:50:06 -0400 Subject: [PATCH 3/6] Inline unnecessary `*-common-defaults` variable definitions --- ddclient.in | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/ddclient.in b/ddclient.in index 826fbcf..faecf6d 100755 --- a/ddclient.in +++ b/ddclient.in @@ -655,21 +655,6 @@ my %variables = ( 'static' => setv(T_BOOL, 0, 1, 0, undef), 'wildcard' => setv(T_BOOL, 0, 1, 0, undef), }, - 'keysystems-common-defaults' => { - 'server' => setv(T_FQDNP, 1, 0, 'dynamicdns.key-systems.net', undef), - 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), - }, - 'dnsexit2-common-defaults' => { - 'ssl' => setv(T_BOOL, 0, 0, 1, undef), - 'server' => setv(T_FQDNP, 1, 0, 'api.dnsexit.com', undef), - 'path' => setv(T_STRING, 0, 0, '/dns/', undef), - 'ttl' => setv(T_NUMBER, 1, 0, 5, 0), - 'zone' => setv(T_STRING, 0, 0, undef, undef) - }, - 'regfishde-common-defaults' => { - 'server' => setv(T_FQDNP, 1, 0, 'dyndns.regfish.de', undef), - 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), - }, ); my %services = ( '1984' => { @@ -1052,7 +1037,8 @@ my %services = ( 'examples' => \&nic_keysystems_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - %{$variables{'keysystems-common-defaults'}}, + 'server' => setv(T_FQDNP, 1, 0, 'dynamicdns.key-systems.net', undef), + 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), }, }, 'dnsexit2' => { @@ -1061,7 +1047,11 @@ my %services = ( 'examples' => \&nic_dnsexit2_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - %{$variables{'dnsexit2-common-defaults'}}, + 'ssl' => setv(T_BOOL, 0, 0, 1, undef), + 'server' => setv(T_FQDNP, 1, 0, 'api.dnsexit.com', undef), + 'path' => setv(T_STRING, 0, 0, '/dns/', undef), + 'ttl' => setv(T_NUMBER, 1, 0, 5, 0), + 'zone' => setv(T_STRING, 0, 0, undef, undef), # nic_updateable() assumes that every service uses a username/login but that is # not true for the DNSExit API. Silence warnings by redefining the username variable # as non-required with value unused. @@ -1074,7 +1064,8 @@ my %services = ( 'examples' => \&nic_regfishde_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - %{$variables{'regfishde-common-defaults'}}, + 'server' => setv(T_FQDNP, 1, 0, 'dyndns.regfish.de', undef), + 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), }, }, 'enom' => { From 4d1b3439ead0c7ec3e4487ec5de414d5ff590112 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 18 May 2024 21:05:57 -0400 Subject: [PATCH 4/6] Use `service-common-defaults` variables This avoids a lot of duplication and improves readability by making it easier to see service-specific variables. --- ddclient.in | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/ddclient.in b/ddclient.in index faecf6d..d254141 100755 --- a/ddclient.in +++ b/ddclient.in @@ -963,15 +963,13 @@ my %services = ( 'update' => \&nic_porkbun_update, 'examples' => \&nic_porkbun_examples, 'variables' => { + %{$variables{'service-common-defaults'}}, 'apikey' => setv(T_PASSWD, 1, 0, '', undef), 'secretapikey' => setv(T_PASSWD, 1, 0, '', undef), 'root-domain' => setv(T_OFQDN, 0, 0, '', undef), 'on-root-domain' => setv(T_BOOL, 0, 0, 0, undef), 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), 'password' => setv(T_PASSWD, 0, 0, 'unused', undef), - 'use' => setv(T_USE, 0, 0, 'disabled', undef), - 'usev4' => setv(T_USEV4, 0, 0, 'disabled', undef), - 'usev6' => setv(T_USEV6, 0, 0, 'disabled', undef), }, }, 'sitelutions' => { @@ -989,25 +987,14 @@ my %services = ( 'update' => \&nic_woima_update, 'examples' => \&nic_woima_examples, 'variables' => { - 'atime' => setv(T_NUMBER, 0, 1, 0, undef), + %{$variables{'service-common-defaults'}}, 'backupmx' => setv(T_BOOL, 0, 1, 0, undef), 'custom' => setv(T_BOOL, 0, 1, 0, undef), - 'ip' => setv(T_IP, 0, 1, undef, undef), - 'login' => setv(T_LOGIN, 1, 0, '', undef), - 'max-interval' => setv(T_DELAY, 0, 0, interval('25d'), 0), - 'min-error-interval' => setv(T_DELAY, 0, 0, interval('5m'), 0), - 'min-interval' => setv(T_DELAY, 0, 0, interval('30s'), 0), - 'mtime' => setv(T_NUMBER, 0, 1, 0, undef), 'mx' => setv(T_OFQDN, 0, 1, '', undef), - 'password' => setv(T_PASSWD, 1, 0, '', undef), 'script' => setv(T_STRING, 1, 1, '/nic/update', undef), 'server' => setv(T_FQDNP, 1, 0, 'dyn.woima.fi', undef), 'static' => setv(T_BOOL, 0, 1, 0, undef), - 'status' => setv(T_ANY, 0, 1, '', undef), - 'warned-min-error-interval' => setv(T_ANY, 0, 1, 0, undef), - 'warned-min-interval' => setv(T_ANY, 0, 1, 0, undef), 'wildcard' => setv(T_BOOL, 0, 1, 0, undef), - 'wtime' => setv(T_DELAY, 0, 1, 0, interval('30s')), }, }, 'yandex' => { From 27b5c535bc4963be8c30aba195aef6e80e9ad444 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 19 May 2024 00:59:12 -0400 Subject: [PATCH 5/6] Use `undef` to disable required variables --- ddclient.in | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/ddclient.in b/ddclient.in index d254141..3cf7336 100755 --- a/ddclient.in +++ b/ddclient.in @@ -663,7 +663,7 @@ my %services = ( 'examples' => \&nic_1984_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'api.1984.is', undef), }, }, @@ -700,12 +700,9 @@ my %services = ( 'examples' => \&nic_cloudns_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, + 'password' => undef, 'dynurl' => setv(T_STRING, 1, 0, undef, undef), - # nic_updateable() assumes that every service uses a username and password but that is - # not true for CloudNS. Silence warnings by redefining the username and password - # variables as non-required with a non-empty default. - 'login' => setv(T_STRING, 0, 0, 'unused', undef), - 'password' => setv(T_STRING, 0, 0, 'unused', undef), }, }, 'digitalocean' => { @@ -714,9 +711,9 @@ my %services = ( 'examples' => \&nic_digitalocean_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'api.digitalocean.com', undef), 'zone' => setv(T_FQDN, 1, 0, '', undef), - 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), }, }, 'dinahosting' => { @@ -773,7 +770,7 @@ my %services = ( 'examples' => \&nic_duckdns_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'www.duckdns.org', undef), }, }, @@ -827,7 +824,7 @@ my %services = ( 'examples' => \&nic_freemyip_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'freemyip.com', undef), }, }, @@ -837,14 +834,13 @@ my %services = ( 'examples' => \&nic_gandi_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, 'min-interval' => setv(T_DELAY, 0, 0, 0, interval('5m')), 'server' => setv(T_FQDNP, 1, 0, 'api.gandi.net', undef), 'script' => setv(T_STRING, 1, 1, '/v5', undef), 'use-personal-access-token' => setv(T_BOOL, 0, 0, 0, undef), 'ttl' => setv(T_DELAY, 0, 0, undef, interval('5m')), 'zone' => setv(T_FQDN, 1, 0, undef, undef), - # Unused variables. - 'login' => setv(T_STRING, 0, 0, 'unused', undef), } }, 'godaddy' => { @@ -920,7 +916,7 @@ my %services = ( 'examples' => \&nic_njalla_examples, 'variables' => { %{$variables{'service-common-defaults'}}, - 'login' => setv(T_STRING, 0, 0, 'unused', undef), + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'njal.la', undef), 'quietreply' => setv(T_BOOL, 0, 1, 0, undef) }, @@ -964,12 +960,12 @@ my %services = ( 'examples' => \&nic_porkbun_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, + 'password' => undef, 'apikey' => setv(T_PASSWD, 1, 0, '', undef), 'secretapikey' => setv(T_PASSWD, 1, 0, '', undef), 'root-domain' => setv(T_OFQDN, 0, 0, '', undef), 'on-root-domain' => setv(T_BOOL, 0, 0, 0, undef), - 'login' => setv(T_LOGIN, 0, 0, 'unused', undef), - 'password' => setv(T_PASSWD, 0, 0, 'unused', undef), }, }, 'sitelutions' => { @@ -1024,8 +1020,8 @@ my %services = ( 'examples' => \&nic_keysystems_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'dynamicdns.key-systems.net', undef), - 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), }, }, 'dnsexit2' => { @@ -1034,15 +1030,12 @@ my %services = ( 'examples' => \&nic_dnsexit2_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, 'ssl' => setv(T_BOOL, 0, 0, 1, undef), 'server' => setv(T_FQDNP, 1, 0, 'api.dnsexit.com', undef), 'path' => setv(T_STRING, 0, 0, '/dns/', undef), 'ttl' => setv(T_NUMBER, 1, 0, 5, 0), 'zone' => setv(T_STRING, 0, 0, undef, undef), - # nic_updateable() assumes that every service uses a username/login but that is - # not true for the DNSExit API. Silence warnings by redefining the username variable - # as non-required with value unused. - 'login' => setv(T_STRING, 0, 0, 'unused', undef), }, }, 'regfishde' => { @@ -1051,8 +1044,8 @@ my %services = ( 'examples' => \&nic_regfishde_examples, 'variables' => { %{$variables{'service-common-defaults'}}, + 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'dyndns.regfish.de', undef), - 'login' => setv(T_LOGIN, 0, 0, 0, 'unused', undef), }, }, 'enom' => { @@ -1074,6 +1067,11 @@ my %services = ( }, }, ); +# Delete undefined variables to make it easier to cancel previously defined variables. +for my $svc (values(%services)) { + my $vars = $svc->{variables}; + delete(@$vars{grep(!defined($vars->{$_}), keys(%$vars))}); +} $variables{'merged'} = { map({ %{$services{$_}{'variables'}} } keys(%services)), %{$variables{'dyndns-common-defaults'}}, From 23b368f5ffc830d651554abf96632c6649dd2fd3 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 19 May 2024 01:10:34 -0400 Subject: [PATCH 6/6] Add missing final comma --- ddclient.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddclient.in b/ddclient.in index 3cf7336..9e73704 100755 --- a/ddclient.in +++ b/ddclient.in @@ -918,7 +918,7 @@ my %services = ( %{$variables{'service-common-defaults'}}, 'login' => undef, 'server' => setv(T_FQDNP, 1, 0, 'njal.la', undef), - 'quietreply' => setv(T_BOOL, 0, 1, 0, undef) + 'quietreply' => setv(T_BOOL, 0, 1, 0, undef), }, }, 'noip' => {