mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-19 12:46:03 +00:00
Added optional loglevel parameter
git-svn-id: https://svn.fhem.de/fhem/trunk@2450 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
2cc2c12e30
commit
b79d8940f2
@ -49,12 +49,13 @@ urlEncode($) {
|
|||||||
sub
|
sub
|
||||||
CustomGetFileFromURL($$@)
|
CustomGetFileFromURL($$@)
|
||||||
{
|
{
|
||||||
my ($quiet, $url, $timeout, $data, $noshutdown) = @_;
|
my ($quiet, $url, $timeout, $data, $noshutdown, $loglevel) = @_;
|
||||||
$timeout = 4.0 if(!defined($timeout));
|
$timeout = 4.0 if(!defined($timeout));
|
||||||
|
$loglevel = 1 if(!$loglevel);
|
||||||
|
|
||||||
my $displayurl= $quiet ? "<hidden>" : $url;
|
my $displayurl= $quiet ? "<hidden>" : $url;
|
||||||
if($url !~ /^(http|https):\/\/([^:\/]+)(:\d+)?(\/.*)$/) {
|
if($url !~ /^(http|https):\/\/([^:\/]+)(:\d+)?(\/.*)$/) {
|
||||||
Log 1, "CustomGetFileFromURL $displayurl: malformed or unsupported URL";
|
Log $loglevel, "CustomGetFileFromURL $displayurl: malformed or unsupported URL";
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ CustomGetFileFromURL($$@)
|
|||||||
if($protocol eq "https") {
|
if($protocol eq "https") {
|
||||||
eval "use IO::Socket::SSL";
|
eval "use IO::Socket::SSL";
|
||||||
if($@) {
|
if($@) {
|
||||||
Log 1, $@;
|
Log $loglevel, $@;
|
||||||
} else {
|
} else {
|
||||||
$conn = IO::Socket::SSL->new(PeerAddr=>"$host:$port", Timeout=>$timeout);
|
$conn = IO::Socket::SSL->new(PeerAddr=>"$host:$port", Timeout=>$timeout);
|
||||||
}
|
}
|
||||||
@ -80,7 +81,7 @@ CustomGetFileFromURL($$@)
|
|||||||
$conn = IO::Socket::INET->new(PeerAddr=>"$host:$port", Timeout=>$timeout);
|
$conn = IO::Socket::INET->new(PeerAddr=>"$host:$port", Timeout=>$timeout);
|
||||||
}
|
}
|
||||||
if(!$conn) {
|
if(!$conn) {
|
||||||
Log 1, "CustomGetFileFromURL $displayurl: Can't connect to $protocol://$host:$port\n";
|
Log $loglevel, "CustomGetFileFromURL $displayurl: Can't connect to $protocol://$host:$port\n";
|
||||||
undef $conn;
|
undef $conn;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -103,7 +104,7 @@ CustomGetFileFromURL($$@)
|
|||||||
vec($rin, $conn->fileno(), 1) = 1;
|
vec($rin, $conn->fileno(), 1) = 1;
|
||||||
my $nfound = select($rout=$rin, undef, undef, $timeout);
|
my $nfound = select($rout=$rin, undef, undef, $timeout);
|
||||||
if($nfound <= 0) {
|
if($nfound <= 0) {
|
||||||
Log 1, "CustomGetFileFromURL $displayurl: Select timeout/error: $!";
|
Log $loglevel, "CustomGetFileFromURL $displayurl: Select timeout/error: $!";
|
||||||
undef $conn;
|
undef $conn;
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user