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 }
public function processAck($m) { $dom = $this->dom; $headerNode = $m->headerNode; $msgId = $m->msgId; $agentSourceId = $m->sourceId; # $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; # $agentSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $originalMsgId = $dom->getElementsByTagName('SIF_OriginalMsgId')->item(0)->nodeValue; $timestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; $status = $dom->getElementsByTagName('SIF_Status'); $status = $status->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($agentSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agentSourceId, $msgId); } else { $agent = new Agent($agentSourceId); if ($agent->isRegistered()) { if ($status == 1) { $agent->unFreezeAgent(); $this->updateMessageQueue($agent, $originalMsgId, $msgId); } else { if ($status == 3) { //done processing if ($originalMsgId == $agent->frozenMsgId) { $agent->unFreezeAgent(); $this->updateMessageQueue($agent, $originalMsgId, $msgId); } else { GeneralError::EventACKError($this->xml); } } else { if ($status == 2) { //Intermediate wait for final $agent->freezeAgent(); $agent->setFrozenMsgId($originalMsgId); $timestamp = Utility::createTimestamp(); $msgId_u = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId_u, $timestamp, $agent->sourceId, $msgId, 0, $originalMsg = null, $desc = null); } } } } else { RegisterError::notRegisteredError($agentSourceId, $msgId); } } }
public function processUnregistration() { $dom = $this->xmlDom; $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()) { if ($agent->unRegister()) { XmlHelper::buildSuccessMessage(Utility::createMessageId(), Utility::createTimestamp(), $agent->sourceId, $originalMsgId, 0); } else { RegisterError::genericError($agent->sourceId, $originalMsgId); } } else { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); } } }
private function processRegistration() { $dom = $this->xmlDom; $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $authenticationLevel = $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(); } $version = $_SESSION['ZONE_VERSION']; $buffer = $dom->getElementsByTagName('SIF_MaxBufferSize')->item(0)->nodeValue; $mode = $dom->getElementsByTagName('SIF_Mode')->item(0)->nodeValue; if ($dom->getElementsByTagName('SIF_Protocol')->item(0)) { $protocolType = $dom->getElementsByTagName('SIF_Protocol')->item(0)->attributes->item(0)->nodeValue; $protocolSecure = $dom->getElementsByTagName('SIF_Protocol')->item(0)->attributes->item(1)->nodeValue; } if ($dom->getElementsByTagName('SIF_URL')->item(0)) { $callBackUrl = $dom->getElementsByTagName('SIF_URL')->item(0)->nodeValue; } $validSourceId = Agent::checkSourceId($originalSourceId); if (!$validSourceId) { RegisterError::invalidSourceId($agent->sourceId, $originalMsgId); } else { //create agent object $agent = new Agent($originalSourceId); if (!Agent::allowedToRegister($agent->agentId)) { RegisterError::genericError($agent->sourceId, $originalMsgId); } else { /* if($version != ZIT::checkVersion($version)){ RegisterError::invalidVersion($agent->sourceId, $originalMsgId); } else{ */ if ($buffer < ZIT::getMinBuffer()) { RegisterError::invalidMaxBuffer($agent->sourceId, $originalMsgId); } else { $empty = null; $agent->authenticationLevel = $this->getSecurityLevel(); $agent->maxBuffersize = $buffer; $agent->protocol = isset($protocolType) ? $protocolType : $empty; $agent->callBackUrl = isset($callBackUrl) ? urlencode($callBackUrl) : $empty; $agent->agentMode = Agent::convertAgentMode(isset($mode) ? $mode : $empty); $agent->secure = Agent::convertSecure(isset($protocolSecure) ? $protocolSecure : $empty); $agent->version = $version; if ($agent->isRegistered()) { if ($agent->updateRegistration()) { $this->createAclAckMessage($agent->sourceId, $originalMsgId); } else { RegisterError::genericError($agent->sourceId, $originalMsgId, 'Error Registering Agent at agent->updateRegistration()'); } //try to update registration } else { if ($agent->register()) { $this->createAclAckMessage($agent->sourceId, $originalMsgId); } else { RegisterError::genericError($agent->sourceId, $originalMsgId, 'Error Registering Agent at agent->register()'); } //try to register } //check if agent is registered } //check if buffer size is valid // }//check if version is valid } //check if agent allowed to register } //check if sourceId is valid }
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 processResponseMessage($xml, $zoneId, $contextId, $agentId) { $results = array('ImmediateUpdate' => true, 'Error' => false); $dom = new DomDocument(); $dom->preserveWhiteSpace = false; $res = $dom->loadXML($xml); if ($res) { $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $agentSourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $timestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue; $originalMsgId = $dom->getElementsByTagName('SIF_OriginalMsgId')->item(0)->nodeValue; $status = $dom->getElementsByTagName('SIF_Status'); $status = $status->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($agentSourceId); if (!$validSourceId) { ZitLog::writeToErrorLog('[Error Pushing Messages] Invalid Source Id In Response', "Reponse Xml:\n{$xml}", 'Push Message Response', $zoneId, $contextId, $agentId); $results['Error'] = true; } else { $agent = new Agent($agentSourceId, $zoneId, $contextId); if ($agent->isRegistered()) { if ($status == 2) { //Intermediate wait for final $results['ImmediateUpdate'] = false; $agent->freezeAgent(); $agent->setFrozenMsgId($originalMsgId); } } else { ZitLog::writeToErrorLog('[Error Pushing Messages] Response Agent Not Registered', "Response agent is not registered in the system", 'Push Message Response', $zoneId, $contextId, $agentId); $results['Error'] = true; } } } else { ZitLog::writeToErrorLog('[Error Pushing Messages] Reponse Xml Invalid', $xml, 'Push Message Response', $zoneId, $contextId, $agentId); $results['Error'] = true; } return $results; }
private function processSleep() { $dom = $this->xmlDom; $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($originalSourceId, $originalMsgId); } else { $agent = new Agent($originalSourceId); if (!$agent->isRegistered()) { RegisterError::notRegisteredError($originalSourceId, $originalMsgId); } else { $agent->putToSleep(); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $originalSourceId, $originalMsgId, 0, $originalMsg = null, $desc = null); } } }
private function processResponse($m) { $dom = $m->dom; $headerNode = $m->headerNode; $originalMsgId = $m->msgId; $this->originalMsgId = $m->msgId; $originalSourceId = $m->sourceId; $version = $m->version; $this->originalSourceId = $originalSourceId; $this->originalMsgId = $originalMsgId; $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 { $msgId = $dom->getElementsByTagName('SIF_RequestMsgId')->item(0)->nodeValue; if (!RequestObject::validRequestMsgId($msgId)) { RequestError::invalidMsgId($originalSourceId, $originalMsgId); } else { $requestObject = new RequestObject($msgId); $sifResponseNode = $dom->getElementsByTagName('SIF_Response')->item(0); $size = strlen($dom->saveXML($sifResponseNode)); if (!$requestObject->compareBufferSize($size)) { $categoryCode = "8"; $sifCode = "11"; $shortDesc = "Response Error"; $longDesc = "SIF_Response is larger than requested SIF_MaxBufferSize"; $this->createResponseError($agent, $msgId, $categoryCode, $sifCode, $shortDesc, $longDesc); SifLogEntry::CreateSifLogEvents($dom->saveXml($headerNode), 4, 2, 'Invalid buffersize for response to agent ' . $agent->sourceId . ' request'); RequestError::invalidBufferSize($originalSourceId, $originalMsgId); } else { $destinationId = $dom->getElementsByTagName('SIF_DestinationId')->item(0)->nodeValue; if (!$requestObject->compareDestinationId($destinationId)) { $categoryCode = "8"; $sifCode = "14"; $shortDesc = "Response Error"; $longDesc = "SIF_DestinationId does not match SIF_SourceId from SIF_Request"; $this->createResponseError($agent, $msgId, $categoryCode, $sifCode, $shortDesc, $longDesc); SifLogEntry::CreateSifLogEvents($dom->saveXml($headerNode), 4, 1, 'Invalid destinationId for response to agent ' . $agent->sourceId . ' request'); RequestError::invalidDestination($originalSourceId, $originalMsgId); } else { if (RequestObject::validMessageVersion($msgId, $version)) { if (ResponseObject::responseExist($msgId)) { $responseObject = new ResponseObject($msgId); $packetNum = $dom->getElementsByTagName('SIF_PacketNumber')->item(0)->nodeValue; if ($packetNum != $responseObject->nextPacketNum) { $categoryCode = "8"; $sifCode = "12"; $shortDesc = "SIF_PacketNumber is invalid in SIF_Response"; $longDesc = 'Invalid packet number of ' . $packetNum . ' was expecting ' . $responseObject->nextPacketNum . 'for response to agent ' . $agent->sourceId . ' request'; //$this->createResponseError($agent, $msgId, $categoryCode, $sifCode, $shortDesc, $longDesc); RequestError::invalidPacketNum($originalSourceId, $originalMsgId, $longDesc); } else { $this->setupResponseOld($agent, $msgId, $responseObject); } } else { $packetNum = $dom->getElementsByTagName('SIF_PacketNumber')->item(0)->nodeValue; if ($packetNum != 1) { $categoryCode = "8"; $sifCode = "12"; $shortDesc = "Response Error"; $longDesc = 'Invalid packet number of ' . $packetNum . ' was expecting 1 for response to agent ' . $agent->sourceId . ' request'; RequestError::invalidPacketNum($originalSourceId, $originalMsgId, $longDesc); } else { $this->setupResponseNew($agent, $msgId, $m); } //check if packetnum is 1 } //check if response with more packets } else { $categoryCode = "8"; $sifCode = "13"; $shortDesc = "Response Error"; $longDesc = "SIF_Response does not match any SIF_Version from SIF_Request."; $this->createResponseError($agent, $msgId, $categoryCode, $sifCode, $shortDesc, $longDesc); RequestError::invalidVersion($originalSourceId, $originalMsgId); } //check if version is valid } // check if valid destination } //check if valid buffer } //check if valid request message id } //check if registered } //check sourceId }
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']); } }