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 }
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 }