mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 09:16:53 +00:00
HttpUtils.pm: file:// URL implemented
git-svn-id: https://svn.fhem.de/fhem/trunk@7125 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
9a3a7b97aa
commit
130e04b710
@ -79,6 +79,21 @@ HttpUtils_ReadErr($)
|
||||
}
|
||||
}
|
||||
|
||||
sub
|
||||
HttpUtils_File($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
|
||||
return 0 if($hash->{url} !~ m+^file://(.*)$+);
|
||||
|
||||
my $fName = $1;
|
||||
return (1, "Absolute URL is not supported") if($fName =~ m+^/+);
|
||||
return (1, ".. in URL is not supported") if($fName =~ m+\.\.+);
|
||||
open(FH, $fName) || return(1, "$fName: $!");
|
||||
my $data = join("", <FH>);
|
||||
close(FH);
|
||||
return (1, undef, $data);
|
||||
}
|
||||
|
||||
sub
|
||||
HttpUtils_Connect($)
|
||||
@ -338,6 +353,8 @@ sub
|
||||
HttpUtils_NonblockingGet($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
my ($isFile, $fErr, $fContent) = HttpUtils_File($hash);
|
||||
return ($fErr, $fContent) if($isFile);
|
||||
my $err = HttpUtils_Connect($hash);
|
||||
$hash->{callback}($hash, $err, "") if($err);
|
||||
}
|
||||
@ -349,6 +366,8 @@ sub
|
||||
HttpUtils_BlockingGet($)
|
||||
{
|
||||
my ($hash) = @_;
|
||||
my ($isFile, $fErr, $fContent) = HttpUtils_File($hash);
|
||||
return ($fErr, $fContent) if($isFile);
|
||||
my $err = HttpUtils_Connect($hash);
|
||||
return ($err, undef) if($err);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user