private function processEvent() { $dom = $this->dom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $originalTimestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agent->sourceId, $originalMsgId); } else { $agent = new Agent($originalSourceId); if ($agent->isRegistered()) { $eventObjectNode = $dom->getElementsByTagName('SIF_EventObject')->item(0); $objectName = $eventObjectNode->getAttribute('ObjectName'); $objectAction = $eventObjectNode->getAttribute('Action'); $objectAction = strtolower($objectAction); if (!DataObject::objectExists($objectName)) { ProvisionError::invalidObject($originalSourceId, $originalMsgId, $objectName); exit; } else { $allowed = $this->hasPermission($objectName, $objectAction, $agent->agentId); if ($allowed) { $provider = DataObject::isProvider($objectName, $agent->agentId); if ($provider) { $this->publishEvent($agent->agentId, $objectName, $objectAction, $_SESSION['ZONE_VERSION'], $dom->saveXml($headerNode)); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, 0, $originalMsg = null, $desc = null); } else { ProvisionError::notProviderError($originalSourceId, $originalMsgId); } } else { switch ($objectAction) { case 'add': ProvisionError::invalidPermissionToPublishAdd($originalSourceId, $originalMsgId, $objectName); break; case 'change': ProvisionError::invalidPermissionToPublishChange($originalSourceId, $originalMsgId, $objectName); break; case 'delete': ProvisionError::invalidPermissionToPublishDelete($originalSourceId, $originalMsgId, $objectName); break; } //switch for error message } //allowed } //object exist } else { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); } //not registered } //valid sourceId }
private function processRequest($m) { $dom = $m->dom; $this->originalSourceId = $m->sourceId; $originalSourceId = $m->sourceId; $this->originalMsgId = $m->msgId; $originalMsgId = $m->msgId; $headerNode = $m->headerNode; $this->headerNode = $headerNode; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agent->sourceId, $originalMsgId); exit; } else { $agent = new Agent($originalSourceId); if (!$agent->isRegistered()) { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); exit; } else { $sentBufferSize = $dom->getElementsByTagName('SIF_MaxBufferSize')->item(0)->nodeValue; if (!Agent::bufferSizeAllowed($sentBufferSize, $agent->agentId)) { $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); } else { $messageNode = $dom->getElementsByTagName('SIF_Message'); $len = $messageNode->item(0)->childNodes->item(0)->childNodes->length - 1; $Mode = $messageNode->item(0)->childNodes->item(0)->childNodes->item($len)->nodeName; if ($Mode == 'SIF_Query') { $sifObjectNode = $dom->getElementsByTagName('SIF_QueryObject')->item(0); $objectName = $sifObjectNode->getAttribute('ObjectName'); } else { $sifObjectNode = $dom->getElementsByTagName('SIF_From')->item(0); $objectName = $sifObjectNode->getAttribute('ObjectName'); } if (!DataObject::objectExists($objectName)) { RequestError::invalidObject($originalSourceId, $originalMsgId, $objectName); exit; } else { if (!DataObject::allowedToRequest($agent->agentId, $objectName)) { ProvisionError::invalidPermissionToRequest($originalSourceId, $originalMsgId, $objectName); exit; } else { $sifDestinationId = $dom->getElementsByTagName('SIF_DestinationId'); if ($sifDestinationId->length != 0) { $sourceId = $sifDestinationId->item(0)->nodeValue; if (!DataObject::validResponder($objectName, $sourceId)) { RequestError::invalidProvider($originalSourceId, $originalMsgId); } else { $this->setupRequest($objectName, $sourceId, $agent); } //check if destination id is valid } else { $this->setupRequest($objectName, $sourceId = null, $agent); } //check if there is a destination id } //check if allowed to request } //check if allowed to request } //check object exist } //check if registered } //check sourceId }
private function processSubscribe() { $dom = $this->dom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $originalSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; if ($headerNode->getElementsByTagName('SIF_Timestamp')->item(0)) { $originalTimestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; } else { $originalTimestamp = Utility::createTimestamp(); } $this->originalSourceId = $originalSourceId; $this->originalMsgId = $originalMsgId; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { ProvisionError::invalidSourceId($originalSourceId, $originalMsgId); exit; } else { $agent = new Agent($originalSourceId); $this->agent = $agent; if (!$this->agent->isRegistered()) { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); exit; } else { $objects = $dom->getElementsByTagName('SIF_Object'); foreach ($objects as $object) { $objectName = $object->getAttribute('ObjectName'); $contexts = $object->getElementsByTagName('SIF_Context'); if (!DataObject::objectExists($objectName)) { ProvisionError::invalidObject($originalSourceId, $originalMsgId, $objectName); exit; } else { if ($contexts->length != 0) { foreach ($contexts as $context) { if (Context::isValidContext($context->nodeValue)) { $contextId = Context::getContextId($context->nodeValue); if (!DataObject::allowedToSubscribe($agent->agentId, $objectName, $contextId)) { ProvisionError::invalidPermissionToSubscribe($originalSourceId, $originalMsgId, $objectName); exit; } else { $dataObject = new DataObject($objectName); $dataObject->contextId = $contextId; array_push($this->subscribeObjects, $dataObject); } //check if allowed to subscribe } else { ProvisionError::contextNotSupportedError($originalSourceId, $originalMsgId); exit; } } //loop through contexts } else { if (!DataObject::allowedToSubscribe($agent->agentId, $objectName)) { ProvisionError::invalidPermissionToSubscribe($originalSourceId, $originalMsgId, $objectName); exit; } else { $dataObject = new DataObject($objectName); array_push($this->subscribeObjects, $dataObject); } //check if allowed to subscribe } // check if there are contexts } //check if object is valid } //loop through objects } //check if registered } //check sourceId }
private function processProvideObjects($objectNode) { $objects = $objectNode->getElementsByTagName('SIF_Object'); foreach ($objects as $object) { $objectName = $object->getAttribute('ObjectName'); $contexts = $object->getElementsByTagName('SIF_Context'); if (!DataObject::objectExists($objectName)) { ProvisionError::invalidObject($this->originalSourceId, $this->originalMsgId, $objectName); if (CODELEVEL != 3) { exit; } else { return false; } } else { if ($contexts->length != 0) { foreach ($contexts as $context) { $contextId = Context::getContextId($context->nodeValue); if (DataObject::alreadyProvided($this->agent->agentId, $objectName, $contextId)) { ProvisionError::alreadyProvided($this->originalSourceId, $this->originalMsgId, $objectName); if (CODELEVEL != 3) { exit; } else { return false; } } else { if (!DataObject::allowedToProvide($this->agent->agentId, $objectName, $contextId)) { ProvisionError::invalidPermissionToProvide($this->originalSourceId, $this->originalMsgId, $objectName); if (CODELEVEL != 3) { exit; } else { return false; } } else { $dataObject = new DataObject($objectName); $dataObject->contextId = $contextId; array_push($this->provideObjects, $dataObject); } //check if allowed to provide } //check if already provided } } else { if (DataObject::alreadyProvided($this->agent->agentId, $objectName)) { ProvisionError::alreadyProvided($this->originalSourceId, $this->originalMsgId, $objectName); if (CODELEVEL != 3) { exit; } else { return false; } } else { if (!DataObject::allowedToProvide($this->agent->agentId, $objectName)) { ProvisionError::invalidPermissionToProvide($this->originalSourceId, $this->originalMsgId, $objectName); if (CODELEVEL != 3) { exit; } else { return false; } } else { $dataObject = new DataObject($objectName); array_push($this->provideObjects, $dataObject); } //check if allowed to provide } //check if already provided } //check if there are contexts } //check if object exist } //loop through objects }
private function processRequest($m) { try { $dom = $m->dom; $this->originalSourceId = $m->sourceId; $originalSourceId = $m->sourceId; $this->originalMsgId = $m->msgId; $originalMsgId = $m->msgId; $headerNode = $m->headerNode; $this->headerNode = $headerNode; $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agent->sourceId, $originalMsgId); exit; } else { $agent = new Agent($originalSourceId); if (!$agent->isRegistered()) { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); exit; } else { $sentBufferSize = $dom->getElementsByTagName('SIF_MaxBufferSize')->item(0)->nodeValue; if (!Agent::bufferSizeAllowed($sentBufferSize, $agent->agentId)) { $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); } else { $messageNode = $dom->getElementsByTagName('SIF_Message'); $len = $messageNode->item(0)->childNodes->item(0)->childNodes->length - 1; $Mode = $messageNode->item(0)->childNodes->item(0)->childNodes->item($len)->nodeName; if ($Mode == 'SIF_Query') { $sifObjectNode = $dom->getElementsByTagName('SIF_QueryObject')->item(0); $objectName = $sifObjectNode->getAttribute('ObjectName'); } else { $sifObjectNode = $dom->getElementsByTagName('SIF_From')->item(0); $objectName = $sifObjectNode->getAttribute('ObjectName'); } if (!DataObject::objectExists($objectName)) { /* This is a temporary fix that needs to be evaluated for correctness. */ if ($objectName == 'SIF_ZoneStatus') { require_once 'main_lib/systemcontrol/SystemControl.php'; $systemControl = new SystemControl($m, false, true); exit; } RequestError::invalidObject($originalSourceId, $originalMsgId, $objectName); exit; } else { if (!DataObject::allowedToRequest($agent->agentId, $objectName)) { ProvisionError::invalidPermissionToRequest($originalSourceId, $originalMsgId, $objectName); exit; } else { $sifDestinationId = $dom->getElementsByTagName('SIF_DestinationId'); if ($sifDestinationId->length != 0) { $sourceId = $sifDestinationId->item(0)->nodeValue; if (!DataObject::validResponder($objectName, $sourceId)) { RequestError::invalidProvider($originalSourceId, $originalMsgId); } else { $this->setupRequest($objectName, $sourceId, $agent); } //check if destination id is valid } else { $this->setupRequest($objectName, $sourceId = null, $agent); } //check if there is a destination id } //check if allowed to request } //check if allowed to request } //check object exist } //check if registered } //check sourceId } catch (Exception $e) { ZitLog::writeToErrorLog("[processRequest]", "Errors:{$e->getTraceAsString}()", "Main Loop", $_SESSION['ZONE_ID']); } }