From 10d734deb709e32bf57f0b9748c9aee9b0906468 Mon Sep 17 00:00:00 2001 From: mike3436 <> Date: Fri, 17 Jun 2016 21:53:44 +0000 Subject: [PATCH] 26_tahoma.pm:2016-02-20 V 0203 perl exception while parsing json string captured git-svn-id: https://svn.fhem.de/fhem/trunk@11681 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/26_tahoma.pm | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/fhem/FHEM/26_tahoma.pm b/fhem/FHEM/26_tahoma.pm index 1428b425c..cc2c8a042 100644 --- a/fhem/FHEM/26_tahoma.pm +++ b/fhem/FHEM/26_tahoma.pm @@ -31,6 +31,7 @@ # 2015-08-20 V 0200 communication to server changes from xml to json # 2015-09-20 V 0201 some standard requests after login which are not neccessary disabled (so the actual requests are not equal to flow of iphone app) # 2016-01-26 V 0202 bugs forcing some startup warning messages fixed +# 2016-02-20 V 0203 perl exception while parsing json string captured package main; @@ -46,6 +47,7 @@ use LWP::ConnCache; use HTTP::Cookies; sub tahoma_parseGetSetupPlaces($$); +sub tahoma_UserAgent_NonblockingGet($); my $hash_; @@ -585,9 +587,16 @@ sub tahoma_dispatch($$$) Log3 $name, 4, "$name: tahoma_dispatch page=$param->{page} dataLen=".length $data; Log3 $name, (length $data > 120)?4:5, "$name: tahoma_dispatch data=".encode_utf8($data); - #my $json = encode_utf8(decode_json($data)); - my $json = JSON->new->utf8(0)->decode($data); - + # perl exception while parsing json string captured + my $json = {}; + eval { $json = JSON->new->utf8(0)->decode($data); }; + if ($@) { + Log3 $name, 3, "$name: tahoma_dispatch json string is faulty"; + $hash->{lastError} = 'json string is faulty'; + $hash->{logged_in} = 0; + return; + } + if( (ref $json ne 'ARRAY') && ($json->{errorResponse}) ) { $hash->{lastError} = $json->{errorResponse}{message}; $hash->{logged_in} = 0; @@ -1006,6 +1015,7 @@ sub tahoma_UserAgent_NonblockingGet($) # keep alive $agent->conn_cache(LWP::ConnCache->new()); + $proxy = '' if (!defined $proxy); Log3 $name, 4, "tahoma_UserAgent_NonblockingGet create userAgent $userAgent, proxy=$proxy"; }