mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
98_HTTPMOD.pm: added new attribute preProcessRegex
git-svn-id: https://svn.fhem.de/fhem/trunk@16013 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
98ea153a79
commit
fbbca7388f
@ -145,6 +145,7 @@
|
|||||||
# fixed a warning when alwaysNum without NumLen is specified
|
# fixed a warning when alwaysNum without NumLen is specified
|
||||||
# 2017-09-06 new attribute reAuthAlways to do the defined authentication steps
|
# 2017-09-06 new attribute reAuthAlways to do the defined authentication steps
|
||||||
# before each get / set / getupdate regardless of any reAuthRegex setting or similar.
|
# 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_JsonFlatter($$;$);
|
||||||
sub HTTPMOD_ExtractReading($$$$$);
|
sub HTTPMOD_ExtractReading($$$$$);
|
||||||
|
|
||||||
my $HTTPMOD_Version = '3.4.0 - 9.9.2017';
|
my $HTTPMOD_Version = '3.4.1 - 18.1.2018';
|
||||||
|
|
||||||
#
|
#
|
||||||
# FHEM module intitialisation
|
# FHEM module intitialisation
|
||||||
@ -274,6 +275,7 @@ sub HTTPMOD_Initialize($)
|
|||||||
"showMatched:0,1 " .
|
"showMatched:0,1 " .
|
||||||
"showError:0,1 " .
|
"showError:0,1 " .
|
||||||
"removeBuf:0,1 " .
|
"removeBuf:0,1 " .
|
||||||
|
"preProcessRegex " .
|
||||||
|
|
||||||
"parseFunction1 " .
|
"parseFunction1 " .
|
||||||
"parseFunction2 " .
|
"parseFunction2 " .
|
||||||
@ -2423,6 +2425,19 @@ sub HTTPMOD_Read($$$)
|
|||||||
($body ? ",\r\nBody: $body" : ", body empty");
|
($body ? ",\r\nBody: $body" : ", body empty");
|
||||||
|
|
||||||
$body = "" if (!$body);
|
$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 = ($header ? $header . "\r\n\r\n" . $body : $body); # for matching sid / reauth
|
||||||
$buffer = $buffer . "\r\n\r\n" . $err if ($err); # for matching reauth
|
$buffer = $buffer . "\r\n\r\n" . $err if ($err); # for matching reauth
|
||||||
|
|
||||||
@ -3506,7 +3521,6 @@ HTTPMOD_AddToQueue($$$$$;$$$$){
|
|||||||
The same restrictions as for DeleteIfUnmatched apply regarding a fhem restart.
|
The same restrictions as for DeleteIfUnmatched apply regarding a fhem restart.
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
|
|
||||||
<li><b>httpVersion</b></li>
|
<li><b>httpVersion</b></li>
|
||||||
defines the HTTP-Version to be sent to the server. This defaults to 1.0.
|
defines the HTTP-Version to be sent to the server. This defaults to 1.0.
|
||||||
<li><b>sslVersion</b></li>
|
<li><b>sslVersion</b></li>
|
||||||
@ -3554,6 +3568,8 @@ HTTPMOD_AddToQueue($$$$$;$$$$){
|
|||||||
<li><b>parseFunction1</b> and <b>parseFunction2</b></li>
|
<li><b>parseFunction1</b> and <b>parseFunction2</b></li>
|
||||||
These functions allow an experienced Perl / Fhem developer to plug in his own parsing functions.<br>
|
These functions allow an experienced Perl / Fhem developer to plug in his own parsing functions.<br>
|
||||||
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.
|
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.
|
||||||
|
<li><b>preProcessRegex</b></li>
|
||||||
|
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.
|
||||||
|
|
||||||
<li><b>Remarks regarding the automatically created userattr entries</b></li>
|
<li><b>Remarks regarding the automatically created userattr entries</b></li>
|
||||||
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.
|
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.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user