示例#1
0
 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;
     }
 }
示例#2
0
文件: Ack.php 项目: Koulio/OpenZIS
 private function updateMessageQueue($agent, $originalMsgId, $msgId)
 {
     $res = DataObject::updateEvent($agent->agentId, $originalMsgId, $msgId);
     if ($res == 1) {
         $timestamp = Utility::createTimestamp();
         $msgId_u = Utility::createMessageId();
         XmlHelper::buildSuccessMessage($msgId_u, $timestamp, $agent->sourceId, $msgId, 0, $originalMsg = null, $desc = null);
     } else {
         GeneralError::EventACKError($this->xml);
     }
 }
示例#3
0
 public static function authenticateAgent($sourceId)
 {
     $agent = new Agent($sourceId);
     $xmlStr = REC_XML;
     $db = Zend_Registry::get('my_db');
     //if authentication type is username and password
     if (Zone::getZoneAuthenticationType() == 1) {
         if (!isset($_SERVER['PHP_AUTH_USER'])) {
             GeneralError::invalidUserError($xmlStr);
             exit;
         } else {
             $username = $_SERVER['PHP_AUTH_USER'];
             $password = $_SERVER['PHP_AUTH_PW'];
             if ($agent->username == $username && $agent->password == $password) {
                 $_SESSION['username'] = $username;
                 return;
             } else {
                 ZitLog::writeToErrorLog('[Invalid User] User does not exist', 'User in agent request does not exist in the system', 'Authenticate Agent', $_SESSION['ZONE_ID'], $agent->agentId);
                 GeneralError::invalidUserError($xmlStr);
                 exit;
             }
         }
     } else {
         if (Zone::getZoneAuthenticationType() == 2) {
             if (!isset($_SERVER['SSL_CLIENT_CERT'])) {
                 ZitLog::writeToErrorLog('[Missing Certificate] Certificate is missing for agent', 'Agent request does not contain a certificate.  Zone is set to certificate authentication', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId);
                 GeneralError::missingSenderCertificate($xmlStr);
                 exit;
             } else {
                 $cert = $_SERVER['SSL_CLIENT_CERT'];
                 $dn = "C: " || $_SERVER['SSL_CLIENT_S_DN_S'] || '<br/>' || "O: " || $_SERVER['SSL_CLIENT_S_DN_O'] || '<br/>' || "OU: " || $_SERVER['SSL_CLIENT_S_DN_OU'] || '<br/>' || "CN: " || $_SERVER['SSL_CLIENT_S_DN_CN'] || '<br/>' || "End Date: " || $_SERVER['SSL_CLIENT_V_END'] || '<br/>';
             }
             if ($agent->certCommonName == null || $agent->certCommonName == '' || $agent->certCommonName == ' ') {
                 $agents = new Agents($db);
                 $row = $agents->fetchRow("agent_id = " . $agent->agentId);
                 $row->cert_common_name = $cert;
                 $row->cert_common_dn = $dn;
                 $row->save();
                 $agent->certCommonName = $cert;
             }
             if ($agent->certCommonName != $cert) {
                 ZitLog::writeToErrorLog('[CN is not valid] CN of certificate is invalid', 'CN of request certificate does not match the CN setup with the agent', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId);
                 GeneralError::agentCommonNameDoesNoMatch($xmlStr);
                 exit;
             }
         }
     }
     /*			if($agent->isRegistered())
     			{
     				//$remoteAddress = SifProcessRequest::getIpAddress();
     				$cn = $_SERVER['SSL_CLIENT_S_DN_CN'];
     				$result  = $_SERVER['SSL_CLIENT_VERIFY'];
     				switch($agent->getAgentRegistrationSifAuthenticationLevel())
     				{
     					case 1:
     						if($cn == null || $cn == '' || $cn == ' '){
     							ZitLog::writeToErrorLog('[Missing Certificate] Certificate is missing for agent', 'Agent request does not contain a certificate.  Zone is set to certificate authentication', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId);
     							GeneralError::missingSenderCertificate(REC_XML);
     							exit;
     						}
     					break;
     					case 3:
     						if($agent->certCommonName != $cn){
     							ZitLog::writeToErrorLog('[CN is not valid] CN of certificate is invalid', 'CN of request certificate does not match the CN setup with the agent', 'Verify Certificate', $_SESSION['ZONE_ID'], $agent->agentId);
     							GeneralError::agentCommonNameDoesNoMatch(REC_XML);
     							exit;
     						}
     					break;
     				}
     			}
     */
     //		}//end authentication type check
 }
示例#4
0
 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;
     }
 }
示例#5
0
 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);
 }
示例#6
0
require_once 'zit_db_adapter.php';
require_once 'zit_db_adapter2.php';
require_once 'db_convertor.php';
//General Error
require_once '../ZIT_APPLICATION/main_lib/GeneralError.php';
try {
    $db = ZitDBAdapter::getDBAdapter();
    Zend_Registry::set('my_db', $db);
} catch (Zend_Exception $e) {
    GeneralError::systemError($xml);
}
try {
    $db2 = ZitDBAdapter2::getDBAdapter();
    Zend_Registry::set('my_db2', $db2);
} catch (Zend_Exception $e) {
    GeneralError::systemError($xml);
}
switch (DB_TYPE) {
    case 'mysql':
        $dbversion = 'mysql';
        break;
    case 'oci8':
        $dbversion = 'oracle';
        break;
}
require_once '../CLASSES/' . $dbversion . '/ZitAdminDB.php';
require_once '../CLASSES/' . $dbversion . '/ZitLog.php';
require_once '../CLASSES/' . $dbversion . '/ZitLogArch.php';
require_once '../CLASSES/' . $dbversion . '/Zones.php';
require_once '../CLASSES/' . $dbversion . '/Contexts.php';
require_once '../CLASSES/' . $dbversion . '/Versions.php';
示例#7
0
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);
}
示例#8
0
文件: Event.php 项目: Koulio/OpenZIS
 private function publishEvent($agentId, $objectName, $objectAction, $version, $m)
 {
     $db = Zend_Registry::get('my_db');
     $dom = $m->dom;
     $event_destination_found = false;
     $headerNode = $m->headerNode;
     $originalMsgId = $m->msgId;
     $originalSourceId = $m->sourceId;
     $originalTimestamp = $headerNode->getElementsByTagName('SIF_Timestamp')->item(0)->nodeValue;
     $dataObject = new DataObject($objectName);
     $actionId = Event::getActionId($objectAction);
     $query = "select agent_subscriptions.agent_id,\r\n\t\t\t \t\t\t agent_registered.agent_mode_id,\r\n\t\t\t \t\t\t agent_registered.sif_version,\r\n\t\t\t \t\t\t agent_registered.maxbuffersize,\r\n\t\t     \t\t\t agent.source_id\r\n\t\t    \t\tfrom " . DBConvertor::convertCase('agent_subscriptions') . "\r\n\t\t   \t\t\tinner join " . DBConvertor::convertCase('agent_registered') . " on agent_registered.agent_Id = agent_subscriptions.agent_id and agent_registered.unregister_timestamp is null\r\n\t\t   \t\t\tinner join " . DBConvertor::convertCase('agent') . " on agent.agent_id = agent_subscriptions.agent_id\r\n\t\t   \t\t\twhere agent_subscriptions.zone_id = " . $_SESSION["ZONE_ID"] . "\r\n\t\t\t\t\t\tand agent_subscriptions.object_type_id = " . $dataObject->objectId . "\r\n\t\t     \t\t\tand agent_subscriptions.context_id = " . $_SESSION["CONTEXT_ID"] . "\r\n\t\t     \t\t\tand agent_subscriptions.context_id = agent_registered.context_id \r\n\t\t     \t\t\tand agent_subscriptions.zone_id = agent_registered.zone_id";
     if ($m->destinationIdFound == true) {
         $query = $query . " and agent.source_id = '" . $m->destinationId . "'";
     }
     $result = $db->fetchAll($query);
     foreach ($result as $row) {
         $error = false;
         $event_destination_found = true;
         switch (DB_TYPE) {
             case 'mysql':
                 $agent_id = intval($row->agent_id);
                 $maxbuffersize = intval($row->maxbuffersize);
                 $source_id = $row->source_id;
                 $agent_mode_id = intval($row->agent_mode_id);
                 $agent_version = $row->sif_version;
                 break;
             case 'oci8':
                 $agent_id = intval($row->AGENT_ID);
                 $maxbuffersize = intval($row->MAXBUFFERSIZE);
                 $source_id = $row->SOURCE_ID;
                 $agent_mode_id = intval($row->AGENT_MODE_ID);
                 $agent_version = $row->SIF_VERSION;
                 break;
         }
         $sifMessageNode = $dom->getElementsByTagName('SIF_Message')->item(0);
         $eventXML = $dom->saveXML($sifMessageNode);
         $eventXML = str_replace('xmlns="http://www.sifinfo.org/uk/infrastructure/2.x" ', '', $eventXML);
         $eventXML = str_replace('xmlns="http://www.sifinfo.org/infrastructure/2.x" ', '', $eventXML);
         $eventXML = str_replace('xmlns="http://www.sifinfo.org/infrastructure/1.x" ', '', $eventXML);
         $eventXML = str_replace('xmlns:sif="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:xsi="http://www.w3.org/2001/XMLSchema-instance" ', '', $eventXML);
         $messageSize = strlen($eventXML);
         if ($messageSize > $maxbuffersize) {
             SifLogEntry::CreateSifLogEvents($header, '4', '2', 'Buffer size of agent ' . $row->source_id . ' is too small to recieve this event [size : ' . $row->maxbuffersize . ']');
             $error = true;
         }
         if ($version != $agent_version) {
             SifLogEntry::CreateSifLogEvents($header, '4', '4', 'Version in event not supported by agent ' . $source_id);
             $error = true;
         }
         if (!$error) {
             $data = array(DBConvertor::convertCase('insert_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('msg_id') => $originalMsgId, DBConvertor::convertCase('agt_id_in') => $agentId, DBConvertor::convertCase('msg_type') => 3, DBConvertor::convertCase('status_id') => 1, DBConvertor::convertCase('agt_id_out') => $agent_id, DBConvertor::convertCase('data') => $eventXML, DBConvertor::convertCase('object_id') => $dataObject->objectId, DBConvertor::convertCase('action_id') => $actionId, DBConvertor::convertCase('agt_mode_id') => $agent_mode_id, DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"]);
             $db->insert(DBConvertor::convertCase('messagequeue'), $data);
         }
     }
     if ($event_destination_found == false) {
         GeneralError::genericError($m, "11", "1", "Generic Error", "SIF DestinationId not found.");
     }
 }