From fbbca7388f9181b365fcdfb5643fb1c6a990cddc Mon Sep 17 00:00:00 2001 From: StefanStrobel <> Date: Sat, 27 Jan 2018 20:47:58 +0000 Subject: [PATCH] 98_HTTPMOD.pm: added new attribute preProcessRegex git-svn-id: https://svn.fhem.de/fhem/trunk@16013 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/98_HTTPMOD.pm | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/fhem/FHEM/98_HTTPMOD.pm b/fhem/FHEM/98_HTTPMOD.pm index 453665033..728b00650 100755 --- a/fhem/FHEM/98_HTTPMOD.pm +++ b/fhem/FHEM/98_HTTPMOD.pm @@ -145,6 +145,7 @@ # fixed a warning when alwaysNum without NumLen is specified # 2017-09-06 new attribute reAuthAlways to do the defined authentication steps # before each get / set / getupdate regardless of any reAuthRegex setting or similar. +# 2018-01-18 added preProcessRegex e.g. to fix broken JSON data in a response # # @@ -210,7 +211,7 @@ sub HTTPMOD_AddToQueue($$$$$;$$$$); sub HTTPMOD_JsonFlatter($$;$); sub HTTPMOD_ExtractReading($$$$$); -my $HTTPMOD_Version = '3.4.0 - 9.9.2017'; +my $HTTPMOD_Version = '3.4.1 - 18.1.2018'; # # FHEM module intitialisation @@ -274,6 +275,7 @@ sub HTTPMOD_Initialize($) "showMatched:0,1 " . "showError:0,1 " . "removeBuf:0,1 " . + "preProcessRegex " . "parseFunction1 " . "parseFunction2 " . @@ -2423,6 +2425,19 @@ sub HTTPMOD_Read($$$) ($body ? ",\r\nBody: $body" : ", body empty"); $body = "" if (!$body); + + my $ppr = AttrVal($name, "preProcessRegex", ""); + if ($ppr) { + my $pprexp = '$body=~' . $ppr; + my $oldSig = ($SIG{__WARN__} ? $SIG{__WARN__} : 'DEFAULT'); + $SIG{__WARN__} = sub { Log3 $name, 3, "$name: read applying preProcessRegex created warning: @_"; }; + eval $pprexp; + $SIG{__WARN__} = $oldSig; + + $body =~ $ppr; + Log3 $name, 5, "$name: Read - body after preProcessRegex: $ppr is $body"; + } + $buffer = ($header ? $header . "\r\n\r\n" . $body : $body); # for matching sid / reauth $buffer = $buffer . "\r\n\r\n" . $err if ($err); # for matching reauth @@ -2447,7 +2462,7 @@ sub HTTPMOD_Read($$$) HTTPMOD_CleanupParsers($hash); return undef; # don't continue parsing response } - + my ($checkAll, $tried, $match, $reading); my @unmatched = (); my @matched = (); @@ -3504,8 +3519,7 @@ HTTPMOD_AddToQueue($$$$$;$$$$){