remove high complexity score by create functions
first run of outsourced most of condition code in new functions
This commit is contained in:
parent
ed34e21d4e
commit
005ca1b852
@ -519,6 +519,137 @@ sub _Get_Message { # wir machen daraus eine privat function (CoolTux)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub _createParamRefForDataLogin {
|
||||||
|
return 0
|
||||||
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
|
; # nur das eigene Package darf private Funktionen aufrufen (CoolTux)
|
||||||
|
my $createParamRefObj = shift;
|
||||||
|
|
||||||
|
return
|
||||||
|
qq({"type":"m.login.token", "token":"$createParamRefObj->{passwd}", "user": "$createParamRefObj->{hash}->{USER}", "txn_id": "z4567gerww", "session":"1234"})
|
||||||
|
if (
|
||||||
|
AttrVal( $createParamRefObj->{hash}->{NAME}, 'matrixLogin', '' ) eq
|
||||||
|
'token' );
|
||||||
|
|
||||||
|
return
|
||||||
|
'{"type":"m.login.password", "refresh_token": true, "identifier":{ "type":"m.id.user", "user":"'
|
||||||
|
. $createParamRefObj->{hash}->{USER}
|
||||||
|
. '" }, "password":"'
|
||||||
|
. ( defined( $createParamRefObj->{passwd} )
|
||||||
|
&& $createParamRefObj->{passwd} ? $createParamRefObj->{passwd} : '' )
|
||||||
|
. '"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{deviceId} )
|
||||||
|
&& $createParamRefObj->{deviceId}
|
||||||
|
? $createParamRefObj->{deviceId}
|
||||||
|
: ''
|
||||||
|
) . '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _createParamRefForDataRegister {
|
||||||
|
return 0
|
||||||
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
|
; # nur das eigene Package darf private Funktionen aufrufen (CoolTux)
|
||||||
|
my $createParamRefObj = shift;
|
||||||
|
|
||||||
|
return
|
||||||
|
'{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{hash}->{USER} )
|
||||||
|
&& $createParamRefObj->{hash}->{USER}
|
||||||
|
? $createParamRefObj->{hash}->{USER}
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
. '" }, "password":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{passwd} )
|
||||||
|
&& $createParamRefObj->{passwd} ? $createParamRefObj->{passwd}
|
||||||
|
: ''
|
||||||
|
) . '"}';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _createParamRefForDataReg1 {
|
||||||
|
return 0
|
||||||
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
|
; # nur das eigene Package darf private Funktionen aufrufen (CoolTux)
|
||||||
|
my $createParamRefObj = shift;
|
||||||
|
|
||||||
|
return
|
||||||
|
'{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{hash}->{USER} )
|
||||||
|
&& $createParamRefObj->{hash}->{USER}
|
||||||
|
? $createParamRefObj->{hash}->{USER}
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
. '" }, "password":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{passwd} )
|
||||||
|
&& $createParamRefObj->{passwd} ? $createParamRefObj->{passwd}
|
||||||
|
: ''
|
||||||
|
) . '"}';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _createParamRefForDataReg2 {
|
||||||
|
return 0
|
||||||
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
|
; # nur das eigene Package darf private Funktionen aufrufen (CoolTux)
|
||||||
|
my $createParamRefObj = shift;
|
||||||
|
|
||||||
|
return '{"username":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{hash}->{USER} )
|
||||||
|
&& $createParamRefObj->{hash}->{USER}
|
||||||
|
? $createParamRefObj->{hash}->{USER}
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
. '", "password":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{passwd} )
|
||||||
|
&& $createParamRefObj->{passwd} ? $createParamRefObj->{passwd}
|
||||||
|
: ''
|
||||||
|
)
|
||||||
|
. '", "auth": {"session":"'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{hash}->{helper}->{session} )
|
||||||
|
&& $createParamRefObj->{hash}->{helper}->{session}
|
||||||
|
? $createParamRefObj->{hash}->{helper}->{session}
|
||||||
|
: ''
|
||||||
|
) . '","type":"m.login.dummy"}}';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _createParamRefForDataRefresh {
|
||||||
|
return 0
|
||||||
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
|
; # nur das eigene Package darf private Funktionen aufrufen (CoolTux)
|
||||||
|
my $createParamRefObj = shift;
|
||||||
|
|
||||||
|
return '{"refresh_token": "'
|
||||||
|
. (
|
||||||
|
defined( $createParamRefObj->{hash}->{helper}->{refresh_token} )
|
||||||
|
&& $createParamRefObj->{hash}->{helper}->{refresh_token}
|
||||||
|
? $createParamRefObj->{hash}->{helper}->{refresh_token}
|
||||||
|
: ''
|
||||||
|
) . '"}';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub _createParamRefForUrlMsg {
|
||||||
|
return 0
|
||||||
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
|
; # nur das eigene Package darf private Funktionen aufrufen (CoolTux)
|
||||||
|
my $createParamRefObj = shift;
|
||||||
|
|
||||||
|
return
|
||||||
|
'r0/rooms/'
|
||||||
|
. AttrVal( $createParamRefObj->{hash}->{NAME}, 'matrixMessage', '!!' )
|
||||||
|
. '/send/m.room.message?access_token='
|
||||||
|
. (
|
||||||
|
$createParamRefObj->{hash}->{helper}->{access_token}
|
||||||
|
? $createParamRefObj->{hash}->{helper}->{access_token}
|
||||||
|
: ''
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
sub _createParamRefForDef {
|
sub _createParamRefForDef {
|
||||||
return 0
|
return 0
|
||||||
unless ( __PACKAGE__ eq caller(0) )
|
unless ( __PACKAGE__ eq caller(0) )
|
||||||
@ -529,16 +660,64 @@ sub _createParamRefForDef {
|
|||||||
|
|
||||||
my $paramref = {
|
my $paramref = {
|
||||||
'logintypes' => {
|
'logintypes' => {
|
||||||
'url' => $createParamRefObjhash->{hash}->{URL} . 'r0/login',
|
'urlPath' => 'r0/login',
|
||||||
'method' => 'GET',
|
'method' => 'GET',
|
||||||
},
|
},
|
||||||
|
|
||||||
'register' => {
|
'register' => {
|
||||||
'url' => $createParamRefObjhash->{hash}->{URL},
|
'urlPath' => 'v3/register',
|
||||||
'data' => '',
|
'data' => _createParamRefForDataRegister($createParamRefObj),
|
||||||
},
|
},
|
||||||
|
|
||||||
|
'reg1' => {
|
||||||
|
'urlPath' => 'v3/register',
|
||||||
|
'data' => _createParamRefForDataReg1($createParamRefObj),
|
||||||
|
},
|
||||||
|
|
||||||
|
'reg2' => {
|
||||||
|
'urlPath' => 'v3/register',
|
||||||
|
'data' => _createParamRefForDataReg2($createParamRefObj),
|
||||||
|
},
|
||||||
|
|
||||||
|
'login' => {
|
||||||
|
'urlPath' => 'v3/login',
|
||||||
|
'data' => _createParamRefForDataLogin($createParamRefObj),
|
||||||
|
},
|
||||||
|
|
||||||
|
'refresh' => {
|
||||||
|
'urlPath' => 'v1/refresh',
|
||||||
|
'data' => _createParamRefForDataRefresh($createParamRefObj),
|
||||||
|
},
|
||||||
|
|
||||||
|
'wellknown' => {
|
||||||
|
'urlPath' => '/.well-known/matrix/client',
|
||||||
|
'data' => undef,
|
||||||
|
},
|
||||||
|
|
||||||
|
'msg' => {
|
||||||
|
'urlPath' => _createParamRefForUrlMsg($createParamRefObj),
|
||||||
|
'data' => '{"msgtype":"m.text", "body":"'
|
||||||
|
. $createParamRefObj->{value} . '"}',
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return $paramref->{$def}->{$paramValue};
|
::Log( 1,
|
||||||
|
'!!!DEBUG - MsgcreateParamRef: ' . $paramref->{$def}->{$paramValue} );
|
||||||
|
|
||||||
|
::Log( 1,
|
||||||
|
'!!!DEBUG - Def: '
|
||||||
|
. $def
|
||||||
|
. ' ParamValue: '
|
||||||
|
. $paramValue
|
||||||
|
. ' Resp: '
|
||||||
|
. $paramref->{$def}->{$paramValue} );
|
||||||
|
return (
|
||||||
|
defined( $paramref->{$def}->{$paramValue} )
|
||||||
|
&& $paramref->{$def}->{$paramValue}
|
||||||
|
? $paramref->{$def}->{$paramValue}
|
||||||
|
: ''
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _PerformHttpRequest { # wir machen daraus eine privat function (CoolTux)
|
sub _PerformHttpRequest { # wir machen daraus eine privat function (CoolTux)
|
||||||
@ -600,13 +779,9 @@ qq($name $hash->{helper}->{access_token} sync2refresh - $hash->{helper}->{next_r
|
|||||||
def => $def,
|
def => $def,
|
||||||
value => $value,
|
value => $value,
|
||||||
now => $now,
|
now => $now,
|
||||||
name => $name,
|
|
||||||
passwd => $passwd,
|
passwd => $passwd,
|
||||||
msgnumber => $msgnumber,
|
msgnumber => $msgnumber,
|
||||||
deviceId => $device_id,
|
deviceId => $deviceId,
|
||||||
url => undef,
|
|
||||||
data => undef,
|
|
||||||
method => undef,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
my $param = {
|
my $param = {
|
||||||
@ -625,58 +800,39 @@ qq($name $hash->{helper}->{access_token} sync2refresh - $hash->{helper}->{next_r
|
|||||||
|
|
||||||
given ($def) {
|
given ($def) {
|
||||||
when ('logintypes') {
|
when ('logintypes') {
|
||||||
$param->{url} = $hash->{URL} . 'r0/login';
|
$param->{url} = $hash->{URL}
|
||||||
$param->{method} = 'GET';
|
. _createParamRefForDef( $def, 'urlPath', $createParamRefObj );
|
||||||
|
$param->{method} =
|
||||||
|
_createParamRefForDef( $def, 'method', $createParamRefObj );
|
||||||
}
|
}
|
||||||
|
|
||||||
when ('register') {
|
when (/^register|reg[1-2]|login|refresh|wellknown$/x) {
|
||||||
$param->{url} = $hash->{URL} . 'v3/register';
|
$param->{url} = $hash->{URL}
|
||||||
|
. _createParamRefForDef( $def, 'urlPath', $createParamRefObj );
|
||||||
$param->{data} =
|
$param->{data} =
|
||||||
'{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'
|
_createParamRefForDef( $def, 'data', $createParamRefObj );
|
||||||
. $hash->{USER}
|
|
||||||
. '" }, "password":"'
|
Log3( $name, 5,
|
||||||
. $passwd . '"}';
|
qq($name $hash->{helper}->{access_token} refreshBeg $param->{'msgnumber'}: $hash->{helper}->{next_refresh} > $now)
|
||||||
|
) if ( $def eq 'refresh' );
|
||||||
}
|
}
|
||||||
|
|
||||||
when ('reg1') {
|
when ('msg') {
|
||||||
$param->{url} = $hash->{URL} . 'v3/register';
|
$param->{url} = $hash->{URL}
|
||||||
|
. _createParamRefForDef( $def, 'urlPath', $createParamRefObj );
|
||||||
$param->{data} =
|
$param->{data} =
|
||||||
'{"type":"m.login.password", "identifier":{ "type":"m.id.user", "user":"'
|
_createParamRefForDef( $def, 'data', $createParamRefObj );
|
||||||
. $hash->{USER}
|
|
||||||
. '" }, "password":"'
|
|
||||||
. $passwd . '"}';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
when ('reg2') {
|
# when ('msg') {
|
||||||
$param->{url} = $hash->{URL} . 'v3/register';
|
# $param->{'url'} =
|
||||||
$param->{data} =
|
# $hash->{URL}
|
||||||
'{"username":"'
|
# . '/_matrix/client/r0/rooms/'
|
||||||
. $hash->{USER}
|
# . AttrVal( $name, 'matrixMessage', '!!' )
|
||||||
. '", "password":"'
|
# . '/send/m.room.message?access_token='
|
||||||
. $passwd
|
# . $hash->{helper}->{access_token};
|
||||||
. '", "auth": {"session":"'
|
# $param->{data} = '{"msgtype":"m.text", "body":"' . $value . '"}';
|
||||||
. $hash->{helper}->{session}
|
# }
|
||||||
. '","type":"m.login.dummy"}}';
|
|
||||||
}
|
|
||||||
|
|
||||||
when ('login') {
|
|
||||||
if ( AttrVal( $name, 'matrixLogin', '' ) eq 'token' ) {
|
|
||||||
$param->{url} = $hash->{URL} . 'v3/login';
|
|
||||||
$param->{data} =
|
|
||||||
qq({"type":"m.login.token", "token":"$passwd", "user": "$hash->{USER}", "txn_id": "z4567gerww", "session":"1234"});
|
|
||||||
|
|
||||||
#$param->{'method'} = 'GET';
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$param->{url} = $hash->{URL} . 'v3/login';
|
|
||||||
$param->{data} =
|
|
||||||
'{"type":"m.login.password", "refresh_token": true, "identifier":{ "type":"m.id.user", "user":"'
|
|
||||||
. $hash->{USER}
|
|
||||||
. '" }, "password":"'
|
|
||||||
. $passwd . '"'
|
|
||||||
. $deviceId . '}';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
when ('login2') {
|
when ('login2') {
|
||||||
$param->{url} = $hash->{URL} . 'v3/login';
|
$param->{url} = $hash->{URL} . 'v3/login';
|
||||||
@ -688,31 +844,6 @@ qq({"type":"m.login.token", "token":"$passwd", "user": "\@$hash->{USER}:matrix.o
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
when ('refresh') {
|
|
||||||
$param->{url} = $hash->{URL} . 'v1/refresh';
|
|
||||||
$param->{data} =
|
|
||||||
'{"refresh_token": "' . $hash->{helper}->{refresh_token} . '"}';
|
|
||||||
|
|
||||||
Log3( $name, 5,
|
|
||||||
qq($name $hash->{helper}->{access_token} refreshBeg $param->{'msgnumber'}: $hash->{helper}->{next_refresh} > $now)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
when ('wellknown') {
|
|
||||||
$param->{url} = $hash->{URL} . '/.well-known/matrix/client';
|
|
||||||
}
|
|
||||||
|
|
||||||
when ('msg') {
|
|
||||||
$param->{url} =
|
|
||||||
$hash->{URL}
|
|
||||||
. 'r0/rooms/'
|
|
||||||
. AttrVal( $name, 'matrixMessage', '!!' )
|
|
||||||
. '/send/m.room.message?access_token='
|
|
||||||
. $hash->{helper}->{access_token};
|
|
||||||
|
|
||||||
$param->{data} = '{"msgtype":"m.text", "body":"' . $value . '"}';
|
|
||||||
}
|
|
||||||
|
|
||||||
when ('questionX') {
|
when ('questionX') {
|
||||||
$hash->{helper}->{question} = $value;
|
$hash->{helper}->{question} = $value;
|
||||||
$value = AttrVal( $name, 'matrixQuestion_' . $value, '' )
|
$value = AttrVal( $name, 'matrixQuestion_' . $value, '' )
|
||||||
@ -951,6 +1082,7 @@ sub ParseHttpResponse {
|
|||||||
Log3( $name, 4, $def . " returned: $data" ); # Eintrag fürs Log
|
Log3( $name, 4, $def . " returned: $data" ); # Eintrag fürs Log
|
||||||
my $decoded = eval { decode_json($data) };
|
my $decoded = eval { decode_json($data) };
|
||||||
Log3( $name, 2, "$name: json error: $@ in data" ) if ($@);
|
Log3( $name, 2, "$name: json error: $@ in data" ) if ($@);
|
||||||
|
|
||||||
if ( $param->{code} == 200 ) {
|
if ( $param->{code} == 200 ) {
|
||||||
$hash->{helper}->{softfail} = 0;
|
$hash->{helper}->{softfail} = 0;
|
||||||
$hash->{helper}->{hardfail} = 0;
|
$hash->{helper}->{hardfail} = 0;
|
||||||
@ -1194,6 +1326,11 @@ qq($name $hash->{helper}->{"access_token"} syncEnd $param->{msgnumber}: $hash->{
|
|||||||
|
|
||||||
#m.relates_to
|
#m.relates_to
|
||||||
}
|
}
|
||||||
|
|
||||||
|
::Log( 1,
|
||||||
|
'!!!DEBUG - TOKEN aus Hash: ' . $hash->{helper}->{access_token} );
|
||||||
|
::Log( 1, '!!!DEBUG - TOKEN aus Decode: ' . $decoded->{access_token} )
|
||||||
|
if ( $decoded->{access_token} );
|
||||||
}
|
}
|
||||||
|
|
||||||
readingsEndUpdate( $hash, 1 );
|
readingsEndUpdate( $hash, 1 );
|
||||||
|
Loading…
Reference in New Issue
Block a user