98_HTTPMOD.pm: kleinere neue Funktione (reAuthAlways)

git-svn-id: https://svn.fhem.de/fhem/trunk@15035 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
StefanStrobel 2017-09-09 12:02:21 +00:00
parent 96fc9b7051
commit b07df6c4b8

View File

@ -141,6 +141,10 @@
# 2017-05-07 fixed typo in documentation # 2017-05-07 fixed typo in documentation
# 2017-05-08 optimized warning signal handling # 2017-05-08 optimized warning signal handling
# 2017-05-09 fixed character encoding of source file for documentation # 2017-05-09 fixed character encoding of source file for documentation
# fixed a bug where updateRequestHash was not called after restart and for MaxAge
# 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.
# #
# #
@ -160,11 +164,10 @@
# Implement IMap und IExpr for get # Implement IMap und IExpr for get
# #
# replacement scope attribute? # replacement scope attribute?
# make axtracting the sid after a get / update an attribute / option? # make extracting the sid after a get / update an attribute / option?
# multi page log extraction? # multi page log extraction?
# Profiling von Modbus übernehmen? # Profiling von Modbus übernehmen?
# extend httpmod to support simple tcp connections aver devio instead of HttpUtils? # extend httpmod to support simple tcp connections over devio instead of HttpUtils?
# extend devio for non blocking connect like httputils?
# #
# #
# #
@ -207,7 +210,7 @@ sub HTTPMOD_AddToQueue($$$$$;$$$$);
sub HTTPMOD_JsonFlatter($$;$); sub HTTPMOD_JsonFlatter($$;$);
sub HTTPMOD_ExtractReading($$$$$); sub HTTPMOD_ExtractReading($$$$$);
my $HTTPMOD_Version = '3.3.11 - 8.5.2017'; my $HTTPMOD_Version = '3.4.0 - 9.9.2017';
# #
# FHEM module intitialisation # FHEM module intitialisation
@ -300,6 +303,7 @@ sub HTTPMOD_Initialize($)
"set[0-9]*ParseResponse:0,1 " . # parse response to set as if it was a get "set[0-9]*ParseResponse:0,1 " . # parse response to set as if it was a get
"reAuthRegex " . "reAuthRegex " .
"reAuthAlways:0,1 " .
"reAuthJSON " . "reAuthJSON " .
"reAuthXPath " . "reAuthXPath " .
"reAuthXPath-Strict " . "reAuthXPath-Strict " .
@ -424,6 +428,7 @@ sub HTTPMOD_Define($$)
$hash->{".setList"} = ""; $hash->{".setList"} = "";
$hash->{".updateHintList"} = 1; $hash->{".updateHintList"} = 1;
$hash->{".updateReadingList"} = 1; $hash->{".updateReadingList"} = 1;
$hash->{".updateRequestHash"} = 1;
return undef; return undef;
} }
@ -1461,6 +1466,7 @@ sub HTTPMOD_Set($@)
my ($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "set", $setNum); my ($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "set", $setNum);
if ($url) { if ($url) {
HTTPMOD_Auth $hash if (AttrVal($name, "reAuthAlways", 0));
HTTPMOD_AddToQueue($hash, $url, $header, $data, "set$setNum", $rawVal); HTTPMOD_AddToQueue($hash, $url, $header, $data, "set$setNum", $rawVal);
} else { } else {
Log3 $name, 3, "$name: no URL for set $setNum"; Log3 $name, 3, "$name: no URL for set $setNum";
@ -1511,6 +1517,7 @@ sub HTTPMOD_Get($@)
my ($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "get", $getNum); my ($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "get", $getNum);
if ($url) { if ($url) {
HTTPMOD_Auth $hash if (AttrVal($name, "reAuthAlways", 0));
HTTPMOD_AddToQueue($hash, $url, $header, $data, "get$getNum", $getVal); HTTPMOD_AddToQueue($hash, $url, $header, $data, "get$getNum", $getVal);
} else { } else {
Log3 $name, 3, "$name: no URL for Get $getNum"; Log3 $name, 3, "$name: no URL for Get $getNum";
@ -1546,6 +1553,7 @@ sub HTTPMOD_GetUpdate($)
# queue main get request # queue main get request
($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "reading"); # context "reading" is used for other attrs relevant for GetUpdate ($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "reading"); # context "reading" is used for other attrs relevant for GetUpdate
if ($url) { if ($url) {
HTTPMOD_Auth $hash if (AttrVal($name, "reAuthAlways", 0));
HTTPMOD_AddToQueue($hash, $url, $header, $data, "update"); # use request type "update" HTTPMOD_AddToQueue($hash, $url, $header, $data, "update"); # use request type "update"
} else { } else {
Log3 $name, 3, "$name: GetUpdate: no Main URL specified"; Log3 $name, 3, "$name: GetUpdate: no Main URL specified";
@ -1570,6 +1578,7 @@ sub HTTPMOD_GetUpdate($)
($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "get", $getNum); ($url, $header, $data) = HTTPMOD_PrepareRequest($hash, "get", $getNum);
if ($url) { if ($url) {
HTTPMOD_Auth $hash if (AttrVal($name, "reAuthAlways", 0));
HTTPMOD_AddToQueue($hash, $url, $header, $data, "get$getNum"); HTTPMOD_AddToQueue($hash, $url, $header, $data, "get$getNum");
} else { } else {
Log3 $name, 3, "$name: no URL for Get $getNum"; Log3 $name, 3, "$name: no URL for Get $getNum";
@ -1743,7 +1752,7 @@ sub HTTPMOD_ExtractReading($$$$$)
$xpathst = HTTPMOD_GetFAttr($name, $context, $num, "XPath-Strict"); $xpathst = HTTPMOD_GetFAttr($name, $context, $num, "XPath-Strict");
$regopt = HTTPMOD_GetFAttr($name, $context, $num, "RegOpt"); $regopt = HTTPMOD_GetFAttr($name, $context, $num, "RegOpt");
$recomb = HTTPMOD_GetFAttr($name, $context, $num, "RecombineExpr"); $recomb = HTTPMOD_GetFAttr($name, $context, $num, "RecombineExpr");
$sublen = HTTPMOD_GetFAttr($name, $context, $num, "AutoNumLen"); $sublen = HTTPMOD_GetFAttr($name, $context, $num, "AutoNumLen", 0);
$alwaysn = HTTPMOD_GetFAttr($name, $context, $num, "AlwaysNum"); $alwaysn = HTTPMOD_GetFAttr($name, $context, $num, "AlwaysNum");
# support for old syntax # support for old syntax
@ -1854,7 +1863,7 @@ sub HTTPMOD_ExtractReading($$$$$)
if ($match == 1) { if ($match == 1) {
# only one match # only one match
$eNum = $num; $eNum = $num;
$subReading = ($alwaysn ? "${reading}-" . sprintf ("%0${sublen}d", 1) : $reading); $subReading = ($alwaysn ? "${reading}-" . ($sublen ? sprintf ("%0${sublen}d", 1) : "1") : $reading);
} else { } else {
# multiple matches -> check for special name of readings # multiple matches -> check for special name of readings
$eNum = $num ."-".$group; $eNum = $num ."-".$group;
@ -1970,6 +1979,8 @@ sub HTTPMOD_DoMaxAge($)
return if (!$readings); return if (!$readings);
$now = gettimeofday(); $now = gettimeofday();
HTTPMOD_UpdateRequestHash($hash) if ($hash->{".updateRequestHash"});
foreach my $reading (sort keys %{$readings}) { foreach my $reading (sort keys %{$readings}) {
my $key = $reading; # in most cases the reading name can be looked up in the readingBase hash my $key = $reading; # in most cases the reading name can be looked up in the readingBase hash
Log3 $name, 5, "$name: MaxAge: check reading $reading"; Log3 $name, 5, "$name: MaxAge: check reading $reading";
@ -3441,6 +3452,8 @@ HTTPMOD_AddToQueue($$$$$;$$$$){
regular Expression to match an error page indicating that a session has expired and a new authentication for read access needs to be done. regular Expression to match an error page indicating that a session has expired and a new authentication for read access needs to be done.
This attribute only makes sense if you need a forms based authentication for reading data and if you specify a multi step login procedure based on the sid.. attributes.<br> This attribute only makes sense if you need a forms based authentication for reading data and if you specify a multi step login procedure based on the sid.. attributes.<br>
This attribute is used for all requests. For set operations you can however specify individual reAuthRegexes with the set[0-9]*ReAuthRegex attributes. This attribute is used for all requests. For set operations you can however specify individual reAuthRegexes with the set[0-9]*ReAuthRegex attributes.
<li><b>reAuthAlways</b></li>
if set to 1 will force authentication requests defined in the sid-attributes to be sent before each getupdate, get or set.
<br><br> <br><br>
<li><b>sid[0-9]*URL</b></li> <li><b>sid[0-9]*URL</b></li>
different URLs or one common URL to be used for each step of an optional login procedure. different URLs or one common URL to be used for each step of an optional login procedure.