mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-04-22 20:24:36 +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:
parent
4a3b8948de
commit
0f041a4f61
@ -1,5 +1,6 @@
|
|||||||
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
|
# 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.
|
# 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
|
- bugfix: 89_FULLY: Support for Fully version 1.33
|
||||||
- feature: 22_HOMEMODE: v1.4.10 add support for PET
|
- feature: 22_HOMEMODE: v1.4.10 add support for PET
|
||||||
- change: 98_DOIFtools: remove unessesary code due to changes in console.js
|
- change: 98_DOIFtools: remove unessesary code due to changes in console.js
|
||||||
|
@ -262,6 +262,7 @@ sub ZoneMinder_API_ReadHostInfo_Callback {
|
|||||||
$zmVersion = 'unknown';
|
$zmVersion = 'unknown';
|
||||||
}
|
}
|
||||||
$hash->{ZM_VERSION} = $zmVersion;
|
$hash->{ZM_VERSION} = $zmVersion;
|
||||||
|
$hash->{model} = $zmVersion;
|
||||||
|
|
||||||
my $zmApiVersion = ZoneMinder_GetConfigValueByKey($hash, $data, 'apiversion');
|
my $zmApiVersion = ZoneMinder_GetConfigValueByKey($hash, $data, 'apiversion');
|
||||||
if (not $zmApiVersion) {
|
if (not $zmApiVersion) {
|
||||||
@ -322,19 +323,21 @@ sub ZoneMinder_API_ReadConfig_Callback {
|
|||||||
|
|
||||||
sub ZoneMinder_GetConfigValueByKey {
|
sub ZoneMinder_GetConfigValueByKey {
|
||||||
my ($hash, $config, $key) = @_;
|
my ($hash, $config, $key) = @_;
|
||||||
my $searchString = '"'.$key.'":"';
|
my $searchString = qr/"$key":\s*"/;
|
||||||
return ZoneMinder_GetFromJson($hash, $config, $searchString, '"');
|
return ZoneMinder_GetFromJson($hash, $config, $searchString, '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ZoneMinder_GetConfigArrayByKey {
|
sub ZoneMinder_GetConfigArrayByKey {
|
||||||
my ($hash, $config, $key) = @_;
|
my ($hash, $config, $key) = @_;
|
||||||
my $searchString = '"'.$key.'":[';
|
# my $searchString = '"'.$key.'":[';
|
||||||
|
my $searchString = qr/"$key":\s*\[/;
|
||||||
return ZoneMinder_GetFromJson($hash, $config, $searchString, ']');
|
return ZoneMinder_GetFromJson($hash, $config, $searchString, ']');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub ZoneMinder_GetConfigValueByName {
|
sub ZoneMinder_GetConfigValueByName {
|
||||||
my ($hash, $config, $key) = @_;
|
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, '"');
|
return ZoneMinder_GetFromJson($hash, $config, $searchString, '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -343,15 +346,30 @@ sub ZoneMinder_GetFromJson {
|
|||||||
my $name = $hash->{NAME};
|
my $name = $hash->{NAME};
|
||||||
|
|
||||||
# Log3 $name, 5, "json: $config";
|
# Log3 $name, 5, "json: $config";
|
||||||
my $searchLength = length($searchString);
|
# my $searchLength = length($searchString);
|
||||||
my $startIdx = index($config, $searchString);
|
my $searchLength;
|
||||||
Log3 $name, 5, "ZoneMinder ($name) - $searchString found at $startIdx";
|
my $prema;
|
||||||
$startIdx += $searchLength;
|
|
||||||
my $endIdx = index($config, $endChar, $startIdx);
|
|
||||||
my $frame = $endIdx - $startIdx;
|
|
||||||
my $searchResult = substr $config, $startIdx, $frame;
|
|
||||||
|
|
||||||
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;
|
return $searchResult;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user