Skip to content

Commit

Permalink
no message
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Jan 29, 2024
1 parent 029e903 commit 8f45e39
Show file tree
Hide file tree
Showing 3 changed files with 221 additions and 226 deletions.
103 changes: 91 additions & 12 deletions ONVIF IO/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,6 @@ protected function StartConnection()
$WSSubscriptionPolicySupport = false;
$WSPullPointSupport = false;
$HasRTSPStreaming = false;
$HasSnapshotUri = false;
if ($this->GetCapabilities()) { // besorgt XAddr und einige Attribute Pflicht für Profil S.
$AnalyticsModuleSupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::AnalyticsModuleSupport);
$RuleSupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::RuleSupport);
Expand All @@ -515,12 +514,23 @@ protected function StartConnection()

// 3.ONVIF Request GetServices
// GetServices besorgt XAddr, Pflicht bei T, selten bei S unterstützt.
if (!$this->GetServices() && $this->Profile->HasProfile(\ONVIF\Profile::T)) {
$GetServices = $this->GetServices();
if (!$GetServices && $this->Profile->HasProfile(\ONVIF\Profile::T)) {
$this->Warnings = array_merge($this->Warnings, [$this->Translate('Failed to get services. Device reported ONVIF T scope, but is not compliant!')]);
$this->LogMessage($this->Translate('Failed to get services. Device reported ONVIF T scope, but is not compliant!'), KL_WARNING);
}
$XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr);

if ($GetServices) {
$WSSubscriptionPolicySupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport);
$WSPullPointSupport = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::WSPullPointSupport);
$HasRTSPStreaming = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasRTSPStreaming);
$HasSnapshotUri = $this->ReadAttributeBoolean(\ONVIF\IO\Attribute::HasSnapshotUri);
$NbrOfVideoSources = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfVideoSources);
$NbrOfAudioSources = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfAudioSources);
$NbrOfInputs = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfInputs);
$NbrOfOutputs = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfOutputs);
$NbrOfSerialPorts = $this->ReadAttributeInteger(\ONVIF\IO\Attribute::NbrOfSerialPorts);
$XAddr = $this->ReadAttributeArray(\ONVIF\IO\Attribute::XAddr);
}
// 4. ONVIF Request GetServiceCapabilities an \ONVIF\WSDL::Management
//$this->GetServiceCapabilities($XAddr[\ONVIF\NS::Management], \ONVIF\WSDL::Management); // noch ohne Funktion..
// Wenn \ONVIF\WSDL::DeviceIO unterstützt
Expand Down Expand Up @@ -615,6 +625,7 @@ protected function StartConnection()
$this->WriteAttributeArray(\ONVIF\IO\Attribute::DigitalInputs, $DigitalInputs);

// Wenn \ONVIF\WSDL::Media2 unterstützt

$Media2Supported = $XAddr[\ONVIF\NS::Media2] != '';
if ($XAddr[\ONVIF\NS::Media2]) {
// 4c.ONVIF Request GetServiceCapabilities an \ONVIF\WSDL::Media2
Expand Down Expand Up @@ -1292,6 +1303,7 @@ protected function GetEventProperties()
$query = '//*[@wstop:topic="true"]/tt:MessageDescription';
$wsTopics = $xpath->query($query);
$TopicData = [];
/** @var \DOMNode $wsData */
foreach ($wsTopics as $wsData) {
$Topic = preg_replace('/\[\d*\]/', '', substr($wsData->parentNode->getNodePath(), $prefixPathLen + 1));
$SourcesNodeList = $xpath->query('tt:Source/tt:SimpleItemDescription', $wsData, true);
Expand All @@ -1318,7 +1330,7 @@ protected function GetProfiles2(string $Token = null, string $ConfigurationEnume
$this->ShowLastError($this->lastSOAPError);
return false;
}
if (is_object($ProfileResult->Profiles)) {
if (!is_array($ProfileResult->Profiles)) {
$Profiles = [];
$Profiles[] = json_decode(json_encode($ProfileResult->Profiles), true);
} else {
Expand Down Expand Up @@ -1434,7 +1446,7 @@ protected function GetProfiles(): bool
$this->ShowLastError($this->lastSOAPError);
return false;
}
if (is_object($ProfileResult->Profiles)) {
if (!is_array($ProfileResult->Profiles)) {
$Profiles = [];
$Profiles[] = json_decode(json_encode($ProfileResult->Profiles), true);
} else {
Expand Down Expand Up @@ -1627,7 +1639,7 @@ protected function GetScopes()
if (!property_exists($ScopeResult, 'Scopes')) {
return false;
}
if (is_object($ScopeResult->Scopes)) {
if (!is_array($ScopeResult->Scopes)) {
$Scopes = [];
$Scopes[] = json_decode(json_encode($ScopeResult->Scopes), true);
} else {
Expand All @@ -1643,7 +1655,7 @@ protected function GetNodes()
if (is_a($Nodes, 'SoapFault')) {
return false;
}
if (is_object($Nodes)) {
if (!is_array($Nodes)) {
$Result = [];
$Result[] = json_decode(json_encode($Nodes), true);
} else {
Expand All @@ -1657,7 +1669,7 @@ protected function GetVideoSources($Uri, $WSDL)
if (is_a($VideoSources, 'SoapFault')) {
return false;
}
if (is_object($VideoSources)) {
if (!is_array($VideoSources)) {
$Result = [];
$Result[] = json_decode(json_encode($VideoSources), true);
} else {
Expand All @@ -1671,7 +1683,7 @@ protected function GetAudioSources($Uri, $WSDL)
if (is_a($AudioSources, 'SoapFault')) {
return false;
}
if (is_object($AudioSources)) {
if (!is_array($AudioSources)) {
$Result = [];
$Result[] = json_decode(json_encode($AudioSources), true);
} else {
Expand Down Expand Up @@ -1735,11 +1747,12 @@ protected function GetServices(): bool
$Params = [
'IncludeCapability'=> true
];
$Services = $this->SendData('', \ONVIF\WSDL::Management, 'GetServices', true, $Params);
$Response = '';
$Services = $this->SendData('', \ONVIF\WSDL::Management, 'GetServices', true, $Params, $Response);
if (is_a($Services, 'SoapFault')) {
return false;
}
if (is_object($Services->Service)) {
if (!is_array($Services->Service)) {
$ServicesResult = [];
$ServicesResult[] = json_decode(json_encode($Services->Service), true);
} else {
Expand All @@ -1758,8 +1771,47 @@ protected function GetServices(): bool
// 'Recording' => '',
// 'Replay' => ''
];*/
//todo

$xml = new DOMDocument();
$xml->loadXML($Response);
$this->SendDebug('TEST', $Response, 0);
$xPath = new DOMXPath($xml);

foreach ($ServicesResult as $Service) {
$XAddr[$Service['Namespace']] = parse_url($Service['XAddr'], PHP_URL_PATH);
$NSKey = array_search($Service['Namespace'], \ONVIF\NS::Namespaces);
$xPath->registerNamespace($NSKey, $Service['Namespace']);

switch ($Service['Namespace']) {
case \ONVIF\NS::Event:
$Query = '//' . $NSKey . ':Capabilities/@WSSubscriptionPolicySupport';
$this->WriteAttributeBooleanByXPathQuery(\ONVIF\IO\Attribute::WSSubscriptionPolicySupport, $Query, $xPath);
$Query = '//' . $NSKey . ':Capabilities/@WSPullPointSupport';
$this->WriteAttributeBooleanByXPathQuery(\ONVIF\IO\Attribute::WSPullPointSupport, $Query, $xPath);
break;
case \ONVIF\NS::DeviceIO:
$Query = '//' . $NSKey . ':Capabilities/@VideoSources';
$this->WriteAttributeIntegerByXPathQuery(\ONVIF\IO\Attribute::NbrOfVideoSources, $Query, $xPath);
$Query = '//' . $NSKey . ':Capabilities/@AudioSources';
$this->WriteAttributeIntegerByXPathQuery(\ONVIF\IO\Attribute::NbrOfAudioSources, $Query, $xPath);
$Query = '//' . $NSKey . ':Capabilities/@RelayOutputs';
$this->WriteAttributeIntegerByXPathQuery(\ONVIF\IO\Attribute::NbrOfOutputs, $Query, $xPath);
$Query = '//' . $NSKey . ':Capabilities/@DigitalInputs';
$this->WriteAttributeIntegerByXPathQuery(\ONVIF\IO\Attribute::NbrOfInputs, $Query, $xPath);
$Query = '//' . $NSKey . ':Capabilities/@SerialPorts';
$this->WriteAttributeIntegerByXPathQuery(\ONVIF\IO\Attribute::NbrOfSerialPorts, $Query, $xPath);
break;
case \ONVIF\NS::Media:
case \ONVIF\NS::Media2:
$Query = '//' . $NSKey . ':StreamingCapabilities/@SnapshotUri';
$this->WriteAttributeBooleanByXPathQuery(\ONVIF\IO\Attribute::HasSnapshotUri, $Query, $xPath);
$Query = '//' . $NSKey . ':StreamingCapabilities/@RTSPStreaming';
$this->WriteAttributeBooleanByXPathQuery(\ONVIF\IO\Attribute::HasRTSPStreaming, $Query, $xPath);
$Query = '//' . $NSKey . ':StreamingCapabilities/@RTP_RTSP_TCP';
$this->WriteAttributeBooleanByXPathQuery(\ONVIF\IO\Attribute::HasRTSPStreaming, $Query, $xPath);
break;
}
}
$this->WriteAttributeArray(\ONVIF\IO\Attribute::XAddr, $XAddr);
return true;
Expand Down Expand Up @@ -1904,6 +1956,7 @@ protected function GetSystemDateAndTime(): bool
* @param string $Function
* @param bool $UseLogin
* @param array $Params
* @return \SoapFault|\stdClass
*/
protected function SendData(string $URI, string $wsdl, string $Function, bool $UseLogin = false, array $Params = [], string &$Response = '', array $Header = [], int $Timeout = 5)
{
Expand Down Expand Up @@ -2147,4 +2200,30 @@ private function SetRenewInterval(object $Result): void
$this->SendDebug('Renew Interval', $Interval - 5, 0);
$this->SetTimerInterval(\ONVIF\IO\Timer::RenewSubscription, ($Interval - 5) * 1000);
}
private static function GetNodeBoolValue(\DOMNode $Node): bool
{
$val = $Node->nodeValue;
$boolval = (is_string($val) ? filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : (bool) $val);
return $boolval === null ? false : $boolval;
}
private function WriteAttributeBooleanByXPathQuery(string $Name, string $Query, \DOMXPath &$xPath)
{
$NodeList = $xPath->query($Query);
/** @var \DOMNode $Value */
if ($NodeList->length) {
$Value = self::GetNodeBoolValue($NodeList->item(0));
$this->SendDebug($Name, $Value, 0);
$this->WriteAttributeBoolean($Name, $Value);
}
}
private function WriteAttributeIntegerByXPathQuery(string $Name, string $Query, \DOMXPath &$xPath)
{
$NodeList = $xPath->query($Query);
/** @var \DOMNode $Value */
if ($NodeList->length) {
$Value = (int) $NodeList->item(0)->nodeValue;
$this->SendDebug($Name, $Value, 0);
$this->WriteAttributeInteger($Name, $Value);
}
}
}
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"compatibility": {
"version": "6.1"
},
"version": "2.15",
"build": 215,
"date": 1706208232
"version": "2.16",
"build": 216,
"date": 1706551768
}
Loading

0 comments on commit 8f45e39

Please sign in to comment.