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($$$$$;$$$$){
  • get|reading[0-9]*DeleteOnError
  • If set to 1 this attribute causes certain readings to be deleted when the website can not be reached and the HTTP request returns an error. Internally HTTPMOD remembers which kind of operation created a reading (update, Get01, Get02 and so on). Specified readings will only be deleted if the same operation returns an error.
    The same restrictions as for DeleteIfUnmatched apply regarding a fhem restart. -
    - +
  • httpVersion
  • defines the HTTP-Version to be sent to the server. This defaults to 1.0. @@ -3554,6 +3568,8 @@ HTTPMOD_AddToQueue($$$$$;$$$$){
  • parseFunction1 and parseFunction2
  • These functions allow an experienced Perl / Fhem developer to plug in his own parsing functions.
    Please look into the module source to see how it works and don't use them if you are not sure what you are doing. +
  • preProcessRegex
  • + can be used to fix a broken HTTP response before parsing. The regex should be a replacement regex like s/match/replacement/g and will be applied to the buffer.
  • Remarks regarding the automatically created userattr entries
  • Fhemweb allows attributes to be edited by clicking on them. However this does not work for attributes that match to a wildcard attribute. To circumvent this restriction HTTPMOD automatically adds an entry for each instance of a defined wildcard attribute to the device userattr list. E.g. if you define a reading[0-9]Name attribute as reading01Name, HTTPMOD will add reading01Name to the device userattr list. These entries only have the purpose of making editing in Fhemweb easier.