/** * @param Session $session * @param CallMessage $msg * @return bool */ private function processCall(Session $session, CallMessage $msg) { $registration = $this->getRegistrationByProcedureName($msg->getProcedureName()); if (!$registration) { $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg); $this->manager->error('No registration for call message: ' . $msg->getProcedureName()); $errorMsg->setErrorURI('wamp.error.no_such_registration'); $session->sendMessage($errorMsg); return false; } $invocationMessage = InvocationMessage::createMessageFrom($msg, $registration); if ($registration->getDiscloseCaller() === true && $session->getAuthenticationDetails()) { $details = ["caller" => $session->getSessionId(), "authid" => $session->getAuthenticationDetails()->getAuthId(), "authmethod" => $session->getAuthenticationDetails()->getAuthMethod()]; $invocationMessage->setDetails($details); } $call = new Call($msg, $session, $invocationMessage, $registration->getSession()); $this->calls->attach($call); $registration->getSession()->sendMessage($invocationMessage); }
/** * processCancel processes cancel message from the caller. * Return true if the Call should be removed from active calls * * @param Session $session * @param CancelMessage $msg * @return bool */ public function processCancel(Session $session, CancelMessage $msg) { if ($this->getCallerSession() !== $session) { Logger::warning($this, "session " . $session->getSessionId() . " attempted to cancel call they did not own."); return false; } if ($this->getCalleeSession() === null) { // this call has not been sent to a callee yet (it is in a queue) // we can just kill it and say it was canceled $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, "wamp.error.canceled"); $details = $errorMsg->getDetails() ?: (object) []; $details->_thruway_removed_from_queue = true; $session->sendMessage($errorMsg); return true; } $details = (object) []; if ($this->getCalleeSession()->getHelloMessage() instanceof HelloMessage) { $details = $this->getCalleeSession()->getHelloMessage()->getDetails(); } $calleeSupportsCancel = false; if (isset($details->roles->callee->features->call_canceling) && is_scalar($details->roles->callee->features->call_canceling)) { $calleeSupportsCancel = (bool) $details->roles->callee->features->call_canceling; } if (!$calleeSupportsCancel) { $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg); $errorMsg->setErrorURI('wamp.error.not_supported'); $session->sendMessage($errorMsg); return false; } $this->setCancelMessage($msg); $this->canceling = true; $calleeSession = $this->getCalleeSession(); $interruptMessage = new InterruptMessage($this->getInvocationRequestId(), (object) []); $calleeSession->sendMessage($interruptMessage); $this->setInterruptMessage($interruptMessage); if (isset($msg->getOptions()->mode) && is_scalar($msg->getOptions()->mode) && $msg->getOptions()->mode == "killnowait") { $errorMsg = ErrorMessage::createErrorMessageFromMessage($msg, "wamp.error.canceled"); $session->sendMessage($errorMsg); return true; } return false; }
/** * @param Session $session * @param EventMessage $msg * @param Subscription $subscription */ private function disclosePublisherOption(Session $session, EventMessage $msg, Subscription $subscription) { if ($subscription->isDisclosePublisher() === true) { $details = ["caller" => $session->getSessionId(), "authid" => $session->getAuthenticationDetails()->getAuthId(), "authrole" => $session->getAuthenticationDetails()->getAuthRole(), "authroles" => $session->getAuthenticationDetails()->getAuthRoles(), "authmethod" => $session->getAuthenticationDetails()->getAuthMethod()]; $msg->setDetails(array_merge($msg->getDetails(), $details)); } }
/** * process YieldMessage * * @param \Thruway\Session $session * @param \Thruway\Message\YieldMessage $msg */ private function processYield(Session $session, YieldMessage $msg) { /* @var $call Call */ $call = isset($this->callInvocationIndex[$msg->getRequestId()]) ? $this->callInvocationIndex[$msg->getRequestId()] : null; if (!$call) { $session->sendMessage(ErrorMessage::createErrorMessageFromMessage($msg)); Logger::error($this, "Received YieldMessage for non-existent call from " . $session->getSessionId()); return; } $keepIndex = $call->processYield($session, $msg); if (!$keepIndex) { $this->removeCall($call); } /* @var $procedure \Thruway\Procedure */ $procedure = isset($this->procedures[$call->getCallMessage()->getUri()]) ? $this->procedures[$call->getCallMessage()->getUri()] : null; if ($procedure && $procedure->getAllowMultipleRegistrations()) { $procedure->processQueue(); } //Process queues on other registrations if we can take more requests if ($session->getPendingCallCount() == 0 && $this->registrationsBySession->contains($session)) { $this->processQueue($session); } }
/** * This allows the AuthenticationManager to clean out auth methods that were registered by * sessions that are dieing. Otherwise the method could be hijacked by another client in the * thruway.auth realm. * * @param \Thruway\Session $session */ public function onSessionClose(Session $session) { if ($session->getRealm() && $session->getRealm()->getRealmName() == "thruway.auth") { // session is closing in the auth domain // check and see if there are any registrations that came from this session $sessionId = $session->getSessionId(); foreach ($this->authMethods as $methodName => $method) { if (isset($method['session_id']) && $method['session_id'] == $sessionId) { unset($this->authMethods[$methodName]); } } } }
/** * @param Session $session */ public function disclosePublisher(Session $session) { $details = $this->getDetails(); $details->publisher = $session->getSessionId(); $details->topic = $this->topic; $authenticationDetails = $session->getAuthenticationDetails(); $details->authid = $authenticationDetails->getAuthId(); $details->authrole = $authenticationDetails->getAuthRole(); $details->authroles = $authenticationDetails->getAuthRoles(); $details->authmethod = $authenticationDetails->getAuthMethod(); if ($authenticationDetails->getAuthExtra() !== null) { $details->_thruway_authextra = $authenticationDetails->getAuthExtra(); } }