public function MessageObject($xmlStr) { if ($xmlStr == '' || $xmlStr == null) { ZitLog::writeToErrorLog('[Xml missing in request]', 'Xml is missing in request can not process message', 'Process Message', $_SESSION['ZONE_ID']); GeneralError::systemError($xmlStr); exit; } $this->xmlStr = $xmlStr; $this->dom = new DomDocument(); /*** Make sure that preserve white space is off for the the DomDocument object. WhiteSpaces interfers with parsing the xml ***/ $this->dom->preserveWhiteSpace = false; $this->res = $this->dom->loadXML($xmlStr); $dom = $this->dom; $this->headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $this->sourceId = $this->headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $this->msgId = $this->headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $messageNode = $dom->getElementsByTagName('SIF_Message'); $this->messageType = isset($messageNode->item(0)->childNodes->item(0)->nodeName) ? $messageNode->item(0)->childNodes->item(0)->nodeName : 'default'; $sifDestinationId = $this->headerNode->getElementsByTagName('SIF_DestinationId'); if ($sifDestinationId->length != 0) { $this->destinationId = $sifDestinationId->item(0)->nodeValue; $this->destinationIdFound = true; } else { $this->destinationId = null; $this->destinationIdFound = false; } }
public static function setupZone($zone) { if ($zone == '' || $zone == null) { ZitLog::writeToErrorLog('[Zone is missing in request]', 'Zone is missing in request', 'Retreive Zone Information'); echo '<FATAL_ERROR>INVALID ZONE</FATAL_ERROR>'; exit; } if (!Zone::checkZoneExist($zone)) { ZitLog::writeToErrorLog('[Zone does not exist]', 'Zone does not exist in the system => ' . substr($zone, 0, 30), 'Retreive Zone Information'); echo '<FATAL_ERROR>INVALID ZONE</FATAL_ERROR>'; exit; } else { $_SESSION['ZONE_NAME'] = $zone; Zone::getZoneId($zone); } }
public function register() { $db = Zend_Registry::get('my_db'); $agentR = new AgentRegistered($db); $data = array(DBConvertor::convertCase('agent_id') => $this->agentId, DBConvertor::convertCase('callback_url') => $this->callBackUrl, DBConvertor::convertCase('agent_mode_id') => $this->agentMode, DBConvertor::convertCase('register_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('protocol_type') => $this->protocol, DBConvertor::convertCase('secure') => $this->secure, DBConvertor::convertCase('sif_version') => $this->version, DBConvertor::convertCase('asleep') => $this->asleep, DBConvertor::convertCase('maxbuffersize') => $this->maxBuffersize, DBConvertor::convertCase('zone_id') => $_SESSION['ZONE_ID'], DBConvertor::convertCase('context_id') => $_SESSION['CONTEXT_ID'], DBConvertor::convertCase('authentication_level_id') => $this->authenticationLevel, DBConvertor::convertCase('frozen') => 0); try { $agentR->insert($data); return true; } catch (Zend_Db_Exception $e) { // echo $e->getMessage(); ZitLog::writeToErrorLog('AgentRegistered Error', '', 'Registration Error', $_SESSION['ZONE_ID']); return false; } /* $n = $agentR->insert($data); echo 'value of $n = '.$n.'.'; if($n == 1){ return true; } else{ return false; } */ }
public static function processMessage($xmlStr) { try { $dom = new DomDocument(); /*** Make sure that preserve white space is off for the the DomDocument object. WhiteSpaces interfers with parsing the xml ***/ $dom->preserveWhiteSpace = false; $res = $dom->loadXML($xmlStr); $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $sourceId = $headerNode->getElementsByTagName('SIF_SourceId')->item(0)->nodeValue; $originalMsgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $validSourceId = Agent::checkSourceId($sourceId); if (!$validSourceId) { RegisterError::invalidSourceId($sourceId, $originalMsgId); } SifProcessRequest::authenticateAgent($sourceId); SifProcessRequest::checkIfZitIsSleeping($dom); SifProcessRequest::checkIfZoneIsSleeping($dom); $messageNode = $dom->getElementsByTagName('SIF_Message'); $messageType = isset($messageNode->item(0)->childNodes->item(0)->nodeName) ? $messageNode->item(0)->childNodes->item(0)->nodeName : 'default'; switch ($messageType) { case 'SIF_Register': $_SESSION['SIF_MESSAGE_TYPE'] = 5; $register = new Register($dom); break; case 'SIF_Unregister': $_SESSION['SIF_MESSAGE_TYPE'] = 18; $unregister = new UnRegister($dom); break; case 'SIF_Ack': $_SESSION['SIF_MESSAGE_TYPE'] = 1; $ack = new Ack($dom, $xmlStr); break; case 'SIF_SystemControl': $systemControl = new SystemControl($dom, $xmlStr); break; case 'SIF_Provision': $_SESSION['SIF_MESSAGE_TYPE'] = 4; $provision = new Provision($dom); break; case 'SIF_Event': $_SESSION['SIF_MESSAGE_TYPE'] = 2; $event = new Event($dom); break; case 'SIF_Provide': $_SESSION['SIF_MESSAGE_TYPE'] = 3; $provide = new Provide($dom); break; case 'SIF_Unprovide': $_SESSION['SIF_MESSAGE_TYPE'] = 17; $unProvide = new UnProvide($dom); break; case 'SIF_Subscribe': $_SESSION['SIF_MESSAGE_TYPE'] = 8; $subscribe = new Subscribe($dom); break; case 'SIF_Unsubscribe': $_SESSION['SIF_MESSAGE_TYPE'] = 19; $unSubscribe = new UnSubscribe($dom); break; case 'SIF_Request': $_SESSION['SIF_MESSAGE_TYPE'] = 6; $request = new Request($dom); break; case 'SIF_Response': $_SESSION['SIF_MESSAGE_TYPE'] = 7; $response = new Response($dom, $xmlStr); break; default: echo '<FATAL_ERROR>INVALID_SIF_REQUEST</FATAL_ERROR>'; exit; break; } //end switch } catch (Exception $e) { ZitLog::writeToErrorLog('[Error processing message]', "Error Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString(), 'Process Message', $_SESSION['ZONE_ID']); } //end exception block }
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; }
public static function processMessage($m) { try { $msgObj = $m; $dom = $m->dom; /*** Make sure that preserve white space is off for the the DomDocument object. WhiteSpaces interfers with parsing the xml ***/ # $dom->preserveWhiteSpace = false; # $res = $dom->loadXML($xmlStr); $headerNode = $msgObj->headerNode; $sourceId = $msgObj->sourceId; $originalMsgId = $msgObj->msgId; $validSourceId = Agent::checkSourceId($msgObj->sourceId); if (!$validSourceId) { RegisterError::invalidSourceId($msgObj->sourceId, $msgObj->msgId); } SifProcessRequest::authenticateAgent($msgObj->sourceId); SifProcessRequest::checkIfZitIsSleeping($msgObj); SifProcessRequest::checkIfZoneIsSleeping($msgObj); switch ($msgObj->messageType) { case 'SIF_Register': require_once 'main_lib/register/Register.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 5; $register = new Register($msgObj->dom); break; case 'SIF_Unregister': require_once 'main_lib/register/RegisterError.php'; require_once 'main_lib/register/UnRegister.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 18; $unregister = new UnRegister($msgObj->dom); break; case 'SIF_Ack': require_once 'main_lib/register/RegisterError.php'; require_once 'main_lib/ack/Ack.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 1; $ack = new Ack($msgObj); break; case 'SIF_SystemControl': require_once 'main_lib/systemcontrol/SystemControl.php'; $systemControl = new SystemControl($msgObj); break; case 'SIF_Provision': require_once 'main_lib/provision/ProvisionError.php'; require_once 'main_lib/provision/Provision.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 4; $provision = new Provision($msgObj->dom); break; case 'SIF_Event': require_once 'main_lib/provision/ProvisionError.php'; require_once 'main_lib/event/Event.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 2; $event = new Event($msgObj); break; case 'SIF_Provide': require_once 'main_lib/provide/Provide.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 3; $provide = new Provide($msgObj->dom); break; case 'SIF_Unprovide': require_once 'main_lib/provide/UnProvide.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 17; $unProvide = new UnProvide($msgObj->dom); break; case 'SIF_Subscribe': require_once 'main_lib/subscribe/Subscribe.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 8; $subscribe = new Subscribe($msgObj->dom); break; case 'SIF_Unsubscribe': require_once 'main_lib/subscribe/UnSubscribe.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 19; $unSubscribe = new UnSubscribe($msgObj->dom); break; case 'SIF_Request': require_once 'main_lib/provision/ProvisionError.php'; # require_once 'main_lib/FilterUtility.php'; require_once 'main_lib/RequestObject.php'; require_once 'main_lib/request/Request.php'; require_once 'main_lib/request/RequestError.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 6; $request = new Request($msgObj); break; case 'SIF_Response': # require_once 'main_lib/FilterUtility.php'; require_once '../CLASSES/' . DB_TYPE . '/AgentPermissions.php'; require_once 'main_lib/ResponseObject.php'; require_once 'main_lib/RequestObject.php'; require_once 'main_lib/request/RequestError.php'; require_once 'main_lib/response/Response.php'; $_SESSION['SIF_MESSAGE_TYPE'] = 7; $response = new Response($msgObj); break; default: echo '<FATAL_ERROR>INVALID_SIF_REQUEST</FATAL_ERROR>'; exit; break; } //end switch } catch (Exception $e) { ZitLog::writeToErrorLog('[Error processing message]', "Error Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString(), 'Process Message', $_SESSION['ZONE_ID']); } //end exception block }
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 { ZitLog::writeToErrorLog('Error Registering Agent at agent->register()->' . $agent->agentId, "Version : {$version}", 'Registration Error', $_SESSION['ZONE_ID']); 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 getFirstMessage($agent) { /* NOTE: CHRISTOPHER WHITELEY Within this section we have allowed the alteration of how SIF Ack messages are needed. If $sif_response, $sif_request, and $sif_event are set to a value of 2 then your system will work according to SIF Specifications. If you do not want to send a SIF_Ack message for any of the three message types below you can change the value to 3. This functionality was done per request of a paid support member. */ $sif_response = 2; $sif_request = 2; $sif_event = 2; $sif_ack = 2; $empty = null; $zero = 0; $id = $zero; $db = Zend_Registry::get('my_db'); # $mysql = '' # .' (' # .' Select response_id v, 1 t ' # .' from ' .DBConvertor::convertCase('response').' where status_id in (1,2) ' # .' and agent_id_requester = '.$agent->agentId.' and context_id = '.$_SESSION['CONTEXT_ID'].' and zone_id = '.$_SESSION['ZONE_ID'] # .') ' # .' union all ' # .' (' # .' Select request_id v, 2 t ' # .' from ' .DBConvertor::convertCase('request').' where status_id in (1,2) ' # .' and agent_id_responder = '.$agent->agentId.' and context_id = '.$_SESSION['CONTEXT_ID'].' and zone_id = '.$_SESSION['ZONE_ID'] # .') ' # .' union all ' # .' (' # .'Select event_id v, 3 t ' # .' from ' .DBConvertor::convertCase('event').' where status_id in (1,2) ' # .' and agent_id_rec = '.$agent->agentId.' and context_id = '.$_SESSION['CONTEXT_ID'].' and zone_id = '.$_SESSION['ZONE_ID'] # .')' # .' ORDER BY t, v LIMIT 1'; $oracle = 'Select v, t from ( Select response_id v, 1 t ' . ' from ' . DBConvertor::convertCase('response') . ' where status_id in (1,2) ' . ' and agent_id_requester = ' . $agent->agentId . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ' union all ' . 'Select request_id v, 2 t ' . 'from ' . DBConvertor::convertCase('request') . ' where status_id in (1,2) ' . ' and agent_id_responder = ' . $agent->agentId . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ' union all ' . 'Select event_id v, 3 t ' . ' from ' . DBConvertor::convertCase('event') . ' where status_id in (1,2) ' . ' and agent_id_rec = ' . $agent->agentId . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ') ORDER BY t, v'; $mysql = 'select id, msg_type, data ' . ' from ' . DBConvertor::convertCase('messagequeue') . ' where agt_id_out = ' . $agent->agentId . ' and zone_id = ' . $_SESSION['ZONE_ID'] . ' and context_id = ' . $_SESSION['CONTEXT_ID'] . ' and status_id in (1,2) ' . ' order by status_id desc, msg_type asc, insert_timestamp asc' . ' Limit 1'; switch (DB_TYPE) { case 'mysql': $sql = $mysql; break; case 'oci8': $sql = $oracle; $db->setLobAsString(true); break; } try { $stmt = $db->query($sql); $result = $stmt->fetchAll(); } catch (Zend_Exception $e) { ZitLog::writeToErrorLog("[SystemControl]", "Errors:{$e->getTraceAsString}() \n \n {$sql}", "Try|Catch block", $_SESSION['ZONE_ID']); GeneralError::systemError($xml); } switch (DB_TYPE) { case 'mysql': $id = isset($result[0]->id) ? $result[0]->id : $zero; # $msgType = isset($result[0]->msg_type) ? $result[0]->msg_type : $zero; $msgType = 4; $XMLData = isset($result[0]->data) ? $result[0]->data : $zero; break; case 'oci8': $id = isset($result[0]->V) ? $result[0]->V : $zero; $msgType = isset($result[0]->T) ? $result[0]->T : $zero; break; } // ZitLog::writeToErrorLog("[SystemControl]", "id: $id --> msgType: $msgType\n\n", "Record Found?", $_SESSION['ZONE_ID']); if ($id != $zero) { switch ($msgType) { case 1: /***** ORACLE ONLY $SIF_ACK is used to set the status of the message read. The SIF Standard states that you should set this value to 2 so that the item can be requested again if an error happens. Setting the item to a 3 will allow you not to send a SIF_Ack Message. *****/ $response = new Responses($db); $where = "response_id = {$id}"; $result2 = $response->fetchAll($where); foreach ($result2 as $row) { switch (DB_TYPE) { case 'mysql': $status_id = $row->status_id; $responseData = $row->response_data; break; case 'oci8': $status_id = $row->STATUS_ID; $responseData = $row->RESPONSE_DATA; break; } } $dom = new DomDocument(); $dom->loadXML($responseData); $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $data = array(DBConvertor::convertCase('status_id') => $sif_response, DBConvertor::convertCase('msg_id') => $msgId); $n = $response->update($data, 'response_id = ' . $id); return $responseData; break; case 2: /***** ORACLE ONLY $SIF_ACK is used to set the status of the message read. The SIF Standard states that you should set this value to 2 so that the item can be requested again if an error happens. Setting the item to a 3 will allow you not to send a SIF_Ack Message. *****/ $request = new Requests($db); $where = "request_id = {$id}"; $result = $request->fetchAll($where); foreach ($result as $row) { switch (DB_TYPE) { case 'mysql': $status_id = $row->status_id; $requestData = $row->request_data; break; case 'oci8': $status_id = $row->STATUS_ID; $messageDataXML = $row->REQUEST_DATA; // $requestData = $messageDataXML->read($messageDataXML->size()); $requestData = $messageDataXML; break; } } $dom = new DomDocument(); $dom->loadXML($requestData); $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $data = array(DBConvertor::convertCase('status_id') => $sif_request, DBConvertor::convertCase('msg_id') => $msgId); $n = $request->update($data, 'request_id = ' . $id); return $requestData; break; case 3: /***** ORACLE ONLY $SIF_ACK is used to set the status of the message read. The SIF Standard states that you should set this value to 2 so that the item can be requested again if an error happens. Setting the item to a 3 will allow you not to send a SIF_Ack Message. *****/ $event = new Events($db); $where = "event_id = {$id}"; $result = $event->fetchAll($where); foreach ($result as $row) { switch (DB_TYPE) { case 'mysql': $status_id = $row->status_id; $eventData = $row->event_data; break; case 'oci8': $status_id = $row->STATUS_ID; $eventData = $row->EVENT_DATA; break; } } $dom = new DomDocument(); $dom->loadXML($eventData); $headerNode = $dom->getElementsByTagName('SIF_Header')->item(0); $msgId = $headerNode->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $data = array(DBConvertor::convertCase('status_id') => $sif_event, DBConvertor::convertCase('msg_id') => $msgId); $n = $event->update($data, 'event_id = ' . $id); return $eventData; break; case 4: $message = new MessageQueues($db); /***** $SIF_ACK is used to set the status of the message read. The SIF Standard states that you should set this value to 2 so that the item can be requested again if an error happens. Setting the item to a 3 will allow you not to send a SIF_Ack Message. *****/ $data = array(DBConvertor::convertCase('status_id') => $sif_ack); $n = $message->update($data, 'id = ' . $id); return $XMLData; break; } } else { return null; } }
private function setupResponseNew($agent, $msgId, $m) { $dom = $m->dom; $dataObject = null; $db = Zend_Registry::get('my_db'); $requesterId = RequestObject::getRequesterId($msgId); $agentModeId = RequestObject::getRequesterAgentMode($msgId); try { $sifObjectDataNode = $dom->getElementsByTagName('SIF_ObjectData')->item(0); $children = isset($sifObjectDataNode->childNodes) ? $sifObjectDataNode->childNodes : ''; if (is_object($children)) { $objectName = isset($children->item(0)->nodeName) ? $children->item(0)->nodeName : null; } else { $objectName = null; ZitLog::writeToErrorLog('[SIF_ObjectData Error]', 'No SIF_ObjectData found from agent = ' . $agent->sourceId, $this->xmlStr); GeneralError::systemError($this->xmlStr); } $dataObject = new DataObject($objectName); } catch (Exception $e) { ZitLog::writeToErrorLog('[Error processing message]', "DataObject Name: " . $objectName . "\nError Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString() . ' ' . $this->xmlStr, 'Process Message', $_SESSION['ZONE_ID']); GeneralError::systemError($this->xmlStr); } $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); $responseXml = $dom->saveXML($sifMessageNode); $responseXml = str_replace('xmlns="http://www.sifinfo.org/infrastructure/1.x"', '', $responseXml); $responseXml = str_replace('xmlns:sif="http://www.sifinfo.org/infrastructure/1.x"', '', $responseXml); $responseXml = str_replace('xmlns="http://www.sifinfo.org/infrastructure/2.x" ', '', $responseXml); $responseXml = str_replace('xmlns="http://www.sifinfo.org/uk/infrastructure/2.x" ', '', $responseXml); $responseXml = str_replace('xmlns="http://www.sifinfo.org/au/infrastructure/2.x" ', '', $responseXml); $responseXml = str_replace('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ', '', $responseXml); # $data = array( # DBConvertor::convertCase('request_msg_id') => $msgId, # DBConvertor::convertCase('response_data') => $responseXml, # DBConvertor::convertCase('next_packet_num') => '2', # DBConvertor::convertCase('status_id') => '1', # DBConvertor::convertCase('agent_id_requester') => intval($requesterId), # DBConvertor::convertCase('agent_id_responder') => $agent->agentId, # DBConvertor::convertCase('agent_mode_id') => intval($agentModeId), # DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], # DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"] # ); # $db->insert(DBConvertor::convertCase('response'), $data); /* Removing the filterUtility as it should be reworked. $filterUtility = new FilterUtility(); $filterUtility->FilterCommonElements($dataObject->objectId, $dom, intval($requesterId)); */ try { $this->xslt = null; $permissions = new AgentPermissions($db); $where = "object_id = " . $dataObject->objectId . " and agent_id = " . $requesterId . " and zone_id = " . $_SESSION['ZONE_ID'] . " and context_id = " . $_SESSION['CONTEXT_ID']; $result = $permissions->fetchAll($where); switch (DB_TYPE) { case 'mysql': $this->xslt = isset($result[0]->xslt) ? $result[0]->xslt : null; break; case 'oci8': $this->xslt = isset($result[0]->XSLT) ? $result[0]->XSLT : null; break; } if ($this->xslt != null) { $xsltpro = new XSLTProcessor(); $XSL = new DOMDocument(); $XSL->loadXML($this->xslt); $xsltpro->importStylesheet($XSL); $XML = new DOMDocument(); $XML->loadXML($responseXml); $responseXml = $xsltpro->transformToXML($XML); } $responseXml = str_replace('<?xml version="1.0"?>' . "\n", '', $responseXml); } catch (Zend_Exception $e) { ZitLog::writeToErrorLog('[Error filtering message]', "DataObject Name: " . $objectName . "\nError Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString() . ' ' . $this->xmlStr, 'Process Message', $_SESSION['ZONE_ID']); GeneralError::systemError($this->xmlStr); } $messagequeue = new MessageQueues($db); $data = null; $data = array(DBConvertor::convertCase('msg_id') => $this->originalMsgId, DBConvertor::convertCase('ref_msg_id') => $msgId, DBConvertor::convertCase('msg_type') => 2, DBConvertor::convertCase('status_id') => '1', DBConvertor::convertCase('version') => $_SESSION['ZONE_VERSION'], DBConvertor::convertCase('insert_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('agt_id_in') => $agent->agentId, DBConvertor::convertCase('agt_id_out') => intval($requesterId), DBConvertor::convertCase('data') => $responseXml, DBConvertor::convertCase('next_packet_num') => 2, DBConvertor::convertCase('agt_mode_id') => intval($agentModeId), DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"]); $messagequeue->insert($data); $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); }
define('ZONE_URL_INDEX', $zoneUrlIndex); define('SERVER_SOURCE_ID', Zit::getSourceId()); /* Proper Values for SIF_VALIDATE ** Y : Validate and Send Error and Log Error ** N : No Validate and Pass Message ** W : Validate and Pass Message and Log Error */ define('SIF_VALIDATE', 'W'); //global $USERNAME; if ($config->code->level == 2) { ini_set('error_reporting', E_ALL & ~E_STRICT); } elseif ($config->code->level == 3) { ini_set('error_reporting', E_ALL & ~E_STRICT); } else { ini_set('error_reporting', 0); } Zone::retrieveZoneSourceId(); define('NODE_NUM', 0); try { if (SifProcessRequest::validateXML($xml)) { define('REC_XML', $xml); $messageObject = new MessageObject($xml); $messageObject->version = SifProcessRequest::retrieveVersion($messageObject); SifProcessRequest::processMessage($messageObject); } else { GeneralError::xmlValidationError($messageObject->xmlStr); } } catch (Zend_Exception $e) { ZitLog::writeToErrorLog("[Main Loop]", "Request Xml:\n{$messageObject->xmlStr} \n\n Errors:{$e->getTraceAsString}()", "Main Loop", $_SESSION['ZONE_ID']); GeneralError::systemError($messageObject->xmlStr); }
require_once 'db_convertor.php'; require_once 'Agent.php'; require_once 'XmlHelper.php'; require_once 'Utility.php'; require_once 'PushMessageHandler.php'; require_once 'ZitLog.php'; $zoneId = $argv[1]; $contextId = $argv[2]; try { ini_set('error_reporting', 0); $db = ZitDBAdapter::getDBAdapter(); $query = "select \r\n\t\t\t\tpush_running,\r\n\t\t\t\tsleep_time_seconds\r\n\t\t\t from \r\n\t\t\t\tpush_handler\r\n\t\t\t where\r\n\t\t\t\tzone_id = " . $zoneId . " \r\n\t\t\t and \r\n\t\t\t\tcontext_id = " . $contextId; $result = $db->fetchAll($query); $running = $result[0]->push_running; $sleep_time_seconds = $result[0]->sleep_time_seconds; while ($running == 1) { sleep((int) $sleep_time_seconds); $pushMessageHandler = new PushMessageHandler($zoneId, $contextId); $pushMessageHandler->processEventMessages(); $pushMessageHandler->processResponseMessages(); $pushMessageHandler->processRequestMessages(); $query = "select \r\n\t\t\t\t\tpush_running\r\n\t\t\t\t from \r\n\t\t\t\t\tpush_handler \r\n\t\t\t\t where\r\n\t\t\t\t\tzone_id = " . $zoneId . " \r\n\t\t\t\t and \r\n\t\t\t\t\tcontext_id = " . $contextId; $result = $db->fetchAll($query); $running = $result[0]->push_running; } } catch (Exception $e) { ZitLog::writeToErrorLog("[Error Pushing Messages] Check Agents", "Error Message\n" . $e->getMessage() . "\n\nStack Trace\n" . $e->getTraceAsString(), 'Push Thread', $zoneId, $contextId); $data = array('push_running' => 0, 'last_stop' => new Zend_Db_Expr(DBConvertor::convertCurrentTime())); $db->update('push_handler', $data, 'zone_id = ' . $zoneId . ' and context_id = ' . $contextId); } return true;
public static function getProviderId($objectName) { try { $empty = null; $id = $empty; $objectId = DataObject::getDataObjectId($objectName); if ($objectId == null) { return 0; } $db = Zend_Registry::get('my_db'); /* $pdo = new ProvisionDataObjectVW($db); $where = " lower(object_name) = lower('".$objectName."')" ." and version_id = ".$_SESSION['ZONE_VERSION_ID'] ." and context_id = ".$_SESSION['CONTEXT_ID']." and zone_id = ".$_SESSION['ZONE_ID']; */ $pdo = new AgentResponder($db); $where = " object_type_id = " . $objectId . " and context_id = " . $_SESSION['CONTEXT_ID'] . " and zone_id = " . $_SESSION['ZONE_ID']; $result = $pdo->fetchAll($where); $row = $result->count(); if ($row != 0) { switch (DB_TYPE) { case 'mysql': $id = $result[0]->agent_id; break; case 'oci8': $id = $result[0]->AGENT_ID; break; } } if ($id == $empty) { return 0; } else { return $id; } } catch (Exception $e) { ZitLog::writeToErrorLog("[getProviderId]", "Errors:{$e->getTraceAsString}()", "getProviderId", $_SESSION['ZONE_ID']); return 0; } }
public static function buildErrorMessage($categoryCode, $errorCode, $shortDesc, $longDesc, $msgId, $timestamp, $originalSourceId, $originalMsgId, $writeToLog = true) { $root = XmlHelper::buildSifAckMessage($msgId, $timestamp, $originalSourceId, $originalMsgId); $sifAck = $root->getElementsByTagName('SIF_Ack'); $sifErrorNode = $root->createElement('SIF_Error'); $sifCategoryNode = $root->createElement('SIF_Category'); $text = $root->createTextNode($categoryCode); $sifCategoryNode->appendChild($text); $sifCodeNode = $root->createElement('SIF_Code'); $text = $root->createTextNode($errorCode); $sifCodeNode->appendChild($text); $sifShortDescNode = $root->createElement('SIF_Desc'); $text = $root->createTextNode($shortDesc); $sifShortDescNode->appendChild($text); $sifLongDescNode = $root->createElement('SIF_ExtendedDesc'); $text = $root->createTextNode($longDesc); $sifLongDescNode->appendChild($text); $sifErrorNode->appendChild($sifCategoryNode); $sifErrorNode->appendChild($sifCodeNode); $sifErrorNode->appendChild($sifShortDescNode); $sifErrorNode->appendChild($sifLongDescNode); $sifAck->item(0)->appendChild($sifErrorNode); $xmlStr = $root->saveXML(); if ($writeToLog) { $_SESSION['SIF_MESSAGE_TYPE'] = 1; ZitLog::writeToLog(REC_XML, $xmlStr); } $length = strlen($xmlStr); header('Content-Length: ' . $length); echo $xmlStr; session_destroy(); exit; }
private function setupRequest($objectName, $sourceId, $agent) { try { $db = ZitDBAdapter::getDBAdapter(); $dom = $this->dom; $providerId = null; if ($sourceId != null) { $agent = new Agent($sourceId); $providerId = $agent->agentId; } else { $providerId = DataObject::getProviderId($objectName); } if ($providerId == 0) { RequestError::invalidProvider($this->originalSourceId, $this->originalMsgId); } else { $error = false; $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); $eventXML = $dom->saveXML($sifMessageNode); $eventXML = str_replace('xmlns:sif="http://www.sifinfo.org/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns:sif="http://www.sifinfo.org/infrastructure/1.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/infrastructure/1.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/uk/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns="http://www.sifinfo.org/au/infrastructure/2.x" ', '', $eventXML); $eventXML = str_replace('xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ', '', $eventXML); $messageId = $dom->getElementsByTagName('SIF_MsgId')->item(0)->nodeValue; $bufferSize = $dom->getElementsByTagName('SIF_MaxBufferSize')->item(0)->nodeValue; /* PUSH all messages to the ZONE Version: DO NOT Check Message Version: */ $version = $_SESSION['ZONE_VERSION']; $query = "select\r\n agent_registered.sif_version,\r\n agent_registered.maxbuffersize,\r\n agent_registered.agent_mode_id,\r\n agent.source_id\r\n from " . DBConvertor::convertCase('agent_registered') . " \r\n inner join " . DBConvertor::convertCase('agent') . " on agent.agent_id = agent_registered.agent_id\r\n where agent_registered.agent_id = {$providerId} and agent_registered.unregister_timestamp is null\r\n and agent_registered.zone_id = " . $_SESSION["ZONE_ID"] . "\r\n and agent_registered.context_id = " . $_SESSION["CONTEXT_ID"]; $result = $db->fetchAll($query); switch (DB_TYPE) { case 'mysql': $agentModeId = $result[0]->agent_mode_id; $maxbuffersize = intval($result[0]->maxbuffersize); $source_id = $result[0]->source_id; $sif_version = $result[0]->sif_version; break; case 'oci8': $agentModeId = $result[0]->AGENT_MODE_ID; $maxbuffersize = intval($result[0]->MAXBUFFERSIZE); $source_id = $result[0]->SOURCE_ID; $sif_version = $result[0]->SIF_VERSION; break; } $messageSize = strlen($eventXML); if ($messageSize > $maxbuffersize) { $error = true; $header = $this->headerNode; SifLogEntry::CreateSifLogEvents($header, '4', '2', 'Buffer size of agent ' . $source_id . ' is too small to recieve this request [size : ' . $maxbuffersize . ']'); } if (!$error) { $dataObject = new DataObject($objectName); $messagequeue = new MessageQueues($db); $data = null; $data = array(DBConvertor::convertCase('msg_id') => $messageId, DBConvertor::convertCase('msg_type') => 1, DBConvertor::convertCase('status_id') => 1, DBConvertor::convertCase('insert_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('agt_id_in') => intval($agent->agentId), DBConvertor::convertCase('agt_id_out') => intval($providerId), DBConvertor::convertCase('data') => $eventXML, DBConvertor::convertCase('maxbuffersize') => intval($bufferSize), DBConvertor::convertCase('version') => $version, DBConvertor::convertCase('agt_mode_id') => intval($agentModeId), DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"]); $messagequeue->insert($data); } $timestamp = Utility::createTimestamp(); $msgId = Utility::createMessageId(); $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0); XmlHelper::buildSuccessMessage($msgId, $timestamp, $this->originalSourceId, $this->originalMsgId, 0, $originalMsg = null, $desc = null); } //invalid provider check } catch (Exception $e) { ZitLog::writeToErrorLog("[setupRequest]", "Errors:{$e->getTraceAsString}()", "Main Loop", $_SESSION['ZONE_ID']); } }