Eliminate unnecessary hashref

Pass the key-value pairs directly instead of via a hashref.
This commit is contained in:
Richard Hansen 2020-07-11 21:36:08 -04:00
parent 7a21c1646c
commit 5f1dacc3bd
3 changed files with 64 additions and 65 deletions

View file

@ -1518,12 +1518,12 @@ sub test_possible_ip {
sub test_geturl {
my $url = shift;
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => opt('login'),
password => opt('password'),
});
);
print "URL $url\n";
print $reply // "<undefined>\n";
exit;
@ -1983,15 +1983,15 @@ EOM
## geturl
######################################################################
sub geturl {
my ($params) = @_;
my $proxy = $params->{proxy};
my $url = $params->{url};
my $login = $params->{login};
my $password = $params->{password};
my $ipversion = $params->{ipversion} // '';
my $headers = $params->{headers} // '';
my $method = $params->{method} // 'GET';
my $data = $params->{data} // '';
my %params = @_;
my $proxy = $params{proxy};
my $url = $params{url};
my $login = $params{login};
my $password = $params{password};
my $ipversion = $params{ipversion} // '';
my $headers = $params{headers} // '';
my $method = $params{method} // 'GET';
my $data = $params{data} // '';
my ($peer, $server, $port, $default_port, $use_ssl);
my ($sd, $request, $reply);
@ -2004,7 +2004,7 @@ sub geturl {
$server =~ s%[?/].*%%;
$url =~ s%^[^?/]*/?%%;
if ($force_ssl || ($globals{'ssl'} && !($params->{ignore_ssl_option} // 0))) {
if ($force_ssl || ($globals{'ssl'} && !($params{ignore_ssl_option} // 0))) {
$use_ssl = 1;
$default_port = '443';
} else {
@ -2073,9 +2073,9 @@ sub geturl {
load_ipv6_support;
$socket_class = 'IO::Socket::INET6';
}
if (defined($params->{_testonly_socket_class})) {
if (defined($params{_testonly_socket_class})) {
$socket_args{original_socket_class} = $socket_class;
$socket_class = $params->{_testonly_socket_class};
$socket_class = $params{_testonly_socket_class};
}
if ($ipversion eq '4') {
$socket_args{Domain} = PF_INET;
@ -2190,7 +2190,7 @@ sub get_ip {
$arg = $url;
if ($url) {
$reply = geturl({ proxy => opt('proxy', $h), url => $url }) // '';
$reply = geturl(proxy => opt('proxy', $h), url => $url) // '';
}
} elsif (($use eq 'cisco')) {
@ -2207,12 +2207,12 @@ sub get_ip {
$queryif =~ s/([\?&= ])/sprintf("%%%02x", ord($1))/ge;
$url = "http://" . opt('fw', $h) . "/level/1/exec/show/ip/interface/brief/${queryif}/CR";
$reply = geturl({
$reply = geturl(
url => $url,
login => opt('fw-login', $h),
password => opt('fw-password', $h),
ignore_ssl_option => 1,
}) // '';
) // '';
$arg = $url;
} elsif (($use eq 'cisco-asa')) {
@ -2229,12 +2229,12 @@ sub get_ip {
$queryif =~ s/([\?&= ])/sprintf("%%%02x", ord($1))/ge;
$url = "https://" . opt('fw', $h) . "/exec/show%20interface%20${queryif}";
$reply = geturl({
$reply = geturl(
url => $url,
login => opt('fw-login', $h),
password => opt('fw-password', $h),
ignore_ssl_option => 1,
}) // '';
) // '';
$arg = $url;
} else {
@ -2248,12 +2248,12 @@ sub get_ip {
$arg = $url;
if ($url) {
$reply = geturl({
$reply = geturl(
url => $url,
login => opt('fw-login', $h),
password => opt('fw-password', $h),
ignore_ssl_option => 1,
}) // '';
) // '';
}
}
if (!defined $reply) {
@ -2660,12 +2660,12 @@ sub nic_dyndns1_update {
$url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO');
}
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
}) // '';
) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
next;
@ -2828,12 +2828,12 @@ sub nic_dyndns2_update {
$url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO');
}
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
}) // '';
) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'});
next;
@ -2938,12 +2938,12 @@ sub nic_noip_update {
$url .= "&myip=";
$url .= $ip if $ip;
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
}) // '';
) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'});
next;
@ -3078,12 +3078,12 @@ sub nic_dslreports1_update {
$url .= "&myip=";
$url .= $ip if $ip;
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
}) // '';
) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
next;
@ -3179,12 +3179,12 @@ sub nic_zoneedit1_update {
$url .= "&dnsto=$ip" if $ip;
$url .= "&zone=$config{$h}{'zone'}" if defined $config{$h}{'zone'};
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
}) // '';
) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'});
next;
@ -3334,12 +3334,12 @@ sub nic_easydns_update {
$url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO');
}
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
}) // '';
) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $hosts, $config{$h}{'server'});
next;
@ -3453,7 +3453,7 @@ sub nic_namecheap_update {
$url .= "&ip=";
$url .= $ip if $ip;
my $reply = geturl({ proxy => opt('proxy'), url => $url }) // '';
my $reply = geturl(proxy => opt('proxy'), url => $url) // '';
if ($reply eq '') {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
next;
@ -3584,13 +3584,13 @@ sub nic_nfsn_make_request {
$header .= "Content-Type: application/x-www-form-urlencoded\n";
}
return geturl({
return geturl(
proxy => opt('proxy'),
url => $url,
headers => $header,
method => $method,
data => $body,
});
);
}
######################################################################
@ -3761,7 +3761,7 @@ sub nic_sitelutions_update {
$url .= "&ip=";
$url .= $ip if $ip;
my $reply = geturl({ proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
if (!defined($reply) || !$reply) {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
next;
@ -3846,7 +3846,7 @@ sub nic_freedns_update {
my $url_tmpl = "http://$config{$_[0]}{'server'}/api/?action=getdyndns&v=2&sha=<credentials>";
my $creds = sha1_hex("$config{$_[0]}{'login'}|$config{$_[0]}{'password'}");
(my $url = $url_tmpl) =~ s/<credentials>/$creds/;
my $reply = geturl({ proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
my $record_list_error = '';
if ($reply && header_ok($_[0], $reply)) {
$reply =~ s/^.*?\n\n//s; # Strip the headers.
@ -3896,7 +3896,7 @@ sub nic_freedns_update {
} else {
my $url = $rec->[2] . "&address=" . $ip;
debug("Update: %s", $url);
my $reply = geturl({proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
if (!defined($reply) || !$reply || !header_ok($h, $reply)) {
$config{$h}{'status'} = 'failed';
failed("updating %s: Could not connect to %s.", $h, $url);
@ -3971,12 +3971,12 @@ sub nic_changeip_update {
$url .= "&ip=";
$url .= $ip if $ip;
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
});
);
if (!defined($reply) || !$reply) {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
next;
@ -4058,12 +4058,12 @@ sub nic_googledomains_update {
$url .= "&myip=";
$url .= $ip if $ip;
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$host}{'login'},
password => $config{$host}{'password'},
});
);
unless ($reply) {
failed("updating %s: Could not connect to %s.", $host, $config{$host}{'server'});
next;
@ -4272,7 +4272,7 @@ sub nic_cloudflare_update {
my $url = "https://$config{$key}{'server'}/zones?";
$url .= "name=".$config{$key}{'zone'};
my $reply = geturl({ proxy => opt('proxy'), url => $url, headers => $headers });
my $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers);
unless ($reply) {
failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'});
next;
@ -4303,7 +4303,7 @@ sub nic_cloudflare_update {
$url .= "type=A&name=$domain";
}
$reply = geturl({ proxy => opt('proxy'), url => $url, headers => $headers });
$reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers);
unless ($reply) {
failed("updating %s: Could not connect to %s.", $domain, $config{$key}{'server'});
next;
@ -4329,13 +4329,13 @@ sub nic_cloudflare_update {
# Set domain
$url = "https://$config{$key}{'server'}/zones/$zone_id/dns_records/$dns_rec_id";
my $data = "{\"content\":\"$ip\"}";
$reply = geturl({
$reply = geturl(
proxy => opt('proxy'),
url => $url,
headers => $headers,
method => "PATCH",
data => $data,
});
);
unless ($reply) {
failed("updating %s: Could not connect to %s.", $domain, $config{$domain}{'server'});
next;
@ -4419,7 +4419,7 @@ sub nic_yandex_update {
my $url = "https://$config{$host}{'server'}/api2/admin/dns/list?";
$url .= "domain=";
$url .= $config{$key}{'login'};
my $reply = geturl({ proxy => opt('proxy'), url => $url, headers => $headers });
my $reply = geturl(proxy => opt('proxy'), url => $url, headers => $headers);
unless ($reply) {
failed("updating %s: Could not connect to %s.", $host, $config{$key}{'server'});
next;
@ -4450,13 +4450,13 @@ sub nic_yandex_update {
$data .= "&content=";
$data .= $ip if $ip;
$reply = geturl({
$reply = geturl(
proxy => opt('proxy'),
url => $url,
headers => $headers,
method => 'POST',
data => $data,
});
);
unless ($reply) {
failed("updating %s: Could not connect to %s.", $host, $config{$host}{'server'});
next;
@ -4534,7 +4534,7 @@ sub nic_duckdns_update {
# Try to get URL
my $reply = geturl({ proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
# No response, declare as failed
if (!defined($reply) || !$reply) {
@ -4605,7 +4605,7 @@ sub nic_freemyip_update {
$url .= $h;
# Try to get URL
my $reply = geturl({ proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
# No response, declare as failed
if (!defined($reply) || !$reply) {
@ -4731,12 +4731,12 @@ sub nic_woima_update {
$url .= "&backmx=" . ynu($config{$h}{'backupmx'}, 'YES', 'NO');
}
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
});
);
if (!defined($reply) || !$reply) {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
next;
@ -4852,7 +4852,7 @@ sub nic_dondominio_update {
# Try to get URL
my $reply = geturl({ proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
# No response, declare as failed
if (!defined($reply) || !$reply) {
@ -4938,7 +4938,7 @@ sub nic_dnsmadeeasy_update {
$url .= "&id=$h";
# Try to get URL
my $reply = geturl({ proxy => opt('proxy'), url => $url });
my $reply = geturl(proxy => opt('proxy'), url => $url);
# No response, declare as failed
if (!defined($reply) || !$reply) {
@ -5009,12 +5009,12 @@ sub nic_ovh_update {
$url .= "&myip=";
$url .= $ip if $ip;
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $url,
login => $config{$h}{'login'},
password => $config{$h}{'password'},
});
);
if (!defined($reply) || !$reply) {
failed("updating %s: Could not connect to %s.", $h, $config{$h}{'server'});
@ -5078,11 +5078,11 @@ sub nic_cloudns_update {
# IP is set in the header X-Forwarded-For you need to add &proxy=1 at the end of the
# DynamicURL." We abuse this to pass the desired IP address to ClouDNS, which might not be
# the same as the client IP address seen by ClouDNS.
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
url => $dynurl . '&proxy=1',
headers => "X-Forwarded-For: $ip\n",
});
);
if (($reply // '') eq '' || !header_ok($hosts, $reply)) {
$config{$_}{'status'} = 'failed' for @hosts;
failed("updating %s: failed to visit DynURL", $hosts);
@ -5142,12 +5142,12 @@ sub nic_dinahosting_update {
$url .= "&domain=$domain";
$url .= "&command=Domain_Zone_UpdateType" . is_ipv6($ip) ? 'AAAA' : 'A';
$url .= "&ip=$ip";
my $reply = geturl({
my $reply = geturl(
proxy => opt('proxy'),
login => $config{$h}{'login'},
password => $config{$h}{'password'},
url => $url,
});
);
$config{$h}{'status'} = 'failed'; # assume failure until otherwise determined
if (!$reply) {
failed("updating %s: failed to visit URL %s", $h, $url);

View file

@ -84,7 +84,7 @@ for my $tc (@test_cases) {
my $name = sprintf("IPv%s client to %s (-%sipv6)",
$tc->{client_ipv} || '*', $uri, $tc->{ipv6_opt} ? '' : 'no');
$ddclient::globals{'ipv6'} = $tc->{ipv6_opt};
my $got = ddclient::geturl({ url => $uri, ipversion => $tc->{client_ipv} });
my $got = ddclient::geturl(url => $uri, ipversion => $tc->{client_ipv});
isnt($got // '', '', $name);
}
}

View file

@ -228,8 +228,7 @@ for my $tc (@test_cases) {
$ddclient::globals{'ssl'} = $tc->{opt_ssl} // 0;
$ddclient::globals{'ssl_ca_dir'} = $tc->{opt_ssl_ca_dir};
$ddclient::globals{'ssl_ca_file'} = $tc->{opt_ssl_ca_file};
my $resp_str = ddclient::geturl({ _testonly_socket_class => 'InterceptSocket',
%{$tc->{params}} });
my $resp_str = ddclient::geturl(_testonly_socket_class => 'InterceptSocket', %{$tc->{params}});
TODO: {
local $TODO = $tc->{todo};
subtest $tc->{name} => sub {