mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-03-10 03:06:37 +00:00
69_SoftliqCloud.pm: Fix garbage JSON
git-svn-id: https://svn.fhem.de/fhem/trunk@24401 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
766d947942
commit
bced2c7104
@ -21,6 +21,7 @@
|
||||
#
|
||||
##############################################################################
|
||||
# Changelog:
|
||||
# 0.1.07: - 2021-05-08 - Optimize garbage JSON processing
|
||||
# 0.1.06: - 2021-04-26 - Split JSON strings to avoid processing multiple root nodes
|
||||
# 0.1.05: Fixed setting numeric parameters
|
||||
# 0.1.04: ANother fix to avoid "garbage" in JSON
|
||||
@ -55,7 +56,7 @@ use Digest::MD5 qw(md5);
|
||||
|
||||
use FHEM::Core::Authentication::Passwords qw(:ALL);
|
||||
|
||||
my $version = "0.1.06";
|
||||
my $version = "0.1.07";
|
||||
|
||||
my $missingModul = '';
|
||||
eval 'use MIME::Base64::URLSafe;1' or $missingModul .= 'MIME::Base64::URLSafe ';
|
||||
@ -296,7 +297,7 @@ sub Define {
|
||||
$hash->{helper}->{passObj} = FHEM::Core::Authentication::Passwords->new( $hash->{TYPE} );
|
||||
|
||||
# get password form old storage and save to new format
|
||||
if ( !defined(ReadPassword($hash)) ) {
|
||||
if ( !defined( ReadPassword($hash) ) ) {
|
||||
if ( defined( ReadPasswordOld($hash) ) ) {
|
||||
my ( $passResp, $passErr ) = $hash->{helper}->{passObj}->setStorePassword( $name, ReadPasswordOld($hash) );
|
||||
if ( defined($passErr) ) {
|
||||
@ -1965,6 +1966,23 @@ sub Ready {
|
||||
return;
|
||||
}
|
||||
|
||||
sub splitTest {
|
||||
my $buf = shift;
|
||||
my $name = "sd18";
|
||||
my @bufs;
|
||||
$buf =~ s///xsm;
|
||||
my $index = index( $buf, '}{' );
|
||||
if ( $index > 0 ) {
|
||||
Log3( $name, LOG_RECEIVE, "[$name] - Splitting double-JSON buffer" );
|
||||
push( @bufs, decode_json(substr( $buf, 0, $index + 1 ) ));
|
||||
push( @bufs, decode_json(substr( $buf, $index + 1 )));
|
||||
}
|
||||
else {
|
||||
push( @bufs, $buf );
|
||||
}
|
||||
return Dumper(@bufs);
|
||||
}
|
||||
|
||||
sub wsReadDevIo {
|
||||
my $hash = shift;
|
||||
my $name = $hash->{NAME};
|
||||
@ -1976,6 +1994,7 @@ sub wsReadDevIo {
|
||||
}
|
||||
$buf =~ s///xsm;
|
||||
$buf =~ s/\\x\{1e\}//xsm;
|
||||
|
||||
#if ( !( $buf =~ /}$/xsm ) ) {
|
||||
# $buf = substr( $buf, 0, rindex( $buf, "}" ) );
|
||||
#}
|
||||
@ -1983,19 +2002,20 @@ sub wsReadDevIo {
|
||||
return;
|
||||
}
|
||||
Log3( $name, LOG_DEBUG, qq([$name] Received from DevIo: $buf) );
|
||||
|
||||
|
||||
my @bufs;
|
||||
my $index = index($buf, '}{');
|
||||
if ($index > 0) {
|
||||
Log3 ($name, LOG_RECEIVE, "[$name] - Splitting double-JSON buffer");
|
||||
@bufs = split(/,/xsm,join($COMMA,substr($buf,0,$index),substr($buf,$index+1)));
|
||||
my $index = index( $buf, '}{' );
|
||||
if ( $index > 0 ) {
|
||||
Log3( $name, LOG_RECEIVE, "[$name] - Splitting double-JSON buffer" );
|
||||
push( @bufs, substr( $buf, 0, $index + 1 ) );
|
||||
push( @bufs, substr( $buf, $index + 1 ) );
|
||||
}
|
||||
else {
|
||||
push(@bufs,$buf);
|
||||
push( @bufs, $buf );
|
||||
}
|
||||
|
||||
foreach my $bufi (@bufs) {
|
||||
Log3 ($name, LOG_RECEIVE, "[$name] - Extracted".$bufi );
|
||||
Log3( $name, LOG_RECEIVE, "[$name] - Extracted" . $bufi );
|
||||
parseWebsocketRead( $hash, $bufi );
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user