2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-07 12:58:13 +00:00

70_ENIGMA2.pm: friendly handling of malformed XML

git-svn-id: https://svn.fhem.de/fhem/trunk@10873 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2016-02-19 08:14:14 +00:00
parent c3f8a27a26
commit db3165b07d

View File

@ -31,7 +31,6 @@ use 5.012;
use strict;
use warnings;
use Data::Dumper;
use XML::Simple;
use IO::Socket;
use HttpUtils;
use Encode;
@ -57,6 +56,10 @@ sub ENIGMA2_Initialize($) {
Log3 $hash, 5, "ENIGMA2_Initialize: Entering";
eval 'use XML::Simple; 1';
return "Please install XML::Simple to use this module."
if ($@);
$hash->{GetFn} = "ENIGMA2_Get";
$hash->{SetFn} = "ENIGMA2_Set";
$hash->{DefFn} = "ENIGMA2_Define";
@ -1038,7 +1041,28 @@ sub ENIGMA2_ReceiveCommand($$$) {
SuppressEmpty => 1,
KeyAttr => {}
);
$return = $parser->XMLin( Encode::encode_utf8($data) );
eval
'$return = $parser->XMLin( Encode::encode_utf8($data) ); 1';
if ($@) {
if ( !defined($cmd) || $cmd eq "" ) {
Log3 $name, 5,
"ENIGMA2 $name: RES ERROR $service - unable to parse malformed XML\n"
. $data;
}
else {
Log3 $name, 5,
"ENIGMA2 $name: RES ERROR $service/"
. urlDecode($cmd)
. " - unable to parse malformed XML\n"
. $data;
}
return undef;
}
undef $parser;
}
else {
@ -1059,7 +1083,8 @@ sub ENIGMA2_ReceiveCommand($$$) {
}
}
$return = Encode::encode_utf8($data) if ( ref($return) ne "HASH" );
$return = Encode::encode_utf8($data)
if ( $return && ref($return) ne "HASH" );
#######################
# process return data