2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-19 12:46:03 +00:00

01_FHEMWEB.pm/DevIo.pm: unicodeEncoding support for Websocket (Forum #126088)

git-svn-id: https://svn.fhem.de/fhem/trunk@25716 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2022-02-20 17:39:00 +00:00
parent 065e29ad32
commit 72f6890c78
2 changed files with 11 additions and 2 deletions

View File

@ -425,6 +425,8 @@ FW_Read($$)
$data = pack("C*", map { $_ ^ $m[$idx++ % 4] } unpack("C*", $data)); $data = pack("C*", map { $_ ^ $m[$idx++ % 4] } unpack("C*", $data));
} }
$data = Encode::decode('UTF-8', $data) if($unicodeEncoding && $op == 1);
my $ret = FW_fC($data); my $ret = FW_fC($data);
FW_addToWritebuffer($hash, FW_addToWritebuffer($hash,
FW_longpollInfo("JSON", defined($ret) ? $ret : "")."\n"); FW_longpollInfo("JSON", defined($ret) ? $ret : "")."\n");
@ -562,6 +564,7 @@ FW_Read($$)
$FW_headerlines. $FW_headerlines.
"\r\n" ); "\r\n" );
$FW_chash->{websocket} = 1; $FW_chash->{websocket} = 1;
delete($FW_chash->{encoding}); # WS specifies its own encoding
my $me = $FW_chash; my $me = $FW_chash;
my ($cmd, $cmddev) = FW_digestCgi($arg); my ($cmd, $cmddev) = FW_digestCgi($arg);

View File

@ -231,7 +231,10 @@ DevIo_DecodeWS($$)
# $op: 0=>Continuation, 1=>Text, 2=>Binary, 8=>Close, 9=>Ping, 10=>Pong # $op: 0=>Continuation, 1=>Text, 2=>Binary, 8=>Close, 9=>Ping, 10=>Pong
Log3 $hash, 5, "Websocket msg: OP:$op LEN:$len MASK:$mask FIN:$fin"; Log3 $hash, 5, "Websocket msg: OP:$op LEN:$len MASK:$mask FIN:$fin";
if($op == 8) { # Close if($op == 1) { # Text
$data = Encode::decode('UTF-8', $data) if($unicodeEncoding);
} elsif($op == 8) { # Close
my $clCode = unpack("n", substr($data,0,2)); my $clCode = unpack("n", substr($data,0,2));
$clCode = "$clCode ($wsCloseCode{$clCode})" if($wsCloseCode{$clCode}); $clCode = "$clCode ($wsCloseCode{$clCode})" if($wsCloseCode{$clCode});
$clCode .= " ".substr($data, 2) if($len > 2); $clCode .= " ".substr($data, 2) if($len > 2);
@ -276,7 +279,10 @@ DevIo_SimpleWrite($$$;$)
$hash->{USBDev}->write($msg); $hash->{USBDev}->write($msg);
} elsif($hash->{TCPDev}) { } elsif($hash->{TCPDev}) {
$msg = DevIo_MaskWS($hash->{binary} ? 0x2:0x1, $msg) if($hash->{WEBSOCKET}); if($hash->{WEBSOCKET}) {
$msg = Encode::encode('UTF-8', $msg) if($unicodeEncoding && !$hash->{binary});
$msg = DevIo_MaskWS($hash->{binary} ? 0x2:0x1, $msg)
}
syswrite($hash->{TCPDev}, $msg); syswrite($hash->{TCPDev}, $msg);
} elsif($hash->{DIODev}) { } elsif($hash->{DIODev}) {