Esempio n. 1
0
 private function setupRequest($objectName, $sourceId, $agent)
 {
     $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($version != '2.*') {
                         if($version != $sif_version) {
                             $header = $this->headerNode;
         					$error = true;
                             SifLogEntry::CreateSifLogEvents($header,
                                     '4',
                                     '4',
                                     'Version in request not supported by agent '.$source_id
                             );
                         }
                     } else {
         				$version = $_SESSION['ZONE_VERSION'];
         			}
         */
         if (!$error) {
             $dataObject = new DataObject($objectName);
             #				$request = new Requests($db);
             #                $data = array(
             #                        DBConvertor::convertCase('request_msg_id')      => $messageId,
             #                        DBConvertor::convertCase('request_timestamp')   => new Zend_Db_Expr(DBConvertor::convertCurrentTime()),
             #                        DBConvertor::convertCase('agent_id_requester')  => $agent->agentId,
             #                        DBConvertor::convertCase('agent_id_responder')  => intval($providerId),
             #                        DBConvertor::convertCase('request_data')        => $eventXML,
             #                        DBConvertor::convertCase('max_buffer_size')     => $bufferSize,
             #                        DBConvertor::convertCase('version')				=> $version,
             #                        DBConvertor::convertCase('agent_mode_id')		=> intval($agentModeId),
             #                        DBConvertor::convertCase('zone_id')         	=> $_SESSION["ZONE_ID"],
             #                        DBConvertor::convertCase('context_id')			=> $_SESSION["CONTEXT_ID"]
             #                );
             #                $request->insert($data);
             $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
 }
Esempio n. 2
0
 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
 }
Esempio n. 3
0
 private function publishEvent($agentId, $objectName, $objectAction, $version, $header)
 {
     $db = Zend_Registry::get('my_db');
     $dom = $this->dom;
     $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 \r\n\t\t\t\t\t\t" . DBConvertor::convertCase('agent_registered') . " on agent_registered.agent_Id = agent_subscriptions.agent_id\r\n\t\t     \t\t\tand 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.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.zone_id = " . $_SESSION["ZONE_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";
     $result = $db->fetchAll($query);
     foreach ($result as $row) {
         $error = false;
         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;
         }
         //            $filterUtility = new FilterUtility();
         //            $filterUtility->FilterCommonElements($dataObject->objectId, $dom, $agent_id);
         $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);
         $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('event_timestamp') => new Zend_Db_Expr(DBConvertor::convertCurrentTime()), DBConvertor::convertCase('agent_id_sender') => $agentId, DBConvertor::convertCase('agent_id_rec') => $agent_id, DBConvertor::convertCase('event_data') => $eventXML, DBConvertor::convertCase('object_id') => $dataObject->objectId, DBConvertor::convertCase('action_id') => $actionId, DBConvertor::convertCase('agent_mode_id') => $agent_mode_id, DBConvertor::convertCase('zone_id') => $_SESSION["ZONE_ID"], DBConvertor::convertCase('context_id') => $_SESSION["CONTEXT_ID"]);
             $db->insert(DBConvertor::convertCase('event'), $data);
         }
     }
 }
Esempio n. 4
0
 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.");
     }
 }