From 3acc0dc955cfd3faf0e32ffc362463b8ae5fecdb Mon Sep 17 00:00:00 2001 From: Marko Oldenburg Date: Wed, 28 Feb 2018 10:08:41 +0100 Subject: [PATCH] change Master play_previous, change all Modules decode_json in a eval --- 21_HEOSGroup.pm | 9 +++++++-- 21_HEOSMaster.pm | 17 +++++++++++++---- 21_HEOSPlayer.pm | 9 +++++++-- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/21_HEOSGroup.pm b/21_HEOSGroup.pm index cd182a5..f134e5d 100644 --- a/21_HEOSGroup.pm +++ b/21_HEOSGroup.pm @@ -38,7 +38,7 @@ use JSON qw(decode_json); use Encode qw(encode_utf8); -my $version = "1.0.0"; +my $version = "1.0.3"; @@ -433,8 +433,13 @@ sub HEOSGroup_Parse($$) { my $decode_json; my $code; + + $decode_json = eval{decode_json(encode_utf8($json))}; + if($@){ + Log3 $name, 3, "HEOSGroup ($name) - JSON error while request: $@"; + return; + } - $decode_json = decode_json(encode_utf8($json)); Log3 $name, 4, "HEOSGroup ($name) - ParseFn wurde aufgerufen"; if( defined($decode_json->{gid}) ) { diff --git a/21_HEOSMaster.pm b/21_HEOSMaster.pm index 81aafdf..92528fb 100644 --- a/21_HEOSMaster.pm +++ b/21_HEOSMaster.pm @@ -65,7 +65,7 @@ eval "use Encode;1" or $missingModul .= "Encode "; -my $version = "1.0.2"; +my $version = "1.0.3"; my %heosCmds = ( 'enableChangeEvents' => 'system/register_for_change_events?enable=', @@ -94,7 +94,7 @@ my %heosCmds = ( 'setMute' => 'player/set_mute?', 'setGroupMute' => 'group/set_mute?', 'playNext' => 'player/play_next?', - 'playPrev' => 'player/play_prev?', + 'playPrev' => 'player/play_previous?', 'playPresetStation' => 'browse/play_preset?', 'playInput' => 'browse/play_input?', 'playStream' => 'browse/play_stream?', @@ -514,7 +514,12 @@ sub HEOSMaster_ProcessRead($$) { $hash->{LAST_RECV} = time(); Log3 $name, 5, "HEOSMaster ($name) - Decoding JSON message. Length: " . length($json) . " Content: " . $json; - my $obj = decode_json($json); + + my $obj = eval{decode_json($json)}; + if($@){ + Log3 $name, 3, "HEOSMaster ($name) - JSON error while request: $@"; + return; + } if(defined($obj->{heos})) { @@ -548,7 +553,11 @@ sub HEOSMaster_ResponseProcessing($$) { unless( defined($json)); Log3 $name, 4, "HEOSMaster ($name) - JSON detected!"; - $decode_json = decode_json(encode_utf8($json)); + $decode_json = eval{decode_json(encode_utf8($json))}; + if($@){ + Log3 $name, 3, "HEOSMaster ($name) - JSON error while request: $@"; + return; + } return Log3 $name, 3, "HEOSMaster ($name) - decode_json has no Hash" unless(ref($decode_json) eq "HASH"); diff --git a/21_HEOSPlayer.pm b/21_HEOSPlayer.pm index 2d3d642..e2a37f6 100644 --- a/21_HEOSPlayer.pm +++ b/21_HEOSPlayer.pm @@ -39,7 +39,7 @@ use Encode qw(encode_utf8); use URI::Escape; #use Data::Dumper; -my $version = "1.0.2"; +my $version = "1.0.3"; @@ -790,8 +790,13 @@ sub HEOSPlayer_Parse($$) { my $decode_json; my $code; + + $decode_json = eval{decode_json(encode_utf8($json))}; + if($@){ + Log3 $name, 3, "HEOSPlayer ($name) - JSON error while request: $@"; + return; + } - $decode_json = decode_json(encode_utf8($json)); Log3 $name, 4, "HEOSPlayer - ParseFn wurde aufgerufen"; if( defined($decode_json->{pid}) ) {