2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 06:39:11 +00:00

70_ZoneMinder: json parsing - again

git-svn-id: https://svn.fhem.de/fhem/trunk@19987 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
delmar 2019-08-12 15:50:38 +00:00
parent 4a3b8948de
commit 0f041a4f61
2 changed files with 30 additions and 11 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
- bugfix: 70_ZoneMinder: json parsing - again
- bugfix: 89_FULLY: Support for Fully version 1.33
- feature: 22_HOMEMODE: v1.4.10 add support for PET
- change: 98_DOIFtools: remove unessesary code due to changes in console.js

View File

@ -262,6 +262,7 @@ sub ZoneMinder_API_ReadHostInfo_Callback {
$zmVersion = 'unknown';
}
$hash->{ZM_VERSION} = $zmVersion;
$hash->{model} = $zmVersion;
my $zmApiVersion = ZoneMinder_GetConfigValueByKey($hash, $data, 'apiversion');
if (not $zmApiVersion) {
@ -322,19 +323,21 @@ sub ZoneMinder_API_ReadConfig_Callback {
sub ZoneMinder_GetConfigValueByKey {
my ($hash, $config, $key) = @_;
my $searchString = '"'.$key.'":"';
my $searchString = qr/"$key":\s*"/;
return ZoneMinder_GetFromJson($hash, $config, $searchString, '"');
}
sub ZoneMinder_GetConfigArrayByKey {
my ($hash, $config, $key) = @_;
my $searchString = '"'.$key.'":[';
# my $searchString = '"'.$key.'":[';
my $searchString = qr/"$key":\s*\[/;
return ZoneMinder_GetFromJson($hash, $config, $searchString, ']');
}
sub ZoneMinder_GetConfigValueByName {
my ($hash, $config, $key) = @_;
my $searchString = '"Name":"'.$key.'","Value":"';
# my $searchString = '"Name":"'.$key.'","Value":"';
my $searchString = qr/"Name":"$key","Value":"/;
return ZoneMinder_GetFromJson($hash, $config, $searchString, '"');
}
@ -343,15 +346,30 @@ sub ZoneMinder_GetFromJson {
my $name = $hash->{NAME};
# Log3 $name, 5, "json: $config";
my $searchLength = length($searchString);
my $startIdx = index($config, $searchString);
Log3 $name, 5, "ZoneMinder ($name) - $searchString found at $startIdx";
$startIdx += $searchLength;
my $endIdx = index($config, $endChar, $startIdx);
my $frame = $endIdx - $startIdx;
my $searchResult = substr $config, $startIdx, $frame;
# my $searchLength = length($searchString);
my $searchLength;
my $prema;
Log3 $name, 5, "ZoneMinder ($name) - looking for $searchString - length: $searchLength. start: $startIdx. end: $endIdx. result: $searchResult";
# my $startIdx = index($config, $searchString);
my $startIdx;
if (my ($match) = $config =~ $searchString) {
$prema = $';
my $ma = $&;
my $poma = $`;
# Log3 $name, 1, "ZM_TEST prematch: $prema match: $ma postmatch: $poma startIdx: $startIdx";
$searchLength = length($ma);
} else {
Log3 $name, 1, "ZoneMinder ($name) - $searchString NOT found. Please report, this is a problem.";
return;
}
Log3 $name, 5, "ZoneMinder ($name) - $searchString found.";
my $searchResult = substr $prema, 0;
my $endIdx = index($searchResult, $endChar);
$searchResult = substr $searchResult, 0, $endIdx;
# Log3 $name, 5, "ZoneMinder ($name) - looking for $searchString - length: $searchLength. start: $startIdx. end: $endIdx. result: $searchResult";
return $searchResult;
}